From patchwork Mon Jun 29 21:02:00 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: 489427 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 62D8314076C for ; Tue, 30 Jun 2015 07:04:54 +1000 (AEST) Received: from localhost ([::1]:44048 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9gEW-0001Dx-8N for incoming@patchwork.ozlabs.org; Mon, 29 Jun 2015 17:04:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9gC7-0004rS-Op for qemu-devel@nongnu.org; Mon, 29 Jun 2015 17:02:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z9gBz-0007ww-HZ for qemu-devel@nongnu.org; Mon, 29 Jun 2015 17:02:23 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:43586) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9gBz-0007w6-Bc for qemu-devel@nongnu.org; Mon, 29 Jun 2015 17:02:15 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t5TL296w029681 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 29 Jun 2015 21:02:09 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t5TL28qv032096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 29 Jun 2015 21:02:08 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t5TL284u029991; Mon, 29 Jun 2015 21:02:08 GMT Received: from l.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 29 Jun 2015 14:02:08 -0700 Received: by l.oracle.com (Postfix, from userid 1000) id 8CFA66A026B; Mon, 29 Jun 2015 17:02:07 -0400 (EDT) From: Konrad Rzeszutek Wilk To: stefano.stabellini@eu.citrix.com, xen-devel@lists.xenproject.org, qemu-devel@nongnu.org Date: Mon, 29 Jun 2015 17:02:00 -0400 Message-Id: <1435611725-15161-4-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1435611725-15161-1-git-send-email-konrad.wilk@oracle.com> References: <1435611725-15161-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 Cc: Konrad Rzeszutek Wilk Subject: [Qemu-devel] [PATCH RFC 1 3/8] xen/pt: Check if reg->init is 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 we want to report. The code will only write up to reg->size so there is no runtime danger. Signed-off-by: Konrad Rzeszutek Wilk --- hw/xen/xen_pt_config_init.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index 91c3a14..bc871c9 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -1901,9 +1901,13 @@ 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%04u expands past register size(%d)!\n", + offset, val, reg->size); + } /* 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; case 2: pci_set_word(s->dev.config + offset, (uint16_t)val); break;