* [PATCH net v3] net/smc: close non-accepted sockets without holding the listen lock
@ 2026-12-05 8:26 Jiayi Zhang
2026-12-05 8:43 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Jiayi Zhang @ 2026-12-05 8:26 UTC (permalink / raw)
To: D. Wythe, Dust Li, Sidraya Jayagond, Mahanta Jambigi, Tony Lu,
Wen Gu, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman
Cc: Willem de Bruijn, netdev, linux-rdma, linux-s390,
syzbot+621fd56ba002faba6392, syzkaller-bugs
syzbot reports a possible deadlock when a listening SMC socket is
closed:
WARNING: possible circular locking dependency detected
...
is trying to acquire lock:
((work_completion)(&new_smc->smc_listen_work)), at: __flush_work
but task is already holding lock:
(sk_lock-AF_SMC/1), at: smc_release+0x3a5/0x620 net/smc/af_smc.c:353
...
-> #1 (sk_lock-AF_SMC/1):
lock_sock_nested+0x41/0xf0 net/core/sock.c:3909
smc_listen_out+0xf2/0x4b0 net/smc/af_smc.c:1941
...
smc_listen_work+0x445/0x5040 net/smc/af_smc.c:2595
-> #0 ((work_completion)(&new_smc->smc_listen_work)):
...
cancel_work_sync+0xcc/0xf0 kernel/workqueue.c:4795
smc_clcsock_release+0x5f/0xe0 net/smc/smc_close.c:29
__smc_release+0x5c2/0x880 net/smc/af_smc.c:318
smc_close_non_accepted+0xda/0x200 net/smc/af_smc.c:1871
smc_close_cleanup_listen net/smc/smc_close.c:45 [inline]
smc_close_active+0x4ff/0x11a0 net/smc/smc_close.c:228
__smc_release+0x634/0x880 net/smc/af_smc.c:294
smc_release+0x1fc/0x620 net/smc/af_smc.c:361
smc_close_active() closes the sockets left on the accept queue of a
listening socket with smc_close_cleanup_listen() while it holds the lock
of the listening socket. Closing such a socket ends in
smc_clcsock_release(), which waits for the socket's smc_listen_work
with cancel_work_sync(). smc_listen_work() takes the lock of the
listening socket in smc_listen_out(). Commit fd57770dd198 ("net/smc: wait
for pending work before clcsock release_sock") added
smc_clcsock_release() and made smc_release() drop the socket's own lock
before calling it. Commit 39f41f367b08 ("net/smc: common release code
for non-accepted sockets") moved these release steps of smc_release()
into the new __smc_release() and made smc_close_non_accepted() call
__smc_release(). Since then smc_close_cleanup_listen() reaches the
cancel_work_sync() with the lock of the listening socket held.
The smc_listen_work of a socket on the accept queue has already taken
and released the listen lock: smc_listen_out() puts the socket on the
queue under that lock and does not take it again. So this does not
deadlock today, but lockdep
cannot tell the listen works apart and reports the dependency on every
such close.
Close the non-accepted sockets after the listen lock is released,
together with the flush of tcp_listen_work that is already done there,
and take the lock again afterwards.
smc_close_cleanup_listen() then walks the accept queue and updates
sk_ack_backlog of the listening socket without the listen lock. The
list is protected by accept_q_lock in smc_accept_enqueue() and
smc_accept_unlink(), but sk_acceptq_added() and sk_acceptq_removed()
rely on the listen lock, and smc_accept_dequeue() walks the list
without accept_q_lock. This is safe because nothing else adds to or
removes from the queue at this point:
- Nothing is added. smc_close_active() has set the listening socket to
SMC_CLOSED under the listen lock, and smc_listen_out() checks the
state under the listen lock and closes a new socket itself instead
of queueing it.
- Nothing is removed by accept(). The SMC_LISTEN case of
smc_close_active() is only reached from smc_release(), after the
last file reference is gone: smc_shutdown() returns -ENOTCONN for a
socket in SMC_LISTEN, and the other caller of __smc_release(),
smc_close_non_accepted(), only closes sockets created for incoming
connections, which are never in SMC_LISTEN. So accept() and poll()
cannot run on the listening socket any more.
smc_listen_out() has checked the state under the lock since
commit 185a4caeecab ("net/smc: fix TOCTOU race between
smc_listen_out() and listener close"). A backport needs that commit
as well: without it, smc_listen_out() can queue a new socket after
the listening socket is closed, and that would race with the
unlocked walk.
Fixes: 39f41f367b08 ("net/smc: common release code for non-accepted sockets")
Reported-by: syzbot+621fd56ba002faba6392@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=621fd56ba002faba6392
Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
Signed-off-by: Jiayi Zhang <zhangjiayi1014@gmail.com>
---
v3:
- changelog only, the code is unchanged: Fixes: now names
39f41f367b08, which made smc_close_non_accepted() reach
smc_clcsock_release(); fd57770dd198 added the cancel_work_sync(),
but smc_close_non_accepted() did not call it then. The history
paragraph is corrected to match (Sashiko)
- the lock_sock_nested() in smc_release() and its comment stay as
they are; as discussed with Mahanta on v1, that cleanup is
separate from this fix (second Sashiko item)
- add Mahanta's Reviewed-by from v2
v2: https://lore.kernel.org/all/20261204055158.1897592-1-zhangjiayi1014@gmail.com/
- changelog only: say why the accept queue and sk_ack_backlog can be
emptied without the listen lock, why shutdown() cannot reach this
path, and that a backport needs 185a4caeecab (Mahanta Jambigi)
v1: https://lore.kernel.org/all/20261202175908.4136866-1-zhangjiayi1014@gmail.com/
Tested with the syzbot C reproducer and the kernel config of the
report, 5 QEMU instances of 10 minutes each: without the patch all 5
report the lockdep splat; with the patch none of the 5 reports anything.
The net selftests were not run.
Mahanta Jambigi's series "net/smc: keep clcsock until socket release"
(net-next v3, posted 2026-12-01) adds a comment to
smc_accept_dequeue() saying that the child and listener locks are held.
With this patch that is no longer true on the cleanup path from
smc_close_active(); Mahanta will adjust that comment in the series.
The two do not conflict textually.
AI tools assisted with the analysis, the code and the changelog.
net/smc/smc_close.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
index 736abfb..2c98b77 100644
--- a/net/smc/smc_close.c
+++ b/net/smc/smc_close.c
@@ -225,9 +225,9 @@ again:
write_unlock_bh(&smc->clcsock->sk->sk_callback_lock);
rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR);
}
- smc_close_cleanup_listen(sk);
release_sock(sk);
flush_work(&smc->tcp_listen_work);
+ smc_close_cleanup_listen(sk);
lock_sock(sk);
break;
case SMC_ACTIVE:
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 8:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 8:26 [PATCH net v3] net/smc: close non-accepted sockets without holding the listen lock Jiayi Zhang
2026-12-05 8:43 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.