From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.6 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796363530; b=pxDXh1HCnZWUw8H5F3OjmlMq78P/D20Lwix00rkq7ldpyqGzqMtFPSlo79WWkpKct810 A/9FGIxj78vgb86ZMFI1441pTA5fcFEmCCfbWuDeV5m9wOHcmp5yp3+QJ7nbwh5xDH2PR pP1Ggm6iMery9GGHv46TUrhQc/Ktim67pxhFBlxbjTfmX25T+Ea1b0TQNRTEF2R0e52xZ XajqxpcdjQy8CyX6h/IybUoUxyXo77WZ0cQvAFn7+0tm7Q1WaOTdvEnouEL4mw/er3Rtc A6vcVLdGHLiKn3EjvT1QA4MyVtLrKy1wduGkGtKbAYYiyh0HoJPCjx9YeNGSZRlk1Cw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796363530; 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=aIFVGm6gLy3z2oFlin6aT/5lSnhK6n3May9RAynEL7I=; b=l8PO3zoKZUiQKaCH3bKc/dB0A9PUTs2GNNkO3nW2xSoyiTSWoJLWQMn+TGTYh/jQk2Gt 4RDIf3E91vRM2rq31G4dBuh10/xHA3eW+v+gOLZQaeAwUG5fiUOhO1aNSN13XPGlxcwQ2 tSLm1T5DuXl8T9tN7aPJEsdozmAgQBp1KxBDXLvsL4GsboHt4i1QIl2BszltHVSJt/uZ9 xwC7lVC5IIeac3sfNs6xNY71is1mrZGhYH4HAValgytjuNQNB6akRS5NsPrT6PWPpQqTB MR3ZFVLQwDckM04To544g74/e1TBGwysOae3q8kL/XMi8XtegA2u/cSxK92x1lzJ/BQ== 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=WLGtdy9I; arc=none smtp.remote-ip=74.125.229.6 Received: from mail-dy2-f6.google.com (mail-dy2-f6.google.com [74.125.229.6]) (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 99FC8606A32F for ; Fri, 4 Dec 2026 05:52:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99FC8606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=WLGtdy9I Received: by mail-dy2-f6.google.com with SMTP id 5a478bee46e88-33e48934fa8so84217eec.0 for ; Thu, 03 Dec 2026 21:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796363529; x=1796968329; 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=aIFVGm6gLy3z2oFlin6aT/5lSnhK6n3May9RAynEL7I=; b=WLGtdy9II6XHcaiXTiFaqNmB7SKlQEekvMGpRzejk23nW+WE4xHfv2P0EBMwZD2Gni 6Q6m6nHre6WKiyWLQ9uG6OoC9NuJCPi6Y8ZvHvs3D8X+D4C4kiA9FEedYqnDOptqvuem EBXeiMpesohgQtywEBXBvC6oU+0jroa51wGyXjaUmK/ddaLHPK4xvBCjkD9rdJwr5w6T 6dzZTHQCw0ZiXqF++Iq5zf0J5DQE21V1djcnN52zUC46JFgZlvxDY+Jxi//1+/bAbxfx G1DpS1qVVp6nhpV5LL2jfrXttZb/ia9hjOOjN14kIrgy4I+TaLNAsUxbGZZdpcPcR9VT dmRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796363529; x=1796968329; 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=aIFVGm6gLy3z2oFlin6aT/5lSnhK6n3May9RAynEL7I=; b=YIk4DaWlEY7O/SrNTxRwePd8m+3pVA+G5TeYSqyMlWvXj5ACNrHXDWtR8ObG2xB/VS lHchpbebDxq1hAAZ5Pm3YIhli0JOnuyzZPom6uKuMqXQ+MGwpvRWX1ZvZgzA7huMN4CU 9u4THgujpItAUX0h1KmntRaCL99Kw5PFuW2/nSzANKVrI58AvOkgzqoYT0qvL8p7ol0Z b3p2PYP2ZiApQjjMSizc8HzikHVTW5dMmw1AHt0OuCQ57HdhxKAsnxZfcnaMp6dOyz8T HHUM7t+MH80/K6TaxeDcA6boGTFdw1DrCTIonrPmPOWTBwBHqun35GA+osvAKmHlKWGN bhZg== X-Forwarded-Encrypted: i=1; AL+hErENCu3NGABUrnpXNEeqcwxiy/i6VUsRRpbEpL9IvsfmemlUZ1sP/CbUVsz+gMqIrYOGNCZllTo=@vger.kernel.org X-Gm-Message-State: APuU4Z9pSaBPvqWX2ImQmIr6XHEa6aiJkE+4mQUxicVTsq0+g9rHYIQf 0HtPrD5f6fQcNpMrANH2DbO2WYxx/Yv6obvZCsw15MSPCM9/6OMraTTY X-Gm-Gg: AZFdTZdr3I33onn83aJEQs9XmXDdgj1I5wsGBNmQnO7OpY1AtcZtiZjqPBf0w85eW2/ o0qmKofEvGLjZ9D6thNjiB89/jZkNrJRx07SEweGu9U9fdCae0h90UjAx/j/hd/y3RVCCMQs5LW 8/rZGF37+9GiELCQLn8B34ummlQsG33PIN2AIhbHx1KsZOsuLI6qW/a5pC02BV49XBwI709CLjN 73WzySsbl/a0IjAkh3HawgsemE1xSQajCS4dcgMjbkeZpMK8pqv4PV6RDY6Y11rA5Pz2rWw1Vky 0hWK1C7aG99ADcKOv1usinaJMW5kS6mzBxGI8EVLICp/Lk5Uf7lI89xP6klEl932VGWB+2FKJok IuvW0Czw3Y0YPwu9FqvyLqqqFa13+hTD8lTiIQcfOqB5Tc6VwI9dAysGmBDKSSSzfKCM8iAPXLL OhvWagi6CJQySIOjgH2oh0MYYnGMgIRmgl0VCJh7wZYe09BtE5s7gYZF6FV7fPjVKLCuH1gKtbj Meewp5odTFN88uCAnemKM8lLo7vHY0JOqMRkr0TUe5oTzBcp9qNDINltweN/aZQdvhrUlODMizC 4bngPfr5TK8pE7zP8mSlN2hijJwqDPFh6uf/jAX10EEwMDfFEcOLN5VW9g== X-Received: by 2002:a05:693c:60c6:b0:387:47d9:aa0e with SMTP id 5a478bee46e88-387521e2745mr1194265eec.31.1796363528655; Thu, 03 Dec 2026 21:52:08 -0800 (PST) Received: from jiayi-vm-sprl-server17.local ([155.69.195.24]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875207a50fsm3716077eec.1.2026.12.03.21.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 21:52:08 -0800 (PST) From: Jiayi Zhang 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@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, syzbot+621fd56ba002faba6392@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: [PATCH net v2] net/smc: close non-accepted sockets without holding the listen lock Date: Fri, 4 Dec 2026 05:51:58 +0000 Message-ID: <20261204055158.1897592-1-zhangjiayi1014@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 the cancel_work_sync(). Because smc_listen_work() holds the lock of the new socket, that commit made __smc_release() drop the socket's own lock before smc_clcsock_release(). smc_close_cleanup_listen() still calls it with the lock of the listening socket held. A socket on the accept queue has already passed that point: smc_listen_out() puts it on the queue under the listen lock and does not take that lock 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: fd57770dd198 ("net/smc: wait for pending work before clcsock release_sock") Reported-by: syzbot+621fd56ba002faba6392@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=621fd56ba002faba6392 Signed-off-by: Jiayi Zhang --- v2: - changelog only, the code is unchanged: 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