🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24033

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

#24033
From: Trond Myklebust
Date: Sun, 29 Nov 2026 01:41
139 lines
13913 bytes
On Thu, 2026-10-29 at 09:49 -0300, Joas Antonio dos Santos wrote:
> When rpcauth_create() fails, rpc_client_register() calls
> rpc_get_sb_net() and then __rpc_clnt_remove_pipedir() whether or not
> a
> pipefs superblock was found.  If rpc_get_sb_net() returns NULL, the
> removal runs without sn->pipefs_sb_lock, and the client is still on
> sn->all_clients until rpc_unregister_client() a line later.  Pipefs
> mount/umount notifications run under pipefs_sb_lock and walk that
> list,
> so they can race with it:
> 
>  - a pipefs mount between rpc_get_sb_net() and
> rpc_unregister_client()
>    gives the client a new directory, which the unlocked
>    rpc_remove_client_dir() then removes while a concurrent umount of
>    that superblock drops the same dentries in
> select_collect_umount();
> 
>  - a umount notification that picked the client up before it was
>    unregistered keeps using it after rpc_new_client() has freed it.
> 
> syzbot hit the first one when racing rpc_pipefs mount/umount with
> NFSv4 mounts (the krb5i rpcauth_create() fails without the gss mech):
> 
>   WARNING: fs/dcache.c:1063 at d_make_discardable+0x28e/0x2f0
> fs/dcache.c:1063
>    __simple_recursive_removal+0x276/0x5c0 fs/libfs.c:625
>    rpc_remove_client_dir+0xf0/0x140 net/sunrpc/rpc_pipe.c:898
>    __rpc_clnt_remove_pipedir net/sunrpc/clnt.c:100 [inline]
>    rpc_client_register+0x605/0x6f0 net/sunrpc/clnt.c:333
>    rpc_new_client+0x977/0x1300 net/sunrpc/clnt.c:437
> 
> With a test-only msleep() after rpc_get_sb_net() returns NULL, the
> syzbot reproducer also triggers the second one:
> 
>   BUG: KASAN: slab-use-after-free in rpc_pipefs_event+0x568/0x57c
>   Write of size 8 at addr fff000000ec53240 by task rpc_repro/107
>    rpc_pipefs_event+0x568/0x57c
>    notifier_call_chain+0xfc/0x384
>    blocking_notifier_call_chain+0x68/0x9c
>    rpc_kill_sb+0xbc/0x1a8
>    deactivate_locked_super+0x98/0x11c
>   Allocated by task 111:
>    rpc_new_client+0x144/0xf04
>   Freed by task 111:
>    kfree+0x1dc/0x5c8
>    rpc_new_client+0x9f8/0xf04
> 
> Do what rpc_free_client() does instead: unregister the client first,
> so
> no later notification can find it, then remove the directory with
> rpc_clnt_remove_pipedir(), which takes pipefs_sb_lock (waiting for a
> notification that is still running) and only removes it if the
> client's
> superblock is the current one.
> 
> 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>
> Assisted-by: Yaga Agent HackerSec Claude:claude-opus-5-5
> ---
> Tested on Linus' master c339f4010dea (arm64, QEMU, generic KASAN,
> PROVE_LOCKING, NFSv4 without RPCSEC_GSS_KRB5) with the syzbot C
> reproducer.  The race window is narrow: the plain reproducer did not
> hit it here in 6 runs, with or without this patch.  To widen it, a
> test-only msleep(20) was added on the err_auth path (after
> rpc_get_sb_net() returns NULL in the unpatched code, and between
> rpc_unregister_client() and the removal with this patch):
> 
>   unpatched + delay:  2 of 2 boots, 16-22 WARNINGs each (mostly
>                       d_make_discardable, plus fast_dput, and
> umount_check /
>                       generic_shutdown_super once) and one KASAN
>                       slab-use-after-free each (rpc_pipefs_event in
> one boot,
>                       rpc_create_client_dir in the other)
>   patched + delay:    3 of 3 boots (9 runs), no WARNING, KASAN or
> lockdep
>                       report
>   patched, no delay:  2 of 2 boots clean
> 
> net/sunrpc/clnt.o builds cleanly with W=1.
> 
>  net/sunrpc/clnt.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
> index 6cedc82..16aff2a 100644
> --- a/net/sunrpc/clnt.c
> +++ b/net/sunrpc/clnt.c
> @@ -328,12 +328,18 @@ static int rpc_client_register(struct rpc_clnt
> *clnt,
>  	}
>  	return 0;
>  err_auth:
> -	pipefs_sb = rpc_get_sb_net(net);
> +	/*
> +	 * Unregister first so that a concurrent pipefs mount cannot
> give the
> +	 * client a new directory, then remove the directory under
> +	 * pipefs_sb_lock like rpc_free_client() does.
> +	 */
>  	rpc_unregister_client(clnt);

