Skip to content

Commit ba08abc

Browse files
author
Peter Zijlstra
committed
objtool,x86: Fix uaccess PUSHF/POPF validation
Commit ab234a2 ("x86/pv: Rework arch_local_irq_restore() to not use popf") replaced "push %reg; popf" with something like: "test $0x200, %reg; jz 1f; sti; 1:", which breaks the pushf/popf symmetry that commit ea24213 ("objtool: Add UACCESS validation") relies on. The result is: drivers/gpu/drm/amd/amdgpu/si.o: warning: objtool: si_common_hw_init()+0xf36: PUSHF stack exhausted Meanwhile, commit c9c324d ("objtool: Support stack layout changes in alternatives") makes that we can actually use stack-ops in alternatives, which means we can revert 1ff865e ("x86,smap: Fix smap_{save,restore}() alternatives"). That in turn means we can limit the PUSHF/POPF handling of ea24213 to those instructions that are in alternatives. Fixes: ab234a2 ("x86/pv: Rework arch_local_irq_restore() to not use popf") Reported-by: Borislav Petkov <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent a38fd87 commit ba08abc

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

arch/x86/include/asm/smap.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ static __always_inline unsigned long smap_save(void)
5858
unsigned long flags;
5959

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

6665
return flags;
@@ -69,9 +68,8 @@ static __always_inline unsigned long smap_save(void)
6968
static __always_inline void smap_restore(unsigned long flags)
7069
{
7170
asm volatile ("# smap_restore\n\t"
72-
ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP)
73-
"push %0; popf\n\t"
74-
"1:"
71+
ALTERNATIVE("", "push %0; popf\n\t",
72+
X86_FEATURE_SMAP)
7573
: : "g" (flags) : "memory", "cc");
7674
}
7775

tools/objtool/check.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,9 @@ static int handle_insn_ops(struct instruction *insn, struct insn_state *state)
24422442
if (update_cfi_state(insn, &state->cfi, op))
24432443
return 1;
24442444

2445+
if (!insn->alt_group)
2446+
continue;
2447+
24452448
if (op->dest.type == OP_DEST_PUSHF) {
24462449
if (!state->uaccess_stack) {
24472450
state->uaccess_stack = 1;

0 commit comments

Comments
 (0)