From: "Michael S. Tsirkin" <mst@redhat.com>
To: sashiko-reviews@lists.linux.dev
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v6] vfio/pci: expose ACPI _ROM through a device region
Date: Fri, 4 Dec 2026 05:32:36 -0500 [thread overview]
Message-ID: <20261204053151-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <sashiko-outbox-249587@kernel.org>
On Fri, Dec 04, 2026 at 10:19:57AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [High] vfio/pci: use of undeclared args in vfio_pci_acpi_rom_rw()
> breaks build
> - [Low] vfio/pci: unbounded pos in vfio_pci_acpi_rom_rw() wraps on
> 32-bit ACPI _ROM
> --
>
> commit 89f4506412531a6bddab13afe01a5db3c586ee11
> Author: Michael S. Tsirkin <mst@redhat.com>
>
> vfio/pci: expose ACPI _ROM through a device region
>
> This commit exposes a PCI device's ACPI _ROM method through a new
> read-only VFIO device region (VFIO_REGION_TYPE_ACPI /
> VFIO_REGION_SUBTYPE_ACPI_ROM) so userspace can read the option ROM
> contents.
>
> > diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> > index df88480876815..f9c225b0bc72e 100644
> > --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> > +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
>
> [ ... ]
>
> > @@ -198,6 +201,85 @@ 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)
> > +{
> > + unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
> > + struct vfio_pci_region *region = &vdev->region[index - VFIO_PCI_NUM_REGIONS];
> > + u64 pos = *ppos & VFIO_PCI_OFFSET_MASK;
> > + struct acpi_object_list params = { ARRAY_SIZE(args), args };
> > + struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
> > + union acpi_object *obj;
> > + size_t available;
> > + /*
> > + * ACPI limits requests to 4K, and some FW seems to only handle
> > + * full 4K aligned blocks. See
> > + * ad4a36263535 ("drm/nouveau/bios: split out shadow methods").
> > + * and
> > + * d1626a965141 ("drm/nouveau/bios: fetch full 4KiB block to determine ACPI ROM image size").
> > + */
> > + 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 } },
> > + };
>
> [Severity: High]
> Does this compile with CONFIG_ACPI enabled? params references args and
> ARRAY_SIZE(args) before args[] is declared. Moving params after args[]
> would fix the build failure.
Ugh. Should teach me not to try hand editing the patch right before
sending(
Pls ignore will retest and resend.
> > +
> > + if (iswrite)
> > + return -EINVAL;
> > +
> > + if (!count)
> > + return 0;
> > +
> > + if (ACPI_FAILURE(acpi_evaluate_object_typed(region->data, NULL, ¶ms,
> > + &result, ACPI_TYPE_BUFFER)))
> > + return -EIO;
> > +
> > + obj = result.pointer;
> > + available = min_t(size_t, obj->buffer.length, SZ_4K);
> > + if (skip >= available) {
> > + kfree(obj);
> > + return 0;
> > + }
> > +
> > + count = min(count, available - skip);
> > + count -= copy_to_user(buf, obj->buffer.pointer + skip, count);
> > + kfree(obj);
> > + if (!count)
> > + return -EFAULT;
> > +
> > + *ppos += count;
> > + return count;
> > +}
>
> [Severity: Low]
> Should pos be bounded before passing it to ACPI _ROM? Because
> VFIO_PCI_OFFSET_MASK allows 40-bit offsets up to 1 TiB, a read at an
> offset >= 4 GiB passes a value above U32_MAX as Arg0.
>
> ACPICA truncates values above U32_MAX to 32 bits on 32-bit DSDT tables
> in acpi_ex_truncate_for32bit_table(), and casts buffer field offsets to
> u32 in acpi_ds_init_buffer_field(). An out-of-range read can therefore
> wrap modulo 4 GiB and alias offset 0 instead of returning 0 or -EINVAL.
>
> In addition, adding count to *ppos in the final 4 KiB of the 40-bit
> offset range can carry into VFIO_PCI_OFFSET_SHIFT, though this is
> currently harmless because ACPI _ROM is registered last. Rejecting
> offsets above U32_MAX (or capping below 4 GiB) avoids both issues.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/fc3a67c19998f3fbfcfa3511a87a56f07697c9a1.1796376699.git.mst@redhat.com?part=1
prev parent reply other threads:[~2026-12-04 10:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 9:55 [PATCH v6] vfio/pci: expose ACPI _ROM through a device region Michael S. Tsirkin
2026-12-04 10:19 ` sashiko-bot
2026-12-04 10:32 ` Michael S. Tsirkin [this message]
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=20261204053151-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=kvm@vger.kernel.org \
--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