From: bo cao <treebacker@foxmail.com>
To: linux-nfs@vger.kernel.org, trondmy@kernel.org, anna@kernel.org
Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org,
Bo Cao <treebacker@foxmail.com>
Subject: [PATCH] pNFS: Fix use-after-free of layout header in pnfs_update_layout()
Date: Thu, 3 Dec 2026 15:54:52 +0800 [thread overview]
Message-ID: <tencent_B61AF4C554D84F6B2B158F49B6DAA9D2E205@qq.com> (raw)
From: Bo Cao <treebacker@foxmail.com>
pnfs_update_layout() drops its reference on the layout header with
pnfs_put_layout_hdr(lo) and then jumps back to the top of the
lookup_again loop. When that was the last reference the header is
freed through kfree_rcu(), but the local variable 'lo' still points
to it.
The check at the top of the loop for failed open state recovery
(added in 2fdbc20036ac) passes 'lo' to the pnfs_update_layout
tracepoint. Its TP_fast_assign reads lo->plh_flags and
lo->plh_stateid, so with the event enabled this reads freed memory.
The tracepoint is the only user of 'lo' at the top of the loop, so
without tracing nothing is dereferenced.
KASAN on v7.4-rc5 with the event enabled, LAYOUTGET failing with an
error that is retried while open state recovery has failed:
[ 282.313103] BUG: KASAN: slab-use-after-free in trace_event_raw_event_pnfs_update_layout+0x5bc/0x5d0
[ 282.313151] Read of size 8 at addr ffff000014d6fe58 by task pnfs_uaf/1905
[ 282.313153]
[ 282.313161] CPU: 0 UID: 65534 PID: 1905 Comm: pnfs_uaf Not tainted 7.4.0-rc5 #8 PREEMPT(full)
[ 282.313164] Hardware name: linux,dummy-virt (DT)
[ 282.313165] Call trace:
[ 282.313173] show_stack+0x18/0x24 (C)
[ 282.313191] dump_stack_lvl+0x74/0x8c
[ 282.313214] print_report+0x118/0x5e0
[ 282.313225] kasan_report+0xc0/0x12c
[ 282.313227] __asan_report_load8_noabort+0x20/0x2c
[ 282.313230] trace_event_raw_event_pnfs_update_layout+0x5bc/0x5d0
[ 282.313232] __traceiter_pnfs_update_layout+0xa0/0xf8
[ 282.313237] trace_pnfs_update_layout+0x100/0x19c
[ 282.313238] pnfs_update_layout+0x490/0x18c4
[ 282.313240] ff_layout_pg_get_read+0x190/0x324
[ 282.313242] ff_layout_pg_init_read+0x370/0x890
[ 282.313243] __nfs_pageio_add_request+0x8e8/0x14d8
Set lo to NULL after each put that is followed by a jump to
lookup_again, so the tracepoint takes its existing NULL branch. The
pointer is re-acquired by pnfs_find_alloc_layout() later in the loop.
The retry path is the one reported by KASAN; the other four sites
have the same pattern by inspection.
Fixes: 2fdbc20036ac ("NFS: avoid infinite loop in pnfs_update_layout.")
Cc: stable@vger.kernel.org
Signed-off-by: Bo Cao <treebacker@foxmail.com>
---
fs/nfs/pnfs.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 14f4a4b12ffd..80e5cac2906c 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -2235,6 +2235,7 @@ pnfs_update_layout(struct inode *ino,
if (IS_ERR(lseg))
goto out_put_layout_hdr;
pnfs_put_layout_hdr(lo);
+ lo = NULL;
goto lookup_again;
}
@@ -2252,6 +2253,7 @@ pnfs_update_layout(struct inode *ino,
lseg,
PNFS_UPDATE_LAYOUT_RETRY);
pnfs_put_layout_hdr(lo);
+ lo = NULL;
goto lookup_again;
}
trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg,
@@ -2288,6 +2290,7 @@ pnfs_update_layout(struct inode *ino,
goto out_put_layout_hdr;
pnfs_put_layout_hdr(lo);
dprintk("%s retrying\n", __func__);
+ lo = NULL;
goto lookup_again;
}
@@ -2305,6 +2308,7 @@ pnfs_update_layout(struct inode *ino,
clear_and_wake_up_bit(NFS_LAYOUT_FIRST_LAYOUTGET,
&lo->plh_flags);
pnfs_put_layout_hdr(lo);
+ lo = NULL;
goto lookup_again;
}
spin_lock(&ino->i_lock);
@@ -2397,6 +2401,7 @@ pnfs_update_layout(struct inode *ino,
trace_pnfs_update_layout(ino, pos, count,
iomode, lo, lseg, PNFS_UPDATE_LAYOUT_RETRY);
pnfs_put_layout_hdr(lo);
+ lo = NULL;
goto lookup_again;
}
} else {
--
2.39.5 (Apple Git-154)
reply other threads:[~2026-12-03 7:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=tencent_B61AF4C554D84F6B2B158F49B6DAA9D2E205@qq.com \
--to=treebacker@foxmail.com \
--cc=anna@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=stable@vger.kernel.org \
--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®