From: Joas Antonio dos Santos Date: Sun, 29 Nov 2026 16:20:25 +0000 Subject: [PATCH v2] SUNRPC: serialize pipedir removal on the rpc_client_register() error path MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 List-Id: B4 Relay Submissions 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