All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Matt Evans" <matt@ozlabs.org>
Cc: linux-pci@vger.kernel.org, media-ci@linuxtv.org,
	kvm@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 1/9] vfio/pci: Remove DMABUF export dependency on vdev->memory_lock
Date: Thu, 24 Sep 2026 15:37:37 +0000	[thread overview]
Message-ID: <20260924153737.951E71F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260924152159.49702-2-matt@ozlabs.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] vfio: incorrect initial DMABUF revoked state allows DMA to disabled BARs
--

commit fb51fe9e3cab37471d1c4237de83fcf89aad79f5
Author: Matt Evans <matt@ozlabs.org>

vfio/pci: Remove DMABUF export dependency on vdev->memory_lock

This commit introduces a new dmabuf_lock to protect the list of exported
DMABUFs and a new bars_revoked flag for tracking BAR revocation state. This
removes the dependency on vdev->memory_lock during DMABUF export in
preparation for future mmap refactoring.

> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 6757054e9d875..1f60661078313 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -663,6 +663,7 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
>  		vdev->has_vga = true;
>  
>  	vfio_pci_core_map_bars(vdev);
> +	vdev->bars_revoked = false;

[Severity: High]
Is this hardcoded initialization safe?

Earlier in vfio_pci_core_enable(), pci_try_reset_function() is called,
which performs a fundamental reset that clears the device's
PCI_COMMAND_MEMORY bit in the physical hardware.

Then vfio_config_init() populates the virtual config space by reading from
the hardware, capturing PCI_COMMAND_MEMORY == 0. Does initializing
bars_revoked to false here fail to match that initial virtual config state?

>  
>  	return 0;
>  

[ ... ]

> diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
> index c16f460c01d68..847ee5cc78e7f 100644
> --- a/drivers/vfio/pci/vfio_pci_dmabuf.c
> +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c

[ ... ]

> @@ -305,12 +305,27 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
>  
>  	/* dma_buf_put() now frees priv */
>  	INIT_LIST_HEAD(&priv->dmabufs_elm);
> -	down_write(&vdev->memory_lock);
> +
> +	/*
> +	 * dmabuf_lock synchronises access (R) or updates (W) to the
> +	 * vdev->dmabufs list and to bars_revoked (see below).  The
> +	 * revocation state of DMABUF elements in the list is written
> +	 * holding both dmabuf_lock(W) and resv, and tested with
> +	 * either.
> +	 *
> +	 * dmabuf_lock -> resv
> +	 *
> +	 * vdev->bars_revoked tracks the BAR revocation status updated
> +	 * via vfio_pci_dma_buf_move(), so the initial DMABUF state
> +	 * follows the same criteria that later update the DMABUF
> +	 * state (BAR zap, etc.).
> +	 */
> +	down_write(&vdev->dmabuf_lock);
>  	dma_resv_lock(priv->dmabuf->resv, NULL);
> -	priv->revoked = !__vfio_pci_memory_enabled(vdev);
> +	priv->revoked = vdev->bars_revoked;

[Severity: High]
Can this incorrect initial state allow P2P DMA to disabled BARs?

If userspace exports a DMABUF at this point, the DMABUF inherits the
un-revoked state from vdev->bars_revoked (false), bypassing the correct
state evaluation.

Could this permit P2P DMA to this DMABUF to be allowed by the kernel but
dropped by the endpoint since memory decoding is disabled? This would trigger
PCIe Unsupported Request (UR) errors, which could potentially be weaponized
by unprivileged users controlling the VFIO device to trigger AER and crash
the host.

>  	list_add_tail(&priv->dmabufs_elm, &vdev->dmabufs);
>  	dma_resv_unlock(priv->dmabuf->resv);
> -	up_write(&vdev->memory_lock);
> +	up_write(&vdev->dmabuf_lock);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260924152159.49702-1-matt@ozlabs.org?part=1

  reply	other threads:[~2026-09-24 15:37 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 15:21 [PATCH v7 0/9] vfio/pci: Add mmap() for DMABUFs Matt Evans
2026-09-24 15:21 ` [PATCH v7 1/9] vfio/pci: Remove DMABUF export dependency on vdev->memory_lock Matt Evans
2026-09-24 15:37   ` sashiko-bot [this message]
2026-09-29 14:12     ` Matt Evans
2026-09-24 15:21 ` [PATCH v7 2/9] vfio/pci: Un-revoke DMABUFs in LOW_POWER_ENTRY_WITH_WAKEUP resume Matt Evans
2026-09-24 15:30   ` sashiko-bot
2026-09-24 15:21 ` [PATCH v7 3/9] dma-buf: Provide dma_buf_set_name() Matt Evans
2026-09-24 15:29   ` sashiko-bot
2026-09-25  8:39   ` Christian König
2026-09-29 11:43     ` Matt Evans
2026-09-24 15:21 ` [PATCH v7 4/9] vfio/pci: Add a helper to look up PFNs for DMABUFs Matt Evans
2026-09-24 15:35   ` sashiko-bot
2026-09-24 15:21 ` [PATCH v7 5/9] vfio/pci: Add a helper to create a DMABUF for a BAR-map VMA Matt Evans
2026-09-24 15:38   ` sashiko-bot
2026-09-24 15:21 ` [PATCH v7 6/9] vfio/pci: Convert BAR mmap() to use a DMABUF Matt Evans
2026-09-24 15:34   ` sashiko-bot
2026-09-28 17:59   ` Alex Mastro
2026-09-24 15:21 ` [PATCH v7 7/9] vfio/pci: Clean up BAR zap and revocation Matt Evans
2026-09-24 15:34   ` sashiko-bot
2026-09-24 15:21 ` [PATCH v7 8/9] vfio/pci: Support mmap() of a VFIO DMABUF Matt Evans
2026-09-24 15:36   ` sashiko-bot
2026-09-24 15:21 ` [PATCH v7 9/9] vfio/pci: Revoke a DMABUF on request from userspace Matt Evans
2026-09-24 15:35   ` sashiko-bot
2026-10-01 21:38 ` [PATCH v7 0/9] vfio/pci: Add mmap() for DMABUFs Alex Williamson
2026-10-02 14:04   ` Matt Evans
2026-10-02 14:51   ` Jason Gunthorpe

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=20260924153737.951E71F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=matt@ozlabs.org \
    --cc=media-ci@linuxtv.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 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.