* [PATCH v2] SUNRPC: serialize pipedir removal on the rpc_client_register() error path
@ 2026-11-29 16:20 Joas Antonio dos Santos via B4 Relay
0 siblings, 0 replies; only message in thread
From: Joas Antonio dos Santos via B4 Relay @ 2026-11-29 16:20 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker, joasantonio108
Cc: Chuck Lever, Jeff Layton, NeilBrown, Olga Kornievskaia, Dai Ngo,
Tom Talpey, linux-nfs, netdev, linux-kernel,
syzbot+2e3c70a51d4ac0f6bdd9, stable
From: Joas Antonio dos Santos <joasantonio108@gmail.com>
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 <joasantonio108@gmail.com>
---
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 <joasantonio108@gmail.com>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-29 16:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 16:20 [PATCH v2] SUNRPC: serialize pipedir removal on the rpc_client_register() error path Joas Antonio dos Santos via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®