From: Joas Antonio dos Santos via B4 Relay <devnull+joasantonio108.gmail.com@kernel.org>
To: Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>,
joasantonio108@gmail.com
Cc: Chuck Lever <cel@kernel.org>, Jeff Layton <jlayton@kernel.org>,
NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
linux-nfs@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
syzbot+2e3c70a51d4ac0f6bdd9@syzkaller.appspotmail.com,
stable@vger.kernel.org
Subject: [PATCH v2] SUNRPC: serialize pipedir removal on the rpc_client_register() error path
Date: Sun, 29 Nov 2026 16:20:25 +0000 [thread overview]
Message-ID: <20261129-sunrpc-err-auth-v2-v2-1-7749f7c18ef0@gmail.com> (raw)
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>
reply other threads:[~2026-11-29 16:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129-sunrpc-err-auth-v2-v2-1-7749f7c18ef0@gmail.com \
--to=devnull+joasantonio108.gmail.com@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=anna@kernel.org \
--cc=cel@kernel.org \
--cc=jlayton@kernel.org \
--cc=joasantonio108@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=netdev@vger.kernel.org \
--cc=okorniev@redhat.com \
--cc=stable@vger.kernel.org \
--cc=syzbot+2e3c70a51d4ac0f6bdd9@syzkaller.appspotmail.com \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®