From patchwork Tue Dec 3 16:28:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 296239 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8197B2C00A1 for ; Wed, 4 Dec 2013 03:28:00 +1100 (EST) Received: from localhost ([::1]:43367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnspK-0008PB-1C for incoming@patchwork.ozlabs.org; Tue, 03 Dec 2013 11:27:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vnsmh-0005Qd-VB for qemu-devel@nongnu.org; Tue, 03 Dec 2013 11:25:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vnsmd-0006hh-AA for qemu-devel@nongnu.org; Tue, 03 Dec 2013 11:25:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vnsmd-0006hc-1X; Tue, 03 Dec 2013 11:25:11 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rB3GP9af024220 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Dec 2013 11:25:09 -0500 Received: from redhat.com ([10.35.213.190]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id rB3GP7D7025775; Tue, 3 Dec 2013 11:25:07 -0500 Date: Tue, 3 Dec 2013 18:28:40 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1386087086-3691-8-git-send-email-mst@redhat.com> References: <1386087086-3691-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1386087086-3691-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-stable@nongnu.org, Anthony Liguori Subject: [Qemu-devel] [PATCH 07/23] hw/pci/pcie_aer.c: fix buffer overruns on invalid state load 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 4) CVE-2013-4529 hw/pci/pcie_aer.c pcie aer log can overrun the buffer if log_num is too large There are two issues in this file: 1. log_max from remote can be larger than on local then buffer will overrun with data coming from state file. 2. log_num can be larger then we get data corrution again with an overflow but not adversary controlled. Fix both issues. Reported-by: Anthony Liguori Reported-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci/pcie_aer.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index 991502e..92f3f20 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -795,15 +795,26 @@ static const VMStateDescription vmstate_pcie_aer_err = { } }; +static int pcie_aer_state_post_load(void *opaque, int version_id) +{ + PCIEAERLog *s = opaque; + + if (s->log_num > s->log_max) { + return -1; + } + return 0; +} + const VMStateDescription vmstate_pcie_aer_log = { .name = "PCIE_AER_ERROR_LOG", .version_id = 1, .minimum_version_id = 1, .minimum_version_id_old = 1, + .post_load = pcie_aer_state_post_load, .fields = (VMStateField[]) { VMSTATE_UINT16(log_num, PCIEAERLog), - VMSTATE_UINT16(log_max, PCIEAERLog), - VMSTATE_STRUCT_VARRAY_POINTER_UINT16(log, PCIEAERLog, log_num, + VMSTATE_UINT16_EQUAL(log_max, PCIEAERLog), + VMSTATE_STRUCT_VARRAY_POINTER_UINT16(log, PCIEAERLog, log_max, vmstate_pcie_aer_err, PCIEAERErr), VMSTATE_END_OF_LIST() }