🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26756

[PATCH net v2] net/smc: close non-accepted sockets without holding the listen lock

#26756
From: Jiayi Zhang
Date: Fri, 04 Dec 2026 05:51
123 lines
16030 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 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 <zhangjiayi1014@gmail.com>
---
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
Technical Details
Message-ID: <20261204055158.1897592-1-zhangjiayi1014@gmail.com>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer05.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-377088-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer05.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-377088-linux-kernel-netdev=dewy.ru
From: zhangjiayi1014@gmail.com (Jiayi Zhang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] net/smc: close non-accepted sockets without holding the listen lock
Date: Fri,  4 Dec 2026 05:51:58 +0000
Organization: Usenet Network
Message-ID: <20261204055158.1897592-1-zhangjiayi1014@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2686194"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/hEdhqm0pcN0JuURx6swJ2/tpfM= sha256:qi75lu4+3rKUOlEz8EHQpG00lC35xCvsluJE1+oNnfs= sha1:Qa7AEah+CXTIPbDRBQ9ztZtupBE= sha256:Spv4nOCW1YEEJGGkKXroTRdBpOpZY/ihTjOoHz8sbL4=
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 D7E26117B17; Fri,  4 Dec 2026 08:52:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.396
X-Spam-Status: No, score=-3.396 tagged_above=-9999 required=6.31 tests=[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 dpCS8pG6sInp; Fri,  4 Dec 2026 08:52:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377088-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 49AD5117AA4; Fri,  4 Dec 2026 08:52:17 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 53CE4261BE; Fri,  4 Dec 2026 05:52:14 +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=1796363531; b=r25Lt7Hx6Sl3bYpy4KiF4A383zCkttlVEZo/Ortiuu4g+DXOjE3VpQk66fssjtk5SxPh w1U+R4g5hZejINFS4Hy0TDouvH4UsdpbQNdBZ0bkBatwEllia7heKQuX4X1pcJNsL9CTj 5O1KGaL07phGsAP/cRz/1OuypuyJ6DaWoWjGYvTvYI6QJsq6RF/hYK8g6vVXUKYpRmHm+ wEBJTwz9KZKzFhHFBBZBbePaCfn00QQ8zyfWOaH3lUbrwANZb8FIH7DKRRs0ATYCPdS5V 51YTrPhbzpBMwijsfPeQkKV7mezL0I9juCWURZkx6f/WpU6/jv/MiLioMRBKK6f5lSA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796363531; 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=aIFVGm6gLy3z2oFlin6aT/5lSnhK6n3May9RAynEL7I=; b=PoqTIzs8JmPzb9zTC3aYIyKHAHmzygPl2zJsm8jaqaDgw/WbY9Q2gnz3GLPFmUx53Q3h CKrpsWmfLyoZ+31lLkDDpzJYchhB0rWhSedKBZyBS7/Hy33uEGnN5LdgNR2H0Dg+nvEOv aA38UcA1cyrt1SKaM46u8v294bgYu6sGCYyQhUCVNH8VWP4P+6rj994RWJ0qQpQgIQFMD 1SXN9Eod+LpbA8ez8CiLru+1/Mp31v0QdZR2aDJINsS4o3mWJ4ZrcafBruWXjVh/MkLvi jNMphrdDFLiAimIJnLI6y/MwbaKEVwECu6Ir7EwAcNvDrztzeafcgpwcZKNXPh2R/gQ==
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=WLGtdy9I; 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 31F62606A680; Fri,  4 Dec 2026 05:52:11 +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=WLGtdy9I
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.6
X-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==
X-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==
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=WLGtdy9I; arc=none smtp.remote-ip=74.125.229.6
X-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 <netdev@vger.kernel.org>; Fri,  4 Dec 2026 05:52:09 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99FC8606A32F
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-f6.google.com with SMTP id 5a478bee46e88-33e48934fa8so84217eec.0 for <netdev@vger.kernel.org>; Thu, 03 Dec 2026 21:52:09 -0800 (PST)
X-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 lHchpbebDxq1hAAZ5Pm3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dvhrUlODMizC 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)
X-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)
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: 15833