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=1796041239; b=WxNlQwRj+6+XTDNGX/YShPso9VbIwox2IH8OWvf2m02oxQpyQRrNTyDfL/A/nOhoHIdq 0HigU6lPM310whL45mufS/E3tUqVOmrdIoA0uDs2XqHIetQ8TNQZQpyQ6RzcU4/2cUPe0 qRs6pmwFgV1Ca+cn6qb2hbuwu15LAMAyQo+oSfF+LyoXvi0GrGrfua3JBU4djRxR8gB5u bprTqx7Pzp/XAGtPoZC18vO3IVCDsKg5DN9o9qmYIonr5fm8j5zO5GYsvxkmlHPHxqeM7 K1ZcWGdQaW7vtcbVBTVAU3s1CXY6Ct7RLW9EIn1zJpxJTOP76WO52Htfw7wRxKuFBtw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796041239; 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=mLp+KQPfTQ7zqHRydCa85B1l8+Lu5fOSF0zPmSt84bNh/GOR+eCb1iSFi03FqvQ3Nofo qH7xWgv1tWk38edTIawVUj7KmARapbonUAkzw00iKzaIEgwZNe+m0WJvntmayqKZOPNMb b+1pTlQBZwoE1WGy5ym4go0bVIKDOoU8zExREyL5axYAQ5UmmeICKflIsk3BzwBhTaoKa 5YSp0oImiV/zepLEjnIbfGEK/IRHq2Mfc7Qjr1VwhV/v94iRJmKAQnzHydLQ2Y0fwXsoW QAq53BXnYZaLfXvwjlOG1Nxdz8rj65Z5AJcKPwKP0i8OvW9z7l7BK3qZG2mWlNN0g3w== 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 53004606A320 for ; Mon, 30 Nov 2026 12:20:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 53004606A320 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-93a40a9a01aso1298892685a.0 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=btjNjrL6dwLipNFHDDgGpzeA0l2nZwuvdVq+O3xMPZwpyu2sJCgyy4Zod1YEGFgdw4 fl8gce9KNm714z26K9tXIurpQqK+uWm/jsJsH2ZrsUhShwOYu2qJk0qt5hT/1oNRYxcQ Wlxqz3Yk1cBAkwwSYSaUnblMWiOQNdI+5asil2h4MYYK+9sgNMJtHKV714S5/ENGrCqS 1g7sO71roLs7sgGJekTuHRBqhZTpCcgGl0XwvsN5WmV5OmjYuaP0C3Hox/rYFc9onY/6 K5G3nU8IXR6t8faNOOt62BEONbmnEMfeqfAUw6/wOAEZb4x0ZbcrvGLvJAL72IGOrI8/ gvUw== X-Forwarded-Encrypted: i=1; AL+hErGWBC3GIoa5WaS06LLRqnNbL7S0+KWR7/ow2xd1ulZs0yNIHsrCzoTnnfcIIV43TTyCrD4Yd2wUVot89hypiHWR@vger.kernel.org X-Gm-Message-State: APuU4Z/CMrw/4Gy6tTCzT9GVxYAzx4IJhoexzXT6v1QK5KFag6YemBsQ ef24r8yUnIus99KKeOLXIb+DHoH7TURd5PJ+w18FZFJzURgZXn3UT5XA X-Gm-Gg: AZFdTZfVWBZA+N0xd5i714rB8TI+ohnXF+lay/Yj1UnME/l5kow4U8lv1yqfpc/U3mb dzTShgqQI71kEJJm569g7N8WvNQMOmX32uTfMoGX1cpo75+o3gg1Putdel/vVqTlRRVvOpb8ie/ eEVBgrwMzLTsrPHAyb7w1TQErYDhkLFYv1BnkSSG0jT3yOjgHrU+OtZDZwPv4J0UCXP+vRkqcWC UVWBR9NBCTUYAjoA43xNdvUGSsuv2Ma5vCVKiCtdU7nLu+0e48hH6c3BAc9wSsoON5Zzs1OlQ7f alX9/IVbMk+Bnzur6zXgx8Fyk06RW3qW+FvWjCSbmv/OyeONWwVdKhIOYJ5U50Cv9pmakaIj67w W4yrBMA2ezuyQ/Jkm6xW4AppzLS0Z/cybHODTL05d3YOXbtmVOn990iE88pqztREdDHyj34CLSa kSon8f0gwmREc78HHyqsiyO13SnzYCIjIMeLwdH1kz+bI7/ZZKlXOpyyC5Xh+FaacqaahG9Fuen Bvn6qRepAkblirPUoVjBI/Cp4Ra5FXatZi6KR87Zt8/IrTX+gBzqRDvO7um1RfCOFhmrnUOAftM H2RSGmpqOMzHalhD2qTCKTV5uYWQkwNEitHYnjX+oJTm5Ycg19ogRTgkxBIE1z9dAfiy/d+hM48 On45CfA5fK1GfI0bxhUWtiM8bKLSi 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-perf-users@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