linux/arch/x86/entry
Peter Zijlstra 9cdbeec409 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: aa93e2ad74 ("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
2022-01-12 16:38:25 +01:00
..
syscalls futex,x86: Wire up sys_futex_waitv() 2021-10-07 13:51:11 +02:00
vdso x86: Remove .fixup section 2021-12-11 09:09:50 +01:00
vsyscall x86: Prepare asm files for straight-line-speculation 2021-12-08 12:25:37 +01:00
calling.h x86/entry: Split PUSH_AND_CLEAR_REGS into two submacros 2021-05-12 10:49:15 +02:00
common.c X86 entry code related updates: 2021-06-29 12:44:51 -07:00
entry_32.S x86/entry_32: Fix segment exceptions 2022-01-12 16:38:25 +01:00
entry_64_compat.S x86/sev-es: Introduce ip_within_syscall_gap() helper 2021-03-08 14:22:17 +01:00
entry_64.S x86/entry_64: Remove .fixup usage 2021-12-11 09:09:46 +01:00
Makefile x86/syscalls: Don't adjust CFLAGS for syscall tables 2021-05-25 16:59:23 +02:00
syscall_32.c x86/syscalls: Stop filling syscall arrays with *_sys_ni_syscall 2021-05-20 15:03:59 +02:00
syscall_64.c x86/syscalls: Stop filling syscall arrays with *_sys_ni_syscall 2021-05-20 15:03:59 +02:00
syscall_x32.c x86/syscalls: Stop filling syscall arrays with *_sys_ni_syscall 2021-05-20 15:03:59 +02:00
thunk_32.S x86: Prepare asm files for straight-line-speculation 2021-12-08 12:25:37 +01:00
thunk_64.S x86: Prepare asm files for straight-line-speculation 2021-12-08 12:25:37 +01:00