Subject: Re: [PATCH net-next v2 6/8] netdev: depend on netdev->lock for xdp features

From: Jakub Kicinski <[email-masked]>
Date: Thu, 10 Apr 2025 19:10:28 -0700

On Thu, 10 Apr 2025 10:10:01 -0700 Kuniyuki Iwashima wrote:
> syzkaller reported splats in register_netdevice() and
> unregister_netdevice_many_notify().
> 
> In register_netdevice(), some devices cannot use
> netdev_assert_locked().
> 
> In unregister_netdevice_many_notify(), maybe we need to
> hold ops lock in UNREGISTER as you initially suggested.
> Now do_setlink() deadlock does not happen.

Ah...  Thank you.

Do you have a reference to use as Reported-by, or its from a
non-public instance ?

I'll test this shortly:

diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index b64c614a00c4..891e2f60922f 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -38,7 +38,8 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,
        u64 xdp_rx_meta = 0;
        void *hdr;
 
-       netdev_assert_locked(netdev); /* note: rtnl_lock may not be held! */
+       /* note: rtnl_lock may or may not be held! */
+       netdev_assert_locked_or_invisible(netdev);
 
        hdr = genlmsg_iput(rsp, info);
        if (!hdr)
@@ -966,7 +967,9 @@ static int netdev_genl_netdevice_event(struct notifier_block *nb,
                netdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_ADD_NTF);
                break;
        case NETDEV_UNREGISTER:
+               netdev_lock(netdev);
                netdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_DEL_NTF);
+               netdev_unlock(netdev);
                break;
        case NETDEV_XDP_FEAT_CHANGE:
                netdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_CHANGE_NTF);