From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385255; b=uLRjFLxTMOCHnz/Xruw0S/ZdsiwEfWGyBjQxzYnjfcmL5THlDRLqRryGeqW0V1rPW96d N2BMdTpTU2aQKvDnu2AXCTxA7UvV213yfTxudHLZoHl7HdUSJxenNbDmmRDXYh30WPCjw UaXnzIHklIBSMMQvKu6+5xkqu3J20JetqTcljiD4lYZErPVMkE2UoSOlIvBGzW6Qa2B45 0DOE37NZE5shc4jYLs+r3Cv2Cxg3zoBz6Oda3Kr+U673PGLvCzGQWBgwtoDb9ga6EHY5h RRk2+U4mNweOaZHF5MuAD8H9w7OQluc/n8BbUmC5p0wXWP55PqQ03hpKWpU/Lqsv1iQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385255; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=q8d8cq9Krbd8RaEhYs1397YGX3K3XF507WA6BXn3sEw=; b=kdMxIW1hVsOCsWdvlUyNTCj0nl0EWsrpheKwQpP2Ad0iIpougcwEihRD+IZEmRsz0doR RRD5ApxQ/W1AtCglY7fr4jwIWR78YBVNl3RsOhEa8vwZvnJuKVZRaVdzdufUEtyqZ3hu6 WuUiiD+tXjMA4S6kZfTsIAQB/0ibX9oy1cce2J3d+MxBGmZhW1YDzwOUYhAGjTsjXUQtk +cbTPBfMaDoFGS0sVelV6k0/SN7nsV0WMYr/l6JDWkDNDVYn8SJhJEdAXGNtmHmmJSjmf u7LN9kcj4fk4dzMVX2SGZJ6saz+ENi4FJvXvc0ZLij2gDp8znQml9ousd/BSfQbCJRg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IOhD7Zqt; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E985B606A33F for ; Fri, 4 Dec 2026 11:54:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IOhD7Zqt Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DA4E1F000CE; Fri, 4 Dec 2026 11:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385254; bh=q8d8cq9Krbd8RaEhYs1397YGX3K3XF507WA6BXn3sEw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=IOhD7ZqtdoAGlENr4+LL4QcovVA6JPBC/6uyVkZMqI03C0XcxHeCpdfYcWgs7fuB1 sA4f3+xVdd465uL1lyR3ttcSXCgglBg8rxZ3PumcRdHnpDTUnj/Tz5eDcjGa+NBmWt UhdY4JeUD1uNK6ZK5YcP/7lrg4n1h8F2ZBMT1z4Yj0WA3BKz/R/5b5vxsdMOMRXlgB kWrtLczv9XWK8Jl7CUfntdXNj5uAev2TF1btBIwXPEhqioQGd+EQPIvBK2bbGX9moa oAeN0KLGsK07es/357XCP+oY5yh/Mal6BMRyfZDb5QtZ+K3FA0lfWz+k0rsMdfVElF S+0/sdHV5rPGQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7] vfio/pci: expose ACPI _ROM through a device region Reply-To: sashiko-reviews@lists.linux.dev To: "Michael S. Tsirkin" Cc: kvm@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:54:13 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] vfio/pci: 32-bit offset and bit-field overflow in vfio_pci_acpi_rom_rw() - [Medium] acpi: u32 overflow in acpi_ds_init_buffer_field() exposed via VFIO _ROM - [Medium] vfio/pci: unpinned ACPI _ROM handle cached in vfio_pci_register_acpi_rom() -- commit 48060cebe78f47e4a597a63ad3811049e5e9dde4 Author: Michael S. Tsirkin vfio/pci: expose ACPI _ROM through a device region This commit registers a read-only VFIO_REGION_SUBTYPE_ACPI_ROM device region when a PCI device provides an ACPI _ROM method, allowing userspace to read the option ROM in 4 KiB chunks. > diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci= _rdwr.c > index df88480876815..ec324cdaa3cc7 100644 > --- a/drivers/vfio/pci/vfio_pci_rdwr.c > +++ b/drivers/vfio/pci/vfio_pci_rdwr.c > @@ -198,6 +201,92 @@ ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_= device *vdev, bool test_mem, > } > EXPORT_SYMBOL_GPL(vfio_pci_core_do_io_rw); > =20 > +#ifdef CONFIG_ACPI > +static ssize_t vfio_pci_acpi_rom_rw(struct vfio_pci_core_device *vdev, > + char __user *buf, size_t count, > + loff_t *ppos, bool iswrite) > +{ [ ... ] > + size_t skip =3D pos % SZ_4K; > + union acpi_object args[] =3D { > + { .integer =3D { .type =3D ACPI_TYPE_INTEGER, .value =3D pos - skip } = }, > + { .integer =3D { .type =3D ACPI_TYPE_INTEGER, .value =3D SZ_4K } }, > + }; > + struct acpi_object_list params =3D { ARRAY_SIZE(args), args }; [ ... ] > + /* > + * A 32-bit AML interpreter cannot handle larger offsets, and ROMs > + * larger than 4G are unlikely. Truncate at the 4G boundary. > + */ > + if (pos > U32_MAX) > + return 0; [Severity: High] Can pos values near U32_MAX or at 512 MiB still overflow 32-bit arithmetic in AML and ACPICA? For pos in [0xFFFFF000, 0xFFFFFFFF], pos <=3D U32_MAX passes, so _ROM recei= ves Arg0 =3D 0xFFFFF000 and Arg1 =3D 0x1000. On a 32-bit ACPI table (acpi_gbl_integer_byte_width =3D=3D 4), acpi_ex_truncate_for32bit_table() truncates Add(Arg0, Arg1) to 0, bypassing firmware bounds checks of the form (Arg0 + Arg1) > RomSize. In addition, at pos =3D 0x1FFFF000 (or 0xFFFFF000), a _ROM method using CreateField(VROM, Arg0 * 8, Arg1 * 8, ...) overflows bit_offset (0xFFFF8000) + bit_count (0x8000) to 0 in u32 inside acpi_ds_init_buffer_field(), bypassing the buffer-length check. acpi_ex_field_datum_io() then performs an unchecked 4 KiB memcpy from buffer.pointer + 0x1FFFF000, which can oops or copy 4 KiB of kernel heap memory to an unprivileged VFIO userspace process. At pos =3D 0x20000000, (u32)(pos * 8) truncates to 0 and aliases 512 MiB back to offset 0. Capping pos well below 512 MiB (such as a realistic PCI ROM limit like SZ_16M) would prevent both byte and bit 32-bit overflows. > + if (ACPI_FAILURE(acpi_evaluate_object_typed(region->data, NULL, ¶ms, > + &result, ACPI_TYPE_BUFFER))) > + return -EIO; [Severity: Medium] Does exposing acpi_evaluate_object_typed() on _ROM with arbitrary userspace offsets hit an unchecked u32 overflow in ACPICA's acpi_ds_init_buffer_field()? drivers/acpi/acpica/dsopcode.c:acpi_ds_init_buffer_field() { ... offset =3D (u32) offset_desc->integer.value; ... if ((bit_offset + bit_count) > (8 * (u32)buffer_desc->buffer.length)) { ... } If platform _ROM AML creates a buffer field from an unclamped Arg0 and userspace reads at pos =3D 0x1FFFF000, bit_offset + bit_count wraps to 0 in u32 and passes the check. acpi_ex_prep_common_field_object() then sets base_byte_offset to 0x1FFFF000 and acpi_ex_field_datum_io() reads 4 KiB past buffer->pointer without bounds checking, letting an unprivileged VFIO user trigger a page fault or leak kernel memory. Checking for 32-bit truncation and overflow in acpi_ds_init_buffer_field() (matching AML_MID_OP in exoparg3.c) alongside tightening the offset cap in vfio_pci_acpi_rom_rw() would close this. [ ... ] > +void vfio_pci_register_acpi_rom(struct vfio_pci_core_device *vdev) > +{ > + acpi_handle handle =3D ACPI_HANDLE(&vdev->pdev->dev), method; > + int ret; > + > + if (!handle || ACPI_FAILURE(acpi_get_handle(handle, "_ROM", &method))) > + return; > + > + ret =3D vfio_pci_core_register_dev_region(vdev, VFIO_REGION_TYPE_ACPI, > + VFIO_REGION_SUBTYPE_ACPI_ROM, > + &vfio_pci_acpi_rom_ops, 0, > + VFIO_REGION_INFO_FLAG_READ, method); [Severity: Medium] Can caching the raw _ROM acpi_handle in region->data lead to a use-after-free if the SSDT defining _ROM is dynamically unloaded while the VFIO device fd remains open? acpi_get_handle() returns an unrefcounted struct acpi_namespace_node pointer. Unloading the SSDT via configfs (acpi_table_drop_item() -> acpi_unload_table() -> acpi_ns_delete_node() -> kmem_cache_free()) frees that node without invalidating region->data. Because vfio_pci_acpi_rom_rw() passes region->data with a NULL pathname to acpi_evaluate_object_typed(), ACPICA skips acpi_get_handle() and passes the freed pointer directly to acpi_ns_get_external_pathname() -> acpi_ns_build_normalized_path(), dereferencing freed slab memory. Checking acpi_has_method(handle, "_ROM") at registration time and passing ACPI_HANDLE(&vdev->pdev->dev) with pathname "_ROM" to acpi_evaluate_object_typed() on each read would avoid holding a dangling namespace node pointer. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/e0ca997750e9064ac6e= 17e2a7cbe957afed27ab1.1796383014.git.mst@redhat.com?part=3D1