From nobody Sat Nov 1 22:16:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509159414446548.6371087699262; Fri, 27 Oct 2017 19:56:54 -0700 (PDT) Received: from localhost ([::1]:59617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8HIh-0005VH-Fl for importer@patchew.org; Fri, 27 Oct 2017 22:56:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8HHk-0005DU-3D for qemu-devel@nongnu.org; Fri, 27 Oct 2017 22:55:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e8HHf-0002ra-8k for qemu-devel@nongnu.org; Fri, 27 Oct 2017 22:55:44 -0400 Received: from ipsumj.de ([109.75.177.107]:36440) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e8HHe-0002mN-Sw for qemu-devel@nongnu.org; Fri, 27 Oct 2017 22:55:39 -0400 Received: from simon by localhost with local (Exim 4.84_2) (envelope-from ) id 1e8HHX-00067N-W9; Sat, 28 Oct 2017 04:55:32 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ipsumj.de; s=js1; h=Message-Id:Date:Subject:Cc:To:From; bh=Ku5dsNCu3iVo/2sG1eVWNLg5qbVp6HTuY47HwOPezhQ=; b=O1SKprqAMy72WnAk5DeIRHUz2hesoSZN6wgQjnecLjT2VIIY50i7hkNtmAJGs7ThMrnEFfeaKmHmLpA4zBv+/FNc83TrK/CmQJtEirkxK/3m9huw5loHGuvjL5mO3hlxRvVFhIytlBTv8v3WaXjLej50pArwzT90abLzZPzn/G5iE1bBvr+qEdPJua2Szx8BDxeC3Uj5JE2yJu80iGlayAd6eWPvYbz+suGJ1lYRoNifMqHOvgaWFkmtoiDhAvg2lBGIgStXh/gT0zHg8li3rbW3Pgz8d9GHNT9LKJrz6oWCq+STKBAqxHWd6yXuuIdP8JqyPhSLclcrkj+u6Y3eOzP2CLcs0LWWI9k0oAR07pggjGwaaJ+hG1RLVwWmqhJof+fXEKs7U5x+KbLfdyW+N+VJf+FrE5xVcY+tf7iPVKm8/MS3/2hDnlwlS/nP4zt4wd89dy0M+jlLDrQvoGmZMlLlIBHQMAJ1C8dVqEv4bhLAUe6eytzWooRLB4tUdj+DqwCzfuThDM6jcohMYMbz9/N9/EfJvZvFb4Qz4I43aPd31Pm7f2JATqkxCLxRneqbe1hMMJLbxTeXMO+ez3UxsnL3DydcYmi3lHGnOPAfEpRv9qCS6deQcXCBhgdrB3NsWtz+94Dvmd9RcdJWDY5YkfCgop6YKb2OqtZwLculVqE=; From: Simon Gaiser To: qemu-devel@nongnu.org Date: Sat, 28 Oct 2017 04:53:15 +0200 Message-Id: <20171028025315.13500-1-hw42@ipsumj.de> X-Mailer: git-send-email 2.15.0.rc1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 109.75.177.107 Subject: [Qemu-devel] [PATCH] xen/pt: Set is_express to avoid out-of-bounds write 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: Anthony Perard , xen-devel@lists.xenproject.org, Simon Gaiser , Stefano Stabellini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The passed-through device might be an express device. In this case the old code allocated a too small emulated config space in pci_config_alloc() since pci_config_size() returned the size for a non-express device. This leads to an out-of-bound write in xen_pt_config_reg_init(), which sometimes results in crashes. So set is_express as already done for KVM in vfio-pci. Shortened ASan report: =3D=3D17512=3D=3DERROR: AddressSanitizer: heap-buffer-overflow on address 0= x611000041648 at pc 0x55e0fdac51ff bp 0x7ffe4af07410 sp 0x7ffe4af07408 WRITE of size 2 at 0x611000041648 thread T0 #0 0x55e0fdac51fe in memcpy /usr/include/x86_64-linux-gnu/bits/string3.= h:53 #1 0x55e0fdac51fe in stw_he_p include/qemu/bswap.h:330 #2 0x55e0fdac51fe in stw_le_p include/qemu/bswap.h:379 #3 0x55e0fdac51fe in pci_set_word include/hw/pci/pci.h:490 #4 0x55e0fdac51fe in xen_pt_config_reg_init hw/xen/xen_pt_config_init.c= :1991 #5 0x55e0fdac51fe in xen_pt_config_init hw/xen/xen_pt_config_init.c:2067 #6 0x55e0fdabcf4d in xen_pt_realize hw/xen/xen_pt.c:830 #7 0x55e0fdf59666 in pci_qdev_realize hw/pci/pci.c:2034 #8 0x55e0fdda7d3d in device_set_realized hw/core/qdev.c:914 [...] 0x611000041648 is located 8 bytes to the right of 256-byte region [0x611000= 041540,0x611000041640) allocated by thread T0 here: #0 0x7ff596a94bb8 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/li= basan.so.4+0xd9bb8) #1 0x7ff57da66580 in g_malloc0 (/lib/x86_64-linux-gnu/libglib-2.0.so.0+= 0x50580) #2 0x55e0fdda7d3d in device_set_realized hw/core/qdev.c:914 [...] Signed-off-by: Simon Gaiser --- I found this by debugging crashes and I'm not familiar with this code, so I'm not sure if this has no unintended side effects. hw/xen/xen_pt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index b6d71bb52a..90ffd45e7d 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -946,6 +946,7 @@ static void xen_pci_passthrough_class_init(ObjectClass = *klass, void *data) k->exit =3D xen_pt_unregister_device; k->config_read =3D xen_pt_pci_read_config; k->config_write =3D xen_pt_pci_write_config; + k->is_express =3D 1; /* We might be */ set_bit(DEVICE_CATEGORY_MISC, dc->categories); dc->desc =3D "Assign an host PCI device with Xen"; dc->props =3D xen_pci_passthrough_properties; --=20 2.15.0.rc1