From patchwork Tue Sep 8 14:09:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 515550 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 92D70140157 for ; Wed, 9 Sep 2015 06:44:32 +1000 (AEST) Received: from localhost ([::1]:34640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZJfb-0000aH-NE for incoming@patchwork.ozlabs.org; Tue, 08 Sep 2015 10:14:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZJbG-0005b0-6z for qemu-devel@nongnu.org; Tue, 08 Sep 2015 10:10:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZJbA-00014n-EC for qemu-devel@nongnu.org; Tue, 08 Sep 2015 10:10:18 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:49139) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZJbA-000148-7L for qemu-devel@nongnu.org; Tue, 08 Sep 2015 10:10:12 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t88EA5vu024320 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Sep 2015 14:10:06 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t88EA5wF016231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 8 Sep 2015 14:10:05 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t88EA5LS022407; Tue, 8 Sep 2015 14:10:05 GMT Received: from l.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 08 Sep 2015 07:10:05 -0700 Received: by l.oracle.com (Postfix, from userid 1000) id 0C5C56A4B96; Tue, 8 Sep 2015 10:10:04 -0400 (EDT) From: Konrad Rzeszutek Wilk To: stefano.stabellini@eu.citrix.com, xen-devel@lists.xenproject.org, qemu-devel@nongnu.org Date: Tue, 8 Sep 2015 10:09:55 -0400 Message-Id: <1441721402-12464-4-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1441721402-12464-1-git-send-email-konrad.wilk@oracle.com> References: <1441721402-12464-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 Cc: JBeulich@suse.com, Konrad Rzeszutek Wilk Subject: [Qemu-devel] [PATCH v2 03/10] xen/pt: Check if reg->init function sets the 'data' past the reg->size 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 It should never happen, but in case it does (an developer adds a new register and the 'init_val' expands past the register size) we want to report. The code will only write up to reg->size so there is no runtime danger of the register spilling across other ones - however to catch this sort of thing we still return an error. Signed-off-by: Konrad Rzeszutek Wilk --- hw/xen/xen_pt_config_init.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index aff51b8..55be4ee 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -1912,9 +1912,15 @@ static int xen_pt_config_reg_init(XenPCIPassthroughState *s, } else val = data; + if (val & ~size_mask) { + XEN_PT_ERR(&s->dev,"Offset 0x%04x:0x%04x expands past register size(%d)!\n", + offset, val, reg->size); + g_free(reg_entry); + return -ENXIO; + } /* This could be just pci_set_long as we don't modify the bits - * past reg->size, but in case this routine is run in parallel - * we do not want to over-write other registers. */ + * past reg->size, but in case this routine is run in parallel or the + * init value is larger, we do not want to over-write registers. */ switch (reg->size) { case 1: pci_set_byte(s->dev.config + offset, (uint8_t)val); break;