]> git.baikalelectronics.ru Git - kernel.git/commit
x86/entry_32: Fix segment exceptions
authorPeter Zijlstra <peterz@infradead.org>
Tue, 11 Jan 2022 11:11:14 +0000 (12:11 +0100)
committerBorislav Petkov <bp@suse.de>
Wed, 12 Jan 2022 15:38:25 +0000 (16:38 +0100)
commit44970aa89e4263d439537770598b3b2bf17dc6f8
tree0a5f6577e801dcb928838528091f1b28d0e86b91
parent310eb4a022ce082cf2ee79a074a71aa4052aa5c8
x86/entry_32: Fix segment exceptions

The LKP robot reported that commit in Fixes: caused a failure. Turns out
the ldt_gdt_32 selftest turns into an infinite loop trying to clear the
segment.

As discovered by Sean, what happens is that PARANOID_EXIT_TO_KERNEL_MODE
in the handle_exception_return path overwrites the entry stack data with
the task stack data, restoring the "bad" segment value.

Instead of having the exception retry the instruction, have it emulate
the full instruction. Replace EX_TYPE_POP_ZERO with EX_TYPE_POP_REG
which will do the equivalent of: POP %reg; MOV $imm, %reg.

In order to encode the segment registers, add them as registers 8-11 for
32-bit.

By setting regs->[defg]s the (nested) RESTORE_REGS will pop this value
at the end of the exception handler and by increasing regs->sp, it will
have skipped the stack slot.

This was debugged by Sean Christopherson <seanjc@google.com>.

 [ bp: Add EX_REG_GS too. ]

Fixes: a83e73a18cda ("x86/entry_32: Remove .fixup usage")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/Yd1l0gInc4zRcnt/@hirez.programming.kicks-ass.net
arch/x86/entry/entry_32.S
arch/x86/include/asm/extable_fixup_types.h
arch/x86/lib/insn-eval.c
arch/x86/mm/extable.c