mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Shigeru Yoshida <syoshida@redhat.com>,
	Trond Myklebust <trondmy@kernel.org>,
	 Anna Schumaker	 <anna@kernel.org>, Chuck Lever <cel@kernel.org>,
	NeilBrown <neil@brown.name>,
	 Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	"David S. Miller"	 <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski	 <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman	 <horms@kernel.org>,
	felix <fuzhen5@huawei.com>
Cc: linux-nfs@vger.kernel.org, netdev@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH] SUNRPC: update clnt->pipefs_sb on pipefs MOUNT/UMOUNT events
Date: Mon, 17 Aug 2026 09:31:12 -0400	[thread overview]
Message-ID: <4a3a7a0cd52e8fc571c967716756f49b8a0f95f2.camel@kernel.org> (raw)
In-Reply-To: <20260817080013.564939-1-syoshida@redhat.com>

On Mon, 2026-08-17 at 17:00 +0900, Shigeru Yoshida wrote:
> Commit bfca5fb4e97c ("SUNRPC: Fix RPC client cleaned up the freed
> pipefs dentries") added a clnt->pipefs_sb field and a consistency
> check in rpc_clnt_remove_pipedir() so that pipedir cleanup is skipped
> when the current superblock does not match the one recorded in the
> client.
> 
> However, __rpc_clnt_handle_event() never updates clnt->pipefs_sb when
> it creates or removes pipedirs in response to RPC_PIPEFS_MOUNT and
> RPC_PIPEFS_UMOUNT notifications.
> 
> This causes a problem for RPC clients that are registered before
> rpc_pipefs is mounted (e.g., before rpc_pipefs is mounted during boot,
> or after it has been unmounted). Such clients have clnt->pipefs_sb set
> to NULL at registration time because rpc_get_sb_net() returns NULL.
> When rpc_pipefs is mounted later, __rpc_clnt_handle_event(MOUNT)
> creates the pipedir but leaves clnt->pipefs_sb as NULL. When the
> client is later destroyed, rpc_clnt_remove_pipedir() sees that the
> current superblock does not match clnt->pipefs_sb and skips cleanup,
> leaving orphaned dentries whose RPC_I(inode)->private pointers
> reference freed rpc_clnt memory. Any subsequent access to these
> orphaned info files triggers a use-after-free [1].
> 
> Fix this by setting clnt->pipefs_sb in __rpc_clnt_handle_event() on
> MOUNT and clearing it on UMOUNT, mirroring what rpc_setup_pipedir()
> already does at client registration time.
> 
> [1]
> BUG: KASAN: slab-use-after-free in rpc_info_open (net/sunrpc/rpc_pipe.c:426)
> Read of size 4 at addr ffff88802ebe0800 by task cat/5079
> 
> Call Trace:
>  <TASK>
>  ...
>  rpc_info_open (net/sunrpc/rpc_pipe.c:426)
>  do_dentry_open (fs/open.c:947)
>  vfs_open (fs/open.c:1052)
>  path_openat (fs/namei.c:4700 fs/namei.c:4863)
>  do_file_open (fs/namei.c:4892)
>  do_sys_openat2 (fs/open.c:1368)
>  __x64_sys_openat (fs/open.c:1385)
>  do_syscall_64 (arch/x86/entry/syscall_64.c:94)
>  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
>  </TASK>
> 
> Allocated by task 5048:
>  ...
>  rpc_new_client (net/sunrpc/clnt.c:377)
>  __rpc_clone_client (net/sunrpc/clnt.c:645)
>  rpc_clone_client_set_auth (net/sunrpc/clnt.c:706)
>  nfs_init_server_rpcclient (fs/nfs/client.c:640)
>  nfs_clone_server (fs/nfs/client.c:1247)
>  nfs4_clone_server (fs/nfs/nfs4proc.c:10683)
>  nfs_do_submount (fs/nfs/namespace.c:288)
>  ...
> 
> Freed by task 24:
>  ...
>  kfree (mm/slub.c:6692)
>  rpc_free_client_work (net/sunrpc/clnt.c:987)
>  process_scheduled_works (kernel/workqueue.c:3405)
>  worker_thread (kernel/workqueue.c:3486)
>  ...
> 
> Fixes: bfca5fb4e97c ("SUNRPC: Fix RPC client cleaned up the freed pipefs dentries")
> Assisted-by: Claude:claude-opus-4-6
> Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
> ---
>  net/sunrpc/clnt.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
> index efa26899bc7d..55617d263d2f 100644
> --- a/net/sunrpc/clnt.c
> +++ b/net/sunrpc/clnt.c
> @@ -179,11 +179,17 @@ static int rpc_clnt_skip_event(struct rpc_clnt *clnt, unsigned long event)
>  static int __rpc_clnt_handle_event(struct rpc_clnt *clnt, unsigned long event,
>  				   struct super_block *sb)
>  {
> +	int err;
> +
>  	switch (event) {
>  	case RPC_PIPEFS_MOUNT:
> -		return rpc_setup_pipedir_sb(sb, clnt);
> +		err = rpc_setup_pipedir_sb(sb, clnt);
> +		if (!err)
> +			clnt->pipefs_sb = sb;
> +		return err;
>  	case RPC_PIPEFS_UMOUNT:
>  		__rpc_clnt_remove_pipedir(clnt);
> +		clnt->pipefs_sb = NULL;
>  		break;
>  	default:
>  		printk(KERN_ERR "%s: unknown event: %ld\n", __func__, event);

Looks right.

Reviewed-by: Jeff Layton <jlayton@kernel.org>

      reply	other threads:[~2026-08-17 13:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  8:00 Shigeru Yoshida
2026-08-17 13:31 ` Jeff Layton [this message]

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=4a3a7a0cd52e8fc571c967716756f49b8a0f95f2.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna@kernel.org \
    --cc=cel@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fuzhen5@huawei.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --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=pabeni@redhat.com \
    --cc=syoshida@redhat.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®