From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795969226; b=o1PHuPztKUpACeDeJ6vo++41NUz+Ut7jIfeM9spcUw1bxnyylJwD6q8vYklE4ojJzRij uzXiz8zx0NTPCJoY2UE28+sfQ2Ap1BXn8r6jk9F/gchD7eEdu8DcY3tbno8MZ4vxgZpI/ ZP3gcV1bOpgA5WRu+3nC+DZheDfQLBHLqNpUgHiS7ksoDhbI3FonsTmdi7qiuQFxF/jiO htLTsl/ZZapJOlilMGVv9MOPE+dOq7qaqVkmYjahUgasDIK0oKnDXqS5zaGJ7iqh2cEgj KiwT3mlbznQc4cvFpJ/CvxIC2paPjbrq6Eq3kIxihqnFK88BSEDZ/21E21vkRMUprXQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795969226; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=HyijHNgbwZ1SE/9FZShInCsE/e3oo0Np21IqXkKIWZk=; b=bEoFGnByIZ4JRBrO5WJo7zptTJLJgVp49fi3wmr1uOjHPKnIf7ntqz4GIp9ycTni0Den 9934hGJnZSkOM0bNX4SOSD5q40m6xanhE3MuOB1nyrKdLwjQXEf8Lp6+XmM0NNIGZ29BJ itG5TR5SUKYgNrl/fopIIlPV7fPevZXAFk03cCiMvNnqaOjXZVKYLBqAw6QLMrFPqrFmR DZRxgXt9nnH4zVgqooh5XnspsWrbcqMOOgC8FUrsJL7c5vYTieHzSY5G4v2dQZRiZAueP YmLvzgDLsj/XKMK8UJ92Asy0QpgamfA9bANPlt6HTBM8kwPYIdIUR9nVF/T3Ctr4qTw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GVhzrmG+; arc=pass header.oldest-pass=0 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 C539E606A31C; Sun, 29 Nov 2026 16:20:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GVhzrmG+ Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795969226; b=kwy5EmJl4E+WO6XSkVblIOGJ8iiRLz+P1B9q2aEcIuuGzL9c8I87ss2fWcydf9aUzCPA CcaTt194u4u5gggjusZcbl0INMYFM93WZ0C2c6nCuW2CLHAAO2biDBf3UPNf6jwdZrrZC TmptkXnPEZj3sBCvJaJk1RQc+l7D+j+KblwTucxrCrCAU9FX1F4CrFWxu4+BmO5c3eHnb D3ovCsYskyM1TAg0qoN1p7LlqaFHzRGZ2zRek7UIzMRdG/KYvPd/JWhibLc60KDPE9Ibc vfXVNvAEiJV6N1jDH431Xl4U1aNj6dFzimg++ENAQOvWIMvN8b+0lFARgbGz0SbrBYw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795969226; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key:X-Endpoint-Received:X-Original-From:Reply-To: Content-Transfer-Encoding; bh=HyijHNgbwZ1SE/9FZShInCsE/e3oo0Np21IqXkKIWZk=; b=J1+ULCisGrnV44SKmfZRDqqP4mkWrNpC9Y80WUV8LB2z0M/HueeF4e4VzNszx0TMNOwA lGH0BqmmRfXOp5T+w6TGVgkr+ubpopMyjWS1uGag0n0AulmP2BxLxuIY8QiCZGnpNcKKT tJ8HlEs4ogsmg4azBYKRrFUzV1SivQIcejBxF8dBhd1JueTfYsbDko7248E1hO/KA3m+H N3el0BPTjtxZ5MEENVrWA7CRLIF0FuHNzS02enDsMtMbrGxsB4cdSxqqwxgcCJeetq97s RgWsieHUs26sjhipjkKeYhOvkDW3ZJZs/HJaeEKyxryKDrErg+m6PWyskZ9MUpxR4yA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id ADDA01F00896; Sun, 29 Nov 2026 16:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795969226; bh=HyijHNgbwZ1SE/9FZShInCsE/e3oo0Np21IqXkKIWZk=; h=From:Date:Subject:To:Cc:Reply-To; b=GVhzrmG+ddzc60/8zBfHuCLM3fptLF7GfJyfnbS4aMr/5yHlxS75U91GBPs39pTnE Zn12qEA8DLB6ZtPBC1vrj0JslqlexrHoOplRVaUfZ1hm7GYAlLXDbdrnUW3A98Jlto cioSOCo7IANvO9yIdH29Cm1q0iHOkgipa5yFmq51GXOgfByvZfbNusZzC2WeHlbKQN CZ4goAdOdxcDFj7AoYpvWT8HkxVxb1wldNndAr7eLpbyk2kP5v9AW6MSVBNzc4cuoa 3O+0CLi+FDzJ8ysfZbgt7LIR17oIxn7QAWptyVOzpmXT5/B0RqahFC7HCv1zLg8Jew nXsz/3Bc73soQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 0D5204E50F; Sun, 29 Nov 2026 16:20:25 +0000 (UTC) From: Joas Antonio dos Santos via B4 Relay Date: Sun, 29 Nov 2026 16:20:25 +0000 Subject: [PATCH v2] SUNRPC: serialize pipedir removal on the rpc_client_register() error path X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261129-sunrpc-err-auth-v2-v2-1-7749f7c18ef0@gmail.com> X-B4-Tracking: v=1; b=H4sIAMhQDGsC/x3MMQqAMAxA0atIZgM2iKJXEYdqo2apktoiFO9uc XzD/xkCq3CAscqgnCTI6QuormA9rN8ZxRUDNdQZQwOG6PVakVXRxvvARNhtzpJzpqV+gRJeyps 8/3Sa3/cDoErIDGQAAAA= To: Trond Myklebust , Anna Schumaker , joasantonio108@gmail.com Cc: Chuck Lever , Jeff Layton , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+2e3c70a51d4ac0f6bdd9@syzkaller.appspotmail.com, stable@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795969224; l=3602; i=joasantonio108@gmail.com; s=20261031; h=from:subject:message-id; bh=kU3n++SprzMhrKY1yTOEoMlGf1yVRr5JKIHFCEXe4rA=; b=kwq7zLrSCzV5p1Zqcv6GFvt9yaXY7QJW9Pbu8sPrnsb+zcEMLGr29b8qAr7VWDlfsQ06Mfqcl c0NkOpgEQCKAFrtG7KWA9PIyuSEA7/Ec24vzArz57VHTRNs5oHMmqYi X-Developer-Key: i=joasantonio108@gmail.com; a=ed25519; pk=ZxAznJT/FcPPdzLrDDFJQm4LLjjHVGBBqDSG3TXS23w= X-Endpoint-Received: by B4 Relay for joasantonio108@gmail.com/20261031 with auth_id=1371 X-Original-From: Joas Antonio dos Santos Reply-To: joasantonio108@gmail.com Content-Transfer-Encoding: 7bit From: Joas Antonio dos Santos When rpcauth_create() fails, rpc_client_register() only holds sn->pipefs_sb_lock for the pipedir removal if rpc_get_sb_net() finds a pipefs superblock. If it does not, the client is taken off sn->all_clients and its directory is removed with no lock held, and a pipefs mount in that window gives the client a new directory that is then removed while a concurrent umount drops the same dentries. syzbot hit this racing rpc_pipefs mount/umount with NFSv4 mounts: WARNING: fs/dcache.c:1063 at d_make_discardable+0x28e/0x2f0 __simple_recursive_removal+0x276/0x5c0 fs/libfs.c:625 rpc_remove_client_dir+0xf0/0x140 net/sunrpc/rpc_pipe.c:898 rpc_client_register+0x605/0x6f0 net/sunrpc/clnt.c:333 rpc_new_client+0x977/0x1300 net/sunrpc/clnt.c:437 Take pipefs_sb_lock unconditionally around rpc_unregister_client() and __rpc_clnt_remove_pipedir(), so no mount or umount notification can run between the two. Fixes: eeee245268c9 ("SUNRPC: Fix a deadlock in rpc_client_register()") Reported-by: syzbot+2e3c70a51d4ac0f6bdd9@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=2e3c70a51d4ac0f6bdd9 Cc: stable@vger.kernel.org Signed-off-by: Joas Antonio dos Santos --- Tested on Linus' master 4f069ab1ec24 (arm64, QEMU, generic KASAN, PROVE_LOCKING, NFSv4 without RPCSEC_GSS_KRB5) with the syzbot C reproducer. The window is narrow, so a test-only msleep(20) was added on the err_auth path to widen it (after rpc_get_sb_net() returns NULL in the unpatched code; before the lock and between the two calls with this patch): unpatched + delay: 2 of 2 boots hit d_make_discardable / fast_dput WARNINGs (9 and 12) patched + delay: 3 of 3 boots (9 runs) clean patched, no delay: 2 of 2 boots (6 runs) clean No lockdep report. net/sunrpc/clnt.o builds cleanly with W=1. --- Changes in v2: - Hold pipefs_sb_lock across rpc_unregister_client() as well, instead of unregistering first and locking afterwards. v1 left a window where a umount no longer found the client and its directory was never removed (Trond Myklebust). - Link to v1: https://lore.kernel.org/r/179327818020.63233.759139320736692367@gmail.com --- net/sunrpc/clnt.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 2f076b4bfd54..98fe954944b4 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -303,6 +303,7 @@ static int rpc_client_register(struct rpc_clnt *clnt, }; struct rpc_auth *auth; struct net *net = rpc_net_ns(clnt); + struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); struct super_block *pipefs_sb; int err; @@ -328,12 +329,20 @@ static int rpc_client_register(struct rpc_clnt *clnt, } return 0; err_auth: - pipefs_sb = rpc_get_sb_net(net); + /* + * Hold pipefs_sb_lock across both steps, whether or not pipefs is + * mounted, so that no mount or umount notification can run between + * taking the client off the list and removing its directory. + */ + mutex_lock(&sn->pipefs_sb_lock); rpc_unregister_client(clnt); __rpc_clnt_remove_pipedir(clnt); + mutex_unlock(&sn->pipefs_sb_lock); + goto out_destroy; out: if (pipefs_sb) rpc_put_sb_net(net); +out_destroy: rpc_sysfs_client_destroy(clnt); rpc_clnt_debugfs_unregister(clnt); return err; --- base-commit: 4f069ab1ec243e6b60dc438772905855c60774e8 change-id: 20261129-sunrpc-err-auth-v2-6fda2dd1427b Best regards, -- Joas Antonio dos Santos