From patchwork Tue Feb 2 02:36:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 576922 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 9C3F2140321 for ; Tue, 2 Feb 2016 13:38:38 +1100 (AEDT) Received: from localhost ([::1]:54855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQQrU-0002rX-NX for incoming@patchwork.ozlabs.org; Mon, 01 Feb 2016 21:38:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQQpj-0007a7-Cj for qemu-devel@nongnu.org; Mon, 01 Feb 2016 21:36:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQQpi-00005u-HX for qemu-devel@nongnu.org; Mon, 01 Feb 2016 21:36:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQQpi-00005q-Ca for qemu-devel@nongnu.org; Mon, 01 Feb 2016 21:36:46 -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 EA3F5804E9; Tue, 2 Feb 2016 02:36:45 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (vpn1-6-248.pek2.redhat.com [10.72.6.248]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u122aNS1024254; Mon, 1 Feb 2016 21:36:41 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Tue, 2 Feb 2016 10:36:07 +0800 Message-Id: <1454380581-7881-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1454380581-7881-1-git-send-email-jasowang@redhat.com> References: <1454380581-7881-1-git-send-email-jasowang@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 Subject: [Qemu-devel] [PULL 03/17] net: cadence_gem: check packet size in gem_recieve 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 receiving packets in 'gem_receive' routine, if Frame Check Sequence(FCS) is enabled, it copies the packet into a local buffer without checking its size. Add check to validate packet length against the buffer size to avoid buffer overflow. Reported-by: Ling Liu Signed-off-by: Prasad J Pandit Signed-off-by: Jason Wang --- hw/net/cadence_gem.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c index f9e4091..e513d9d 100644 --- a/hw/net/cadence_gem.c +++ b/hw/net/cadence_gem.c @@ -678,6 +678,10 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) } else { unsigned crc_val; + if (size > sizeof(rxbuf) - sizeof(crc_val)) { + size = sizeof(rxbuf) - sizeof(crc_val); + } + bytes_to_copy = size; /* The application wants the FCS field, which QEMU does not provide. * We must try and calculate one. */