From: David Windsor <dwindsor@gmail.com>
To: peterz@infradead.org, oleg@redhat.com, mhiramat@kernel.org,
x86@kernel.org
Cc: tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, hpa@zytor.com, andrii@kernel.org,
jolsa@kernel.org, linux-trace-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
David Windsor <dwindsor@gmail.com>
Subject: [PATCH] uprobes/x86: Recognize user ENDBR64 without kernel IBT
Date: Mon, 30 Nov 2026 07:20:35 -0500 [thread overview]
Message-ID: <20261130122035.1586780-1-dwindsor@gmail.com> (raw)
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
next reply other threads:[~2026-11-30 12:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 12:20 David Windsor [this message]
2026-11-30 12:27 ` [PATCH] uprobes/x86: Recognize user ENDBR64 without kernel IBT sashiko-bot
2026-11-30 20:53 ` Masami Hiramatsu (Google)
2026-12-01 20:40 ` Andrii Nakryiko
2026-12-01 21:18 ` David Windsor
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=20261130122035.1586780-1-dwindsor@gmail.com \
--to=dwindsor@gmail.com \
--cc=andrii@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.