You're now calling rpc_unregister_client() without holding
pipefs_sb_lock. What happens if clnt->pipefs_sb is unmounted here while
the client is no longer on all_clients?

> -	__rpc_clnt_remove_pipedir(clnt);
> +	rpc_clnt_remove_pipedir(clnt);
> +	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;

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com
Technical Details
Message-ID: <8ee16fe4c66fdc6afa8cb7928098b983b0b65884.camel@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373328-linux-kernel-netdev=dewy.ru
References: <179327818020.63233.759139320736692367@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373328-linux-kernel-netdev=dewy.ru
From: trondmy@kernel.org (Trond Myklebust)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] SUNRPC: serialize pipedir removal on the
 rpc_client_register() error path
Date: Sat, 28 Nov 2026 20:41:15 -0500
Organization: Usenet Network
Message-ID: <8ee16fe4c66fdc6afa8cb7928098b983b0b65884.camel@kernel.org>
References: <179327818020.63233.759139320736692367@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1077723"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:xel08BmzlZVh46uY8joIV//5igc= sha256:sCpgaVqVlN2yrSGWkdZEE2tLd2C17oxfpaOvAGF6dqc=
	sha1:tJc3++rOLkj5TcmcIwSu62Nbm/8= sha256:Q+owYHpijJbkuxfk2uF3zU2qLLD9fQkyfBJsrvrAPaw=
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 3A5DD125F91; Sun, 29 Nov 2026 04:41:45 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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,
	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 azb6SXKopdfs;
	Sun, 29 Nov 2026 04:41:41 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373328-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 0E7E0125F90; Sun, 29 Nov 2026 04:41:31 +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 580BA28B17; Sun, 29 Nov 2026 01:41:23 +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=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795916479;
	b=fOM+ESBnS5IOu1JwWRnVp+vkDa2XnMb6eA9g+IXQvdIksPNkF+lc5UV3MJQOnv2nETKl
	 a26elOIcIwv60T+tGatxwTGhKbd10zM0hoBx8jfpb3osKHWAnDNW/khmwjoU2VJEF6Unj
	 QF7ga1EGuM8LkNaINcuCSlJfPeBgcbYI+KXcRwniIuxLT7AHFmGpmXo+91o4iTMezXNly
	 Ct1O4eScqC6rB6QvO69zzlKXKbaaxLWK+sunStAaY136ytA8DSvBSUIg5WLHoBTZA3Vgl
	 RKO1HCMVVwliLpEJj4mbCSX6J7fbAJ1p1xgWBixAS97P6HpHx87cA/h1AXyfSJGjqlA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795916479;
	h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Subject:
	 From:To:Cc:Date:In-Reply-To:References:Content-Type:
	 Content-Transfer-Encoding:User-Agent:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version;
	bh=88OI/GWXZE8K+GruHQmPmmt7HbwEg632hTEEad41hdQ=;
	b=om/Z3abPocRWBznqtSVkpJ/saiaSGR/8jDaF9HmyUy4VwWMlnLXOO+n4n9epYn02Va2I
	 1KZ1D447I/p9uZKVI+XW7jHtSldI/PZFjOftbZV+4P5rWfgV6O5zN2pTVpv+37O2jyv8h
	 olQyTjlcjZdEth6jah3PhYoSLlb7lAV/8CIqhxLc4wq0Tvr7GFGAucfKJdf0HhPAbApPs
	 BFFicfFHENIkBcN+ABvIo8dS1JNqLvhkXy3o9fKmvas17124IeUgRLWewOEIFke+fQvox
	 g292SrhkYoHXOmVdIbP4/CRXLmTOeLoksoBPiUVApbcN1DXAa0rdMmZJzZeq4wXTUuQ==
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=lFDmxrBp;
	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 18406606A6A0;
	Sun, 29 Nov 2026 01:41:19 +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=lFDmxrBp
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795916478;
	b=DCWXM0w7rOf21TZcPha3dUCtudDx9jeZ2hZSUPjPYAnulU627Qgn+r934FLYlxgyaTDM
	 5NAP+XYaNMChnUAroa0v/31le4npSTu71l9tYt0Bek20CLD0KRBtfC9kpfIACcTSntPHb
	 0maSBeIWUGiH8RpGlOgMIqMoMYw6cE/1FOAALhjLS1DPUZkc5gE9plhVcKr1Adsw0MgI3
	 KCfzsYYxYpQ8pDBaUCj+MkObezVc/wQ4gY34bwpyDQ/Ytr18HzUUsM+xuM6ylj4LqawoF
	 hZ1j4LPfsrNJ8/YE5c7vLpsNtZVZ752fZdkmjZe6kE4Vx0V1CJhv68uuUstPZjr6a+Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795916478;
	h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date:
	 In-Reply-To:References:Content-Type:Content-Transfer-Encoding:
	 User-Agent:MIME-Version;
	bh=88OI/GWXZE8K+GruHQmPmmt7HbwEg632hTEEad41hdQ=;
	b=Ii08tKsGP7oWrv3yfjdaVLMcLDOWpysyyrku8TouLZ9Wu8Xf47QZLSQi4/zXUek2YsUf
	 Ob4+jE+0P0RZIp5/gm+wM3iLKoRlTl/TRuVMRKBHkTw3LCqcmY+7Uc4q+Cc5QzgQ3WpWc
	 auMZlwgUOrO+NYWBmPtP213OwBVYJJFlmbUZaFX1vANNyBznRsiLBHtp5/F8lXyk3TFf8
	 I6dQXyTJr7gWpOJSRneianKWIKP58l+idAs1xM4zQcV1SuZy2wOrdew3qwrVTgCMIEfM0
	 w+WUjylYpx4k058ufMDcdZmHmmV6WFWhL2jg/Ofa8ExC4a354cm5tKOhezoEvPk88DQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lFDmxrBp;
	arc=none 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 36A5B606A336;
	Sun, 29 Nov 2026 01:41:17 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C141C1F00896;
	Sun, 29 Nov 2026 01:41:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795916477;
	bh=88OI/GWXZE8K+GruHQmPmmt7HbwEg632hTEEad41hdQ=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=lFDmxrBpVfVvVtI37ZUMPo0ChO3q/6z+FVlMIuU08/ahPvSPz6h3BHoOTECI0xmt8
	 pO9Ff1SIDg1Jv81/SDVpy3KiGcLpc29pza2wSawcEidKlSzoybgcksUiVTGSO7oAb7
	 nkygAjDdutSixC++xmMu5yZSNcF3NSikrEUKo3jEiHYYtRn2VoVq1i5QpT18vke2pz
	 aNmv0klTX7+P/DtnQEMX3ChMNJ4qCvlrldntdyrVZSym94oV2m938wu/Wf47FWc/Dv
	 OADOYVFc55343He+7W9rhXM6yl6nXXjROLGn6ltaHo6ckKcd42LtUnrd2ubj8iwClB
	 O9/sjmi1907JQ==
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>, 
	syzbot+2e3c70a51d4ac0f6bdd9@syzkaller.appspotmail.com, 
	linux-nfs@vger.kernel.org, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <179327818020.63233.759139320736692367@gmail.com>
X-User-Agent: Evolution 3.62.1 (3.62.1-1.fc45) 
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