From: sashiko-bot@kernel.org
To: "Alexander Graf" <graf@amazon.com>
Cc: dri-devel@lists.freedesktop.org, nvdimm@lists.linux.dev
Subject: Re: [PATCH v2 11/12] virtio_pci: support VIRTIO_F_DMB
Date: Tue, 18 Aug 2026 21:40:57 +0000 [thread overview]
Message-ID: <20260818214057.6E2801F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260818211425.91009-12-graf@amazon.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Out-of-bounds MMIO read in `vp_dmb_mem_type_supported` due to `mdev->common_len` exceeding the actual mapped BAR size.
--
--- Patch [11]: [PATCH v2 11/12] virtio_pci: support VIRTIO_F_DMB ---
commit 2b2d786abf770566580dde39b790350db36f5d09
Author: Alexander Graf <graf@amazon.com>
virtio_pci: support VIRTIO_F_DMB
Let a modern virtio-pci device place its virtqueues and the buffers they
reference in a Device Memory Buffer of its own: accept VIRTIO_F_DMB from
vp_transport_features(), and implement the get_dmb_shm_id config op on
top of vp_modern_get_dmb_shm_id(). get_dmb_shm_id reports the shared
memory id of the region that holds the buffer.
Link: https://lore.kernel.org/virtio-comment/20260818060255.6853-1-graf@amazon.com/
> diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
> index 565d37b630b31..c893e31e51590 100644
> --- a/drivers/virtio/virtio_pci_modern.c
> +++ b/drivers/virtio/virtio_pci_modern.c
[ ... ]
> @@ -364,6 +364,29 @@ static void vp_modern_avq_cleanup(struct virtio_device *vdev)
> }
> }
>
> +/*
> + * A device reports the memory type of its Device Memory Buffer region in
> + * dmb_mem_type, and the field is valid as soon as the device offers
> + * VIRTIO_F_DMB. VIRTIO_DMB_MEM_TYPE_COHERENT says that a write by either side
> + * becomes visible to the other with no cache maintenance by the driver, which
> + * is what plain loads and stores on the region need. A common configuration
> + * structure too short to hold the field reports no type at all, and reading it
> + * there would fall outside what vp_modern_probe() mapped. This is the only
> + * place that measures the structure against the field, because the read
> + * happens before vp_check_common_size() runs.
> + */
> +static bool vp_dmb_mem_type_supported(struct virtio_pci_device *vp_dev)
> +{
> + size_t need = offsetofend(struct virtio_pci_modern_common_cfg,
> + dmb_mem_type);
> +
> + if (vp_dev->mdev.common_len < need)
> + return false;
> +
> + return vp_modern_get_dmb_mem_type(&vp_dev->mdev) ==
[Severity: High]
This isn't a bug introduced by this patch, but does this bounds check
rely on an inflated common_len that could allow out-of-bounds MMIO reads?
If a buggy or malicious PCI device sets the capability length to 68 or more,
but places it near the end of the BAR such that the remaining space is only
between 56 (minlen) and 67 bytes, vp_modern_map_capability() sets
mdev->common_len to the un-clamped capability length:
drivers/virtio/virtio_pci_modern_dev.c:vp_modern_map_capability() {
...
if (length > size)
length = size;
if (len)
*len = length; /* mdev->common_len receives the inflated length */
if (minlen + offset < minlen ||
minlen + offset > pci_resource_len(dev, bar)) {
...
}
Since pci_iomap_range() will only map up to the physical end of the BAR,
the actual mapped region is shorter than common_len.
Because common_len is inflated, the check (vp_dev->mdev.common_len < need)
passes here, allowing vp_modern_get_dmb_mem_type() to perform a read
which is physically outside the mapped PCI BAR.
Could this unmapped read trigger a PCIe Unsupported Request and Master Abort,
potentially panicking the host system?
> + VIRTIO_DMB_MEM_TYPE_COHERENT;
> +}
> +
> static void vp_transport_features(struct virtio_device *vdev, u64 features)
> {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260818211425.91009-1-graf@amazon.com?part=11
next prev parent reply other threads:[~2026-08-18 21:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 21:14 [PATCH v2 00/12] virtio: support devices that own their virtqueue memory Alexander Graf
2026-08-18 21:14 ` [PATCH v2 01/12] virtio_ring: remove the unused map sync API Alexander Graf
2026-08-18 21:14 ` [PATCH v2 02/12] virtio: drop the sync operations from virtio_map_ops Alexander Graf
2026-08-18 21:14 ` [PATCH v2 03/12] vdpa: drop the VIRTIO_DEVICE_F_MASK example value Alexander Graf
2026-08-18 21:14 ` [PATCH v2 04/12] virtio_ring: return -ENOMEM when a packed ring mapping fails Alexander Graf
2026-08-18 21:14 ` [PATCH v2 05/12] virtio: add the VIRTIO_F_DMB feature bit Alexander Graf
2026-08-18 21:14 ` [PATCH v2 06/12] virtio_pci: read the device memory buffer registers Alexander Graf
2026-08-18 21:14 ` [PATCH v2 07/12] virtio_pci: create virtqueues with the device's mapping token Alexander Graf
2026-08-18 21:14 ` [PATCH v2 08/12] virtio: add a device memory buffer region allocator Alexander Graf
2026-08-18 21:14 ` [PATCH v2 09/12] virtio: locate the device memory buffer after feature negotiation Alexander Graf
2026-08-18 21:14 ` [PATCH v2 10/12] virtio: treat VIRTIO_F_DMB as implying VIRTIO_F_ACCESS_PLATFORM Alexander Graf
2026-08-18 21:14 ` [PATCH v2 11/12] virtio_pci: support VIRTIO_F_DMB Alexander Graf
2026-08-18 21:40 ` sashiko-bot [this message]
2026-08-18 21:14 ` [PATCH v2 12/12] virtio: expose device memory buffer occupancy over debugfs Alexander Graf
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=20260818214057.6E2801F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=graf@amazon.com \
--cc=nvdimm@lists.linux.dev \
--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.