linux/arch/x86/include/uapi/asm
Andy Lutomirski 6c25da5ad5 x86/signal/64: Re-add support for SS in the 64-bit signal context
This is a second attempt to make the improvements from c6f2062935
("x86/signal/64: Fix SS handling for signals delivered to 64-bit
programs"), which was reverted by 51adbfbba5c6 ("x86/signal/64: Add
support for SS in the 64-bit signal context").

This adds two new uc_flags flags.  UC_SIGCONTEXT_SS will be set for
all 64-bit signals (including x32).  It indicates that the saved SS
field is valid and that the kernel supports the new behavior.

The goal is to fix a problems with signal handling in 64-bit tasks:
SS wasn't saved in the 64-bit signal context, making it awkward to
determine what SS was at the time of signal delivery and making it
impossible to return to a non-flat SS (as calling sigreturn clobbers
SS).

This also made it extremely difficult for 64-bit tasks to return to
fully-defined 16-bit contexts, because only the kernel can easily do
espfix64, but sigreturn was unable to set a non-flag SS:ESP.
(DOSEMU has a monstrous hack to partially work around this
limitation.)

If we could go back in time, the correct fix would be to make 64-bit
signals work just like 32-bit signals with respect to SS: save it
in signal context, reset it when delivering a signal, and restore
it in sigreturn.

Unfortunately, doing that (as I tried originally) breaks DOSEMU:
DOSEMU wouldn't reset the signal context's SS when clearing the LDT
and changing the saved CS to 64-bit mode, since it predates the SS
context field existing in the first place.

This patch is a bit more complicated, and it tries to balance a
bunch of goals.  It makes most cases of changing ucontext->ss during
signal handling work as expected.

I do this by special-casing the interesting case.  On sigreturn,
ucontext->ss will be honored by default, unless the ucontext was
created from scratch by an old program and had a 64-bit CS
(unfortunately, CRIU can do this) or was the result of changing a
32-bit signal context to 64-bit without resetting SS (as DOSEMU
does).

For the benefit of new 64-bit software that uses segmentation (new
versions of DOSEMU might), the new behavior can be detected with a
new ucontext flag UC_SIGCONTEXT_SS.

To avoid compilation issues, __pad0 is left as an alias for ss in
ucontext.

The nitty-gritty details are documented in the header file.

This patch also re-enables the sigreturn_64 and ldt_gdt_64 selftests,
as the kernel change allows both of them to pass.

Tested-by: Stas Sergeev <stsp@list.ru>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Borislav Petkov <bp@alien8.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
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: Pavel Emelyanov <xemul@parallels.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/749149cbfc3e75cd7fcdad69a854b399d792cc6f.1455664054.git.luto@kernel.org
[ Small readability edit. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-02-17 08:32:11 +01:00
..
a.out.h
auxvec.h
bitsperlong.h x86/headers/uapi: Fix __BITS_PER_LONG value for x32 builds 2015-10-02 09:43:21 +02:00
boot.h
bootparam.h x86/boot: Obsolete the MCA sys_desc_table 2015-07-21 10:55:11 +02:00
byteorder.h
debugreg.h
e820.h libnvdimm, e820: make CONFIG_X86_PMEM_LEGACY a tristate option 2015-08-19 00:34:34 -04:00
errno.h
fcntl.h
hw_breakpoint.h create non-empty arch/x86/include/uapi/asm/ files 2012-12-17 17:15:11 -08:00
hyperv.h kvm/x86: Hyper-V SynIC timers 2015-12-16 18:49:45 +01:00
ioctl.h
ioctls.h
ipcbuf.h
ist.h
Kbuild perf kvm: Use defines of kvm events 2014-07-16 17:57:32 -03:00
kvm_para.h kvm uapi: Add KICK_CPU and PV_UNHALT definition to uapi 2013-08-26 12:46:01 +03:00
kvm_perf.h perf kvm: Use defines of kvm events 2014-07-16 17:57:32 -03:00
kvm.h KVM: x86: rename quirk constants to KVM_X86_QUIRK_* 2015-07-23 08:24:42 +02:00
ldt.h x86/tls: Don't validate lm in set_thread_area() after all 2014-12-18 12:12:26 +01:00
mce.h x86/RAS: Remove mce.usable_addr 2015-11-24 09:12:35 +01:00
mman.h
msgbuf.h
msr.h x86/uapi: Do not export <asm/msr-index.h> as part of the user API headers 2015-06-07 15:36:04 +02:00
mtrr.h x86/mm/mtrr: Use symbolic define as a retval for disabled MTRRs 2015-05-27 14:40:57 +02:00
param.h
perf_regs.h
poll.h
posix_types_32.h
posix_types_64.h
posix_types_x32.h
posix_types.h
prctl.h
processor-flags.h x86/asm: Drop repeated macro of X86_EFLAGS_AC definition 2015-08-28 07:33:34 +02:00
ptrace-abi.h x86/asm/entry/64: Fix comments 2015-03-04 22:50:49 +01:00
ptrace.h x86/asm/entry/64: Fix comments 2015-03-04 22:50:49 +01:00
resource.h
sembuf.h x86, uapi, x32: Use __kernel_ulong_t in x86 struct semid64_ds 2014-01-20 14:45:13 -08:00
setup.h create non-empty arch/x86/include/uapi/asm/ files 2012-12-17 17:15:11 -08:00
shmbuf.h
sigcontext32.h x86/headers: Remove direct sigcontext32.h uses 2015-09-08 10:03:59 +02:00
sigcontext.h x86/signal/64: Re-add support for SS in the 64-bit signal context 2016-02-17 08:32:11 +01:00
siginfo.h
signal.h consolidate kernel-side struct sigaction declarations 2013-02-03 15:09:22 -05:00
socket.h
sockios.h
stat.h x86, x32: Use __kernel_long_t/__kernel_ulong_t in x86-64 stat.h 2013-12-20 16:04:35 -08:00
statfs.h
svm.h KVM: x86: work around infinite loop in microcode when #AC is delivered 2015-11-10 12:06:24 +01:00
swab.h
termbits.h
termios.h
types.h
ucontext.h x86/signal/64: Re-add support for SS in the 64-bit signal context 2016-02-17 08:32:11 +01:00
unistd.h
vm86.h
vmx.h KVM: x86: add pcommit support 2015-10-01 15:06:35 +02:00
vsyscall.h x86, vdso: Move the vvar and hpet mappings next to the 64-bit vDSO 2014-05-05 13:19:01 -07:00