From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796449941; b=TBujrwtXTr6w+pH11Gmw1iyKlTL1SCShvKJ06Z/VXbEpXdDG35sCuQuxD2DpBu2Coup5 IQJyKf8JROdqmdV65A+jnnMF+42KX+2GBwkjAXYKVjTw9safDISkYOP21s40TKnnYJWUU fza1zMmUl743d3RikUC/YA998InzO61bGDsgCjxU249g6pSDKuADCdjL2dCQRCnuu/sLe xBnG/hk8zRmHPiCyvskUIcAuGdGFOO7tVu4WoLnTLsluJi9kFUcvOV28/nqNUCqHrFomQ zsjpwc1UKH67863AbLu8EPswdZKbBtyuMOs+DwXqMrXJwMcdICCb+IXJuE1VCNg/RmQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796449941; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=co6OhUSZjODaFx2trkYhJm2zK0QH3fdME5ATJQp9cTo=; b=ZL0upou6r5MBT2sEutEjsrDor40drz6IvKBUXYgFaU7YWhl9VbdW98GQ+VsfOhVyhj84 s51u0KsIj1L81S59JNAitODHpmPcRzNRmYZW3mrnNV+26z5OITpGNv0ptFHZR5D7xn5dJ hE47PzsDC2/FEOGDP+7+Y8pp/e6eVy/aVhXTufBQV7h27jTSbSDb9Lh0xT7DlfycX3YSp 3bW96Gxwwvcv6FC3X0D9TZUSbG4itAPQawrdweqaXZcf+DTHBasfZoFNt5q0GhfJ0Knrl 5Sp7PXdNNX2q+eV9JK9GCdWGHTVVUffHB8Aqdv4S5TEteOw7FJ9mtkSM+7WYuUhK6gA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gddsb6GR; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38252606A322; Sat, 5 Dec 2026 05:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gddsb6GR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A7991F00936; Sat, 5 Dec 2026 05:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796449940; bh=co6OhUSZjODaFx2trkYhJm2zK0QH3fdME5ATJQp9cTo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gddsb6GRhAYJrNfda3uGolXVyN6JImj3CqsI7Ts5PbhOgLlXG4dXvcESLJHffKBa+ opspFTiyDj4rP/yB1B3+IVus3QuvqsuQonrU1Ouloi1APbwS6IsUzy9M/j34uMVOxP Hb5UbY8yHP6LhHol0MgcCd2ThziMy3hbbtLlfu7o01BYnHSDHN2vLlYBqnsAKGsxyL p9amzPPN//OkT5lFmRJ6gFM12v6IwgRZER8UtFMKVn9xgDBLFk8f6MBDGjN7eq21i9 8cRf9UTVsIA1vDWc9eQ3y6CAyg9bKgGy2xCdzJZv59maoXhyMW6yBEaw9Rwdp5BYGy ZeDThdwRQ/TxQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net v2] net/smc: close non-accepted sockets without holding the listen lock Reply-To: sashiko-reviews@lists.linux.dev To: "Jiayi Zhang" Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261204055158.1897592-1-zhangjiayi1014@gmail.com> References: <20261204055158.1897592-1-zhangjiayi1014@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 05:52:20 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] net/smc: Fixes tag cites fd57770dd198 instead of 39f41f367b08 - [Low] net/smc: stale comment and lock_sock_nested() branch in smc_release() -- commit d3e01a0fbfe2599dc1b40b1c050d934382921eae Author: Jiayi Zhang > net/smc: close non-accepted sockets without holding the listen lock > > 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 relea= se_sock") > Reported-by: syzbot+621fd56ba002faba6392@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=3D621fd56ba002faba6392 > Signed-off-by: Jiayi Zhang [Severity: Low] Should the Fixes tag cite 39f41f367b08 ("net/smc: common release code for non-accepted sockets") instead of fd57770dd198 ("net/smc: wait for pending work before clcsock release_sock")? In that earlier commit, __smc_release() did not exist yet and smc_close_non_accepted() released clcsock directly without calling smc_clcsock_release() or cancel_work_sync(). smc_listen_work() also did not take the new socket's lock until 2c7f14ed9c19 ("net/smc: fix LGR and link use-after-free issue"). It was 39f41f367b08 ("net/smc: common release code for non-accepted sockets") that extracted __smc_release() and made smc_close_non_accepted() call it, connecting smc_close_cleanup_listen() to smc_clcsock_release() under the listening socket lock. Updating the Fixes tag and the changelog description of the introducing commit would keep both accurate. > diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c > index 736abfbd2aafa..2c98b77f5caea 100644 > --- a/net/smc/smc_close.c > +++ b/net/smc/smc_close.c > @@ -225,9 +225,9 @@ int smc_close_active(struct smc_sock *smc) > write_unlock_bh(&smc->clcsock->sk->sk_callback_lock); > rc =3D 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: [Severity: Low] As reported by Mahanta Jambigi on v1 [1], moving smc_close_cleanup_listen() after release_sock() leaves the SMC_LISTEN special case and comment in smc_release() stale: net/smc/af_smc.c:smc_release() { ... if (sk->sk_state =3D=3D SMC_LISTEN) /* smc_close_non_accepted() is called and acquires * sock lock for child sockets again */ lock_sock_nested(sk, SINGLE_DEPTH_NESTING); else lock_sock(sk); ... } Because smc_close_non_accepted() no longer runs while the listening socket lock is held, this comment is now inaccurate and the lock_sock_nested() branch is obsolete. Can it be simplified to lock_sock(sk) or have its comment updated? [1] https://lore.kernel.org/r/1bf819d9-fb9f-4f6c-adf2-4b289982fea6@linux.ib= m.com --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204055158.1897= 592-1-zhangjiayi1014@gmail.com?part=3D1