All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v6] vfio/pci: expose ACPI _ROM through a device region
Date: Fri, 04 Dec 2026 10:19:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-249587@kernel.org> (raw)
In-Reply-To: <fc3a67c19998f3fbfcfa3511a87a56f07697c9a1.1796376699.git.mst@redhat.com>

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.

> +
> +	if (iswrite)
> +		return -EINVAL;
> +
> +	if (!count)
> +		return 0;
> +
> +	if (ACPI_FAILURE(acpi_evaluate_object_typed(region->data, NULL, &params,
> +						    &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

  reply	other threads:[~2026-12-04 10:19 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 [this message]
2026-12-04 10:32   ` Michael S. Tsirkin

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-249587@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.