🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24176

[PATCH v2] SUNRPC: serialize pipedir removal on the rpc_client_register() error path

#24176
From: Joas Antonio dos Santos via B4 R...
Date: Sun, 29 Nov 2026 16:20
94 lines
14292 bytes
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>
Technical Details
Message-ID: <20261129-sunrpc-err-auth-v2-v2-1-7749f7c18ef0@gmail.com>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373566-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373566-linux-kernel-netdev=dewy.ru
From: devnull+joasantonio108.gmail.com@kernel.org (Joas Antonio dos Santos via B4 Relay)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v2] SUNRPC: serialize pipedir removal on the
 rpc_client_register() error path
Date: Sun, 29 Nov 2026 16:20:25 +0000
Organization: Usenet Network
Message-ID: <20261129-sunrpc-err-auth-v2-v2-1-7749f7c18ef0@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1208512"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ZFp6rFstPhpBrUdn5ixIuNx5Z38= sha256:33neGVkPId0DKUT66shnJHkdW0G935ePIjzFahUy7EI=
	sha1:XuMN/9hCGfb/2JpMK0+6V6johCA= sha256:CqcALCls1a4UHPjKu6T1i2sN5juCVWZmMlbRmgl7ePU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 48FF8125F9A; Sun, 29 Nov 2026 19:20:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	FREEMAIL_REPLYTO_END_DIGIT=0.25, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jiwf88FpMqXq;
	Sun, 29 Nov 2026 19:20:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373566-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 4B456125F96; Sun, 29 Nov 2026 19:20:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 02ECD241CD; Sun, 29 Nov 2026 16:20:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795969237;
	b=sMqy5NOYcQr8dpgAENvdtW03bgPACBephda8NELlcDgsOQ1MqIFyqj6SFHeWIst7yvB5
	 jsaIv1ywDTm1sdnuj/C7da3kRw3VwpWS1ViJOZCWvhV60IZ+yf6EpyWavNlJz6Y6Dcxg+
	 rd4954qNgx7Ra8BRl0UuDbVISjV6HIXsdVaJc0l0+TX9tghfzgSpw3ogX5ZPwCKYqQecv
	 M7tM3sROzpCoic0Nh6RgZoSWou3SOLSwJlGJxXLLrbtaYUnjqkwnaZrPk001bkVukNkXA
	 bG+TaNoP8mBjOlLW8BFzpM4kzXkmX8qf8/1uRqIdQSSHMfIWrPtCnYBz0SuBY2q/VfA==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795969237;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date:
	 Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence: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=lzhiaCCU7ew8fR8n0pnTgANmbCn+ny4n+FCtoCCg3TnIFDAQlnIN7hM0D8DeHwSLh9nQ
	 5fDlrzM10OYklsH5t3aKj7wcCQgT3Y5yeQULq9Vppe+z+gajjpB7BCfiOvpR/xveM+rpz
	 wtMy7lJMvkneUx1lhzM0poiTEotxmUX4jOFq6pqnSIbcwyE9lXTDM62jg+2piqTPrJ7jb
	 QvqBmyd4bLnwGxgSwEyx5yfD2aqW5i8v4Bjapn8+GXJIJCgg6ixutONUgIHX6RLIuf81i
	 4mVdPd9JYPvK01namC7GObK4BDrNAqEmOOrz97snKL4rm5Lmvp3slI1hpj3t8zqErBw==
X-ARC-Authentication-Results: i=3; 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=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B146D606A327;
	Sun, 29 Nov 2026 16:20:37 +0000 (UTC)
X-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=GVhzrmG+
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-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==
X-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==
X-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
X-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)
X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
X-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==
X-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==
X-ARC-Authentication-Results: i=1; smtp.kernel.org; 
	arc=none smtp.remote-ip=100.80.115.77
X-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)
X-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==
X-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)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-B4-Tracking: v=1; b=H4sIAMhQDGsC/x3MMQqAMAxA0atIZgM2iKJXEYdqo2apktoiFO9uc
 XzD/xkCq3CAscqgnCTI6QuormA9rN8ZxRUDNdQZQwOG6PVakVXRxvvARNhtzpJzpqV+gRJeyps
 8/3Sa3/cDoErIDGQAAAA=
X-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
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 <joasantonio108@gmail.com>
X-Reply-To: joasantonio108@gmail.com