Re: [RFC PATCH v1 02/11] unwind_user: Support Minimal DWARF CFI user-space unwinding

From
bot+bpf-ci@kernel.org
Date
2026-11-23 00:40:03
Also in
bpf, kvmarm, linux-arch, linux-efi, linux-kbuild, linux-kselftest, linux-perf-users, linux-riscv, lkml, rust-for-linux
Reply to
Ian Rogers, 2026-11-22
unwind_user: Support Minimal DWARF CFI user-space unwinding
TL;DR:
- Possible wrong stack pointer after 32-bit compat vdso sigreturn FDE, giving
  bogus user callchain IPs
- Speculation fence in get_user_word() may be a no-op on all architectures
- Return: doc mismatch (nit)
quoted hunk ↗ jump to hunk
diff --git a/kernel/unwind/user.c b/kernel/unwind/user.c
--- a/kernel/unwind/user.c
+++ b/kernel/unwind/user.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -11,14 +12,38 @@
 static inline int
 get_user_word(unsigned long *word, unsigned long base, int off, unsigned int ws)
 {
 	unsigned long __user *addr = (void __user *)base + off;
+
+	/*
+	 * On architectures whose get_user() uses a conditional access_ok()
+	 * branch rather than branchless address masking, fence bad access_ok()
+	 * speculation so chained cfa_indirect stack reads cannot transiently
+	 * dereference kernel addresses.
+	 */
+	if (!can_do_masked_user_access()) {
+		if (!access_ok(addr, ws)) {
+			*word = 0;
+			return -EFAULT;
+		}
+		barrier_nospec();
+	}
The commit message says this block fences non-masked access_ok() checks "so
chained cfa_indirect user stack loads cannot speculatively dereference
kernel addresses".  Does this code provide that protection on any
architecture that uses it?

x86_64 is the only architecture selecting HAVE_UNWIND_USER_CFI at this
commit, and it defines masked_user_access_begin(), so
can_do_masked_user_access() is true and the whole block is compiled out.

arm64 and riscv enable this later in the series.  Neither defines
masked_user_access_begin(), so the branch is taken, but neither defines
barrier_nospec() either, so it falls back to the empty generic
definition:

    # define barrier_nospec() do { } while (0)

That leaves only an access_ok() check that get_user() repeats right
after.

The comment's condition also looks off for arm64, whose get_user()
already masks the pointer without a branch (__uaccess_mask_ptr()), yet it
still takes this branch.  can_do_masked_user_access() only reports
whether masked_user_access_begin() exists, not how get_user() is
implemented.

Should the comment and changelog describe what the code does (defer to
the arch barrier_nospec()), or should the block be dropped since
get_user() already does the access_ok() check?

[ ... ]
quoted hunk ↗ jump to hunk
diff --git a/kernel/unwind/user_cfi.c b/kernel/unwind/user_cfi.c
--- /dev/null
+++ b/kernel/unwind/user_cfi.c
[ ... ]
quoted hunk ↗ jump to hunk
+ * Return: 0 on success, -ENOENT if no PT_GNU_EH_FRAME covers @ip's VMA,
+ * -EINTR if killed while waiting for mmap_lock, -EFAULT on user copy fault, or
+ * -EINVAL if current->mm is absent or @state->ws is unsupported.
+ */
+static int find_user_eh_frame_hdr(struct unwind_user_state *state,
This isn't a bug, but does this Return: list match the code?

parse_user_elf64_eh_hdr() and parse_user_elf32_eh_hdr() also return
-EINVAL for bad magic, wrong EI_CLASS, a bad e_phentsize, or e_phnum of 0
or above 64, and find_user_eh_frame_hdr() passes that through:

    if (state->ws == 8)
        err = parse_user_elf64_eh_hdr(elf_base, out_hdr_uaddr, out_hdr_size);
    ...
    if (err)
        return err;

That happens for any VM_EXEC file mapping at vm_pgoff 0 that is not an ELF
image of the task's class, for example a memfd JIT region, the [uprobes]
XOL page, or an x32 binary (ws == 8 but ELFCLASS32).

The errno also changes once the VMA is cached.  The slot is marked valid
with eh_hdr_uaddr = 0 before parsing, so the first lookup returns -EINVAL
or -EFAULT, and every later lookup in the same VMA hits:

    if (!c->eh_hdr_uaddr)
        return -ENOENT;

So the documented -EFAULT/-EINVAL distinction only holds for the first
lookup.  The walk falls back to FP either way.  Could the Return: list
name the invalid-ELF -EINVAL case and say that cached negative entries
report -ENOENT, or should the cache keep the original error?

[ ... ]
quoted hunk ↗ jump to hunk
+	lookup_ip = (state->topmost || state->signal) ? state->ip : state->ip - 1;
+
+	err = find_user_eh_frame_hdr(state, lookup_ip, &hdr_uaddr, &hdr_size);
+	if (!err)
+		err = dwarf_cfi_unwind_user_eh_frame_hdr(hdr_uaddr, hdr_size,
+							 lookup_ip, &arch, &row);
+	if (err == -ENOENT && lookup_ip != state->ip) {
+		/*
+		 * A signal trampoline without a leading NOP has state->ip at
+		 * the exact start of its FDE, where state->ip - 1 misses.
+		 */
+		err = find_user_eh_frame_hdr(state, state->ip, &hdr_uaddr,
+					     &hdr_size);
+		if (!err)
+			err = dwarf_cfi_unwind_user_eh_frame_hdr(hdr_uaddr,
+								 hdr_size,
+								 state->ip,
+								 &arch, &row);
+		if (!err && !row.signal)
+			err = -ENOENT;
+	}
For 32-bit compat tasks on x86_64, does this retry path accept the vdso32
sigreturn FDE and then hand back the wrong caller stack pointer?

Compat tasks that do not set SA_RESTORER return from signal handlers
through the vDSO trampolines (vdso32_image.sym___kernel_rt_sigreturn).  In
arch/x86/entry/vdso/vdso32/sigreturn.S the FDE starts exactly at
__kernel_rt_sigreturn, and the nop in front of it is outside any FDE.  So
the first lookup at state->ip - 1 returns -ENOENT, and this retry at
state->ip finds the 'S' FDE and accepts it.

That FDE describes the interrupted registers as:

    CFI_DEF_CFA	esp,	\sc - 4
    CFI_OFFSET	eip,    IA32_SIGCONTEXT_ip
    ...
    CFI_OFFSET	esp,    IA32_SIGCONTEXT_sp
    CFI_OFFSET	ebp,    IA32_SIGCONTEXT_bp

The interrupted esp is the value saved at CFA + IA32_SIGCONTEXT_sp, not
the CFA itself.  dwarf_cfi_exec_insns() only applies DW_CFA_offset* to
fp_reg and ra_reg:

    if (lo == arch->fp_reg || lo == cie->ra_reg)

so the esp rule is silently dropped.  unwind_user_next_cfi() then builds
a row with cfa_base SP, cfa_indirect false, cfa_off = sc - 4, and
unwind_user_next_common() gets the correct RA and FP from the sigcontext
but sets state->sp = cfa, which is the address of the sigcontext inside
the signal frame rather than the interrupted esp.

The next step uses state->ip with this wrong SP.  If the interrupted
function's CFA is SP-based (default -fomit-frame-pointer i386 code, or
any prologue/epilogue/leaf), the CFA becomes &sigcontext + N, the
progression check passes, and the RA is read from inside the sigcontext
(for example the gs/ds selector words).  The result is bogus IPs in the
deferred user callchain, and the walk never falls back to FP.

The commit message claims "32-bit compat user unwinding on x86" and
support for "signal trampolines without leading NOPs", which is this
trampoline.  Should a signal row whose SP is restored from memory either
be translated, for example by treating "esp at CFA+off" as an SP-indirect
CFA, or be rejected so the unwind falls back to FP instead of producing
wrong frames?

No later commit in the series changes dwarf_cfi.c, user_cfi.c or user.c.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45087188604
Thread (26 messages) 26 messages, 3 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help