From patchwork Tue Aug 9 03:52:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chaojianhu X-Patchwork-Id: 657076 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 3s7gPq0n3Sz9sR8 for ; Tue, 9 Aug 2016 13:54:07 +1000 (AEST) Received: from localhost ([::1]:33341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWy7A-0001FR-Uh for incoming@patchwork.ozlabs.org; Mon, 08 Aug 2016 23:54:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWy6G-0000Ea-8W for qemu-devel@nongnu.org; Mon, 08 Aug 2016 23:53:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWy6D-0006cD-4p for qemu-devel@nongnu.org; Mon, 08 Aug 2016 23:53:08 -0400 Received: from blu004-omc2s10.hotmail.com ([65.55.111.85]:55196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWy6D-0006c6-0q; Mon, 08 Aug 2016 23:53:05 -0400 Received: from BLU436-SMTP98 ([65.55.111.71]) by BLU004-OMC2S10.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Mon, 8 Aug 2016 20:53:04 -0700 X-TMN: [+6p7uL/wdLvB9XmEiurSQztHeT5cWB3CBKQM7T9Xqik=] X-Originating-Email: [chaojianhu@hotmail.com] Message-ID: From: chaojianhu To: qemu-devel@nongnu.org Date: Tue, 9 Aug 2016 11:52:54 +0800 X-Mailer: git-send-email 1.9.1 X-OriginalArrivalTime: 09 Aug 2016 03:53:03.0763 (UTC) FILETIME=[87C3E630:01D1F1F1] MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 65.55.111.85 Subject: [Qemu-devel] [PATCH] 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: qemu-trivial@nongnu.org, jasowang@redhat.com, alistair.francis@xilinx.com, qemu-arm@nongnu.org, edgar.iglesias@gmail.com, chaojianhu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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;