public inbox for linux-nfs@vger.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, Chuck Lever <chuck.lever@oracle.com>
Subject: Re: [PATCH] NFSD: Fix delegation reference leak in nfsd4_revoke_states
Date: Tue, 24 Mar 2026 12:54:57 -0400	[thread overview]
Message-ID: <e9e404382c7bb54df498a6e368f522f2ae313820.camel@kernel.org> (raw)
In-Reply-To: <20260324151812.85482-1-cel@kernel.org>

On Tue, 2026-03-24 at 11:18 -0400, Chuck Lever wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
> 
> When revoking delegation state, nfsd4_revoke_states() takes an extra
> reference on the stid before calling unhash_delegation_locked(). If
> unhash_delegation_locked() returns false (the delegation was already
> unhashed by a concurrent path), dp is set to NULL and
> revoke_delegation() is skipped, but the extra reference is never
> released. Each occurrence permanently pins the stid in memory. The
> leaked reference also prevents nfs4_put_stid() from decrementing
> cl_admin_revoked, leaving the counter permanently inflated.
> 
> Drop the extra reference in the failure path.
> 
> Fixes: 8dd91e8d31fe ("nfsd: fix race between laundromat and free_stateid")
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
>  fs/nfsd/nfs4state.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index 6b9c399b89df..0fefae6b0a48 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -1389,7 +1389,8 @@ static void destroy_delegation(struct nfs4_delegation *dp)
>   * stateid or it's called from a laundromat thread (nfsd4_landromat()) that
>   * determined that this specific state has expired and needs to be revoked
>   * (both mark state with the appropriate stid sc_status mode). It is also
> - * assumed that a reference was taken on the @dp state.
> + * assumed that a reference was taken on the @dp state. This function
> + * consumes that reference.
>   *
>   * If this function finds that the @dp state is SC_STATUS_FREED it means
>   * that a FREE_STATEID operation for this stateid has been processed and
> @@ -1836,6 +1837,10 @@ void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb)
>  					mutex_unlock(&stp->st_mutex);
>  					break;
>  				case SC_TYPE_DELEG:
> +					/* Extra reference guards against concurrent
> +					 * FREE_STATEID; revoke_delegation() consumes
> +					 * it, otherwise release it directly.
> +					 */
>  					refcount_inc(&stid->sc_count);
>  					dp = delegstateid(stid);
>  					spin_lock(&state_lock);
> @@ -1845,6 +1850,8 @@ void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb)
>  					spin_unlock(&state_lock);
>  					if (dp)
>  						revoke_delegation(dp);
> +					else
> +						nfs4_put_stid(stid);
>  					break;
>  				case SC_TYPE_LAYOUT:
>  					ls = layoutstateid(stid);

Good catch!

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

      reply	other threads:[~2026-03-24 16:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 15:18 [PATCH] NFSD: Fix delegation reference leak in nfsd4_revoke_states Chuck Lever
2026-03-24 16:54 ` 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=e9e404382c7bb54df498a6e368f522f2ae313820.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=cel@kernel.org \
    --cc=chuck.lever@oracle.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox