From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796041240; b=CRUHPpGvbRjQtcf1hINb6lgeW3J+gEleFIzPsTR645gurgQYoCbwpRyDXwNAtaq9OUzi vA+gkMBAfU1IgpYfCX1I5I0yInfFZsb0iJCytcmDvtdCMmGdcf/FTXfc0Yj8jFjxALC4R sF7JJSO8IZ7t12oP7Ntxs0WsVrGTcGAOw06+LBdYKtSlICRhw4dxKcKF4vsC8XVHHGeIW 6gy0115siijj+0SYAc2t+MPwZyNmCLAGM7a+cA1EHZn9yqjjssnaTDR+NF2/IdVumwsuL S+kk6YrlK4S1BR6bYUsw5lX5RIB2DllTAEw+pJnzmEbnRr551kd/F0iv7jFyWqkCNfA== 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=sJzoVWII3NH3beLyDbbMeYMq7LztQkGvsERLhB7JbXgclJD5CykOj3rxFHh+BMrLKkDG Ys0PMQKP3ZL7it8LftA0mdRS0VCoriKsMtKVqsO/u6C7eVt6wfRspOwYkBROC+yWLVGks hP0U+OsKfy0a5yts6Q6hAA9vl/EHm2iummnsFd0KX0rq8wbfhuPY/+FRPInh7BaTddvWx /HLfRaARJsawG4m1dKtsRIl5TT1IMR3FyPc53IMZMwdYIfak/DC+1Tam3awWXJEYtygc3 3utIdHaCxoJ7LGpCKLXJoZZzr4RF9NR53/RhMGsEO8+wSFhmN4Q136LUkjSny79lzxA== 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.169 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 59EF3606A325 for ; Mon, 30 Nov 2026 12:20:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 59EF3606A325 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-f169.google.com with SMTP id af79cd13be357-9497a167a6aso1321871285a.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=obMagBDnmvw4V7iQxtD4y/QDSQmqxte5CSKl+sBkeonXAn7GJDwD9LiRs4//BA7dtn jEciY7t5vpR+Qx+elK9+g90XXe+Nnlec6r847Ra84lmjARMRun7YNWiSOZU3bHpELOV5 B2eufPnMYZ80/rXMX0DN0BaEJABhohg0czG1R6s+kRGOVpCOObL+SRZqbFfAMl5m+n61 8Hbp2czEOVRYE3OwMpCXLREzWjF6EQvzuDmu/8aftFxl9JXkADWfgLAbqzLqRxTKoNBv CyWKCTAxaXwnY5uQ1m4iKPP4W9vAwvq+0FzU+xslM+v9hi4aanGfjVWv26w9dus0pZib Qfyg== X-Forwarded-Encrypted: i=1; AL+hErEPgpe1G0sehMUzOGQl2kh1qGzBk4Y3vhdyFqL52c6T4kOrQ77sU0dQOP9JwqZp7tiXGJ9kWaIIwRgfK8VyGvO8vws=@vger.kernel.org X-Gm-Message-State: APuU4Z9BCyxVQe/ytwOm/GOMKt5J/Yw4xCjaEGIcp2nxNL/SgN8oAHKd I7Wx6adHiNwf80u5pD8F7/uDC2nT9/KAxfGZZicR5V3Hh8MorfwT8phz X-Gm-Gg: AZFdTZdV7HSU0a7z34IxCxXKFLHI/irDZxX9KIqJisjm399C67HiBjCl+VVXy3DGVjS JXMME5AVQWXVkqoQ97wVG5ddY9jAexpW80FCcsE61MOd/wVY4c2ue6XrvqXir7+/kCWTha8DgKt J+uLC1e6S/jyQcSBTHFVIwHYgGgQ/zyFeEGoKd+gGykxwttQe84q8mPUtBuaJH6J2DG43LCnPvb GPm9lwz9kR3ZkDYTEZXE2pFgyvqYVTOowzfzYdCXU2eQWSq6VJAwFCuy2oT+j0H48ZiRerVKa/q bjh0yRKHD+WLc5zGVqXvA9YlCUvJdBFWEkrgGlpmNjHIXyW4TzUGrVzIBNPL8mDcj6zP6cQP7S4 vh0m0skk6yQVPbxYys4ezHce8v0oPRDINcley4/bHwv5tZFUSk++3i14FYS/pvnUPDhuLc66NbG +VTQI+bjHw33mznVK/FUAU5iLp7QwLK3kAw5RWPkGOoI9Dp07HAYPjJhhlQ/03EqdwLchbEsGBy 2MtwNxEHOetROaVVn/4jX3rgpOzG9cIq2SsOGi78udK3h/YGOWT7qEKTgWtDFjiSKvYMhjbMEzW ww643Dhtw+QS7mad2bt6creIp4Oc+LAihdzwBCBUAW3oAIUXD62IBCDCHFfs4vg2JBTAquYslXD trbZJekpfE5v6yB0XH/KWKJKKiSLG 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-trace-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