linux/tools/testing/selftests
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
..
breakpoints add breakpoints/.gitignore 2016-01-07 13:38:24 -07:00
capabilities selftests/capabilities: clean up for Makefile 2015-11-23 13:20:10 -07:00
cpu-hotplug selftests: change cpu on-off-test.sh name to be unique 2015-04-01 10:32:52 -06:00
efivarfs selftests: add .gitignore for efivarfs 2015-10-15 20:00:32 -06:00
exec selftests: exec: revert to default emit rule 2015-09-14 16:45:05 -06:00
firmware selftests: firmware: add empty string and async tests 2016-01-07 14:41:07 -07:00
ftrace ftracetest: Add instance create and delete test 2015-11-24 09:29:14 -05:00
futex tools:testing/selftests: fix typo in futex/README 2015-11-16 19:22:49 -07:00
intel_pstate tools, testing, add test for intel_pstate driver 2015-11-23 13:30:59 -07:00
ipc selftest/ipc: enable cross compilation 2015-04-02 12:41:52 -06:00
kcmp selftests: Set CC using CROSS_COMPILE once in lib.mk 2015-03-19 15:16:51 -06:00
lib selftests: run lib/test_printf module 2015-11-06 17:50:42 -08:00
membarrier membarrier: clean up selftest 2015-09-22 15:09:53 -07:00
memfd selftests: Make scripts executable 2015-11-03 16:54:57 -07:00
memory-hotplug selftests: Change memory on-off-test.sh name to be unique 2015-04-01 10:33:02 -06:00
mount selftests/mount: output WARN messages when mount test skipped 2015-05-26 15:58:06 -06:00
mqueue selftests: Add missing #include directives 2015-11-03 16:53:53 -07:00
net soreuseport: pass skb to secondary UDP socket lookup 2016-01-06 01:28:04 -05:00
powerpc selftests/powerpc: Add script to test HMI functionality 2015-12-17 10:46:43 +11:00
pstore selftests/pstore: add pstore test scripts going with reboot 2015-10-15 20:00:32 -06:00
ptrace add ptrace/.gitignore 2016-01-07 13:38:11 -07:00
rcutorture torture: Place console.log files correctly from the get-go 2015-12-05 17:58:34 -08:00
seccomp linux-kselftest-4.5-rc1 2016-01-17 13:31:50 -08:00
size selftests: Set CC using CROSS_COMPILE once in lib.mk 2015-03-19 15:16:51 -06:00
static_keys selftests: Make scripts executable 2015-11-03 16:54:57 -07:00
sysctl selftests: Add install target 2015-03-13 15:21:56 -06:00
timers linux-kselftest-4.5-rc1 2016-01-17 13:31:50 -08:00
user selftests: Introduce minimal shared logic for running tests 2015-03-13 15:13:40 -06:00
vm update .gitignore in selftests/vm 2016-01-07 13:37:41 -07:00
x86 x86/signal/64: Re-add support for SS in the 64-bit signal context 2016-02-17 08:32:11 +01:00
zram seltests/zram: fix syntax error 2015-09-14 16:40:57 -06:00
gen_kselftest_tar.sh selftests: Add tool to generate kselftest tar archive 2015-03-24 08:43:19 -06:00
kselftest_install.sh selftests: Add kselftest install tool 2015-03-24 08:43:05 -06:00
kselftest.h kselftest: Add exit code defines 2015-05-26 15:58:08 -06:00
lib.mk selftests: change install command to rsync 2015-09-14 16:43:51 -06:00
Makefile selftest/ipc: actually test it 2015-11-23 13:21:15 -07:00