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 v3 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
Date: Thu, 15 Oct 2026 16:18:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-173162@kernel.org> (raw)
In-Reply-To: <20261014161754.3782346-2-almasrymina@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: devmem: UAF in dmabuf unmap due to skipped unmap on physical device unregister
--
commit 9aa963a98903abc88d8d047a795dac2c2807eebc
Author: Mina Almasry <almasrymina@google.com>
net: devmem: unmap dma_buf synchronously on queue uninstall
This commit adds synchronous unmapping of a dma_buf when the last bound RX queue
is uninstalled or the bound physical device is unregistered. The intention is to
prevent a use-after-free crash in dma_unmap_sg_attrs() that happens when the
device is removed (freeing dma_dev) before the binding is completely freed on
socket close.
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index f4d60654ce7fd..93cc2815d935a 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
[ ... ]
> @@ -153,6 +176,38 @@ 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]
When a virtual device leases an RX queue from a physical device,
netdev_nl_bind_rx_doit() maps a dmabuf using the physical device's dma_dev but
sets binding->dev to the virtual device. If the physical device is unregistered,
will this condition cause the unmap to be skipped because binding->dev does not
match the physical device?
> +
> + mutex_lock(&binding->lock);
> + WRITE_ONCE(binding->dev, NULL);
> + if (!netif_is_queue_leasee(dev))
> + net_devmem_dmabuf_binding_unmap(binding);
[Severity: High]
If the virtual device unregisters (either directly or due to the physical device
unregistering), this explicit check skips the unmapping step for leased queues.
Does this leave the dmabuf mapped to the physical device's soon-to-be-freed
dma_dev, and ultimately lead to the same use-after-free crash during socket
close?
> + mutex_unlock(&binding->lock);
> +}
[ ... ]
> @@ -529,16 +588,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);
[Severity: High]
Similar to the issue above, does explicitly skipping the unmap here for leased
queues prevent synchronous unmapping and trigger a use-after-free in
__net_devmem_dmabuf_binding_free() when it uses the freed dma_dev?
> + mutex_unlock(&binding->lock);
> }
> + break;
> }
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261014161754.3782346-1-almasrymina@google.com?part=1
next prev parent reply other threads:[~2026-10-15 16:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 16:17 [PATCH net v3 0/4] net: devmem: fix RX and TX binding teardown on device unregistration Mina Almasry
2026-10-14 16:17 ` [PATCH net v3 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall Mina Almasry
2026-10-15 16:18 ` sashiko-bot [this message]
2026-10-15 19:21 ` netdev-bot+sashiko
2026-10-14 16:17 ` [PATCH net v3 2/4] net: devmem: detach TX bindings on NETDEV_UNREGISTER Mina Almasry
2026-10-15 19:21 ` netdev-bot+sashiko
2026-10-14 16:17 ` [PATCH net v3 3/4] netdevsim: support devmem RX and TX bindings Mina Almasry
2026-10-15 16:18 ` sashiko-bot
2026-10-15 19:21 ` netdev-bot+sashiko
2026-10-14 16:17 ` [PATCH net v3 4/4] selftests: net: add devmem RX and TX netdev unregister tests Mina Almasry
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-173162@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.