Commit 1ff865e3 authored by Peter Zijlstra's avatar Peter Zijlstra

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: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarMiroslav Benes <mbenes@suse.cz>
Acked-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Link: https://lkml.kernel.org/r/20200429101802.GI13592@hirez.programming.kicks-ass.net
parent 7117f16b
...@@ -57,8 +57,10 @@ static __always_inline unsigned long smap_save(void) ...@@ -57,8 +57,10 @@ static __always_inline unsigned long smap_save(void)
{ {
unsigned long flags; unsigned long flags;
asm volatile (ALTERNATIVE("", "pushf; pop %0; " __ASM_CLAC, asm volatile ("# smap_save\n\t"
X86_FEATURE_SMAP) ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP)
"pushf; pop %0; " __ASM_CLAC "\n\t"
"1:"
: "=rm" (flags) : : "memory", "cc"); : "=rm" (flags) : : "memory", "cc");
return flags; return flags;
...@@ -66,7 +68,10 @@ static __always_inline unsigned long smap_save(void) ...@@ -66,7 +68,10 @@ static __always_inline unsigned long smap_save(void)
static __always_inline void smap_restore(unsigned long flags) static __always_inline void smap_restore(unsigned long flags)
{ {
asm volatile (ALTERNATIVE("", "push %0; popf", X86_FEATURE_SMAP) asm volatile ("# smap_restore\n\t"
ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP)
"push %0; popf\n\t"
"1:"
: : "g" (flags) : "memory", "cc"); : : "g" (flags) : "memory", "cc");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment