From: netdev-bot+sashiko@kernel.org
To: almasrymina@google.com
Cc: kuba@kernel.org, asml.silence@gmail.com, dw@davidwei.uk,
sdf@fomichev.me, ap420073@gmail.com, pabeni@redhat.com,
kaiyuanz@google.com, bobbyeshleman@meta.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, horms@kernel.org,
shuah@kernel.org, sumit.semwal@linaro.org,
christian.koenig@amd.com, daniel@iogearbox.net,
razor@blackwall.org, tariqt@nvidia.com, kaifengw@google.com,
dtatulea@nvidia.com
Subject: Re: [PATCH net v3 2/4] net: devmem: detach TX bindings on NETDEV_UNREGISTER
Date: Thu, 15 Oct 2026 19:21:06 +0000 [thread overview]
Message-ID: <179209206664.434549.4640692175922263115@kernel.org> (raw)
In-Reply-To: <20261014161754.3782346-3-almasrymina@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The TX-binding dangling `binding->dev` use-after-free can still
happen through a race in the leased-queue (netkit) bind-tx path.
--
net: devmem: detach TX bindings on NETDEV_UNREGISTER
This extends net_devmem_dev_unregister() to cover TX devmem bindings.
When binding->dev unregisters, the patch clears the binding's LIVE mark
and both dev and vdev, then unmaps the dma_buf after synchronize_net().
When only binding->vdev unregisters, it clears just binding->vdev.
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index 93cc2815d935a..dd07203076808 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
> @@ -192,9 +192,55 @@ net_devmem_dev_unregister_rx(struct net_devmem_dmabuf_binding *binding,
> mutex_unlock(&binding->lock);
> }
>
> +static bool
> +net_devmem_dev_unregister_tx(struct net_devmem_dmabuf_binding *binding,
> + unsigned long xa_idx, struct net_device *dev)
> +{
> + if (READ_ONCE(binding->dev) == dev) {
[ ... ]
> + return true;
> + }
> +
> + if (READ_ONCE(binding->vdev) == dev) {
> + mutex_lock(&binding->lock);
> + WRITE_ONCE(binding->vdev, NULL);
> + mutex_unlock(&binding->lock);
> + }
[Severity: High]
Can a TX binding still end up with a dangling binding->dev through the
leased queue (netkit) bind-tx path?
In netdev_nl_bind_tx_doit(), when the target is a NETMEM_TX_NO_DMA
leasee, netdev_find_netmem_tx_dev() finds the physical device. It reads
the lease without taking the physical device's lock. It also only checks
netif_device_present(), and the unregister path never clears that:
net/core/netdev-genl.c:netdev_find_netmem_tx_dev() {
...
phys_dev = lease_rxq->dev;
if (netif_device_present(phys_dev) &&
phys_dev->netmem_tx == NETMEM_TX_DMA)
return phys_dev;
...
}
The bind then goes ahead without rechecking bind_dev->reg_state:
net/core/netdev-genl.c:netdev_nl_bind_tx_doit() {
...
if (bind_dev != netdev)
netdev_lock(bind_dev);
dma_dev = netdev_queue_get_dma_dev(bind_dev, 0, NETDEV_QUEUE_TYPE_TX);
binding = net_devmem_bind_dmabuf(bind_dev,
...
}
On the direct path, netdev_get_by_index_lock()->netdev_put_lock() rejects
reg_state > NETREG_REGISTERED. Nothing does the same check for bind_dev
here.
The sequence seems to be:
1. The physical device P unregisters.
unregister_netdevice_many_notify() sets P->reg_state to
NETREG_UNREGISTERING and calls the NETDEV_UNREGISTER notifiers.
2. The netdev-genl notifier runs before netkit's, because it was
registered earlier with equal priority. It calls
net_devmem_dev_unregister(P) under netdev_lock(P).
3. A concurrent unprivileged bind-tx on netkit already holds netkit's
lock and is blocked in netdev_lock(P). It now continues. The lease is
still in place, so it creates a binding with dev = P and
vdev = netkit, maps the dmabuf, and marks the binding LIVE.
4. netkit_check_lease_unregister(P) unregisters netkit. In
net_devmem_dev_unregister(netkit)->net_devmem_dev_unregister_tx(),
binding->dev is P, so only the branch above runs and only
binding->vdev is cleared.
5. netdev_run_todo() sets P->reg_state to NETREG_UNREGISTERED. Any
rebroadcast NETDEV_UNREGISTER then returns early at:
if (dev->reg_state != NETREG_UNREGISTERING)
return;
net_devmem_bind_dmabuf() sets binding->dev = dev without taking a
netdev_hold(), so P can be freed.
6. When the socket closes, netdev_nl_sock_priv_destroy() reads the stale
binding->dev and calls netdev_hold() and netdev_lock() on it. This is
the same oops quoted in the commit message. The dma_buf also stays
attached to the removed device until the final free.
NETDEV_CMD_BIND_TX is unprivileged. Hitting this needs a race with the
physical device's unregistration. That is still the path the commit
message and the 1abe839b34ae Fixes: tag say this patch fixes. Later
patches in the series don't appear to touch net/ or drivers/net/netkit.c
to address it.
Would it make sense to recheck bind_dev->reg_state after
netdev_lock(bind_dev) in netdev_nl_bind_tx_doit()? Extending the
unregister walk doesn't look like it can close this window on its own.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261014161754.3782346-1-almasrymina%40google.com
next prev parent reply other threads:[~2026-10-15 19:21 UTC|newest]
Thread overview: 8+ 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 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 [this message]
2026-10-14 16:17 ` [PATCH net v3 3/4] netdevsim: support devmem RX and TX bindings Mina Almasry
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=179209206664.434549.4640692175922263115@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=almasrymina@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=ap420073@gmail.com \
--cc=asml.silence@gmail.com \
--cc=bobbyeshleman@meta.com \
--cc=christian.koenig@amd.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=dtatulea@nvidia.com \
--cc=dw@davidwei.uk \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kaifengw@google.com \
--cc=kaiyuanz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tariqt@nvidia.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox