Skip to content

Commit 1ff865e

Browse files
author
Peter Zijlstra
committed
x86,smap: Fix smap_{save,restore}() alternatives
As reported by objtool: lib/ubsan.o: warning: objtool: .altinstr_replacement+0x0: alternative modifies stack lib/ubsan.o: warning: objtool: .altinstr_replacement+0x7: alternative modifies stack the smap_{save,restore}() alternatives violate (the newly enforced) rule on stack invariance. That is, due to there only being a single ORC table it must be valid to any alternative. These alternatives violate this with the direct result that unwinds will not be correct when it hits between the PUSH and POP instructions. Rewrite the functions to only have a conditional jump. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 7117f16 commit 1ff865e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

arch/x86/include/asm/smap.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,21 @@ static __always_inline unsigned long smap_save(void)
5757
{
5858
unsigned long flags;
5959

60-
asm volatile (ALTERNATIVE("", "pushf; pop %0; " __ASM_CLAC,
61-
X86_FEATURE_SMAP)
60+
asm volatile ("# smap_save\n\t"
61+
ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP)
62+
"pushf; pop %0; " __ASM_CLAC "\n\t"
63+
"1:"
6264
: "=rm" (flags) : : "memory", "cc");
6365

6466
return flags;
6567
}
6668

6769
static __always_inline void smap_restore(unsigned long flags)
6870
{
69-
asm volatile (ALTERNATIVE("", "push %0; popf", X86_FEATURE_SMAP)
71+
asm volatile ("# smap_restore\n\t"
72+
ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP)
73+
"push %0; popf\n\t"
74+
"1:"
7075
: : "g" (flags) : "memory", "cc");
7176
}
7277

0 commit comments

Comments
 (0)