Skip to content

Commit 25e73b7

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
x86/ibt: Suppress spurious ENDBR
It was reported that under certain circumstances GCC emits ENDBR instructions for _THIS_IP_ usage. Specifically, when it appears at the start of a basic block -- but not elsewhere. Since _THIS_IP_ is never used for control flow, these ENDBR instructions are completely superfluous. Override the _THIS_IP_ definition for x86_64 to avoid this. Less ENDBR instructions is better. Fixes: 156ff4a ("x86/ibt: Base IBT bits") Reported-by: David Kaplan <[email protected]> Reviewed-by: Andrew Cooper <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5290e88 commit 25e73b7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/x86/include/asm/linkage.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
#undef notrace
99
#define notrace __attribute__((no_instrument_function))
1010

11+
#ifdef CONFIG_64BIT
12+
/*
13+
* The generic version tends to create spurious ENDBR instructions under
14+
* certain conditions.
15+
*/
16+
#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=r" (__here)); __here; })
17+
#endif
18+
1119
#ifdef CONFIG_X86_32
1220
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
1321
#endif /* CONFIG_X86_32 */

include/linux/instruction_pointer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
#ifndef _LINUX_INSTRUCTION_POINTER_H
33
#define _LINUX_INSTRUCTION_POINTER_H
44

5+
#include <asm/linkage.h>
6+
57
#define _RET_IP_ (unsigned long)__builtin_return_address(0)
8+
9+
#ifndef _THIS_IP_
610
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
11+
#endif
712

813
#endif /* _LINUX_INSTRUCTION_POINTER_H */

0 commit comments

Comments
 (0)