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] Commit "net: devmem: resolve leased RX queues to physical device
on bind" fixes a memory-safety bug in leased-queue devmem RX teardown,…
--
net: devmem: resolve leased RX queues to physical device on bind
At bind-rx time, this commit resolves leased RX queues to the physical
net_device and its physical rx_queue indices. It holds
netdev_lock(virt_dev) and then netdev_lock(phys_dev) across the DMA
device lookup, the dmabuf mapping and the queue opens.
phys_dev and phys_rxq are stored in the binding so that teardown paths
serialize on the physical device lock. The rxq->mp_params clearing moves
into __netif_mp_uninstall_rxq().
> - When the physical device unregisters first,
> dev_memory_provider_uninstall(phys_dev) passes phys_rxq to
> mp_dmabuf_devmem_uninstall(), which searches binding->bound_rxqs for
> virt_rxq, fails to match, and leaves the dmabuf mapped.
[ ... ]
> These issues were identified by code inspection and selftest development
> while extending devmem unregister teardown to leased queues; they have not
> been observed in production or tested on real hardware. Verified with
> netdevsim and netkit selftests in nl_netdev.py and nk_qlease.py.
[Severity: Low]
Does "leaves the dmabuf mapped" cover the full consequence here? And
should this patch carry Fixes: tags?
Before this patch, when the physical device unregisters first, the
cascaded unlease path is the one that matches virt_rxq:
netif_rxq_cleanup_unlease(phys_rxq, virt_rxq)
__netif_mp_uninstall_rxq(virt_rxq, &p)
mp_dmabuf_devmem_uninstall(binding, virt_rxq)
That call empties bound_rxqs and clears binding->dev. It skips the unmap
because virt_rxq->lease is still set:
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);
}
net_devmem_dev_unregister() does not unmap it either. binding->dev does
not match phys_dev, and the leasee device is skipped.
So the dma_buf attachment stays mapped while the physical dma_dev is
freed. When the netlink socket is closed later, this call chain would run
against the freed device:
__net_devmem_dmabuf_binding_free()->dma_buf_unmap_attachment()
This looks like the same slab-use-after-free in dma_unmap_sg_attrs()
that KASAN caught in commit c4466d2c3e77 ("net: devmem: unmap dma_buf
synchronously on queue uninstall").
Could the commit message describe this as a use-after-free rather than a
mapping leak? Tags like these would also let stable trees that carry the
queue lease support pick it up:
Fixes: 5602ad61ebee ("net: Proxy netif_mp_{open,close}_rxq for leased queues")
Fixes: c4466d2c3e77 ("net: devmem: unmap dma_buf synchronously on queue uninstall")
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40google.com