From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lFDmxrBp Received: by smtp.kernel.org (Postfix) with ESMTPSA id C141C1F00896; Sun, 29 Nov 2026 01:41:16 +0000 (UTC) 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== Message-ID: <8ee16fe4c66fdc6afa8cb7928098b983b0b65884.camel@kernel.org> Subject: Re: [PATCH] SUNRPC: serialize pipedir removal on the rpc_client_register() error path From: Trond Myklebust To: Joas Antonio dos Santos , Anna Schumaker Cc: Chuck Lever , Jeff Layton , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , syzbot+2e3c70a51d4ac0f6bdd9@syzkaller.appspotmail.com, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sat, 28 Nov 2026 20:41:15 -0500 In-Reply-To: <179327818020.63233.759139320736692367@gmail.com> References: <179327818020.63233.759139320736692367@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.62.1 (3.62.1-1.fc45) X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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.=C2=A0 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.=C2=A0 Pipefs > mount/umount notifications run under pipefs_sb_lock and walk that > list, > so they can race with it: >=20 > =C2=A0- a pipefs mount between rpc_get_sb_net() and > rpc_unregister_client() > =C2=A0=C2=A0 gives the client a new directory, which the unlocked > =C2=A0=C2=A0 rpc_remove_client_dir() then removes while a concurrent umou= nt of > =C2=A0=C2=A0 that superblock drops the same dentries in > select_collect_umount(); >=20 > =C2=A0- a umount notification that picked the client up before it was > =C2=A0=C2=A0 unregistered keeps using it after rpc_new_client() has freed= it. >=20 > syzbot hit the first one when racing rpc_pipefs mount/umount with > NFSv4 mounts (the krb5i rpcauth_create() fails without the gss mech): >=20 > =C2=A0 WARNING: fs/dcache.c:1063 at d_make_discardable+0x28e/0x2f0 > fs/dcache.c:1063 > =C2=A0=C2=A0 __simple_recursive_removal+0x276/0x5c0 fs/libfs.c:625 > =C2=A0=C2=A0 rpc_remove_client_dir+0xf0/0x140 net/sunrpc/rpc_pipe.c:898 > =C2=A0=C2=A0 __rpc_clnt_remove_pipedir net/sunrpc/clnt.c:100 [inline] > =C2=A0=C2=A0 rpc_client_register+0x605/0x6f0 net/sunrpc/clnt.c:333 > =C2=A0=C2=A0 rpc_new_client+0x977/0x1300 net/sunrpc/clnt.c:437 >=20 > With a test-only msleep() after rpc_get_sb_net() returns NULL, the > syzbot reproducer also triggers the second one: >=20 > =C2=A0 BUG: KASAN: slab-use-after-free in rpc_pipefs_event+0x568/0x57c > =C2=A0 Write of size 8 at addr fff000000ec53240 by task rpc_repro/107 > =C2=A0=C2=A0 rpc_pipefs_event+0x568/0x57c > =C2=A0=C2=A0 notifier_call_chain+0xfc/0x384 > =C2=A0=C2=A0 blocking_notifier_call_chain+0x68/0x9c > =C2=A0=C2=A0 rpc_kill_sb+0xbc/0x1a8 > =C2=A0=C2=A0 deactivate_locked_super+0x98/0x11c > =C2=A0 Allocated by task 111: > =C2=A0=C2=A0 rpc_new_client+0x144/0xf04 > =C2=A0 Freed by task 111: > =C2=A0=C2=A0 kfree+0x1dc/0x5c8 > =C2=A0=C2=A0 rpc_new_client+0x9f8/0xf04 >=20 > 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. >=20 > Fixes: eeee245268c9 ("SUNRPC: Fix a deadlock in > rpc_client_register()") > Reported-by: syzbot+2e3c70a51d4ac0f6bdd9@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=3D2e3c70a51d4ac0f6bdd9 > Cc: stable@vger.kernel.org > Signed-off-by: Joas Antonio dos Santos > 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.=C2=A0 The race window is narrow: the plain reproducer did not > hit it here in 6 runs, with or without this patch.=C2=A0 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): >=20 > =C2=A0 unpatched + delay:=C2=A0 2 of 2 boots, 16-22 WARNINGs each (mostly > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 d_make_discardable, = plus fast_dput, and > umount_check / > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 generic_shutdown_sup= er once) and one KASAN > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 slab-use-after-free = each (rpc_pipefs_event in > one boot, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rpc_create_client_di= r in the other) > =C2=A0 patched + delay:=C2=A0=C2=A0=C2=A0 3 of 3 boots (9 runs), no WARNI= NG, KASAN or > lockdep > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 report > =C2=A0 patched, no delay:=C2=A0 2 of 2 boots clean >=20 > net/sunrpc/clnt.o builds cleanly with W=3D1. >=20 > =C2=A0net/sunrpc/clnt.c | 10 ++++++++-- > =C2=A01 file changed, 8 insertions(+), 2 deletions(-) >=20 > 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, > =C2=A0=09} > =C2=A0=09return 0; > =C2=A0err_auth: > -=09pipefs_sb =3D rpc_get_sb_net(net); > +=09/* > +=09 * Unregister first so that a concurrent pipefs mount cannot > give the > +=09 * client a new directory, then remove the directory under > +=09 * pipefs_sb_lock like rpc_free_client() does. > +=09 */ > =C2=A0=09rpc_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? > -=09__rpc_clnt_remove_pipedir(clnt); > +=09rpc_clnt_remove_pipedir(clnt); > +=09goto out_destroy; > =C2=A0out: > =C2=A0=09if (pipefs_sb) > =C2=A0=09=09rpc_put_sb_net(net); > +out_destroy: > =C2=A0=09rpc_sysfs_client_destroy(clnt); > =C2=A0=09rpc_clnt_debugfs_unregister(clnt); > =C2=A0=09return err; --=20 Trond Myklebust Linux NFS client maintainer, Hammerspace trondmy@kernel.org, trond.myklebust@hammerspace.com