RE: [patch 11/16] x86/ldt: Force access bit for CS/SS
From: David Laight
Date: Tue Dec 19 2017 - 07:10:31 EST
From: Andy Lutomirski
> Sent: 12 December 2017 19:27
> > Why is the iret exception unrecoverable anyway? Does anybody even know?
> Weird microcode shit aside, a fault on IRET will return to kernel code with kernel GS, and then the
> next time we enter the kernel we're backwards. We could fix idtentry to get this right, but the code
> is already tangled enough.
Notwithstanding a readonly LDT, the iret (and pop %ds, pop %es that probably
precede it) are all likely to fault in kernel if the segment registers are invalid.
(Setting %fs and %gs for 32 bit processes is left to the reader.)
Unlike every other fault in the kernel code segment, gsbase will contain
the user value, not the kernel one.
The kernel code must detect this somehow and correct everything before (probably)
generating a SIGSEGV and returning to the user's signal handler with the
invalid segment registers in the signal context.
Assuming this won't happen (because the segment registers are always valid)
is likely to be a recipe for disaster (or an escalation).
I guess the problem with a readonly LDT is that you don't want to fault
setting the 'accesses' bit.