From: sashiko-bot@kernel.org
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v7] vfio/pci: expose ACPI _ROM through a device region
Date: Fri, 04 Dec 2026 11:54:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-249736@kernel.org> (raw)
In-Reply-To: <e0ca997750e9064ac6e17e2a7cbe957afed27ab1.1796383014.git.mst@redhat.com>
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 <mst@redhat.com>
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);
>
> +#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 = pos % SZ_4K;
> + union acpi_object args[] = {
> + { .integer = { .type = ACPI_TYPE_INTEGER, .value = pos - skip } },
> + { .integer = { .type = ACPI_TYPE_INTEGER, .value = SZ_4K } },
> + };
> + struct acpi_object_list params = { 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 <= U32_MAX passes, so _ROM receives
Arg0 = 0xFFFFF000 and Arg1 = 0x1000. On a 32-bit ACPI table
(acpi_gbl_integer_byte_width == 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 = 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 = 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 = (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 = 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 = ACPI_HANDLE(&vdev->pdev->dev), method;
> + int ret;
> +
> + if (!handle || ACPI_FAILURE(acpi_get_handle(handle, "_ROM", &method)))
> + return;
> +
> + ret = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/e0ca997750e9064ac6e17e2a7cbe957afed27ab1.1796383014.git.mst@redhat.com?part=1
next prev parent reply other threads:[~2026-12-04 11:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:19 [PATCH v7] vfio/pci: expose ACPI _ROM through a device region Michael S. Tsirkin
2026-12-04 11:54 ` sashiko-bot [this message]
2026-12-04 15:03 ` Alex Williamson
2026-12-04 15:41 ` Michael S. Tsirkin
2026-12-04 16:38 ` Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-249736@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox