mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@kernel.org>
To: WenTao Liang <vulab@iscas.ac.cn>, anna@kernel.org
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 stable@vger.kernel.org
Subject: Re: [PATCH] pnfs: fix refcount leak in pnfs_report_layoutstat()
Date: Thu, 11 Jun 2026 13:36:54 -0400	[thread overview]
Message-ID: <9a42893cb1c829b943bd40dbb55151e97499916a.camel@kernel.org> (raw)
In-Reply-To: <20260611154747.94154-1-vulab@iscas.ac.cn>

On Thu, 2026-06-11 at 23:47 +0800, WenTao Liang wrote:
> When pnfs_report_layoutstat() calls pnfs_get_layout_hdr() and passes
> the reference through the inode field of the layoutstats data to
> nfs42_proc_layoutstats_generic(), if rpc_run_task() in that function
> fails (IS_ERR), nfs42_proc_layoutstats_generic() returns immediately
> without releasing the reference.  This leaks the layout header
> reference, leaks the allocated data, and leaves the
> NFS_INO_LAYOUTSTATS flag stuck on the inode, preventing further
> layoutstat reporting.
> 
> Fix by calling nfs42_layoutstat_release(data) before returning on
> rpc_run_task() error, matching the existing error handling for a
> missing inode.
> 
> Cc: stable@vger.kernel.org
> Fixes: be3a5d233922 ("NFSv.2/pnfs Add a LAYOUTSTATS rpc function")
> Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
> ---
>  fs/nfs/nfs42proc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c
> index 7602ede6f75f..7637ad894563 100644
> --- a/fs/nfs/nfs42proc.c
> +++ b/fs/nfs/nfs42proc.c
> @@ -1076,8 +1076,10 @@ int nfs42_proc_layoutstats_generic(struct
> nfs_server *server,
>  	nfs4_init_sequence(server->nfs_client, &data->args.seq_args,
>  			   &data->res.seq_res, 0, 0);
>  	task = rpc_run_task(&task_setup);
> -	if (IS_ERR(task))
> +	if (IS_ERR(task)) {
> +		nfs42_layoutstat_release(data);
>  		return PTR_ERR(task);

NACK! If you'd bothered to read the code, you would have found that
rpc_run_task() already cleans up on failure. This patch just introduces
a massive use-after-free.

> +	}
>  	rpc_put_task(task);
>  	return 0;
>  }

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com

      reply	other threads:[~2026-06-11 17:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11 15:47 WenTao Liang
2026-06-11 17:36 ` Trond Myklebust [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=9a42893cb1c829b943bd40dbb55151e97499916a.camel@kernel.org \
    --to=trondmy@kernel.org \
    --cc=anna@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vulab@iscas.ac.cn \
    /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®