Remove nbd_reclassify_socket() and its lockdep class keys, reverting commit d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular dependency") and commit 9280e6edf656 ("nbd: don't warn when reclassifying a busy socket lock"). Unlike kernel-internal sockets created via sock_create_kern(), NBD sockets are passed from user space as already-connected file descriptors and remain accessible to user-space system calls, timers, and softirqs. Calling sock_lock_init_class_and_name() on a live user-space socket: - Races lockdep_init_map_type() against concurrent lock_acquire() calls in bh_lock_sock() and lock_sock_nested(), corrupting lockdep state and causing spinlock/lockdep splats. - Calls sk_owner_set() repeatedly when the same socket fd is passed to NBD_SET_SOCK multiple times, leaking module reference counts because sk_prot_free() only calls sk_owner_put() once. - Does not prevent circular lockdep reports when user space performs sendmsg() on the retained socket fd and faults in user pages under sk_lock-AF_INET-NBD. The reclassification suppressed a false positive involving the chain fs_reclaim -> q->q_usage_counter -> ... -> sk_lock, where the last step was socket transmission from nbd_queue_rq(). Now that request transmission is deferred from nbd_queue_rq() to a workqueue, sk_lock is no longer acquired while blk-mq holds q->q_usage_counter, and transmission happens under memalloc_noio_save(), so no fs_reclaim -> sk_lock dependency is recorded for NBD sockets. Hence socket lockdep reclassification is no longer needed. Fixes: d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular dependency") Fixes: 9280e6edf656 ("nbd: don't warn when reclassifying a busy socket lock") Reported-by: syzbot+b29ed72382b0e218323a@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/6aec63fd.5f5735a5.290c1c.0003.GAE@google.com/ Signed-off-by: Bart Van Assche --- drivers/block/nbd.c | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index fd0789849612..f713779b5a5d 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1318,42 +1318,6 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd, return sock; } -#ifdef CONFIG_DEBUG_LOCK_ALLOC -static struct lock_class_key nbd_key[3]; -static struct lock_class_key nbd_slock_key[3]; - -static void nbd_reclassify_socket(struct socket *sock) -{ - struct sock *sk = sock->sk; - - if (!sock_allow_reclassification(sk)) - return; - - switch (sk->sk_family) { - case AF_INET: - sock_lock_init_class_and_name(sk, "slock-AF_INET-NBD", - &nbd_slock_key[0], - "sk_lock-AF_INET-NBD", - &nbd_key[0]); - break; - case AF_INET6: - sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD", - &nbd_slock_key[1], - "sk_lock-AF_INET6-NBD", - &nbd_key[1]); - break; - case AF_UNIX: - sock_lock_init_class_and_name(sk, "slock-AF_UNIX-NBD", - &nbd_slock_key[2], - "sk_lock-AF_UNIX-NBD", - &nbd_key[2]); - break; - } -} -#else -static inline void nbd_reclassify_socket(struct socket *sock) {} -#endif - static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg, bool netlink) { @@ -1376,7 +1340,6 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg, sock = nbd_get_socket(nbd, arg, &err); if (!sock) return err; - nbd_reclassify_socket(sock); if (!netlink && !nbd->task_setup && !test_bit(NBD_RT_BOUND, &config->runtime_flags))