Skip to contentSkip to conversation

x86/asm/entry/32, selftests: Add 'test_syscall_vdso' test

PATCH New Denys Vlasenko 2 participants 2 messages Sep 16, 2015 – Sep 18, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 x86/asm/entry/32, selftests: Add 'test_syscall_vdso' test

This new test checks that all x86 registers are preserved across 32-bit syscalls. It tests syscalls through VDSO (if available) and through INT 0x80, normally and under ptrace.

If kernel is a 64-bit one, high registers (r8..r15) are poisoned before the syscall is called and are checked afterwards.

They must be either preserved, or cleared to zero (but r11 is special); r12..15 must be preserved for INT 0x80.

EFLAGS is checked for changes too, but change there is not considered to be a bug (paravirt kernels do not preserve arithmetic flags).

Run-tested on 64-bit kernel:

$ ./test_syscall_vdso_32
[RUN]	Executing 6-argument 32-bit syscall via VDSO
[OK]	Arguments are preserved across syscall
[NOTE]	R11 has changed:0000000000200ed7 - assuming clobbered by SYSRET insn
[OK]	R8..R15 did not leak kernel data
[RUN]	Executing 6-argument 32-bit syscall via INT 80
[OK]	Arguments are preserved across syscall
[OK]	R8..R15 did not leak kernel data
[RUN]	Running tests under ptrace
[RUN]	Executing 6-argument 32-bit syscall via VDSO
[OK]	Arguments are preserved across syscall
[OK]	R8..R15 did not leak kernel data
[RUN]	Executing 6-argument 32-bit syscall via INT 80
[OK]	Arguments are preserved across syscall
[OK]	R8..R15 did not leak kernel data

On 32-bit paravirt kernel:

$ ./test_syscall_vdso_32
[NOTE]	Not a 64-bit kernel, won't test R8..R15 leaks
[RUN]	Executing 6-argument 32-bit syscall via VDSO
[WARN]	Flags before=0000000000200ed7 id 0 00 o d i s z 0 a 0 p 1 c
[WARN]	Flags  after=0000000000200246 id 0 00 i z 0 0 p 1
[WARN]	Flags change=0000000000000c91 0 00 o d s 0 a 0 0 c
[OK]	Arguments are preserved across syscall
[RUN]	Executing 6-argument 32-bit syscall via INT 80
[OK]	Arguments are preserved across syscall
[RUN]	Running tests under ptrace
[RUN]	Executing 6-argument 32-bit syscall via VDSO
[OK]	Arguments are preserved across syscall
[RUN]	Executing 6-argument 32-bit syscall via INT 80
[OK]	Arguments are preserved across syscall
CC Linus Torvalds <[email protected]>
CC Steven Rostedt <[email protected]>
CC Ingo Molnar <[email protected]>
CC Borislav Petkov <[email protected]>
CC "H. Peter Anvin" <[email protected]>
CC Andy Lutomirski <[email protected]>
CC Oleg Nesterov <[email protected]>
CC Frederic Weisbecker <[email protected]>
CC Alexei Starovoitov <[email protected]>
CC Will Drewry <[email protected]>
CC Kees Cook <[email protected]>

---

Changes in v2:
does not fail if VDSO can't be found;
tests INT 80 syscall method;
tests syscalls under ptrace;
switched to /* */ comments

Changes in v3:
added checking for r8..r15 info leaks

Changes in v4:
re-added Makefile change

Changes in v5:
use fputs to print a string, not printf ("warning: format not a string literal")

 tools/testing/selftests/x86/Makefile            |   2 +-
 tools/testing/selftests/x86/test_syscall_vdso.c | 401 ++++++++++++++++++++++++
 tools/testing/selftests/x86/thunks_32.S         |  55 ++++
 3 files changed, 457 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/x86/test_syscall_vdso.c
 create mode 100644 tools/testing/selftests/x86/thunks_32.S
tools/testing/selftests/x86/Makefile +2 -1
index caa60d5..84effa6 100644
@@ -5,7 +5,7 @@ include ../lib.mk
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt
-TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn
+TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn test_syscall_vdso
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
@@ -60,3 +60,4 @@ endif
 
 # Some tests have additional dependencies.
 sysret_ss_attrs_64: thunks.S
+test_syscall_vdso_32: thunks_32.S
tools/testing/selftests/x86/test_syscall_vdso.c new file +401 -0

