From: sashiko-bot@kernel.org
To: "Mina Almasry" <almasrymina@google.com>, dri-devel@lists.freedesktop.org
Cc: media-ci@linuxtv.org
Subject: Re: [PATCH net v2 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
Date: Tue, 13 Oct 2026 17:43:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-170248@kernel.org> (raw)
In-Reply-To: <20261012174300.2338784-2-almasrymina@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: use-after-free in dma_unmap_sg_attrs() for devmem leased RX bindings
--
commit 0978772617865658c49d5d8aff7d5a2c206deaf4
Author: Mina Almasry <almasrymina@google.com>
net: devmem: unmap dma_buf synchronously on queue uninstall
This commit changes the unmapping of the dma_buf attachment to happen
synchronously when the queue is uninstalled. It introduces
net_devmem_dmabuf_binding_unmap() to clear the attachment, preventing a
use-after-free if the physical device is unregistered while references
are still held.
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index f4d60654ce7fd..02d607cc87217 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
[ ... ]
> @@ -153,6 +176,35 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)
> percpu_ref_kill(&binding->ref);
> }
>
> +static void
> +net_devmem_dev_unregister_rx(struct net_devmem_dmabuf_binding *binding,
> + unsigned long xa_idx, struct net_device *dev)
> +{
> + if (xa_get_mark(&net_devmem_dmabuf_bindings, xa_idx,
> + NET_DEVMEM_BINDING_LIVE) ||
> + READ_ONCE(binding->dev) != dev)
> + return;
[Severity: High]
For leased RX queues, if the physical device unregisters, could binding->dev
still point to the virtual device instead of the physical device?
If the physical device unregisters without prior unleasing, or if the queue
was previously uninstalled (setting binding->dev to NULL), this check would
evaluate to true and skip the unmapping. This would leave the dma_buf
mapped to the physical device's dma_dev, which is subsequently freed.
When the binding is ultimately destroyed via
__net_devmem_dmabuf_binding_free(), could this trigger a use-after-free in
dma_buf_unmap_attachment_unlocked() when it accesses the freed dma_dev?
> +
> + mutex_lock(&binding->lock);
> + WRITE_ONCE(binding->dev, NULL);
> + if (!netif_is_queue_leasee(dev))
> + net_devmem_dmabuf_binding_unmap(binding);
> + mutex_unlock(&binding->lock);
> +}
[ ... ]
> @@ -529,16 +585,19 @@ static void mp_dmabuf_devmem_uninstall(void *mp_priv,
> unsigned long xa_idx;
>
> xa_for_each(&binding->bound_rxqs, xa_idx, bound_rxq) {
> - if (bound_rxq == rxq) {
> - xa_erase(&binding->bound_rxqs, xa_idx);
> - if (xa_empty(&binding->bound_rxqs)) {
> - mutex_lock(&binding->lock);
> - ASSERT_EXCLUSIVE_WRITER(binding->dev);
> - WRITE_ONCE(binding->dev, NULL);
> - mutex_unlock(&binding->lock);
> - }
> - break;
> + if (bound_rxq != rxq)
> + continue;
> +
> + xa_erase(&binding->bound_rxqs, xa_idx);
> + if (xa_empty(&binding->bound_rxqs)) {
> + mutex_lock(&binding->lock);
> + ASSERT_EXCLUSIVE_WRITER(binding->dev);
> + WRITE_ONCE(binding->dev, NULL);
> + if (!rxq->lease)
> + net_devmem_dmabuf_binding_unmap(binding);
> + mutex_unlock(&binding->lock);
[Severity: High]
Here binding->dev is unconditionally set to NULL, but for leased queues,
net_devmem_dmabuf_binding_unmap() is explicitly skipped.
If the physical device is later unregistered, won't
net_devmem_dev_unregister_rx() fail to unmap the binding because
binding->dev was already set to NULL?
Could this result in the dma_buf remaining mapped to the physical device
until the binding is eventually freed, causing a use-after-free at that
time?
> }
> + break;
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012174300.2338784-1-almasrymina@google.com?part=1
next prev parent reply other threads:[~2026-10-13 17:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 17:42 [PATCH net v2 0/4] net: devmem: fix RX and TX binding teardown on device unregistration Mina Almasry
2026-10-12 17:42 ` [PATCH net v2 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall Mina Almasry
2026-10-13 17:43 ` sashiko-bot [this message]
2026-10-13 18:14 ` netdev-bot+sashiko
2026-10-12 17:42 ` [PATCH net v2 2/4] net: devmem: detach TX bindings on NETDEV_UNREGISTER Mina Almasry
2026-10-13 17:43 ` sashiko-bot
2026-10-13 18:14 ` netdev-bot+sashiko
2026-10-12 17:42 ` [PATCH net v2 3/4] netdevsim: support devmem RX and TX bindings Mina Almasry
2026-10-13 17:43 ` sashiko-bot
2026-10-13 18:14 ` netdev-bot+sashiko
2026-10-12 17:43 ` [PATCH net v2 4/4] selftests: net: add devmem RX and TX netdev unregister tests Mina Almasry
2026-10-13 17:43 ` sashiko-bot
2026-10-13 18:14 ` netdev-bot+sashiko
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-170248@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=almasrymina@google.com \
--cc=dri-devel@lists.freedesktop.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.