[RFC PATCH] namei: revalidate the symlink dentry before invoking get_link in RCU-walk
From: Qing Zhang
Date: Wed Nov 18 2026 - 03:40:05 EST
RCU pathwalk validates the symlink dentry before following it, but
additional work separates that validation from sampling and invoking
the get_link callback.
XFS can recycle a reclaimable inode in place without waiting for
pre-existing RCU readers to complete. The recycle path calls
xfs_reinit_inode(), which calls inode_init_always() and resets i_op
to empty_iops. A reader retaining an inode pointer from the previous
VFS lifetime can therefore sample a NULL get_link callback.
We observed this failure on an XFS filesystem running
5.4.119-19.0009.44 while codebuddy was following
/root/.codebuddy/debug/latest through access().
The complete Oops below has only its timestamps omitted:
BUG: kernel NULL pointer dereference, address: 0000000000000000
#PF: supervisor instruction fetch in kernel mode
#PF: error_code(0x0010) - not-present page
PGD 14fcb5067 P4D 14fcb5067 PUD 1f2c9c7067 PMD 0
Oops: 0010 [#1] SMP NOPTI
CPU: 32 PID: 852915 Comm: codebuddy Kdump: loaded Tainted: G O 5.4.119-19.0009.44 #1
Hardware name: Tencent Cloud CVM, BIOS seabios-1.9.1-qemu-project.org 04/01/2014
RIP: 0010:0x0
Code: Bad RIP value.
RSP: 0018:ffffc9001905bcd8 EFLAGS: 00010246
RAX: ffffffff8227fe80 RBX: ffffc9001905bd80 RCX: 0000000000000000
RDX: ffffc9001905bde8 RSI: ffff888654eb2798 RDI: 0000000000000000
RBP: ffffc9001905bd10 R08: 0000000000000001 R09: ffff888214aa28c0
R10: 330074736574616c R11: 0000000000000006 R12: 0000000000000000
R13: ffff888654eb2798 R14: ffff888214aa28c0 R15: ffffc9001905bde8
FS: 00007f28e6deef00(0000) GS:ffff889f41800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffffffffd6 CR3: 0000000214f6a002 CR4: 0000000000370ee0
DR0: 0000000001e188ba DR1: 0000000002d86940 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000600
Call Trace:
trailing_symlink+0x1da/0x260
path_lookupat.isra.47+0x79/0x220
filename_lookup.part.63+0xa0/0x170
? kmem_cache_alloc+0xfc/0x250
? getname_flags+0x4f/0x1e0
user_path_at_empty+0x3e/0x50
do_faccessat+0xb3/0x250
__x64_sys_access+0x1b/0x20
do_syscall_64+0x4d/0x150
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f28e6fbcb4b
Code: f8 ff 74 d8 8b 44 24 04 e9 77 ff ff ff e8 cd 2a 02 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa b8 15 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 05 c3 0f 1f 40 00 48 8b 15 99 72 10 00 f7 d8
RSP: 002b:00007fff69e37768 EFLAGS: 00000246 ORIG_RAX: 0000000000000015
RAX: ffffffffffffffda RBX: 00007fff69e37910 RCX: 00007f28e6fbcb4b
RDX: 000000000000001d RSI: 0000000000000000 RDI: 0000024989890000
RBP: 00007fff69e377c0 R08: 0000000000000031 R09: 00007fff69e37410
R10: 000002498c0a5000 R11: 0000000000000246 R12: 0000000000000002
R13: 0000000000000001 R14: 0000024989612860 R15: 00007fff69e37938
Modules linked in: iptable_filter udp_diag ib_core(O) mlx_compat(O) fuse ipt_REJECT nf_reject_ipv4 nfsv3 nfs_acl rpcsec_gss_krb5 auth_rpcgss nfsv4 nfs lockd grace fscache veth tcp_diag inet_diag nf_conntrack_netlink xt_statistic xt_nat ip_set ip_vs_sh ip_vs_wrr ip_vs_rr ip_vs xt_addrtype xt_MASQUERADE xt_conntrack xt_comment xt_mark nft_chain_nat overlay nft_counter nft_compat nf_tables nfnetlink sunrpc edac_core crc32_pclmul ghash_clmulni_intel aesni_intel crypto_simd cryptd glue_helper virtio_balloon xfs sch_fq_codel iptable_nat nf_nat binfmt_misc nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 ip_tables cirrus drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops drm crc32c_intel virtio_net sr_mod i2c_core cdrom net_failover failover floppy autofs4
CR2: 0000000000000000
Disassembly of the faulting kernel identifies the indirect call in
get_link(), inlined into trailing_symlink():
trailing_symlink+0x1a3: mov 0x8(%rax),%rcx
trailing_symlink+0x1a7: testb $0x40,0x38(%rbx)
trailing_symlink+0x1ab: jne trailing_symlink+0x1cf
trailing_symlink+0x1cf: xor %edi,%edi
trailing_symlink+0x1d1: mov %rcx,-0x30(%rbp)
trailing_symlink+0x1d5: call __x86_indirect_thunk_rcx
The return address is trailing_symlink+0x1da. RAX resolves to
empty_iops.55072, and its get_link member at offset 8 is NULL.
RCX is zero and RDI is NULL, identifying the RCU-walk invocation.
The failure occurs before entering an XFS get_link handler.
RBX identifies the walker's nameidata at 0xffffc9001905bd80.
The vmcore contains:
nd->flags = 81 (0x51, including LOOKUP_RCU)
nd->depth = 1
nd->stack = 0xffffc9001905bdd8
nd->link_inode = 0xffff888654eb2798
The saved link entry contains:
saved.link.dentry = 0xffff888214aa28c0
&saved.done = 0xffffc9001905bde8
saved.seq = 6154122
Thus nd->link_inode matches RSI, and &saved.done matches RDX.
The saved dentry is named "latest". In the later vmcore snapshot:
dentry->d_inode = NULL
dentry->d_seq.sequence = 6157892
The sequence to compare is the saved link's sequence, not nd->seq.
The difference establishes that the saved snapshot is stale relative
to the dump state; it does not identify a count of unlink or create
operations.
On CPU22, codebuddy PID 1034866 is executing do_unlinkat() followed
by XFS inactivation for the same objects:
do_unlinkat:
name = "/root/.codebuddy/debug/latest"
dentry = 0xffff888214aa28c0
inode = 0xffff888654eb2798
xfs_inactive_ifree:
ip = 0xffff888654eb2640
&ip->i_vnode = 0xffff888654eb2798
i_ino = 7522958322
The saved register state and the later inode contents must be
distinguished. At the fault, the sampled operations-table pointer
in RAX is empty_iops and the callback in RCX is NULL. By the time
the vmcore is captured, inode->i_op instead points to
xfs_inline_symlink_inode_operations, whose get_link callback is
xfs_vn_get_link_inline.
The XFS recycle path explains how this intermediate table can become
visible to an old reader:
xfs_iget_cache_hit()
-> xfs_reinit_inode()
-> inode_init_always()
-> inode->i_op = &empty_iops
Exiting the recycling task's own RCU read-side critical section does
not wait for the walker's critical section to finish. Eventual
call_rcu() freeing protects object memory, but does not prevent
in-place reinitialisation of the retained object.
These observations support recycling across the old reader's inode
snapshot. They do not identify the reinitialising task: PID 1034866
is the unlinker observed at dump time, not an established writer of
empty_iops. No scheduling delay responsible for widening the race
window was captured.
Sample the operations-table pointer and callback once, then recheck
the saved dentry sequence before invoking the callback in RCU mode.
Return -ECHILD if the sequence changed or the sampled callback is
NULL, allowing lookup to retry without invoking that callback.
This revisits Ian Kent's January 2022 proposal with additional crash
evidence identifying empty_iops as the sampled operations table.
Rejecting RCU-walk inside a filesystem get_link handler cannot
protect this pre-callback failure, since the handler is never entered.
This check targets the observed stale-snapshot callback invocation.
It does not replace filesystem guarantees about inode identity or
symlink-body lifetime, and does not protect against changes after
the revalidation.
Link: https://lore.kernel.org/all/164180589176.86426.501271559065590169.stgit@xxxxxxxxxxxxxxxxx/
Signed-off-by: Qing Zhang <diasyzhang@xxxxxxxxxxx>
---
RFC notes:
The crash was observed on 5.4.119-19.0009.44. The patch targets
current mainline; a mainline reproduction has not yet been obtained.
This is additional evidence for the previously discussed failure
mode, not a claim that the NULL-callback race is new.
The diff is derived from Ian Kent's original fs/namei.c proposal,
extended to sample i_op once and to reject a NULL callback.
Would this defensive check be acceptable independently of a broader
XFS inode-lifetime change? If not, what companion change would be
required before reconsidering it?
Base:
141b164bbe186423e295b139e40e8e2d11cf1341
Testing:
Build-tested: make fs/namei.o with the change applied (rc=0, no new
warnings). The reported crash kernel is 5.4.119-19.0009.44; a
mainline reproduction has not yet been obtained, so no runtime
testing of the fix itself has been performed.
fs/namei.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/namei.c b/fs/namei.c
index 925aeb63bfa1..20c2c06ec3e9 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2063,10 +2063,16 @@ static noinline const char *pick_link(struct nameidata *nd, struct path *link,
res = READ_ONCE(inode->i_link);
if (!res) {
+ const struct inode_operations *i_op;
const char * (*get)(struct dentry *, struct inode *,
struct delayed_call *);
- get = inode->i_op->get_link;
+ i_op = READ_ONCE(inode->i_op);
+ get = READ_ONCE(i_op->get_link);
if (nd->flags & LOOKUP_RCU) {
+ /* Reject a stale snapshot before invoking the callback. */
+ if (unlikely(read_seqcount_retry(&link->dentry->d_seq,
+ last->seq) || !get))
+ return ERR_PTR(-ECHILD);
res = get(NULL, inode, &last->done);
if (res == ERR_PTR(-ECHILD) && try_to_unlazy(nd))
res = get(link->dentry, inode, &last->done);
--
2.43.7