401 lines not on this page · raw message

tools/testing/selftests/x86/thunks_32.S new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#1 lore raw

[tip:x86/asm] x86/asm/entry/32, selftests: Add 'test_syscall_vdso ' test

x86/asm/entry/32, selftests: Add 'test_syscall_vdso' test
Commit-ID:  c25be94f2870bf75552a41ad8b15f756e19ffb1d
Gitweb:     http://git.kernel.org/tip/c25be94f2870bf75552a41ad8b15f756e19ffb1d
Author:     Denys Vlasenko <[email protected]>
AuthorDate: Wed, 16 Sep 2015 20:23:29 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 18 Sep 2015 09:40:48 +0200

x86/asm/entry/32, selftests: Add 'test_syscall_vdso' test

This new test checks that all x86 registers are preserved across 32-bit syscalls. It tests syscalls through VDSO (if available) and through INT 0x80, normally and under ptrace.

If kernel is a 64-bit one, high registers (r8..r15) are poisoned before the syscall is called and are checked afterwards.

They must be either preserved, or cleared to zero (but r11 is special); r12..15 must be preserved for INT 0x80.

EFLAGS is checked for changes too, but change there is not considered to be a bug (paravirt kernels do not preserve arithmetic flags).

Run-tested on 64-bit kernel:

	$ ./test_syscall_vdso_32
	[RUN]	Executing 6-argument 32-bit syscall via VDSO
	[OK]	Arguments are preserved across syscall
	[NOTE]	R11 has changed:0000000000200ed7 - assuming clobbered by
	SYSRET insn [OK]	R8..R15 did not leak kernel data
	[RUN]	Executing 6-argument 32-bit syscall via INT 80
	[OK]	Arguments are preserved across syscall
	[OK]	R8..R15 did not leak kernel data
	[RUN]	Running tests under ptrace
	[RUN]	Executing 6-argument 32-bit syscall via VDSO
	[OK]	Arguments are preserved across syscall
	[OK]	R8..R15 did not leak kernel data
	[RUN]	Executing 6-argument 32-bit syscall via INT 80
	[OK]	Arguments are preserved across syscall
	[OK]	R8..R15 did not leak kernel data

On 32-bit paravirt kernel:

	$ ./test_syscall_vdso_32
	[NOTE]	Not a 64-bit kernel, won't test R8..R15 leaks
	[RUN]	Executing 6-argument 32-bit syscall via VDSO
	[WARN]	Flags before=0000000000200ed7 id 0 00 o d i s z 0 a 0 p 1 c
	[WARN]	Flags  after=0000000000200246 id 0 00 i z 0 0 p 1
	[WARN]	Flags change=0000000000000c91 0 00 o d s 0 a 0 0 c
	[OK]	Arguments are preserved across syscall
	[RUN]	Executing 6-argument 32-bit syscall via INT 80
	[OK]	Arguments are preserved across syscall
	[RUN]	Running tests under ptrace
	[RUN]	Executing 6-argument 32-bit syscall via VDSO
	[OK]	Arguments are preserved across syscall
	[RUN]	Executing 6-argument 32-bit syscall via INT 80
	[OK]	Arguments are preserved across syscall
Cc Alexei Starovoitov <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Will Drewry <[email protected]>
---
 tools/testing/selftests/x86/Makefile               |   3 +-
 tools/testing/selftests/x86/test_syscall_vdso.c    | 401 +++++++++++++++++++++
 .../selftests/x86/{thunks.S => thunks_32.S}        |  66 ++--
 3 files changed, 430 insertions(+), 40 deletions(-)
tools/testing/selftests/x86/Makefile +2 -1
index 29089b2..fd55bc3 100644
@@ -5,7 +5,7 @@ include ../lib.mk
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt
-TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn
+TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn test_syscall_vdso
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
@@ -60,3 +60,4 @@ endif
 
 # Some tests have additional dependencies.
 sysret_ss_attrs_64: thunks.S
+test_syscall_vdso_32: thunks_32.S
tools/testing/selftests/x86/test_syscall_vdso.c new file +401 -0

401 lines not on this page · raw message

tools/testing/selftests/x86/thunks_32.S renamed from tools/testing/selftests/x86/thunks.S +27 -39

85 lines not on this page · raw message