]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: fix use-after-free in the netdev_nl_sock_priv_destroy()
authorTaehee Yoo <ap420073@gmail.com>
Fri, 28 Mar 2025 06:22:37 +0000 (06:22 +0000)
committerJakub Kicinski <kuba@kernel.org>
Mon, 31 Mar 2025 23:44:49 +0000 (16:44 -0700)
In the netdev_nl_sock_priv_destroy(), an instance lock is acquired
before calling net_devmem_unbind_dmabuf(), then releasing an instance
lock(netdev_unlock(binding->dev)).
However, a binding is freed in the net_devmem_unbind_dmabuf().
So using a binding after net_devmem_unbind_dmabuf() occurs UAF.
To fix this UAF, it needs to use temporary variable.

Fixes: ba6f418fbf64 ("net: bubble up taking netdev instance lock to callers of net_devmem_unbind_dmabuf()")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Mina Almasry <almasrymina@google.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250328062237.3746875-1-ap420073@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/netdev-genl.c

index fd1cfa9707dc8a77bed199263bb69992c42b8cd1..3afeaa8c5dc510a5e7ea904ea7f3c3d9e2773fa5 100644 (file)
@@ -951,12 +951,14 @@ void netdev_nl_sock_priv_destroy(struct netdev_nl_sock *priv)
 {
        struct net_devmem_dmabuf_binding *binding;
        struct net_devmem_dmabuf_binding *temp;
+       struct net_device *dev;
 
        mutex_lock(&priv->lock);
        list_for_each_entry_safe(binding, temp, &priv->bindings, list) {
-               netdev_lock(binding->dev);
+               dev = binding->dev;
+               netdev_lock(dev);
                net_devmem_unbind_dmabuf(binding);
-               netdev_unlock(binding->dev);
+               netdev_unlock(dev);
        }
        mutex_unlock(&priv->lock);
 }