net: devmem: fix RX and TX binding teardown on device unregistration
Subsystems (6)
v5 cover net: devmem: fix RX and TX binding teardown on device unregistration
Fix two device-unregistration lifecycle bugs in devmem TCP bindings and add netdevsim support plus selftests covering both RX and TX device unregistration. These issues were found via LLM-assisted code review (Sashiko) and reproduced and verified with the new nl_netdev.py selftests on netdevsim (not tested on real hardware):
1. net: devmem: unmap dma_buf synchronously on queue uninstall Synchronously unmap and detach binding->attachment under binding->lock when the last RX queue is uninstalled in mp_dmabuf_devmem_uninstall() or closed in net_devmem_unbind_dmabuf(), and unmap remaining unbound RX bindings on NETDEV_UNREGISTER, preventing slab-use-after-free in dma_unmap_sg_attrs() when the binding is freed after dma_dev. Factor out net_devmem_lock_dev() and net_devmem_unlock_dev() to synchronize netdev_nl_sock_priv_destroy() and __net_devmem_dmabuf_binding_free() against NETDEV_UNREGISTER.
2. net: devmem: detach TX bindings on NETDEV_UNREGISTER Extend net_devmem_dev_unregister() to fully detach and unmap TX bindings when binding->dev unregisters, or clear binding->vdev alone when only a virtual device unregisters while binding->dev lives.
3. netdevsim: support devmem RX and TX bindings
Enable PP_FLAG_DMA_MAP | PP_FLAG_ALLOW_UNREADABLE_NETMEM, 64-bit DMA mask on nsim_bus_dev, and NETMEM_TX_DMA on netdevsim so devmem RX/TX bindings can be exercised in software selftests.
4. selftests: net: add devmem RX and TX netdev unregister tests Add devmem_bind_rx_unregister_check and devmem_bind_tx_unregister_check to tools/testing/selftests/net/nl_netdev.py.
---
v5:
- Rebase onto net after the net-next merge and state how the issues were discovered and tested (Jakub).
- 1/4: Inline net_devmem_dev_unregister_rx() into
net_devmem_dev_unregister() (Stanislav). Factor out
net_devmem_lock_dev() and net_devmem_unlock_dev() and clear binding->dev after unmapping and re-acquiring the xarray lock so __net_devmem_dmabuf_binding_free() cannot free the binding while net_devmem_dev_unregister() is still accessing it, and reject RX devmem net_iovs in validate_xmit_unreadable_skb() (Sashiko).
- 2/4: Inline the TX unregistration check into net_devmem_dev_unregister() (Stanislav), clear binding->vdev under the xarray lock, and lock binding->dev in __net_devmem_dmabuf_binding_free() for TX bindings as
well (Sashiko).
- 3/4: Configure the DMA mask and dma_parms in nsim_bus_probe() gated on dma_pci_p2pdma_supported(), require PP_DMA_INDEX_BITS before setting PP_FLAG_DMA_MAP, check for NULL ns->rq in nsim_pp_hold_write(), and drop unreadable or net_iov skbs at the start of nsim_start_xmit() (Sashiko).
- 4/4: Tolerate non-UTF-8 dma-buf names in debugfs bufinfo (Sashiko).
- Link to v4: https://lore.kernel.org/netdev/[email protected]/
v4:
- 1/4: Unmap RX bindings in net_devmem_unbind_dmabuf() once their queues
are closed, and make netif_mp_close_rxq() report queue restart
failures, so the NETDEV_UNREGISTER walk only handles bindings whose
queue failed to restart. Drop net_devmem_lock: walk the bindings under
the xarray lock and take the instance lock of binding->dev in the
final free. (Stanislav) Record a queue in bound_rxqs before opening
it. (Sashiko)
- 2/4: Detach and unmap TX bindings directly from the walk, without a
grace period or a second pass. (Stanislav)
- Link to v3: https://lore.kernel.org/netdev/[email protected]/
v3:
- 1/4: Run the NETDEV_UNREGISTER walk under the netdev instance lock,
and skip it when the device only moves to another netns. (Sashiko)
- 2/4: Detach all matching TX bindings, then synchronize_net() once
before unmapping them. (Sashiko)
- 3/4: Only request page pool DMA mapping with CONFIG_HAS_DMA, refuse
pp_hold on memory provider pools, and drop unreadable skbs in the
software PSP checksum path. (Sashiko)
- 4/4: Check only the test's dma-buf in debugfs, skip instead of passing silently, clean up on errors, compute UDMABUF_CREATE per arch, and
add the needed config options. (Sashiko, Dragos)
- Link to v2: https://lore.kernel.org/netdev/[email protected]/
v2:
- 1/4: Don't unmap when a leased queue is unleased. Keep bindings in net_devmem_dmabuf_bindings until freed, hidden from TX lookups by an
xarray mark, and unmap unbound RX bindings on NETDEV_UNREGISTER. Update
the binding->lock and binding->ref comments. (Sashiko)
- 2/4: Detach TX bindings from the same net_devmem_lock-protected walk,
which now also covers unbound TX bindings, and clear the LIVE mark
instead of erasing the ID. The walk no longer uses RCU or takes
binding references (Stanislav).
- Link to v1: https://lore.kernel.org/netdev/[email protected]/
Mina Almasry (4):
net: devmem: unmap dma_buf synchronously on queue uninstall
net: devmem: detach TX bindings on NETDEV_UNREGISTER
netdevsim: support devmem RX and TX bindings
selftests: net: add devmem RX and TX netdev unregister tests
drivers/net/netdevsim/bus.c | 9 ++ drivers/net/netdevsim/netdev.c | 33 ++++- drivers/net/netdevsim/netdevsim.h | 1 + include/net/page_pool/memory_provider.h | 4 +- net/core/dev.c | 4 +- net/core/devmem.c | 181 +++++++++++++++++++---- net/core/devmem.h | 37 ++++- net/core/netdev-genl.c | 16 +- net/core/netdev_rx_queue.c | 26 ++-- tools/testing/selftests/net/config | 4 + tools/testing/selftests/net/nl_netdev.py | 125 +++++++++++++++- 11 files changed, 373 insertions(+), 67 deletions(-)
base-commit: 5838f10563d58afca6711edb5e4eda968ca181d9
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH v5 1/4 net: devmem: unmap dma_buf synchronously on queue uninstall
When a bound net_device is unregistered while userspace still holds a netlink or TCP socket reference on a devmem binding, mp_dmabuf_devmem_uninstall() clears binding->dev to NULL so netdev_nl_sock_priv_destroy() will not touch the unregistered net_device, but leaves the dma_buf attachment mapped until __net_devmem_dmabuf_binding_free() runs later on socket close.
Because dma_buf_dynamic_attach() does not take a reference on dma_dev, device removal frees dma_dev while the attachment is still mapped. Closing the netlink socket afterwards triggers a slab use-after-free in dma_unmap_sg_attrs():
BUG: KASAN: slab-use-after-free in dma_unmap_sg_attrs+0x76/0x2b0 Read of size 8 at addr ffff88810fae64b0 by task kworker/3:1/53 Workqueue: events __net_devmem_dmabuf_binding_free Call Trace: dma_unmap_sg_attrs+0x76/0x2b0 unmap_udmabuf+0x8e/0x100 dma_buf_unmap_attachment+0x145/0x330 dma_buf_unmap_attachment_unlocked+0x96/0x130 __net_devmem_dmabuf_binding_free+0x156/0x2e0 Freed by task 9: kfree+0x1b8/0x550 nsim_bus_dev_release+0xe/0x60 device_release+0xcf/0x250
Add net_devmem_dmabuf_binding_unmap() serialized under binding->lock and null out binding->sgt and binding->attachment after unmapping so unmapping is idempotent across queue uninstall and deferred binding destruction. Call it synchronously when the last bound RX queue is uninstalled in mp_dmabuf_devmem_uninstall(), except when a leased queue is unleased: the physical device is still registered and, if restarting its queue failed, may still be using the binding.
The same use-after-free happens when the netlink socket is closed before the device is removed but RX tokens keep the binding alive. Once its queues are closed, nothing DMAs into an RX binding anymore and the outstanding tokens only need the net_iovs, so unmap it in net_devmem_unbind_dmabuf(), and reject RX devmem net_iovs in validate_xmit_unreadable_skb(). Make netif_mp_close_rxq() return an error when a queue failed to restart and may still be using the binding. Such a binding stays mapped and keeps binding->dev. Record a queue in bound_rxqs before opening it, so that a failed bind never leaves a queue using the binding without unbind knowing about it.
Keep bindings in net_devmem_dmabuf_bindings until they are freed and hide unbound ones from TX lookups with an xarray mark, so that on NETDEV_UNREGISTER the remaining unbound RX bindings of the device can be found, detached and unmapped, unless the device is a virtual device leasing queues, for the same reason as above. The walk runs under the device's instance lock and is skipped when the device only moves to another netns. Factor out net_devmem_lock_dev() and net_devmem_unlock_dev() and use them in both netdev_nl_sock_priv_destroy() and __net_devmem_dmabuf_binding_free(), so a binding the walk finds under the xarray lock stays alive while it is detached.
This issue was found via LLM-assisted code review (Sashiko) and reproduced and verified with the new nl_netdev.py selftest on netdevsim (not tested on real hardware).
---
v5:
- Inline net_devmem_dev_unregister_rx() into net_devmem_dev_unregister() (Stanislav).
- Factor out net_devmem_lock_dev() and net_devmem_unlock_dev() and clear binding->dev after unmapping and re-acquiring the xarray lock so __net_devmem_dmabuf_binding_free() cannot free the binding while net_devmem_dev_unregister() is still accessing it (Sashiko).
- Reject RX devmem net_iovs in validate_xmit_unreadable_skb() so an RX binding is not unmapped while its net_iovs are in flight on TX (Sashiko).
v4:
- Unmap RX bindings in net_devmem_unbind_dmabuf() once their queues are closed, and make netif_mp_close_rxq() report queue restart failures. The NETDEV_UNREGISTER walk only handles bindings whose queue failed to restart (Stanislav).
- Drop net_devmem_lock. Walk the bindings under the xarray lock, and take the instance lock of binding->dev in the final free (Stanislav).
- Record a queue in bound_rxqs before opening it, so unbind knows about every queue using the binding (Sashiko).
v3:
- Run the NETDEV_UNREGISTER walk under the netdev instance lock so it cannot race with net_devmem_unbind_dmabuf() (Sashiko).
- Skip the walk when the device only moves to another netns (Sashiko).
v2:
- Don't unmap when a leased queue is unleased (Sashiko).
- Unmap unbound RX bindings on NETDEV_UNREGISTER; keep bindings in net_devmem_dmabuf_bindings until freed, hidden from TX lookups by NET_DEVMEM_BINDING_LIVE (Sashiko).
- Update the binding->lock and binding->ref comments (Sashiko).
--- include/net/page_pool/memory_provider.h | 4 +- net/core/dev.c | 4 +- net/core/devmem.c | 173 ++++++++++++++++++++---- net/core/devmem.h | 31 ++++- net/core/netdev-genl.c | 16 +-- net/core/netdev_rx_queue.c | 26 ++-- 6 files changed, 198 insertions(+), 56 deletions(-)
include/net/page_pool/memory_provider.h +2 -2
@@ -36,8 +36,8 @@ void net_mp_niov_clear_page_pool(struct net_iov *niov);int netif_mp_open_rxq (struct net_device *dev,unsigned int rxq_idx,const struct pp_memory_provider_params *p,struct netlink_ext_ack *extack); -void netif_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx, -const struct pp_memory_provider_params *old_p); +int netif_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx, +const struct pp_memory_provider_params *old_p);/** * net_mp_netmem_place_in_cache() - give a netmem to a page pool
net/core/dev.c +3 -1
@@ -4181,10 +4181,12 @@ static struct sk_buff *validate_xmit_unreadable_skb(struct sk_buff *skb, shinfo =skb_shinfo (skb); +/* All net_iovs in an unreadable skb share the same binding. */ if (shinfo->nr_frags >0 ) { niov =netmem_to_net_iov (skb_frag_netmem (&shinfo->frags[0 ]));if (net_is_devmem_iov (niov) && -READ_ONCE (net_devmem_iov_binding (niov)->dev) != dev) + (net_devmem_iov_binding (niov)->direction !=DMA_TO_DEVICE || +READ_ONCE (net_devmem_iov_binding (niov)->dev) != dev)) goto out_free; }
net/core/devmem.c +146 -27
259 lines not on this page · raw message
net/core/devmem.h +28 -3
@@ -21,7 +21,9 @@ struct net_devmem_dmabuf_binding {struct dma_buf *dmabuf;struct dma_buf_attachment *attachment;struct sg_table *sgt; -/* Physical NIC that does the actual DMA for this binding. */ +/* Physical NIC that does the actual DMA for this binding. Set at bind +* time and cleared to NULL under netdev_lock(dev). +*/ struct net_device *dev;/* Opaque cookie identifying the virtual device (e.g. netkit) the user * called bind-tx on. Used only for pointer comparison. Never
@@ -30,7 +32,7 @@ struct net_devmem_dmabuf_binding {void *vdev;possible_net_t net;kuid_t uid; -/* Protect dev */ +/* Serialize net_devmem_dmabuf_binding_unmap() on attachment and sgt */ struct mutex lock;/* The user holds a ref (via the netlink API) for as long as they want
@@ -41,7 +43,8 @@ struct net_devmem_dmabuf_binding {* * The binding undos itself and unmaps the underlying dmabuf once all * those refs are dropped and the binding is no longer desired or in -* use. +* use. RX bindings are unmapped earlier when their queues are closed or +* uninstalled, unless a leased or busy queue may still use the binding. * * net_devmem_net_iov_inc_ref() on dmabuf net_iovs will increment this * reference, making sure that the binding remains alive until all the
@@ -94,7 +97,13 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,const struct sock *nl_sk, struct netlink_ext_ack *extack);struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf (u32 id); +struct net_device * +net_devmem_lock_dev (struct net_devmem_dmabuf_binding *binding, +netdevice_tracker *dev_tracker); +void net_devmem_unlock_dev (struct net_device *dev, +netdevice_tracker *dev_tracker);void net_devmem_unbind_dmabuf (struct net_devmem_dmabuf_binding *binding); +void net_devmem_dev_unregister (struct net_device *dev);int net_devmem_bind_dmabuf_to_queue (struct net_device *dev,u32 rxq_idx,struct net_devmem_dmabuf_binding *binding,struct netlink_ext_ack *extack);
@@ -177,11 +186,27 @@ static inline struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)return NULL ; } +static inline struct net_device * +net_devmem_lock_dev (struct net_devmem_dmabuf_binding *binding, +netdevice_tracker *dev_tracker) +{ +return NULL ; +} + +static inline void +net_devmem_unlock_dev (struct net_device *dev,netdevice_tracker *dev_tracker) +{ +} +static inline void net_devmem_unbind_dmabuf (struct net_devmem_dmabuf_binding *binding) { } +static inline void net_devmem_dev_unregister (struct net_device *dev) +{ +} + static inline int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, struct net_devmem_dmabuf_binding *binding,
net/core/netdev-genl.c +3 -13
@@ -1476,20 +1476,9 @@ void netdev_nl_sock_priv_destroy(struct netdev_nl_sock *priv)mutex_lock (&priv->lock);list_for_each_entry_safe (binding, temp, &priv->bindings, list) { -mutex_lock (&binding->lock); - dev = binding->dev; -if (!dev) { -mutex_unlock (&binding->lock); -net_devmem_unbind_dmabuf (binding); -continue ; - } -netdev_hold (dev, &dev_tracker,GFP_KERNEL ); -mutex_unlock (&binding->lock); - -netdev_lock (dev); + dev =net_devmem_lock_dev (binding, &dev_tracker);net_devmem_unbind_dmabuf (binding); -netdev_unlock (dev); -netdev_put (dev, &dev_tracker); +net_devmem_unlock_dev (dev, &dev_tracker); }mutex_unlock (&priv->lock); }
@@ -1513,6 +1502,7 @@ static int netdev_genl_netdevice_event(struct notifier_block *nb,if (READ_ONCE (netdev->reg_state) ==NETREG_UNREGISTERED )break ;netdev_lock (netdev); +net_devmem_dev_unregister (netdev);netdev_genl_dev_notify (netdev,NETDEV_CMD_DEV_DEL_NTF );netdev_unlock (netdev);break ;
net/core/netdev_rx_queue.c +16 -10
@@ -275,8 +275,8 @@ int netif_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx,return ret; } -static void __netif_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx, -const struct pp_memory_provider_params *old_p) +static int __netif_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx, +const struct pp_memory_provider_params *old_p) {struct netdev_queue_config qcfg[2 ];struct netdev_rx_queue *rxq;
@@ -289,35 +289,41 @@ static void __netif_mp_close_rxq(struct net_device *dev, unsigned int rxq_idx,*/ if (dev->reg_state >NETREG_REGISTERED && !rxq->mp_params.mp_ops) -return ; +return 0 ;if (WARN_ON_ONCE (rxq->mp_params.mp_ops != old_p->mp_ops || rxq->mp_params.mp_priv != old_p->mp_priv)) -return ; +return -EINVAL ;netdev_queue_config (dev, rxq_idx, &qcfg[0 ]);memset (&rxq->mp_params,0 ,sizeof (rxq->mp_params));netdev_queue_config (dev, rxq_idx, &qcfg[1 ]); err =netdev_rx_queue_reconfig (dev, rxq_idx, &qcfg[0 ], &qcfg[1 ]); -WARN_ON (err && err != -ENETDOWN ); +if (err == -ENETDOWN ) +return 0 ; +WARN_ON (err); +return err; } -void netif_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx, -const struct pp_memory_provider_params *old_p) +int netif_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx, +const struct pp_memory_provider_params *old_p) { +int ret; +if (WARN_ON_ONCE (rxq_idx >= dev->real_num_rx_queues)) -return ; +return -EINVAL ;if (!netif_rxq_is_leased (dev, rxq_idx))return __netif_mp_close_rxq (dev, rxq_idx, old_p);if (!__netif_get_rx_queue_lease (&dev, &rxq_idx,NETIF_VIRT_TO_PHYS )) {WARN_ON_ONCE (1 ); -return ; +return -EINVAL ; }netdev_lock (dev); -__netif_mp_close_rxq (dev, rxq_idx, old_p); + ret =__netif_mp_close_rxq (dev, rxq_idx, old_p);netdev_unlock (dev); +return ret; } void __netif_mp_uninstall_rxq(struct netdev_rx_queue *rxq,
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewRe: [PATCH net v5 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: devmem: leased RX bindings never unmapped before dma_dev is freed --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: devmem: leased RX bindings never unmapped before dma_dev is freed --
commit b250f1e4ffd826ff4e6f5c24e078e06c36365baf
Author: Mina Almasry <[email protected]>
net: devmem: unmap dma_buf synchronously on queue uninstall
This patch adds synchronous dma_buf unmapping when RX queues are closed, uninstalled, or when the bound net_device is unregistered, to avoid a slab use-after-free in dma_unmap_sg_attrs() if dma_dev is freed while the devmem binding is still alive.
Quoted 4 lines
net/core/devmem.c +0
-0
[ ... ]
Quoted 43 lines
net/core/devmem.c +33
-1@@ -143,12 +228,45 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) rxq_idx =get_netdev_rx_queue_index (rxq); -netif_mp_close_rxq (binding->dev, rxq_idx, &mp_params); +if (netif_mp_close_rxq (binding->dev, rxq_idx, &mp_params)) + busy = true; + } + +if (binding->direction ==DMA_FROM_DEVICE && binding->dev && !busy) { +net_devmem_dmabuf_binding_unmap (binding); +WRITE_ONCE (binding->dev,NULL ); }percpu_ref_kill (&binding->ref); } +void net_devmem_dev_unregister (struct net_device *dev) +{ +struct net_devmem_dmabuf_binding *binding; +unsigned long xa_idx; + +netdev_assert_locked (dev); + +if (dev->reg_state !=NETREG_UNREGISTERING ) +return ; + +xa_lock (&net_devmem_dmabuf_bindings); +xa_for_each (&net_devmem_dmabuf_bindings, xa_idx, binding) { +if (binding->direction !=DMA_FROM_DEVICE || +READ_ONCE (binding->dev) != dev || +xa_get_mark (&net_devmem_dmabuf_bindings, xa_idx, +NET_DEVMEM_BINDING_LIVE )) +continue ; + +xa_unlock (&net_devmem_dmabuf_bindings); +if (!netif_is_queue_leasee (dev)) +net_devmem_dmabuf_binding_unmap (binding); +xa_lock (&net_devmem_dmabuf_bindings); +WRITE_ONCE (binding->dev,NULL ); + } +xa_unlock (&net_devmem_dmabuf_bindings); +}
[ ... ]
Quoted 16 lines
net/core/devmem.c +3
-9@@ -551,16 +669,17 @@ 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 ; +
net/core/devmem.c static void mp_dmabuf_devmem_uninstall(void *mp_priv, · line 684
Quoted 10 lines
net/core/devmem.c +7
-0+xa_erase (&binding->bound_rxqs, xa_idx); +if (xa_empty (&binding->bound_rxqs)) { +if (!rxq->lease) +net_devmem_dmabuf_binding_unmap (binding); +ASSERT_EXCLUSIVE_WRITER (binding->dev); +WRITE_ONCE (binding->dev,NULL ); } +break ; } }
[Severity: High]
As reported by Sashiko on v2 [1], for an RX binding on a leased queue (for example via netkit), can the binding still be left mapped after the backing physical device is unregistered and its dma_dev is freed?
When netdev_nl_bind_rx_doit() binds to a virtual queue-leasee device, the dmabuf is attached to the physical device's dma_dev, but binding->dev is set to the virtual device and net_devmem_bind_dmabuf_to_queue() records the virtual rxq in binding->bound_rxqs while netif_mp_open_rxq() installs mp_params on the physical rxq.
When the virtual device unregisters (either directly or via netkit_check_lease_unregister() when the physical device unregisters), ndo_uninit runs:
netkit_uninit()
netkit_queue_unlease()
netdev_rx_queue_unlease(virt_rxq, phys_rxq)
netif_rxq_cleanup_unlease(phys_rxq, virt_rxq)
__netif_mp_close_rxq(phys_rxq->dev, rxq_idx, &p)
__netif_mp_uninstall_rxq(virt_rxq, &p)
mp_dmabuf_devmem_uninstall(binding, virt_rxq)Because netdev_rx_queue_unlease() only clears rxq_src->lease and rxq_dst->lease after netif_rxq_cleanup_unlease() returns:
net/core/netdev_rx_queue.c:netdev_rx_queue_unlease() {
...
netif_rxq_cleanup_unlease(rxq_src, rxq_dst); WRITE_ONCE(rxq_src->lease, NULL);
WRITE_ONCE(rxq_dst->lease, NULL);
...}
rxq->lease is still non-NULL in mp_dmabuf_devmem_uninstall(), so it skips net_devmem_dmabuf_binding_unmap(binding) while emptying binding->bound_rxqs and setting binding->dev to NULL. If the netlink socket is closed afterwards, net_devmem_unbind_dmabuf() sees binding->dev == NULL and also skips unmapping.
Similarly, if the netlink socket was closed earlier and netif_mp_close_rxq() failed (busy == true), net_devmem_dev_unregister() on the virtual device skips net_devmem_dmabuf_binding_unmap(binding) because netif_is_queue_leasee(dev) is true, and then clears binding->dev to NULL.
In both cases, when the physical device finishes unregistering, dev_memory_provider_uninstall() and net_devmem_dev_unregister() on the physical device cannot find or unmap the binding because binding->bound_rxqs is empty and binding->dev was the virtual device (and is now NULL). Once the physical device frees its dma_dev, won't __net_devmem_dmabuf_binding_free() later hit the same slab use-after-free in dma_unmap_sg_attrs()?
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH net v5 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
In reply to Mina AlmasryThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 (1) · 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 dma_dev use-after-free this patch says it fixes can still happen for RX bindings made on a virtual device that leases queues,…
Pre-existing issues:
- [Medium] At this commit, net_devmem_dev_unregister() skips TX (DMA_TO_DEVICE) bindings.
--
net: devmem: unmap dma_buf synchronously on queue uninstall
This commit unmaps RX devmem dma_buf bindings earlier: when the last bound RX queue is uninstalled, when the binding is unbound, or on NETDEV_UNREGISTER. Previously the unmap waited until the final binding free. Bindings now stay in the global xarray until they are freed, with an xarray mark hiding unbound ones from TX lookups, and netif_mp_close_rxq() now reports queue restart failures. The aim is to avoid a use-after-free of dma_dev in dma_unmap_sg_attrs() after the device is removed.
Quoted 4 lines
net/core/devmem.c +0
-0
[ ... ]
Quoted 24 lines
net/core/devmem.c +14
-1@@ -143,12 +228,45 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) rxq_idx =get_netdev_rx_queue_index (rxq); -netif_mp_close_rxq (binding->dev, rxq_idx, &mp_params); +if (netif_mp_close_rxq (binding->dev, rxq_idx, &mp_params)) + busy = true; + } + +if (binding->direction ==DMA_FROM_DEVICE && binding->dev && !busy) { +net_devmem_dmabuf_binding_unmap (binding); +WRITE_ONCE (binding->dev,NULL ); }percpu_ref_kill (&binding->ref); } +void net_devmem_dev_unregister (struct net_device *dev) +{ +struct net_devmem_dmabuf_binding *binding; +unsigned long xa_idx; + +netdev_assert_locked (dev); +
net/core/devmem.c void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) · line 259
Quoted 10 lines
net/core/devmem.c +10
-0+if (dev->reg_state !=NETREG_UNREGISTERING ) +return ; + +xa_lock (&net_devmem_dmabuf_bindings); +xa_for_each (&net_devmem_dmabuf_bindings, xa_idx, binding) { +if (binding->direction !=DMA_FROM_DEVICE || +READ_ONCE (binding->dev) != dev || +xa_get_mark (&net_devmem_dmabuf_bindings, xa_idx, +NET_DEVMEM_BINDING_LIVE )) +continue ;
[Severity: Medium]
This issue was not introduced by this patch, but at this commit TX (DMA_TO_DEVICE) bindings are skipped here. Their binding->dev is never cleared, and they stay mapped until __net_devmem_dmabuf_binding_free().
That has three consequences. The deferred dma_unmap_sg_attrs() can run on a freed dma_dev. netdev_nl_sock_priv_destroy()->net_devmem_lock_dev() can call netdev_hold() and netdev_lock() on a freed net_device. And the invariant in the new net_devmem_lock_dev() kernel-doc does not hold for TX bindings.
The old netdev_nl_sock_priv_destroy() already called netdev_hold() on a stale TX binding->dev, so this predates the patch. The next patch in the series, "net: devmem: detach TX bindings on NETDEV_UNREGISTER", appears to fix it. That patch clears the LIVE mark, unmaps the binding and clears dev and vdev for TX bindings with binding->dev == dev. It also calls net_devmem_lock_dev() in __net_devmem_dmabuf_binding_free() for both directions.
Quoted 9 lines
net/core/devmem.c +9
-0+ +xa_unlock (&net_devmem_dmabuf_bindings); +if (!netif_is_queue_leasee (dev)) +net_devmem_dmabuf_binding_unmap (binding); +xa_lock (&net_devmem_dmabuf_bindings); +WRITE_ONCE (binding->dev,NULL ); + } +xa_unlock (&net_devmem_dmabuf_bindings); +}
[ ... ]
Quoted 16 lines
net/core/devmem.c +3
-9@@ -551,16 +669,17 @@ 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 ; +
net/core/devmem.c static void mp_dmabuf_devmem_uninstall(void *mp_priv, · line 684
Quoted 10 lines
net/core/devmem.c +7
-0+xa_erase (&binding->bound_rxqs, xa_idx); +if (xa_empty (&binding->bound_rxqs)) { +if (!rxq->lease) +net_devmem_dmabuf_binding_unmap (binding); +ASSERT_EXCLUSIVE_WRITER (binding->dev); +WRITE_ONCE (binding->dev,NULL ); } +break ; } }
[Severity: High]
Can the dma_dev use-after-free still happen for an RX binding made on a virtual device that leases queues, such as netkit leasing from a physical NIC?
In that case binding->dev is the netkit device and bound_rxqs holds the netkit rxq. dma_dev is the physical NIC's DMA device, which netdev_queue_get_dma_dev() finds by following the lease.
On unlease, the call chain is:
netkit_uninit()
netkit_queue_unlease()
netdev_rx_queue_unlease()
netif_rxq_cleanup_unlease()
__netif_mp_close_rxq(phys_rxq->dev, rxq_idx, &p);
__netif_mp_uninstall_rxq(virt_rxq, &p);
mp_dmabuf_devmem_uninstall()The lease pointers are cleared only after the cleanup returns:
net/core/netdev_rx_queue.c:netdev_rx_queue_unlease() {
...
netif_rxq_cleanup_unlease(rxq_src, rxq_dst);
WRITE_ONCE(rxq_src->lease, NULL);
WRITE_ONCE(rxq_dst->lease, NULL);
...
}So rxq->lease is always non-NULL here. The unmap is skipped, but binding->dev is still set to NULL. netif_rxq_cleanup_unlease() also ignores the new return value of __netif_mp_close_rxq(), so even a successful close of the physical queue leaves the mapping in place.
After this, which path unmaps the binding?
net_devmem_unbind_dmabuf() unmaps only when binding->dev is non-NULL.
net_devmem_dev_unregister() on the physical device matches only binding->dev == dev, so it never finds this binding.
dev_memory_provider_uninstall() on the physical device calls uninstall with the physical rxq. That never matches the netkit rxq stored in bound_rxqs.
The binding then stays mapped until __net_devmem_dmabuf_binding_free(). If the NIC was removed before that, the call to dma_buf_unmap_attachment()->dma_unmap_sg_attrs() uses the freed physical dma_dev. This is the same KASAN trace quoted in the commit message.
There are two ways to reach this:
Remove the physical NIC while the netlink socket is still open. netkit_check_lease_unregister() runs from the physical device's NETDEV_UNREGISTER and unregisters netkit. The unlease therefore runs while the physical device is NETREG_UNREGISTERING, which seems to contradict this part of the commit message:
"except when a leased queue is unleased: the physical device is still registered and, if restarting its queue failed, may still be using the binding."
Delete netkit first. The physical queue close succeeds, but the unmap is skipped anyway. If the physical NIC is removed later, while the socket or RX tokens still hold the binding, the deferred unmap runs on the freed device.
The leasee branch in net_devmem_dev_unregister() has the same problem. It skips the unmap when netif_is_queue_leasee(dev) is true but still clears binding->dev, so nothing can unmap the binding before the physical device goes away.
Could the lease case decide whether to unmap based on whether the physical queue close succeeded, instead of skipping the unmap whenever rxq->lease is set?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261030083539.777877-1-almasrymina%40google.com
Re: [PATCH net v5 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
Quoted 6 lines · On Sun, Nov 1, 2026 at 3:01 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 (1) · Low: 0
Quoted 9 lines
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
dma_devuse-after-free this patch says it fixes can still happen for RX bindings made on a virtual device that leases queues,…
I know about the issues with leased devices. That needs a bit of a rework, which I have done locally, and would like to send out as a follow up fix.
--
Thanks,
Mina
Paolo Abeni
maintainerRe: [PATCH net v5 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
Quoted 13 lines · Mina Almasry
Quoted 12 lines · On Sun, Nov 1, 2026 at 3:01 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 (1) · 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).
Quoted 7 lines
Quoted 3 lines
- [High] The
dma_devuse-after-free this patch says it fixes can still happen for RX bindings made on a virtual device that leases queues,…I know about the issues with leased devices. That needs a bit of a rework, which I have done locally, and would like to send out as a follow up fix.
Will such follow-up rework the code touched by current patch/series? how much? I'm under the impression that at least the fix for the issue reported here would be quite overlapping.
/P
Re: [PATCH net v5 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
Quoted 8 lines · Paolo Abeni
Quoted 6 lines · Mina Almasry
Quoted 4 lines · On Sun, Nov 1, 2026 at 3:01 PM <[email protected]> wrote:
- [High] The
dma_devuse-after-free this patch says it fixes can still happen for RX bindings made on a virtual device that leases queues,...
Quoted 8 lines
Quoted 3 lines
I know about the issues with leased devices. That needs a bit of a rework, which I have done locally, and would like to send out as a follow up fix.
Will such follow-up rework the code touched by current patch/series? how much? I'm under the impression that at least the fix for the issue reported here would be quite overlapping.
/P
I pushed the follow-up branch on top of v5 here so you can see the exact diff:
https://github.com/mina/linux/compare/devmem-teardown-v4...devmem-lease-bind-map-dev
(commits: https://github.com/mina/linux/commits/devmem-lease-bind-map-dev)
There is some overlap (~55 lines of v5 touched across a 6-patch +262/-99 follow-up): it renames binding->dev/vdev to binding->map_dev/bind_dev, passes the net_device explicitly to net_devmem_lock_dev(), factors out net_devmem_close_rxqs(), and replaces the !rxq->lease / !netif_is_queue_leasee() skips in net_devmem_dev_unregister() and mp_dmabuf_devmem_uninstall().
I kept it separate only to keep this net fix smaller and easier to review, since the lease issue is pre-existing. Happy to either land v5 first and send those 6 patches right after, or fold them into a v6 if you prefer avoiding the churn.
Signature · 2 lines
Thanks, Mina
Paolo Abeni
maintainerRe: [PATCH net v5 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
Quoted 27 lines · Mina Almasry
Quoted 7 lines · Paolo Abeni
Quoted 6 lines · Mina Almasry
Quoted 4 lines · On Sun, Nov 1, 2026 at 3:01 PM <[email protected]> wrote:
- [High] The
dma_devuse-after-free this patch says it fixes can still happen for RX bindings made on a virtual device that leases queues,...Quoted 8 lines
Quoted 3 lines
I know about the issues with leased devices. That needs a bit of a rework, which I have done locally, and would like to send out as a follow up fix.
Will such follow-up rework the code touched by current patch/series? how much? I'm under the impression that at least the fix for the issue reported here would be quite overlapping.
/P
I pushed the follow-up branch on top of v5 here so you can see the exact diff:
https://github.com/mina/linux/compare/devmem-teardown-v4...devmem-lease-bind-map-dev
(commits: https://github.com/mina/linux/commits/devmem-lease-bind-map-dev)There is some overlap (~55 lines of v5 touched across a 6-patch +262/-99 follow-up): it renames binding->dev/vdev to binding->map_dev/bind_dev, passes the
net_deviceexplicitly tonet_devmem_lock_dev(), factors outnet_devmem_close_rxqs(), and replaces the !rxq->lease / !netif_is_queue_leasee() skips innet_devmem_dev_unregister()andmp_dmabuf_devmem_uninstall().
Quoted 4 lines
I kept it separate only to keep this net fix smaller and easier to review, since the lease issue is pre-existing. Happy to either land v5 first and send those 6 patches right after, or fold them into a v6 if you prefer avoiding the churn.
I hoped for something smaller :)
I definitely would not fold the 2 series.
I'm wondering if this could be considered net-next material? pointing to net-next will offer better guarantees for all the work to land in the same release (no need to repost in such a case, I can apply this one to net-next directly).
/P
Re: [PATCH net v5 1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
Quoted 33 lines · Paolo Abeni
Quoted 27 lines · Mina Almasry
Quoted 7 lines · Paolo Abeni
Quoted 6 lines · Mina Almasry
Quoted 4 lines · On Sun, Nov 1, 2026 at 3:01 PM <[email protected]> wrote:
- [High] The
dma_devuse-after-free this patch says it fixes can still happen for RX bindings made on a virtual device that leases queues,...Quoted 8 lines
Quoted 3 lines
I know about the issues with leased devices. That needs a bit of a rework, which I have done locally, and would like to send out as a follow up fix.
Will such follow-up rework the code touched by current patch/series? how much? I'm under the impression that at least the fix for the issue reported here would be quite overlapping.
/P
I pushed the follow-up branch on top of v5 here so you can see the exact diff:
https://github.com/mina/linux/compare/devmem-teardown-v4...devmem-lease-bind-map-dev
(commits: https://github.com/mina/linux/commits/devmem-lease-bind-map-dev)There is some overlap (~55 lines of v5 touched across a 6-patch +262/-99 follow-up): it renames binding->dev/vdev to binding->map_dev/bind_dev, passes the
net_deviceexplicitly tonet_devmem_lock_dev(), factors outnet_devmem_close_rxqs(), and replaces the !rxq->lease / !netif_is_queue_leasee() skips innet_devmem_dev_unregister()andmp_dmabuf_devmem_uninstall().Quoted 4 lines
I kept it separate only to keep this net fix smaller and easier to review, since the lease issue is pre-existing. Happy to either land v5 first and send those 6 patches right after, or fold them into a v6 if you prefer avoiding the churn.
Quoted 9 lines
I hoped for something smaller :)
I definitely would not fold the 2 series.
I'm wondering if this could be considered net-next material? pointing to net-next will offer better guarantees for all the work to land in the same release (no need to repost in such a case, I can apply this one to net-next directly).
I'm more than happy with net-next. Honestly so many AI-foudn fixes requiring so many refactors that net-next makes sense most of the time now, for me at least. Thank you Paolo!
Signature · 2 lines
Thanks, Mina
PATCH v5 2/4 net: devmem: detach TX bindings on NETDEV_UNREGISTER
In reply to Mina AlmasryTX devmem bindings (NETDEV_CMD_BIND_TX) have no bound RX queues, so mp_dmabuf_devmem_uninstall() never runs when binding->dev or binding->vdev unregisters. As a result, binding->dev and binding->vdev dangle pointing to freed struct net_device memory, and the dma_buf remains attached and mapped after device removal.
Closing the netlink socket after netdev unregistration dereferences the freed struct net_device in netdev_nl_sock_priv_destroy():
BUG: unable to handle page fault for address: ffff88824ca9b000 Oops: Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:netdev_nl_sock_priv_destroy+0xbd/0x1e0 Call Trace: genl_release+0xf5/0x190 netlink_release+0xd01/0x18d0 __sock_release+0xb0/0x270 sock_close+0x18/0x20
Extend net_devmem_dev_unregister() and __net_devmem_dmabuf_binding_free() to TX bindings, including ones whose netlink socket is already closed but which TCP retransmits keep alive:
- When binding->dev (the physical DMA-capable device) unregisters, clear the binding's NET_DEVMEM_BINDING_LIVE mark, unmap the dma_buf, and clear both binding->vdev and binding->dev. No grace period is
needed: the device is already closed, so nothing hands the DMA addresses to the hardware anymore, and concurrent senders only compare against binding->dev.
- When only binding->vdev (virtual device) unregisters while binding->dev lives, only clear binding->vdev so no new TX sends match the virtual device while allowing in-flight TX packets on binding->dev to finish DMA safely.
This issue was found via LLM-assisted code review (Sashiko) and reproduced and verified with the new nl_netdev.py selftest on netdevsim (not tested on real hardware).
---
v5:
- Inline the TX unregistration check into net_devmem_dev_unregister() (Stanislav), and clear binding->vdev under the xarray lock (Sashiko).
- Lock binding->dev in __net_devmem_dmabuf_binding_free() for TX bindings as well now that net_devmem_dev_unregister() detaches them (Sashiko).
v4:
- Detach and unmap TX bindings directly from the xarray walk, without a grace period or a second pass (Stanislav).
v3:
- Detach all matching TX bindings first, then call synchronize_net() once before unmapping them, instead of once per binding. Don't wait for a grace period when only binding->vdev is cleared, since vdev is never dereferenced (Sashiko).
- Don't detach TX bindings when the device only moves to another netns (Sashiko).
v2:
- Build on the net_devmem_dev_unregister() walk from the previous patch, so unbound TX bindings are also detached (Sashiko). Clear the binding's LIVE mark instead of erasing its ID.
- The walk holds net_devmem_lock, which the final free also takes before erasing the binding, instead of using RCU and percpu_ref_tryget(), so it no longer takes a binding reference (Stanislav).
--- net/core/devmem.c | 24 ++++++++++++++++-------- net/core/devmem.h | 6 ++++-- 2 files changed, 20 insertions(+), 10 deletions(-)
net/core/devmem.c +16 -8
@@ -149,7 +149,7 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) {struct net_devmem_dmabuf_binding *binding =container_of (wq,typeof (*binding), unbind_w);netdevice_tracker dev_tracker; -struct net_device *dev =NULL ; +struct net_device *dev;if (binding->freelist) WARN(binding->free_count != binding->area.num_niovs,
@@ -157,8 +157,7 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) binding->area.num_niovs, binding->free_count);kvfree (binding->area.niovs); -if (binding->direction ==DMA_FROM_DEVICE ) - dev =net_devmem_lock_dev (binding, &dev_tracker); + dev =net_devmem_lock_dev (binding, &dev_tracker);net_devmem_dmabuf_binding_unmap (binding);xa_erase (&net_devmem_dmabuf_bindings, binding->id);net_devmem_unlock_dev (dev, &dev_tracker);
@@ -252,11 +251,20 @@ void net_devmem_dev_unregister(struct net_device *dev)xa_lock (&net_devmem_dmabuf_bindings);xa_for_each (&net_devmem_dmabuf_bindings, xa_idx, binding) { -if (binding->direction !=DMA_FROM_DEVICE || -READ_ONCE (binding->dev) != dev || -xa_get_mark (&net_devmem_dmabuf_bindings, xa_idx, -NET_DEVMEM_BINDING_LIVE )) -continue ; +if (binding->direction ==DMA_FROM_DEVICE ) { +if (READ_ONCE (binding->dev) != dev || +xa_get_mark (&net_devmem_dmabuf_bindings, xa_idx, +NET_DEVMEM_BINDING_LIVE )) +continue ; + }else { +if (READ_ONCE (binding->vdev) == dev) +WRITE_ONCE (binding->vdev,NULL ); +if (READ_ONCE (binding->dev) != dev) +continue ; +WRITE_ONCE (binding->vdev,NULL ); +__xa_clear_mark (&net_devmem_dmabuf_bindings, xa_idx, +NET_DEVMEM_BINDING_LIVE ); + }xa_unlock (&net_devmem_dmabuf_bindings);if (!netif_is_queue_leasee (dev))
net/core/devmem.h +4 -2
@@ -26,8 +26,8 @@ struct net_devmem_dmabuf_binding {*/ struct net_device *dev;/* Opaque cookie identifying the virtual device (e.g. netkit) the user -* called bind-tx on. Used only for pointer comparison. Never -* dereferenced. +* called bind-tx on. Used only for pointer comparison via READ_ONCE() +* and cleared with WRITE_ONCE() on unregistration. Never dereferenced. */ void *vdev;possible_net_t net;
@@ -45,6 +45,8 @@ struct net_devmem_dmabuf_binding {* those refs are dropped and the binding is no longer desired or in * use. RX bindings are unmapped earlier when their queues are closed or * uninstalled, unless a leased or busy queue may still use the binding. +* TX bindings are also unmapped earlier if their device is +* unregistered. * * net_devmem_net_iov_inc_ref() on dmabuf net_iovs will increment this * reference, making sure that the binding remains alive until all the
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewRe: [PATCH net v5 2/4] net: devmem: detach TX bindings on NETDEV_UNREGISTER
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: devmem: UAF when netdev_nl_bind_tx_doit() races with phys_dev unregister --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: devmem: UAF when netdev_nl_bind_tx_doit() races with phys_dev unregister --
commit ccf551ffb7f8200a4b1a6abbb90f90e5db975e35
Author: Mina Almasry <[email protected]>
net: devmem: detach TX bindings on NETDEV_UNREGISTER
This commit extends net_devmem_dev_unregister() and __net_devmem_dmabuf_binding_free() to handle TX devmem bindings when a physical or virtual network device unregisters. When binding->dev unregisters, the binding is unmarked live, its dma_buf is unmapped, and both binding->vdev and binding->dev are cleared; when only binding->vdev unregisters, only binding->vdev is cleared.
Quoted 32 lines
net/core/devmem.c +2
-8@@ -149,7 +149,7 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) {struct net_devmem_dmabuf_binding *binding =container_of (wq,typeof (*binding), unbind_w);netdevice_tracker dev_tracker; -struct net_device *dev =NULL ; +struct net_device *dev;if (binding->freelist) WARN(binding->free_count != binding->area.num_niovs,@@ -157,8 +157,7 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) binding->area.num_niovs, binding->free_count);kvfree (binding->area.niovs); -if (binding->direction ==DMA_FROM_DEVICE ) - dev =net_devmem_lock_dev (binding, &dev_tracker); + dev =net_devmem_lock_dev (binding, &dev_tracker);net_devmem_dmabuf_binding_unmap (binding);xa_erase (&net_devmem_dmabuf_bindings, binding->id);net_devmem_unlock_dev (dev, &dev_tracker);@@ -252,11 +251,20 @@ void net_devmem_dev_unregister(struct net_device *dev)xa_lock (&net_devmem_dmabuf_bindings);xa_for_each (&net_devmem_dmabuf_bindings, xa_idx, binding) { -if (binding->direction !=DMA_FROM_DEVICE || -READ_ONCE (binding->dev) != dev || -xa_get_mark (&net_devmem_dmabuf_bindings, xa_idx, -NET_DEVMEM_BINDING_LIVE )) -continue ;
net/core/devmem.c void net_devmem_dev_unregister(struct net_device *dev) · line 263
Quoted 10 lines
net/core/devmem.c +10
-0+if (binding->direction ==DMA_FROM_DEVICE ) { +if (READ_ONCE (binding->dev) != dev || +xa_get_mark (&net_devmem_dmabuf_bindings, xa_idx, +NET_DEVMEM_BINDING_LIVE )) +continue ; + }else { +if (READ_ONCE (binding->vdev) == dev) +WRITE_ONCE (binding->vdev,NULL ); +if (READ_ONCE (binding->dev) != dev) +continue ;
[Severity: High]
Can binding->dev be left pointing to a freed physical net_device if netdev_nl_bind_tx_doit() on a virtual device races with physical device unregistration?
When a NETMEM_TX_NO_DMA virtual device (vdev, such as netkit) leases an RX queue from a physical device (phys_dev), phys_dev is pinned via rxq_src->lease_tracker until vdev is unregistered.
When phys_dev unregisters in unregister_netdevice_many_notify(), its reg_state is set to NETREG_UNREGISTERING under netdev_lock(phys_dev) while __LINK_STATE_PRESENT remains set. During call_netdevice_notifiers() for NETDEV_UNREGISTER on phys_dev, netdev_genl_netdevice_event() runs first, calling net_devmem_dev_unregister(phys_dev) under netdev_lock(phys_dev). Only after that notifier completes does netkit_notifier() invoke netkit_check_lease_unregister(phys_dev) -> unregister_netdevice_many() to acquire netdev_lock(vdev) and set vdev->reg_state to NETREG_UNREGISTERING.
Because netdev_nl_family has parallel_ops enabled and NETDEV_CMD_BIND_TX does not hold rtnl_lock(), a concurrent netdev_nl_bind_tx_doit() on vdev can grab netdev_lock(vdev) via netdev_get_by_index_lock() while vdev->reg_state is still NETREG_REGISTERED, look up phys_dev via netdev_find_netmem_tx_dev(), and then acquire netdev_lock(bind_dev) after net_devmem_dev_unregister() has already finished on phys_dev:
net/core/netdev-genl.c:netdev_find_netmem_tx_dev() {
...
for (i = 0; i < dev->real_num_rx_queues; i++) {
lease_rxq = READ_ONCE(__netif_get_rx_queue(dev, i)->lease);
if (!lease_rxq)
continue;
phys_dev = lease_rxq->dev;
if (netif_device_present(phys_dev) &&
phys_dev->netmem_tx == NETMEM_TX_DMA)
return phys_dev;
}
}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,
bind_dev != netdev ? netdev : NULL,
dma_dev, DMA_TO_DEVICE, dmabuf_fd,
PAGE_SHIFT, priv, NETLINK_CB(skb).sk,
info->extack);
}Since netdev_nl_bind_tx_doit() does not check that bind_dev->reg_state == NETREG_REGISTERED after taking netdev_lock(bind_dev), it creates the binding with binding->dev = phys_dev and binding->vdev = vdev.
When vdev then runs net_devmem_dev_unregister(vdev), this branch sees binding->vdev == vdev and binding->dev == phys_dev != vdev, so it only clears binding->vdev to NULL and continues without unmapping the dma_buf or clearing binding->dev. Because net_devmem_dev_unregister(phys_dev) already ran, binding->dev is never cleared. Once netkit_uninit() drops the lease reference and netdev_run_todo() frees phys_dev, won't netdev_nl_sock_priv_destroy() or __net_devmem_dmabuf_binding_free() dereference the freed phys_dev in net_devmem_lock_dev()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH net v5 2/4] net: devmem: detach TX bindings on NETDEV_UNREGISTER
In reply to Mina AlmasryThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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] This patch's TX detach is incomplete.
--
net: devmem: detach TX bindings on NETDEV_UNREGISTER
This commit extends net_devmem_dev_unregister() to TX devmem bindings. When binding->dev unregisters, the walk clears the LIVE mark, unmaps the dma_buf, and clears both binding->dev and binding->vdev. When only binding->vdev unregisters, it clears just binding->vdev. The commit also makes __net_devmem_dmabuf_binding_free() call net_devmem_lock_dev() for TX bindings.
Quoted 4 lines
net/core/devmem.c +0
-0
[ ... ]
Quoted 23 lines
net/core/devmem.c +5
-7@@ -157,8 +157,7 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq) binding->area.num_niovs, binding->free_count);kvfree (binding->area.niovs); -if (binding->direction ==DMA_FROM_DEVICE ) - dev =net_devmem_lock_dev (binding, &dev_tracker); + dev =net_devmem_lock_dev (binding, &dev_tracker);net_devmem_dmabuf_binding_unmap (binding);xa_erase (&net_devmem_dmabuf_bindings, binding->id);net_devmem_unlock_dev (dev, &dev_tracker);@@ -252,11 +251,20 @@ void net_devmem_dev_unregister(struct net_device *dev)xa_lock (&net_devmem_dmabuf_bindings);xa_for_each (&net_devmem_dmabuf_bindings, xa_idx, binding) { -if (binding->direction !=DMA_FROM_DEVICE || -READ_ONCE (binding->dev) != dev || -xa_get_mark (&net_devmem_dmabuf_bindings, xa_idx, -NET_DEVMEM_BINDING_LIVE )) -continue ; +if (binding->direction ==DMA_FROM_DEVICE ) { +if (READ_ONCE (binding->dev) != dev || +xa_get_mark (&net_devmem_dmabuf_bindings, xa_idx, +NET_DEVMEM_BINDING_LIVE ))
net/core/devmem.c void net_devmem_dev_unregister(struct net_device *dev) · line 267
Quoted 10 lines
net/core/devmem.c +10
-0+continue ; + }else { +if (READ_ONCE (binding->vdev) == dev) +WRITE_ONCE (binding->vdev,NULL ); +if (READ_ONCE (binding->dev) != dev) +continue ; +WRITE_ONCE (binding->vdev,NULL ); +__xa_clear_mark (&net_devmem_dmabuf_bindings, xa_idx, +NET_DEVMEM_BINDING_LIVE ); + }
[Severity: High]
Can a leased bind-tx still create a TX binding on the physical device after this walk has already run for that device?
net_devmem_dev_unregister() runs once per device. It is called from netdev_genl_netdevice_event() under netdev_lock(dev), and does nothing unless reg_state is NETREG_UNREGISTERING.
Take a virtual device V (for example netkit) with a queue leased from a physical device X. When bind-tx is issued on V, netdev_nl_bind_tx_doit() locks X and binds to it without checking X->reg_state again:
net/core/netdev-genl.c:netdev_nl_bind_tx_doit() {
...
bind_dev = netdev_find_netmem_tx_dev(netdev);
...
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,
bind_dev != netdev ? netdev : NULL,
...
}netdev_find_netmem_tx_dev() only checks netif_device_present(X), and unregister_netdevice_many_notify() does not clear that bit.
netdev_genl_nb is registered at subsys_initcall and the netkit notifier at module_init, with the same priority. On NETDEV_UNREGISTER of X, the netdev-genl walk for X therefore finishes and unlocks X before netkit_check_lease_unregister() queues V for unregistration. Until then V stays NETREG_REGISTERED and its lease to X stays in place.
That seems to allow this ordering:
CPU1 (unregister of X) CPU2 (unprivileged bind-tx on V)netdev_genl_netdevice_event(X)
netdev_lock(X)
net_devmem_dev_unregister(X)
netdev_unlock(X)
netdev_nl_bind_tx_doit()
netdev_get_by_index_lock(V)
bind_dev = X (via the lease)
netdev_lock(X)
net_devmem_bind_dmabuf(X, V, ...)
LIVE binding, binding->dev = X
netdev_unlock(X)
netkit_check_lease_unregister(X)
unregister of V
net_devmem_dev_unregister(V)
binding->dev != V, so only
binding->vdev is cleared
netkit_queue_unlease()
netdev_put() on Xnetdev_run_todo()
X is freed
The walk for X never runs again, and the binding holds no reference on X, so binding->dev is left pointing at the freed X.
When the netlink socket is closed later, wouldn't netdev_nl_sock_priv_destroy()->net_devmem_lock_dev() call netdev_hold() and netdev_lock() on freed memory? That is the oops quoted in the commit message.
With the __net_devmem_dmabuf_binding_free() change above, the deferred free work also calls net_devmem_lock_dev() for TX bindings, so it is a second path that dereferences the stale binding->dev. The dma_buf also stays attached and mapped to X's DMA device.
The non-leased path looks safe, because netdev_put_lock() checks reg_state again under the instance lock. The later patches in this series don't seem to touch this path.
Would it close the window to reject the bind with -ENODEV when bind_dev->reg_state != NETREG_REGISTERED after netdev_lock(bind_dev)? unregister_netdevice_many_notify() writes reg_state under that lock, and the devmem walk runs later under the same lock.
Quoted 3 lines
net/core/devmem.c +0
-0xa_unlock (&net_devmem_dmabuf_bindings);if (!netif_is_queue_leasee (dev))
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261030083539.777877-1-almasrymina%40google.com
Re: [PATCH net v5 2/4] net: devmem: detach TX bindings on NETDEV_UNREGISTER
Quoted 6 lines · On Sun, Nov 1, 2026 at 3:01 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
Quoted 7 lines
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] This patch's TX detach is incomplete.
I know about the issues with leased devices. That needs a bit of a rework, which I have done locally, and would like to send out as a follow up fix so I don't hold back this series.
Signature · 2 lines
Thanks, Mina
PATCH v5 3/4 netdevsim: support devmem RX and TX bindings
In reply to Mina AlmasrySet a 64-bit DMA mask and UINT_MAX max segment size on nsim_bus_dev in nsim_bus_probe() when direct DMA mapping is supported, enable NETMEM_TX_DMA on the netdevsim net_device, and configure page_pool instances with PP_FLAG_ALLOW_UNREADABLE_NETMEM and queue_idx, plus PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV when a DMA mask and PP_DMA_INDEX_BITS are available, so devmem bind-rx and bind-tx netlink operations can be tested against netdevsim in software selftests.
The pp_hold debugfs file allocates pages from the queue 0 page pool, so refuse it when that pool is absent or backed by a memory provider, and take the netdev instance lock there so a concurrent bind-rx cannot swap the pool in between. Since netdevsim forwards TX skbs in software without a DMA engine, drop unreadable or net_iov skbs in nsim_start_xmit().
---
v5:
- Configure the DMA mask and dma_parms in nsim_bus_probe() gated on dma_pci_p2pdma_supported(), and require PP_DMA_INDEX_BITS before setting PP_FLAG_DMA_MAP so page_pool_scrub() can unmap inflight pages on 32-bit builds (Sashiko).
- Check for NULL ns->rq in nsim_pp_hold_write() and drop unreadable or net_iov skbs at the start of nsim_start_xmit() (Sashiko).
v3:
- Only request page pool DMA mapping when CONFIG_HAS_DMA is set (Sashiko).
- Refuse pp_hold on a page pool backed by a memory provider, under the netdev instance lock (Sashiko).
- Drop unreadable skbs in the software PSP path when it would have to checksum the payload (Sashiko).
--- drivers/net/netdevsim/bus.c | 9 +++++++++ drivers/net/netdevsim/netdev.c | 33 +++++++++++++++++++++++++------ drivers/net/netdevsim/netdevsim.h | 1 + 3 files changed, 37 insertions(+), 6 deletions(-)
drivers/net/netdevsim/bus.c +9 -0
@@ -5,6 +5,7 @@#include <linux/completion.h> #include <linux/device.h> +#include <linux/dma-mapping.h> #include <linux/idr.h> #include <linux/kernel.h> #include <linux/list.h>
@@ -416,6 +417,14 @@ static int nsim_bus_probe(struct device *dev) {struct nsim_bus_dev *nsim_bus_dev =to_nsim_bus_dev (dev); +if (dma_pci_p2pdma_supported (dev) && + !dma_coerce_mask_and_coherent (dev,DMA_BIT_MASK (64 ))) { + dev->dma_parms = &nsim_bus_dev->dma_parms; +dma_set_max_seg_size (dev,UINT_MAX ); + }else { + dev->dma_mask =NULL ; + } +return nsim_drv_probe (nsim_bus_dev); }
drivers/net/netdevsim/netdev.c +27 -6
@@ -133,6 +133,10 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)int dr;rcu_read_lock (); +if (!skb_frags_readable (skb) || + (skb_shinfo (skb)->nr_frags && +skb_frag_is_net_iov (&skb_shinfo (skb)->frags[0 ]))) + goto out_drop_any;if (!nsim_ipsec_tx (ns, skb)) goto out_drop_any;
@@ -422,19 +426,27 @@ static int nsim_poll(struct napi_struct *napi, int budget)return done; } -static int nsim_create_page_pool (struct page_pool **p,struct napi_struct *napi) +static int nsim_create_page_pool (struct net_device *dev,struct page_pool **p, +struct napi_struct *napi,int idx) { +struct netdevsim *ns =netdev_priv (dev);struct page_pool_params params = { .order =0 , .pool_size =NSIM_RING_SIZE , + .flags =PP_FLAG_ALLOW_UNREADABLE_NETMEM , + .max_len =PAGE_SIZE , .nid =NUMA_NO_NODE , - .dev = &napi->dev->dev, + .dev = &ns->nsim_bus_dev->dev, .napi = napi, .dma_dir =DMA_BIDIRECTIONAL , - .netdev = napi->dev, + .netdev = dev, + .queue_idx = idx, };struct page_pool *pool; +if (ns->nsim_bus_dev->dev.dma_mask &&PP_DMA_INDEX_BITS ) + params.flags |=PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV ; + pool =page_pool_create (¶ms);if (IS_ERR (pool))return PTR_ERR (pool);
@@ -458,7 +470,7 @@ static int nsim_init_napi(struct netdevsim *ns)for (i =0 ; i < dev->num_rx_queues; i++) { rq = ns->rq[i]; - err =nsim_create_page_pool (&rq->page_pool, &rq->napi); + err =nsim_create_page_pool (dev, &rq->page_pool, &rq->napi, i);if (err) goto err_pp_destroy; }
@@ -770,14 +782,16 @@ nsim_queue_mem_alloc(struct net_device *dev,if (ns->rq_reset_mode ==1 ) {if (!netif_running (ns->netdev))return -ENETDOWN ; -return nsim_create_page_pool (&qmem->pp, &ns->rq[idx]->napi); +return nsim_create_page_pool (dev, &qmem->pp, + &ns->rq[idx]->napi, idx); } qmem->rq =nsim_queue_alloc ();if (!qmem->rq)return -ENOMEM ; - err =nsim_create_page_pool (&qmem->rq->page_pool, &qmem->rq->napi); + err =nsim_create_page_pool (dev, &qmem->rq->page_pool, &qmem->rq->napi, + idx);if (err) goto err_free;
@@ -937,12 +951,16 @@ nsim_pp_hold_write(struct file *file, const char __user *data,return ret;rtnl_lock (); +netdev_lock (ns->netdev); ret = count;if (val == !!ns->page) goto exit;if (!netif_running (ns->netdev) && val) { ret = -ENETDOWN ; + }else if (val && (!ns->rq || +page_pool_is_unreadable (ns->rq[0 ]->page_pool))) { + ret = -EOPNOTSUPP ; }else if (val) { ns->page =page_pool_dev_alloc_pages (ns->rq[0 ]->page_pool);if (!ns->page)
@@ -954,6 +972,7 @@ nsim_pp_hold_write(struct file *file, const char __user *data, } exit: +netdev_unlock (ns->netdev);rtnl_unlock ();return ret; }
@@ -1059,6 +1078,8 @@ static int nsim_init_netdevsim(struct netdevsim *ns) ns->netdev->netdev_ops = &nsim_netdev_ops; ns->netdev->stat_ops = &nsim_stat_ops; ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops; +if (ns->nsim_bus_dev->dev.dma_mask) + ns->netdev->netmem_tx =NETMEM_TX_DMA ;netdev_lockdep_set_classes (ns->netdev); err =nsim_udp_tunnels_info_create (ns->nsim_dev, ns->netdev);
drivers/net/netdevsim/netdevsim.h +1 -0
@@ -476,6 +476,7 @@ int nsim_setup_tc(struct net_device *dev, enum tc_setup_type type,#define NSIM_BUS_DEV_MAX_VFS 4struct nsim_bus_dev {struct device dev; +struct device_dma_parameters dma_parms;struct list_head list;unsigned int port_count;unsigned int num_queues;/* Number of queues for each port on this bus */
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewRe: [PATCH net v5 3/4] netdevsim: support devmem RX and TX bindings
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Not a bug (baseline: false positive).
--
netdevsim: support devmem RX and TX bindings
This patch sets a 64-bit DMA mask on the netdevsim bus device and turns on NETMEM_TX_DMA on the netdevsim net_device. It also sets up the page pools so they can be backed by unreadable netmem, which lets the devmem bind-rx and bind-tx netlink operations be tested against netdevsim. pp_hold is refused on memory-provider backed pools, and unreadable or net_iov skbs are dropped in nsim_start_xmit().
Quoted 15 lines
drivers/net/netdevsim/netdev.c +4
-0@@ -133,6 +133,10 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)int dr;rcu_read_lock (); +if (!skb_frags_readable (skb) || + (skb_shinfo (skb)->nr_frags && +skb_frag_is_net_iov (&skb_shinfo (skb)->frags[0 ]))) + goto out_drop_any;if (!nsim_ipsec_tx (ns, skb)) goto out_drop_any;
[ ... ]
drivers/net/netdevsim/netdev.c static int nsim_init_netdevsim(struct netdevsim *ns) · line 1082
Quoted 6 lines
drivers/net/netdevsim/netdev.c +2
-0@@ -1059,6 +1078,8 @@ static int nsim_init_netdevsim(struct netdevsim *ns) ns->netdev->netdev_ops = &nsim_netdev_ops; ns->netdev->stat_ops = &nsim_stat_ops; ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops; +if (ns->nsim_bus_dev->dev.dma_mask) + ns->netdev->netmem_tx =NETMEM_TX_DMA ;
[Severity: Low]
This isn't a bug, but the docs and the driver don't quite match here. Documentation/networking/netmem.rst describes the mode as:
NETMEM_TX_DMA: for physical devices that perform DMA.
nsim_init_netdevsim() sets NETMEM_TX_DMA, but nsim_start_xmit() above drops every unreadable or net_iov skb.
As I understand it, NETMEM_TX_NO_DMA would not work for this test. That is because netdev_find_netmem_tx_dev() only resolves a NO_DMA device by following leased RX queues to a physical NETMEM_TX_DMA device:
net/core/netdev-genl.c:netdev_find_netmem_tx_dev() {
...
if (dev->netmem_tx == NETMEM_TX_DMA)
return dev;
if (dev->netmem_tx != NETMEM_TX_NO_DMA)
return NULL;
...
}Traffic also behaves the same as before. Under NETMEM_TX_NONE, validate_xmit_unreadable_skb() already freed these skbs. Now the driver drops them and counts them through dev_dstats_tx_dropped().
Would it help to add a short comment next to this assignment? It could say that netdevsim advertises NETMEM_TX_DMA only so the bind-tx control path works, and that devmem TX data is dropped in nsim_start_xmit().
Quoted 3 lines
drivers/net/netdevsim/netdev.c +0
-0netdev_lockdep_set_classes (ns->netdev); err =nsim_udp_tunnels_info_create (ns->nsim_dev, ns->netdev);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261030083539.777877-1-almasrymina%40google.com
PATCH v5 4/4 selftests: net: add devmem RX and TX netdev unregister tests
In reply to Mina AlmasryAdd devmem_bind_rx_unregister_check and devmem_bind_tx_unregister_check to nl_netdev.py to verify that unregistering a netdevsim device while a netlink socket holds an active RX or TX devmem binding synchronously detaches the dma_buf attachment and cleanly closes the netlink socket without use-after-free or page faults.
Add the dma-buf, udmabuf and devmem options the tests need to tools/testing/selftests/net/config.
---
v5:
- Tolerate non-UTF-8 dma-buf names when parsing debugfs bufinfo (Sashiko).
v3:
- Count attachments of the test's own dma-buf only, and skip instead of passing when debugfs bufinfo is not readable (Sashiko).
- Close the netlink socket after removing the device, clean up with defer(), and skip on EOPNOTSUPP from bind-rx/bind-tx (Sashiko).
- Replace the hardcoded UDMABUF_CREATE value with a helper that computes it for the running architecture (Sashiko, Dragos), and close the memfd and /dev/udmabuf fds on errors (Sashiko).
- Add the needed options to tools/testing/selftests/net/config (Sashiko).
--- tools/testing/selftests/net/config | 4 + tools/testing/selftests/net/nl_netdev.py | 125 ++++++++++++++++++++++- 2 files changed, 126 insertions(+), 3 deletions(-)
tools/testing/selftests/net/config +4 -0
@@ -12,6 +12,7 @@ CONFIG_CRYPTO_ARIA=y CONFIG_CRYPTO_CHACHA20POLY1305=m CONFIG_CRYPTO_SHA1=y CONFIG_CRYPTO_SM4_GENERIC=y +CONFIG_DEBUG_FS=y CONFIG_DEBUG_INFO_BTF=y CONFIG_DEBUG_INFO_BTF_MODULES=n CONFIG_DUMMY=y
@@ -79,6 +80,7 @@ CONFIG_NET_CLS_BPF=m CONFIG_NET_CLS_FLOWER=m CONFIG_NET_CLS_MATCHALL=m CONFIG_NET_CLS_U32=m +CONFIG_NET_DEVMEM=y CONFIG_NETDEVSIM=m CONFIG_NET_DROP_MONITOR=m CONFIG_NETFILTER=y
@@ -123,6 +125,7 @@ CONFIG_OPENVSWITCH=m CONFIG_PAGE_POOL_STATS=y CONFIG_PSAMPLE=m CONFIG_RPS=y +CONFIG_SYNC_FILE=y CONFIG_SYN_COOKIES=y CONFIG_SYSCTL=y CONFIG_SYSFS=y
@@ -133,6 +136,7 @@ CONFIG_TEST_BLACKHOLE_DEV=m CONFIG_TLS=m CONFIG_TRACEPOINTS=y CONFIG_TUN=y +CONFIG_UDMABUF=y CONFIG_USER_NS=y CONFIG_VETH=y CONFIG_VLAN_8021Q=y
tools/testing/selftests/net/nl_netdev.py +122 -3
145 lines not on this page · raw message
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewRe: [PATCH net v5 4/4] selftests: net: add devmem RX and TX netdev unregister tests
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch adds CONFIG_UDMABUF=y to tools/testing/selftests/net/config, but the fragment does not pull in…
--
selftests: net: add devmem RX and TX netdev unregister tests
This adds devmem_bind_rx_unregister_check and devmem_bind_tx_unregister_check to nl_netdev.py. They check that removing a netdevsim device while a netlink socket holds an RX or TX devmem binding detaches the dma_buf right away. The commit also adds the dma-buf, udmabuf and devmem options the tests need to the net selftest config fragment.
Quoted 4 lines
tools/testing/selftests/net/config +0
-0
[ ... ]
tools/testing/selftests/net/config CONFIG_TEST_BLACKHOLE_DEV=m · line 139
Quoted 5 lines
tools/testing/selftests/net/config +1
-0@@ -133,6 +136,7 @@ CONFIG_TEST_BLACKHOLE_DEV=m CONFIG_TLS=m CONFIG_TRACEPOINTS=y CONFIG_TUN=y +CONFIG_UDMABUF=y
[Severity: Low]
Will CONFIG_UDMABUF=y actually get enabled from this fragment on a minimal base config? UDMABUF in drivers/dma-buf/Kconfig has these dependencies:
config UDMABUF
bool "userspace dmabuf misc driver"
default n
depends on DMA_SHARED_BUFFER
depends on MEMFD_CREATE || COMPILE_TEST
depends on MMU
CONFIG_SYNC_FILE=y takes care of DMA_SHARED_BUFFER. MEMFD_CREATE has no default, though, and can only be set directly under EXPERT. Normally it is turned on because TMPFS or HUGETLBFS selects it, and this fragment asks for neither.
If the base config has MEMFD_CREATE=n and COMPILE_TEST=n, Kconfig will quietly drop UDMABUF. Both new tests would then skip in _create_udmabuf() and never reach the unregister path:
if not os.path.exists("/dev/udmabuf"):
raise KsftSkipEx("/dev/udmabuf is not available")
tools/testing/selftests/bpf/config lists CONFIG_TMPFS=y next to CONFIG_UDMABUF=y, and tools/testing/selftests/drivers/net/hw/config has CONFIG_HUGETLBFS=y. Should CONFIG_TMPFS=y be added here as well?
Quoted 3 lines
tools/testing/selftests/net/config +0
-0CONFIG_USER_NS=y CONFIG_VETH=y CONFIG_VLAN_8021Q=y
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261030083539.777877-1-almasrymina%40google.com
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 16 lines · On Fri, 30 Oct 2026 08:35:34 +0000 you wrote:
Fix two device-unregistration lifecycle bugs in devmem TCP bindings and add netdevsim support plus selftests covering both RX and TX device unregistration. These issues were found via LLM-assisted code review (Sashiko) and reproduced and verified with the new
nl_netdev.pyselftests on netdevsim (not tested on real hardware):1. net: devmem: unmap
dma_bufsynchronously on queue uninstall Synchronously unmap and detachbinding->attachmentunderbinding->lockwhen the last RX queue is uninstalled inmp_dmabuf_devmem_uninstall()or closed innet_devmem_unbind_dmabuf(), and unmap remaining unbound RX bindings onNETDEV_UNREGISTER, preventing slab-use-after-free indma_unmap_sg_attrs()when the binding is freed afterdma_dev. Factor outnet_devmem_lock_dev()andnet_devmem_unlock_dev()to synchronizenetdev_nl_sock_priv_destroy()and__net_devmem_dmabuf_binding_free()againstNETDEV_UNREGISTER.
Quoted 1 line
[...]
Here is the summary with links:
- [net,v5,1/4] net: devmem: unmap dma_buf synchronously on queue uninstall
https://git.kernel.org/netdev/net-next/c/c4466d2c3e77 - [net,v5,2/4] net: devmem: detach TX bindings on NETDEV_UNREGISTER https://git.kernel.org/netdev/net-next/c/ede1618064a9 - [net,v5,3/4] netdevsim: support devmem RX and TX bindings https://git.kernel.org/netdev/net-next/c/c153da399354 - [net,v5,4/4] selftests: net: add devmem RX and TX netdev unregister tests https://git.kernel.org/netdev/net-next/c/121ba2ac7968
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html