Re: [RFC PATCH v1 06/11] arm64: unwind_user: Support Minimal DWARF CFI and FP user unwinding

From
sashiko-bot@kernel.org
Date
2026-11-23 00:16:12
Also in
bpf, kvmarm, linux-efi, linux-kbuild, linux-perf-users
Reply to
Ian Rogers, 2026-11-22
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] arm64: unwind_user: shifted rt_sigframe base in
  unwind_user_sigreturn()
- [Medium] arm64: unwind_user: wrong state->sp on FP-to-CFI frame
  transition
- [Medium] arm64: unwind_user: Thumb bit 0 not stripped in
  unwind_user_strip_pac()
--

commit 6b2ce687ccf3b40dba131fb7a09e5054f9d0557a
Author: Ian Rogers [off-list ref]

arm64: unwind_user: Support Minimal DWARF CFI and FP user unwinding

This commit adds arm64 support for user-space DWARF CFI and frame pointer
unwinding, including register mappings, pointer authentication stripping,
and vDSO signal trampoline recovery.
quoted hunk ↗ jump to hunk
diff --git a/arch/arm64/include/asm/unwind_user.h b/arch/arm64/include/asm/unwind_user.h
new file mode 100644
index 0000000000000..38d0641ae5549
--- /dev/null
+++ b/arch/arm64/include/asm/unwind_user.h
@@ -0,0 +1,126 @@
[ ... ]
quoted hunk ↗ jump to hunk
+static inline unsigned long unwind_user_strip_pac(unsigned long ip,
+						  bool ra_signed)
+{
+	if (IS_ENABLED(CONFIG_COMPAT) &&
+	    compat_user_mode(task_pt_regs(current)))
+		return ip;
+	return ptrauth_strip_user_insn_pac(ip);
+}
+#define unwind_user_strip_pac unwind_user_strip_pac
[Severity: Medium]
Should unwind_user_strip_pac() clear bit 0 (ip & ~1UL) for 32-bit compat
tasks?

In AArch32 Thumb mode, BL/BLX and compat_setup_return() set bit 0 of LR to
indicate Thumb state.  Leaving bit 0 set records odd addresses in the
callchain and causes lookup_ip = state->ip - 1 in unwind_user_next_cfi() to
evaluate to return_pc rather than return_pc - 1, applying post-call CFA rule
changes prematurely or missing the FDE when a call is at the end of a
function.

[ ... ]
quoted hunk ↗ jump to hunk
+#ifdef CONFIG_HAVE_UNWIND_USER_FP
+
+/*
+ * AArch64 PCS stores {fp, lr} at [fp, fp + 16), while 32-bit AArch32 compat
+ * APCS stores struct compat_frame_tail {fp, sp, lr} at [compat_fp - 12, compat_fp).
+ */
+#define ARCH_INIT_USER_FP_FRAME(ws)			\
+	.cfa_off	= (ws) == 8 ? 2 * (ws) : 0,	\
+	.ra_off		= -1 * (ws),			\
+	.fp_off		= (ws) == 8 ? -2 * (ws) : -3 * (ws), \
+	.use_fp		= true,
+
+#endif /* CONFIG_HAVE_UNWIND_USER_FP */
[Severity: Medium]
Does ARCH_INIT_USER_FP_FRAME() leave state->sp inaccurate when an inner
frame unwound via FP transitions to an outer frame unwound via SP-based
DWARF CFI?

On AArch64, a function with frame size N > 16 places its frame record at the
lowest address of its frame (callee_fp = caller_sp - N).  Setting cfa_off =
16 with use_fp = true updates state->sp to callee_fp + 16 = caller_sp -
(N - 16) rather than caller_sp (and on AArch32, cfa_off = 0 sets state->sp
to compat_fp rather than loading compat_frame_tail.sp from [compat_fp - 8]).
If unwind_user_next() then resumes UNWIND_USER_TYPE_CFI on an outer caller
whose FDE uses DWARF_CFI_BASE_SP, the outer CFA is computed from the wrong
state->sp and reads the caller's saved registers from the wrong stack
offset.
quoted hunk ↗ jump to hunk
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 80398ac83c3b1..41dfbfcc1d2eb 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -1705,6 +1706,59 @@ void __init minsigstksz_setup(void)
+bool unwind_user_sigreturn(struct unwind_user_state *state)
+{
+	struct mm_struct *mm = current->mm;
+	struct rt_sigframe __user *sf;
+	unsigned long sigtramp;
+	u64 fp_lr[2], sp_pc[2];
+
+	if (!mm || state->ws != 8 || !mm->context.vdso)
+		return false;
+
+	sigtramp = (unsigned long)VDSO_SYMBOL(mm->context.vdso, sigtramp);
+	if (state->ip != sigtramp &&
+	    !(state->topmost && state->ip == sigtramp + 4))
+		return false;
+
+	if (state->sp & 0xfUL)
+		return false;
+
+	sf = (struct rt_sigframe __user *)state->sp;
+	if (copy_from_user(fp_lr, &sf->uc.uc_mcontext.regs[29], sizeof(fp_lr)) ||
+	    copy_from_user(sp_pc, &sf->uc.uc_mcontext.sp, sizeof(sp_pc)))
+		return false;
[Severity: Medium]
Can unwind_user_sigreturn() read from a shifted struct rt_sigframe pointer
when the signal handler was unwound via frame pointers?

When a signal handler with stack frame size S > 16 is unwound via
UNWIND_USER_TYPE_FP, unwind_user_next_fp() sets state->ip = sigtramp and
state->sp = handler_fp + 16 = (unsigned long)user->sigframe - (S - 16),
which remains 16-byte aligned.  On the next step, unwind_user_sigreturn()
casts that shifted state->sp to struct rt_sigframe __user *; for a 32-byte
handler frame, sf is user->sigframe - 16, so reading regs[29..30] and
{sp, pc} actually reads regs[27..28] and regs[29..30] from the real
sigcontext, passing the alignment and non-zero checks and corrupting the
rest of the unwind walk.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122235757.3456048-1-irogers@google.com?part=6
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