Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/entry/32: Restore FLAGS on SYSEXIT

We weren't restoring FLAGS at all on SYSEXIT. Apparently no one cared.

With this patch applied, native kernels should always honor
task_pt_regs()->flags, which opens the door for some sys_iopl()
cleanups. I'll do those as a separate series, though, since getting
it right will involve tweaking some paravirt ops.

( The short version is that, before this patch, sys_iopl(), invoked via
SYSENTER, wasn't guaranteed to ever transfer the updated
regs->flags, so sys_iopl() had to change the hardware flags register
as well. )

Reported-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/3f98b207472dc9784838eb5ca2b89dcc845ce269.1457578375.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
c2c9b52f 67f590e8

+9
+9
arch/x86/entry/entry_32.S
··· 343 343 popl %eax /* pt_regs->ax */ 344 344 345 345 /* 346 + * Restore all flags except IF. (We restore IF separately because 347 + * STI gives a one-instruction window in which we won't be interrupted, 348 + * whereas POPF does not.) 349 + */ 350 + addl $PT_EFLAGS-PT_DS, %esp /* point esp at pt_regs->flags */ 351 + btr $X86_EFLAGS_IF_BIT, (%esp) 352 + popfl 353 + 354 + /* 346 355 * Return back to the vDSO, which will pop ecx and edx. 347 356 * Don't bother with DS and ES (they already contain __USER_DS). 348 357 */