From patchwork Mon Mar 31 14:16:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 335400 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 A9F5F140095 for ; Tue, 1 Apr 2014 01:23:56 +1100 (EST) Received: from localhost ([::1]:48955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUd7y-0003U0-D9 for incoming@patchwork.ozlabs.org; Mon, 31 Mar 2014 10:23:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUd0x-0000N5-59 for qemu-devel@nongnu.org; Mon, 31 Mar 2014 10:16:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUd0r-0000du-V0 for qemu-devel@nongnu.org; Mon, 31 Mar 2014 10:16:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59807) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUd0q-0000dP-QQ; Mon, 31 Mar 2014 10:16:33 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2VEGRs9028304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 31 Mar 2014 10:16:28 -0400 Received: from redhat.com (vpn1-4-232.ams2.redhat.com [10.36.4.232]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id s2VEGP2V026081; Mon, 31 Mar 2014 10:16:26 -0400 Date: Mon, 31 Mar 2014 17:16:55 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1396275242-10810-16-git-send-email-mst@redhat.com> References: <1396275242-10810-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1396275242-10810-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , qemu-stable@nongnu.org, dgilbert@redhat.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v4 15/30] stellaris_enet: avoid buffer orerrun on incoming migration (part 3) 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 CVE-2013-4532 s->tx_frame_len is read from the wire and can later used as an index into s->tx_fifo[] for memset() when a DATA command is issued by the guest. In this case s->tx_frame_len is checked to avoid an overrun, but if the value is negative a subsequently executed guest can underrun the buffer with zeros via the memset() call. Additionally, tx_frame_len is used to validate that tx_fifo_len doesn't exceed the fifo bounds - the assumption being that data model never makes it exceed 2032. Fix this by failing migration if the incoming value of s->tx_frame_len is less than -1 (the emulation code allows from -1 as a special case) or if it exceeds 2032. Reported-by: Michael Roth Reported-by: Peter Maydell Signed-off-by: Michael S. Tsirkin --- hw/net/stellaris_enet.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index aed00fd..90ff950 100644 --- a/hw/net/stellaris_enet.c +++ b/hw/net/stellaris_enet.c @@ -373,7 +373,11 @@ static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id) s->mtxd = qemu_get_be32(f); s->mrxd = qemu_get_be32(f); s->np = qemu_get_be32(f); - s->tx_frame_len = qemu_get_be32(f); + v = qemu_get_be32(f); + if (v < -1 || s->tx_frame_len > 2032) { + return -EINVAL; + } + s->tx_frame_len = v; v = qemu_get_be32(f); /* How many bytes does data use in tx fifo. */ sz = s->tx_frame_len == -1 ? 2 : 4;