From patchwork Wed Aug 10 20:38:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9274033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C33806022E for ; Wed, 10 Aug 2016 20:38:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0B1426255 for ; Wed, 10 Aug 2016 20:38:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4CBA283E6; Wed, 10 Aug 2016 20:38:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CA61D26255 for ; Wed, 10 Aug 2016 20:38:44 +0000 (UTC) Received: from localhost ([::1]:43826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXaGw-0005bJ-AL for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Aug 2016 16:38:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXaGf-0005UJ-Hw for qemu-devel@nongnu.org; Wed, 10 Aug 2016 16:38:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXaGb-0003aR-A9 for qemu-devel@nongnu.org; Wed, 10 Aug 2016 16:38:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36832) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXaGb-0003aL-4F for qemu-devel@nongnu.org; Wed, 10 Aug 2016 16:38:21 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 069A683F42; Wed, 10 Aug 2016 20:38:20 +0000 (UTC) Received: from javelin.localdomain (vpn1-5-129.sin2.redhat.com [10.67.5.129]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7AKcFxJ015590 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 10 Aug 2016 16:38:17 -0400 From: P J P To: Qemu developers Date: Thu, 11 Aug 2016 02:08:14 +0530 Message-Id: <1470861494-17834-1-git-send-email-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 10 Aug 2016 20:38:20 +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] [PATCH] net: vmxnet: check fragments count at pkt initialisation 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: Dmitry Fleytman , Jason Wang , Li Qiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Li Qiang When net transport abstraction layer initialises the pkt, the maximum fragmentation count is not checked. This could lead to an integer overflow causing a NULL pointer dereference. Add check to avoid it. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit Acked-by: Dmitry Fleytman --- hw/net/net_tx_pkt.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index 53dfaa2..7ea3c17 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -58,9 +58,12 @@ struct NetTxPkt { bool is_loopback; }; +#define NET_PKT_MAX_FRAGS 16 /* ref: MAX_SKB_FRAGS in kernel driver */ + void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev, uint32_t max_frags, bool has_virt_hdr) { + assert(max_frags <= NET_PKT_MAX_FRAGS); struct NetTxPkt *p = g_malloc0(sizeof *p); p->pci_dev = pci_dev;