From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796041240; b=jgOJ9wMoGjZAEjRponRyypWDBL7r5APRgH2rDn3cDgmTB5X/J2Z3Bkg8Zw7GIAA3JFta SXlgbJ7wcI5N1H2OW6E+LqP7hVkJrwQpPJ3qD65ty7kjxZzE5wASm2Ivw5GReMM5TIMDy 0TNAj962i1SZnKkD7Bbg5Rs+lB54ImirSwsfeObNtSp9tIvAvTKmffPtntnLKor0/gUmu PP5cAHHVxB+khSVCQougSUQ6X7IWXGz1nrPE69eywKuns81bx2/o1VNM5S8OUl8r2ULuL OAbIjIT6Dwo/Bl0xjTtC6OBk3JUW2PKw24DMoDyTe8qMQYFc1ipj/wdXWRYBg5jmHvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796041240; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=uRkdS2Eo3zk51tlM8N/W0AYSysXgnvpTiHeSgoQ30bc=; b=pFcV+7KjSQPgtCvnJcRq6zzU5dlnDBZA24uGQzWf/OEweWdzoX+FDi360jIbgudQKA6S VyTfoDANMNG/D04uklhxK+Zf8Cx+lajp0K4Fc5YZZrArsQhMpB4X23FSRt3iusGxnhejy 9Y8Bnh87pdEx4ApeyGYhGB6XrSXHC4tCCnVxW2tl7BACuMJ5lljOR8KEA7VvdrV6mF/WY IqKLw8uT6thL3YDZPjRh0zq9wnnuUMm4gUOPvSaP6HysZkAGVsb18GNAHmybwamkE9fId 25sM1BPoeLPEx7EW9C2VHqi2rTT2GaWaIoe/nHJb86J+xi6dQCLFBCPP5H9mddvc2PQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=p19kigJs; arc=none smtp.remote-ip=209.85.222.182 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52F74606A31C for ; Mon, 30 Nov 2026 12:20:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 52F74606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=p19kigJs Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-9497a167a6aso1321871185a.1 for ; Mon, 30 Nov 2026 04:20:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796041238; x=1796646038; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=uRkdS2Eo3zk51tlM8N/W0AYSysXgnvpTiHeSgoQ30bc=; b=p19kigJs6BRxm7sdYAjKLtV0c84t1ZkZx7XZtflmfShA580Soa5uCWgeECkrPmoONd d3SI4gLETPd5MsFezUveSEKq7s+37HJmcLNX5ILYO8KFdlEuCy2MFf3yqFrsB8lxC7ii eVO8QvGlwh4Y+y/kTATTEJJ8l2ImIxjfJhPmFLElXz403+NatKCXcuoPnTxmX4X0PzvG X55+eFFgdMD+z6wywrtrh3lz2F+/wpJYKD58O7KuBkp4GkWKb/klIv5QSTbDC06nkVHt b6nwsTLe/b9XUzlrhEcJhhbl0WQb95MNy5VmRS2U0zwApLS2mwwwV0kShq97rd1y2Ez5 PcCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796041238; x=1796646038; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=uRkdS2Eo3zk51tlM8N/W0AYSysXgnvpTiHeSgoQ30bc=; b=T79u/d7XvEmaxZP4r/QUfolhbOtCWbmV2gFYFCt4fejAyznQxpmZnPuzwq32oOVi5c YytbLv1/BL+IsTLxPebGDoiSXNOx8LrpfW0vzZrgLT967lm5VvCkseG7UeRHgHZNsTDb dT7GQ89ZSe5ufh82nSPmw3GlJaR11ROjNLIM7UTUPAT+vS3UQquD9je2yoZ6xAkpOFjG +xNgwZIYOYFMuI0kFIgImxzBLvuZc3eGCw/q2m44dWsljTH1LPPRa4vvrW1dAtjmhDNl kXgERSCh+qk/O4kIVYHb0juE9DWKY22NXrLLyMPsrk54dqhqgqumzUH1f7FAItHSRJ/+ DUZg== X-Forwarded-Encrypted: i=1; AL+hErGhBFJdNIR++Kqk2xMpHd9tkyc06Q1TGQOqhtLIDfIFNlybogX0hpNk+c/GXgigs+d2uZPfmuSdpUpVP2U=@vger.kernel.org X-Gm-Message-State: APuU4Z/VPlsTuDnyAdxct/y+VuQ/q/3GlxBXdPCinq4O+cFBBhKiaRp7 jPi6DQ1iAHaxTaCfLAYZRbEbIrEcajp0os2lptlrKGRMAgmDB+ieK0VvMJhQpC26a2k= X-Gm-Gg: AZFdTZdl0Dsi2a0piaJk6UKY0VLL7uHLtuHMQ4cJZyji9q5K5GCRKQrjs80LNZIjvod 7nHme4zLppw8aYvwXAxzMb0b4qHd0ns5MWf/gxz/0oG5uqG0Y2UcZA2Gz8qxLAaa/KEhu1U30/U Gc89RAN78PfkGIeQXsmA8ca0kNXUtl7B5QG1Fbj+U9F1hdDAmH5eOU0uiZjNJmRoxRKDreaWtJq ZhqPK9OGI1Inf7PFypqrklQGwgVLfxHbd5DaWwiSLwl0scZHZKdi0lF2r3wYlOsb8+WdPnroljk GWi+LIbN7wGcEnc1yFdQIRFp23JwpMMIH76a3o3GnE3lUYeHHW5n6KDd+5+XO+WO4QxGGzfiW16 qW0E5bzratyPVeLkwTOKNUcbXdjQwiV8svQo2LnpopjWd/wO2PM8wSl40oowmMCBgrRdaIXlroo cgn0n+WtN9BBJOVDp1xMPQJa5ZSSZB/Pf374HN4b3N/40ZY/pXJrjz+2tqcp/3ADaRJImr6N1+d J0MHfwny6EiIxHhdTm0ulo8PR+RYn6b0Dpul1wKnm4mNRwqrNni3ljntmRSNT5GAvFSppl0E4bm Qfu2ptf98mVE276KlJtQu4/rSvgICTW9EIom9bgpQzlK3hw7yG+1gBwFCpUBPlXvjvXl5JcnwV1 9g1lMf0MQ3ScGR0sUgIM84/5li2Og X-Received: by 2002:a05:620a:258b:b0:93e:6e6a:b686 with SMTP id af79cd13be357-949b36034f8mr6129938085a.29.1796041238168; Mon, 30 Nov 2026 04:20:38 -0800 (PST) Received: from battery.lan (pool-138-88-31-60.washdc.fios.verizon.net. [138.88.31.60]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949bb418241sm2499296185a.38.2026.11.30.04.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 04:20:37 -0800 (PST) From: David Windsor 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 Subject: [PATCH] uprobes/x86: Recognize user ENDBR64 without kernel IBT Date: Mon, 30 Nov 2026 07:20:35 -0500 Message-ID: <20261130122035.1586780-1-dwindsor@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 #include +#include #include #include #include +#include #include #include @@ -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