Article View: linux.kernel.netdev
Article #27295[PATCH net v3] net/smc: close non-accepted sockets without holding the listen lock
From: Jiayi Zhang
Date: Sat, 05 Dec 2026 08:26
Date: Sat, 05 Dec 2026 08:26
136 lines
16881 bytes
16881 bytes
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
Technical Details
Message-ID:
<20261205082648.3076069-1-zhangjiayi1014@gmail.com>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!peer04.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377885-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!peer04.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377885-linux-kernel-netdev=dewy.ru From: zhangjiayi1014@gmail.com (Jiayi Zhang) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3] net/smc: close non-accepted sockets without holding the listen lock Date: Sat, 5 Dec 2026 08:26:48 +0000 Organization: Usenet Network Message-ID: <20261205082648.3076069-1-zhangjiayi1014@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2986357"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:shtK9kBxrMS1/TnAhRmKgKQkJzE= sha256:1jhiCj3pgWVLkTl5JqIW+LuRhkORjmWTd1FpmR1lQFI= sha1:/MNb+CwxE4taCCUmOMMmvb/qNis= sha256:5b8ibSqN+c/cxSyqW1QT/jmZ69T9DZX/vn9AfcgUxDU= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 8A579117DA8; Sat, 5 Dec 2026 11:27:24 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.296 X-Spam-Status: No, score=-3.296 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xzn4dIVo-vtf; Sat, 5 Dec 2026 11:27:17 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377885-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 1CE36117DA6; Sat, 5 Dec 2026 11:27:07 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 7B67D35299; Sat, 5 Dec 2026 08:27:03 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796459223; b=qqYElJxu9xya+tFZU6Cv5tfWlxQrXzTpi3+5agDpkpqMk8Lgmrk4TYDlc2MfUy/8LhHr wBSRQlDcECDi4UIQVym5SF07CO7aJ7+4VxOauRfD8rE+a6zz2RFaMvE5zLXbviMlX+Eeh aB1oTtkvIqTdnKx9K34WZvITBVcHni59TzLAmRG+4FZ+DRpkxchr50Ke/nYBe8Fd87bm/ WmUtu5xBPt4RMUytLY6do5Gc4L90gDWQwNnC0s+RyAicTCTAohuKg2r81NOv3NFT+7+AC 5eJz6EQLWQssJBCgewuiRltfDT6NlwbQ/sv4qTGOv8zulrtDGQCnviyATkUJ0GVw79A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459223; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature: X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State: X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID: X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=vM9qxd3UnHmgbOLagJ0eyyweUYVPDPOwzUGUu/+kxYg=; b=aOKm9lPZGmIeExHIjlOqjO8284ohoxjjKNmjNhO/1Vkc0jgW7S7bU6nftVqsDGEGzxH2 E1fulTU+72kUvnXXmLyzZU4RUudCsFCosGx28jGD5FhtRISME865jhKffsg7oNebUDN1c IMHG7PFxfNFR7DPmooYCauvUMLObfZqCAQP55EoUeaO41wl7L5bYsHh/8IU0uhEvwCAqt xsDFkW18anwbogwnGmBGOlM2QU6u/HE0pX6b8p4y2BV6GFHINfzxCtWL5VwQfjJB3eIPB jDQ5MEgVvjdYDdiOGRv2FzR5OVli7LNqec65X8O6YEy7T1lKe5veIcAwghFbQPLfWlA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=XLNIi2pR; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53285606A337; Sat, 5 Dec 2026 08:27:03 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=XLNIi2pR X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.8 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796459222; b=K8Vsroaw2SCU/T/R4X7e5WWgjteMwz9fh86GTU7pFAI0lKs64HuVonFnyXGHXKXMjct/ bl0+hDuMnpWYZsREKgb9d+00bApfcEpksOis1gyOW8oXsJsGaFlsDHhNHdCW4SYSigcDC RCLlo0bWzrXXi3XoWvoA0P/1kTXZeC9vKVAKobq52BWAtnpK0Bgjl2JLmR97YXkAicXV7 7wQdYHTgf7z71eBr2lFk9R0wIueATzt08Y6qzJLvkjZrUFFU7TXAKBHnzh0NJ0ih9xaPb 6xgrc46ajwG70TYeNPT51KEKnhQkw8Yd86iWxB12kNdRVryTv92R1WtTpBtgA9BRRfA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459222; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=vM9qxd3UnHmgbOLagJ0eyyweUYVPDPOwzUGUu/+kxYg=; b=bHJZVjluph70P2ZnnPl9gPbu63KPc5qStXAr6OTIWdUiqxS9/nP3V2r+rdsVjIwaCnSK QO8+LknNplGoITSCFI6xDyQvCyYpo98c77UIpMquhUF5PtD81HgB1kMObaxK6022F042e FT7P1Huw+dY+RzvQVBV8AnooL82wxuzh8QpA+Z4sxjYGHNySb2sEDEkyuX6Y3S/1lBbAa rRRofxNXgxcktLHNnSW2xGd+bSA369hKJl5pdnfkBoHw+GPI96UBiiwXEjcxtVQcai/Hj l0jGN8UAkG/lo1onL+VlS2XRZ7W3xqyaITvTgfejQIiFkEpcIp8mg5a+Sp5+dsJVaqg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=XLNIi2pR; arc=none smtp.remote-ip=74.125.229.8 X-Received: from mail-dy2-f8.google.com (mail-dy2-f8.google.com [74.125.229.8]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F4AA606A330 for <netdev@vger.kernel.org>; Sat, 5 Dec 2026 08:27:01 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F4AA606A330 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com X-Received: by mail-dy2-f8.google.com with SMTP id 5a478bee46e88-36a6ce64b95so801321eec.1 for <netdev@vger.kernel.org>; Sat, 05 Dec 2026 00:27:01 -0800 (PST) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796459221; x=1797064021; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=vM9qxd3UnHmgbOLagJ0eyyweUYVPDPOwzUGUu/+kxYg=; b=XLNIi2pRypYluK5wUtfYdsNtQf7bqpAXJ4h2n6zJgdb3PujnFCBlJ1lV0uLsaX+qnw 65chaOtFh0apxSf/YrJUzIiiZxSEQq3faiooGOEKoBlR9/ol7SwaqAeaOoyoUfCUTfX3 k2FPldP336+VTLZqIoXK3qBwiitkF6jEzEyzIqsqiMv1Q7OhuK88CG7Doij08vcTqjXL 0zSx2qXhtQlGeci/I6zmWT9pf6+JJ0Yyn2UiWCZ7S5FG5/LZeQMUW6EtM7jOLEwG2IHs mspCr+nRtErGF9WQ2+fZoUIeas2ZldVBhQbt8kXMvybOjyuUmjR4KtwF48aW4/Q+g4pZ Syew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796459221; x=1797064021; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vM9qxd3UnHmgbOLagJ0eyyweUYVPDPOwzUGUu/+kxYg=; b=Vl5Q+xUzKsVxbbuPFGKYujDrkRFtnkoyNKirWEnlMQWGr0dN7WgwijrjUB3wEX4I03 m2NNcgLxIu5kuAVpqkwkKYsbsNQJc9o16XrUZTTFocEaxu6gKLb3yxotC3n8dsMULx4+ YEhu6GbHvYX8/7iIqjo+SasvSizWfIMFmzxevcoU1dsOH2gRgK57PBn6AGgsaPVWtPpX iPbJTP0XAwrzxnI79JhdmPyX1++L3G6/UdMtPRGanS8bqL3U95n0VkCgwOZ5mTXe7dzH EgPqOCmDqHcnDLl2I31yRMhjsx18eDBGhKAd+gcrMR0EJJfAWkDThIuDvRAVkXWgWZvx FS7A== X-Forwarded-Encrypted: i=1; AL+hErFAIRkE3S97OwT5F36rs1MAw7IyJjawJL/izwRGB7Ye8vcQQC37d3/A0H+ZknYXxz10k6Y3WS4=@vger.kernel.org X-Gm-Message-State: AB4q+uGA3KCbE0iIpXlok1eAikZWqhPW/qRMtAB/8cv7oT9IKSjUNwpO kctgSh6ngoFgirOA+9f0pcRtL6InMyLKOTjI/6kHgzsz1le8KOIcUT/R X-Gm-Gg: AZFdTZcEni0upuVr8FjtQjoN2H0pAVG5suez27ADrLbVH7RNVnGfGO/DZUnjwrcYfz2 etrRHQehZ+xfkMrFiJpmwks2p/hN1+68zz0MH6Gt1diqi5UOm4jqo+aAbWFHfVkhy5RylStrt07 +gclnFAYh5W3ECXgzm3CTqifQWs2bYBKv73pE3QL0D5J/HhG1hCiLlL8F40B9fBSERms4z7xQg4 7bQru9MVZQxrTik6WT2zgqj6JDkBnvTH/f3XdQg2ax6MFKvvm4e51t+uzkL3E0yIhLE2kACEWvr 6MrTbqapFkr/ej5INAcDGYo0q3rQvyTxmsFBI9SJhP9SWPobYU0kXZeRC4Q1rgE3xMrcn6kP/xp 0gpaM2sSmszAFwWy/R73qdvkf+IFo8KVBBmvYM0G4MjkJojeWPsr1AG/wNYcjE6Kg8WMk/nvBzl 9MALWO62j10CVlofsyOfb8KlrfuklgWlmzXVBA8CGgOkts0mw2pmu7jQtOiku5QSnXGDzXfM2E9 vX3uPKeCQbt5GN3bZ2Q+VxcfZxi0v/7MC5lyyoliWcQ7qAT+uKLbAitPo/ozH5wZT8/IFgW2sPQ hyPqfFZqjqEzQ+Mde6NSgd6YPXlwUN2W4ykkXg9KR/gPe2d0iF8SVC4z07NuYPcTzKwhAxQFvZo wLA== X-Received: by 2002:a05:693c:885c:b0:385:1e1c:9ab5 with SMTP id 5a478bee46e88-387521659femr4238638eec.20.1796459220465; Sat, 05 Dec 2026 00:27:00 -0800 (PST) X-Received: from jiayi-vm-sprl-server17.local ([155.69.195.24]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521bdedbsm16212496eec.12.2026.12.05.00.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 00:27:00 -0800 (PST) X-Cc: Willem de Bruijn <willemb@google.com>, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, syzbot+621fd56ba002faba6392@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Received-Bytes: 16684