mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] NFS: Fix layout header use-after-free in pnfs_update_layout()
@ 2026-09-17 16:29 Wentao Liang
  2026-09-17 17:49 ` Anna Schumaker
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-17 16:29 UTC (permalink / raw)
  To: anna; +Cc: linux-kernel, linux-nfs, trondmy, Wentao Liang, stable

When waiting for an in-progress layoutreturn to complete, the retry path
drops the reference on the layout header with pnfs_put_layout_hdr() and
only then passes the layout header to trace_pnfs_update_layout(). If
that was the last reference, for example because the layout was torn
down while the task slept in pnfs_prepare_to_retry_layoutget(), the
tracepoint dereferences freed memory.

Move the pnfs_put_layout_hdr() call after the tracepoint so the layout
header is still valid while it is being traced.

Fixes: 2c8d5fc37fe2 ("pNFS: Stricter ordering of layoutget and layoutreturn")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 fs/nfs/pnfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 743467e9ba20..aee523134c0f 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -2229,11 +2229,11 @@ pnfs_update_layout(struct inode *ino,
 		dprintk("%s wait for layoutreturn\n", __func__);
 		lseg = ERR_PTR(pnfs_prepare_to_retry_layoutget(lo));
 		if (!IS_ERR(lseg)) {
-			pnfs_put_layout_hdr(lo);
 			dprintk("%s retrying\n", __func__);
 			trace_pnfs_update_layout(ino, pos, count, iomode, lo,
 						 lseg,
 						 PNFS_UPDATE_LAYOUT_RETRY);
+			pnfs_put_layout_hdr(lo);
 			goto lookup_again;
 		}
 		trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg,
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] NFS: Fix layout header use-after-free in pnfs_update_layout()
  2026-09-17 16:29 [PATCH] NFS: Fix layout header use-after-free in pnfs_update_layout() Wentao Liang
@ 2026-09-17 17:49 ` Anna Schumaker
  0 siblings, 0 replies; 2+ messages in thread
From: Anna Schumaker @ 2026-09-17 17:49 UTC (permalink / raw)
  To: Wentao Liang; +Cc: linux-kernel, linux-nfs, Trond Myklebust, stable

Hi Wentao,

On Thu, Sep 17, 2026, at 12:29 PM, Wentao Liang wrote:
> When waiting for an in-progress layoutreturn to complete, the retry path
> drops the reference on the layout header with pnfs_put_layout_hdr() and
> only then passes the layout header to trace_pnfs_update_layout(). If
> that was the last reference, for example because the layout was torn
> down while the task slept in pnfs_prepare_to_retry_layoutget(), the
> tracepoint dereferences freed memory.
>
> Move the pnfs_put_layout_hdr() call after the tracepoint so the layout
> header is still valid while it is being traced.
>
> Fixes: 2c8d5fc37fe2 ("pNFS: Stricter ordering of layoutget and layoutreturn")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>

This patch is already upstream as commit 13e198a90ca4 (included as part of
Linux 7.2).

Thanks,
Anna

> ---
>  fs/nfs/pnfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
> index 743467e9ba20..aee523134c0f 100644
> --- a/fs/nfs/pnfs.c
> +++ b/fs/nfs/pnfs.c
> @@ -2229,11 +2229,11 @@ pnfs_update_layout(struct inode *ino,
>  		dprintk("%s wait for layoutreturn\n", __func__);
>  		lseg = ERR_PTR(pnfs_prepare_to_retry_layoutget(lo));
>  		if (!IS_ERR(lseg)) {
> -			pnfs_put_layout_hdr(lo);
>  			dprintk("%s retrying\n", __func__);
>  			trace_pnfs_update_layout(ino, pos, count, iomode, lo,
>  						 lseg,
>  						 PNFS_UPDATE_LAYOUT_RETRY);
> +			pnfs_put_layout_hdr(lo);
>  			goto lookup_again;
>  		}
>  		trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg,
> -- 
> 2.34.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-17 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 16:29 [PATCH] NFS: Fix layout header use-after-free in pnfs_update_layout() Wentao Liang
2026-09-17 17:49 ` Anna Schumaker

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®