From patchwork Tue Aug 9 07:34:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 657138 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 3s7mPM6BR7z9sf9 for ; Tue, 9 Aug 2016 17:39:03 +1000 (AEST) Received: from localhost ([::1]:33995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bX1cr-0004ud-ER for incoming@patchwork.ozlabs.org; Tue, 09 Aug 2016 03:39:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bX1Yl-00012y-0M for qemu-devel@nongnu.org; Tue, 09 Aug 2016 03:34:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bX1Yk-0003if-3b for qemu-devel@nongnu.org; Tue, 09 Aug 2016 03:34:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46538) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bX1Yj-0003iS-UQ for qemu-devel@nongnu.org; Tue, 09 Aug 2016 03:34:46 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88422BAED; Tue, 9 Aug 2016 07:34:45 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-4-112.pek2.redhat.com [10.72.4.112]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u797YYPX006454; Tue, 9 Aug 2016 03:34:43 -0400 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 9 Aug 2016 15:34:33 +0800 Message-Id: <1470728073-30141-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1470728073-30141-1-git-send-email-jasowang@redhat.com> References: <1470728073-30141-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 09 Aug 2016 07:34:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/3] hw/net: Fix a heap overflow in xlnx.xps-ethernetlite X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , chaojianhu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: chaojianhu The .receive callback of xlnx.xps-ethernetlite doesn't check the length of data before calling memcpy. As a result, the NetClientState object in heap will be overflowed. All versions of qemu with xlnx.xps-ethernetlite will be affected. Reported-by: chaojianhu Signed-off-by: chaojianhu Signed-off-by: Jason Wang Reviewed-by: Alistair Francis --- hw/net/xilinx_ethlite.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/net/xilinx_ethlite.c b/hw/net/xilinx_ethlite.c index 54db2b8..35de353 100644 --- a/hw/net/xilinx_ethlite.c +++ b/hw/net/xilinx_ethlite.c @@ -197,6 +197,10 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size) } D(qemu_log("%s %zd rxbase=%x\n", __func__, size, rxbase)); + if (size > (R_MAX - R_RX_BUF0 - rxbase) * 4) { + D(qemu_log("ethlite packet is too big, size=%x\n", size)); + return -1; + } memcpy(&s->regs[rxbase + R_RX_BUF0], buf, size); s->regs[rxbase + R_RX_CTRL0] |= CTRL_S;