Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] uprobes/x86: Recognize user ENDBR64 without kernel IBT
@ 2026-11-30 12:20 David Windsor
  0 siblings, 0 replies; only message in thread
From: David Windsor @ 2026-11-30 12:20 UTC (permalink / raw)
  To: peterz, oleg, mhiramat, x86
  Cc: tglx, mingo, bp, dave.hansen, hpa, andrii, jolsa,
	linux-trace-kernel, linux-perf-users, linux-kernel, David Windsor

When a uprobe is placed at the start of a function, the prologue has not
run yet and the return address is still at *regs->sp. To capture the
caller, the unwinder checks is_uprobe_at_func_entry(), which looks at
the probed instruction for a push %rbp or an endbr64.

The endbr64 check uses is_endbr(). On a kernel built without
CONFIG_X86_KERNEL_IBT that is a stub returning false, so a uprobe on a
function starting with endbr64 is not treated as a function entry and
the caller is missing from the stack trace. Most binaries start their
functions with endbr64 since -fcf-protection=branch is on by default.

Whether the user binary contains endbr64 has nothing to do with whether
the kernel was built with IBT. Compare the probed instruction against
gen_endbr() instead, and move gen_endbr() out of the HAS_KERNEL_IBT
block so it is available without kernel IBT. is_endbr() is unchanged.

Fixes: cfa7f3d2c526 ("perf,x86: avoid missing caller address in stack traces captured in uprobe")
Signed-off-by: David Windsor <dwindsor@gmail.com>
---
 arch/x86/include/asm/ibt.h | 39 +++++++++++++++++++++++---------------
 arch/x86/kernel/uprobes.c  | 11 +++++++++--
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/ibt.h b/arch/x86/include/asm/ibt.h
index 5e45d6424722..c0cf481d50d5 100644
--- a/arch/x86/include/asm/ibt.h
+++ b/arch/x86/include/asm/ibt.h
@@ -17,6 +17,30 @@
  *
  * When all the above are satisfied, HAS_KERNEL_IBT will be 1, otherwise 0.
  */
+
+#ifndef __ASSEMBLER__
+
+/*
+ * Not dependent on HAS_KERNEL_IBT: userspace can contain ENDBR64 regardless
+ * of whether the kernel itself is built with IBT.
+ */
+static __always_inline __attribute_const__ u32 gen_endbr(void)
+{
+	u32 endbr;
+
+	/*
+	 * Generate ENDBR64 in a way that is sure to not result in
+	 * an ENDBR64 instruction as immediate.
+	 */
+	asm ( "mov $~0xfa1e0ff3, %[endbr]\n\t"
+	      "not %[endbr]\n\t"
+	       : [endbr] "=&r" (endbr) );
+
+	return endbr;
+}
+
+#endif /* __ASSEMBLER__ */
+
 #if defined(CONFIG_X86_KERNEL_IBT) && !defined(__DISABLE_EXPORTS)
 
 #define HAS_KERNEL_IBT	1
@@ -41,21 +65,6 @@
 	_ASM_PTR fname "\n\t"				\
 	".popsection\n\t"
 
-static __always_inline __attribute_const__ u32 gen_endbr(void)
-{
-	u32 endbr;
-
-	/*
-	 * Generate ENDBR64 in a way that is sure to not result in
-	 * an ENDBR64 instruction as immediate.
-	 */
-	asm ( "mov $~0xfa1e0ff3, %[endbr]\n\t"
-	      "not %[endbr]\n\t"
-	       : [endbr] "=&r" (endbr) );
-
-	return endbr;
-}
-
 static __always_inline __attribute_const__ u32 gen_endbr_poison(void)
 {
 	/*
diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index fc07bcd0f462..bbb71ec44c6a 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -15,9 +15,11 @@
 #include <linux/syscalls.h>
 
 #include <linux/kdebug.h>
+#include <linux/unaligned.h>
 #include <asm/processor.h>
 #include <asm/insn.h>
 #include <asm/insn-eval.h>
+#include <asm/ibt.h>
 #include <asm/mmu_context.h>
 #include <asm/nops.h>
 
@@ -1928,8 +1930,13 @@ bool is_uprobe_at_func_entry(struct pt_regs *regs)
 	if (auprobe->insn[0] == 0x55)
 		return true;
 
-	/* endbr64 (64-bit only) */
-	if (user_64bit_mode(regs) && is_endbr((u32 *)auprobe->insn))
+	/*
+	 * endbr64 (64-bit only). Compare against gen_endbr() rather than
+	 * is_endbr(): the latter is a stub when CONFIG_X86_KERNEL_IBT is
+	 * unset, but userspace can contain ENDBR64 regardless.
+	 */
+	if (user_64bit_mode(regs) &&
+	    get_unaligned((u32 *)auprobe->insn) == gen_endbr())
 		return true;
 
 	return false;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30 12:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 12:20 [PATCH] uprobes/x86: Recognize user ENDBR64 without kernel IBT David Windsor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox