From patchwork Tue Feb 23 16:08:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 586946 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7C17214076E for ; Wed, 24 Feb 2016 03:12:30 +1100 (AEDT) Received: from localhost ([::1]:58161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYFZc-0007NY-FP for incoming@patchwork.ozlabs.org; Tue, 23 Feb 2016 11:12:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYFW6-00016I-M5 for qemu-devel@nongnu.org; Tue, 23 Feb 2016 11:08:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYFW5-0003nT-7y for qemu-devel@nongnu.org; Tue, 23 Feb 2016 11:08:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYFW5-0003nO-2E for qemu-devel@nongnu.org; Tue, 23 Feb 2016 11:08:49 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id C41507DCC5; Tue, 23 Feb 2016 16:08:48 +0000 (UTC) Received: from javelin.localdomain (vpn1-48-150.bne.redhat.com [10.64.48.150]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1NG8U36032034 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 23 Feb 2016 11:08:43 -0500 From: P J P To: Qemu Developers Date: Tue, 23 Feb 2016 21:38:26 +0530 Message-Id: <1456243707-29345-2-git-send-email-ppandit@redhat.com> In-Reply-To: <1456243707-29345-1-git-send-email-ppandit@redhat.com> References: <1456243707-29345-1-git-send-email-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang , Prasad J Pandit , Markus Armbruster , Liu Ling Subject: [Qemu-devel] [PATCH v2 1/2] net: check packet payload length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Prasad J Pandit While computing IP checksum, 'net_checksum_calculate' reads payload length from the packet. It could exceed the given 'data' buffer size. Add a check to avoid it. Reported-by: Liu Ling Signed-off-by: Prasad J Pandit --- net/checksum.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) Update as per review: -> https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg04062.html diff --git a/net/checksum.c b/net/checksum.c index 14c0855..bd89083 100644 --- a/net/checksum.c +++ b/net/checksum.c @@ -59,6 +59,11 @@ void net_checksum_calculate(uint8_t *data, int length) int hlen, plen, proto, csum_offset; uint16_t csum; + /* Ensure data has complete L2 & L3 headers. */ + if (length < 14 + 20) { + return; + } + if ((data[14] & 0xf0) != 0x40) return; /* not IPv4 */ hlen = (data[14] & 0x0f) * 4; @@ -76,8 +81,9 @@ void net_checksum_calculate(uint8_t *data, int length) return; } - if (plen < csum_offset+2) - return; + if (plen < csum_offset + 2 || plen + hlen >= length) { + return; + } data[14+hlen+csum_offset] = 0; data[14+hlen+csum_offset+1] = 0;