All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever <cel@kernel.org>, NeilBrown <neilb@ownmail.net>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH v1] NFSD: Keep an evicted NFSv4.0 openowner off close_lru
Date: Wed, 02 Dec 2026 09:53:24 -0500	[thread overview]
Message-ID: <a14a158543bead1df41fdbd09691036d51ee1320.camel@kernel.org> (raw)
In-Reply-To: <20261202144159.108984-1-cel@kernel.org>

On Wed, 2026-12-02 at 09:41 -0500, Chuck Lever wrote:
> An NFSv4.0 OPEN that evicts an unconfirmed openowner can race with
> a CLOSE on that owner. release_openowner() takes the owner off
> nn->close_lru only when oo_last_closed_stid is set. That field stays
> NULL until the CLOSE reaches move_to_close_lru(), which then adds the
> unhashed owner to the list.
> 
> __destroy_client() finds close_lru entries only through cl_openowners,
> so it misses the stranded owner and frees the nfs4_client. The
> laundromat later reads the freed client through oo_owner.so_client,
> and can go on to take cl_lock in it:
> 
>   BUG: KASAN: slab-use-after-free in is_client_expired
>   Read of size 8 by task kworker/u19:2/84
>   Workqueue: nfsd4 laundromat_main
>    is_client_expired
>    nfs4_laundromat
>    laundromat_main
> 
>   Freed by task 84:
>    kmem_cache_free
>    free_client
>    __destroy_client
>    expire_client
>    nfs4_process_client_reaplist
>    nfs4_laundromat
> 
> Any client permitted to OPEN on an NFSv4.0 export can provoke the
> use-after-free. NFSv4.1 and later create openowners confirmed.
> 
> After the list add in move_to_close_lru(), test under cl_lock whether
> the owner is hashed, and if not, remove it with
> release_last_closed_stateid(). release_openowner() unhashes the owner
> under cl_lock before it reads oo_last_closed_stid under client_lock.
> move_to_close_lru() sets oo_last_closed_stid under client_lock before
> its test under cl_lock. At least one of the two therefore removes the
> owner, and release_last_closed_stateid() drops the stateid reference
> only once.
> 
> Until that test, a fresh oo_time keeps the laundromat off the owner,
> and the CLOSE pins the client through cl_rpc_users. Testing inside
> the existing client_lock section would need a second path that skips
> the list add and puts the stateid by hand.
> 
> Fixes: 3234975f477f ("nfsd: Remove nfs4_lock_state(): nfsd4_open and nfsd4_open_confirm")
> Signed-off-by: Chuck Lever <cel@kernel.org>
> ---
>  fs/nfsd/nfs4state.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index 6ddb35f5ae5a..c40b48125202 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -6145,8 +6145,9 @@ move_to_close_lru(struct nfs4_ol_stateid *s, struct net *net)
>  {
>  	struct nfs4_ol_stateid *last;
>  	struct nfs4_openowner *oo = openowner(s->st_stateowner);
> -	struct nfsd_net *nn = net_generic(s->st_stid.sc_client->net,
> -						nfsd_net_id);
> +	struct nfs4_client *clp = s->st_stid.sc_client;
> +	struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
> +	bool unhashed;
>  
>  	dprintk("NFSD: move_to_close_lru nfs4_openowner %p\n", oo);
>  
> @@ -6178,6 +6179,17 @@ move_to_close_lru(struct nfs4_ol_stateid *s, struct net *net)
>  	spin_unlock(&nn->client_lock);
>  	if (last)
>  		nfs4_put_stid(&last->st_stid);
> +
> +	/*
> +	 * A release_openowner() that reads oo_last_closed_stid before the
> +	 * store above leaves @oo on close_lru unhashed. __destroy_client()
> +	 * reaches close_lru entries only through cl_openowners.
> +	 */
> +	spin_lock(&clp->cl_lock);
> +	unhashed = nfs4_openowner_unhashed(oo);
> +	spin_unlock(&clp->cl_lock);
> +	if (unhashed)
> +		release_last_closed_stateid(oo);
>  }
>  
>  static noinline_for_stack struct nfs4_file *


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

      reply	other threads:[~2026-12-02 14:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 14:41 [PATCH v1] NFSD: Keep an evicted NFSv4.0 openowner off close_lru Chuck Lever
2026-12-02 14:53 ` 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=a14a158543bead1df41fdbd09691036d51ee1320.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=cel@kernel.org \
    --cc=dai.ngo@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@ownmail.net \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.