Skip to contentSkip to conversation

x86, selftests: Add a test for the "sysret_ss_attrs" bug

PATCH In review Andy Lutomirski 3 participants 3 messages Apr 24, 2015 – May 8, 2015

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

PATCH 1/1 x86, selftests: Add a test for the "sysret_ss_attrs" bug

On AMD CPUs, SYSRET can return with a valid SS descriptor with with the hidden attributes set to an unusable state. Make sure the kernel doesn't let this happen. This detects an as-yet-unfixed regression.

Note that the 64-bit version of this test fails on AMD CPUs on all kernel versions, although the issue in the 64-bit case is much less severe than in the 32-bit case.

Tests: e7d6eefaaa44 x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

---

[resend -- it seems like only some recipients got it last time]

We're still mulling over the fix, but we have a good test case now.

tools/testing/selftests/x86/Makefile | 5 +-

 tools/testing/selftests/x86/run_x86_tests.sh  |   2 +
 tools/testing/selftests/x86/sysret_ss_attrs.c | 112 ++++++++++++++++++++++++++
 tools/testing/selftests/x86/thunks.S          |  67 +++++++++++++++
 4 files changed, 185 insertions(+), 1 deletion(-)
 mode change 100644 => 100755 tools/testing/selftests/x86/run_x86_tests.sh
 create mode 100644 tools/testing/selftests/x86/sysret_ss_attrs.c
 create mode 100644 tools/testing/selftests/x86/thunks.S
tools/testing/selftests/x86/Makefile +4 -1
index ddf63569df5a..9309097f58e8 100644
@@ -1,6 +1,6 @@
 .PHONY: all all_32 all_64 check_build32 clean run_tests
 
-TARGETS_C_BOTHBITS := sigreturn single_step_syscall
+TARGETS_C_BOTHBITS := sigreturn single_step_syscall sysret_ss_attrs
 
 BINARIES_32 := $(TARGETS_C_BOTHBITS:%=%_32)
 BINARIES_64 := $(TARGETS_C_BOTHBITS:%=%_64)
@@ -46,3 +46,6 @@ check_build32:
 	  echo "  yum install glibc-devel.*i686";			\
 	  exit 1;							\
 	fi
+
+# Some tests have additional dependencies.
+sysret_ss_attrs_64: thunks.S
tools/testing/selftests/x86/run_x86_tests.sh +2 -0
old mode 100644
new mode 100755
index 3fc19b376812..d25034280dd5
@@ -4,10 +4,12 @@
 # script here.
 ./sigreturn_32 || exit 1
 ./single_step_syscall_32 || exit 1
+./sysret_ss_attrs_32 || exit 1
 
 if [[ "$uname -p" -eq "x86_64" ]]; then
     ./sigreturn_64 || exit 1
     ./single_step_syscall_64 || exit 1
+    ./sysret_ss_attrs_64 || exit 1
 fi
 
 exit 0
tools/testing/selftests/x86/sysret_ss_attrs.c new file +112 -0

112 lines not on this page · raw message

tools/testing/selftests/x86/thunks.S new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.3.0
#1 lore raw
Quoted 7 lines · Andy Lutomirski

On AMD CPUs, SYSRET can return with a valid SS descriptor with with the hidden attributes set to an unusable state. Make sure the kernel doesn't let this happen. This detects an as-yet-unfixed regression.

Note that the 64-bit version of this test fails on AMD CPUs on all kernel versions, although the issue in the 64-bit case is much less severe than in the 32-bit case.

Confirmed to detect the "bug" in 64-bit userspace.

#2 lore raw

[tip:x86/asm] x86, selftests: Add a test for the "sysret_ss_attrs " bug

In reply to Andy Lutomirski
x86, selftests: Add a test for the "sysret_ss_attrs" bug
Commit-ID:  e22438f8e997ac1c8911d8808b6a4c492cd8bc6e
Gitweb:     http://git.kernel.org/tip/e22438f8e997ac1c8911d8808b6a4c492cd8bc6e
Author:     Andy Lutomirski <[email protected]>
AuthorDate: Fri, 24 Apr 2015 15:09:19 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 8 May 2015 13:33:59 +0200

x86, selftests: Add a test for the "sysret_ss_attrs" bug

On AMD CPUs, SYSRET can return with a valid SS descriptor with with the hidden attributes set to an unusable state. Make sure the kernel doesn't let this happen. This detects an as-yet-unfixed regression.

Note that the 64-bit version of this test fails on AMD CPUs on all kernel versions, although the issue in the 64-bit case is much less severe than in the 32-bit case.

Tests: e7d6eefaaa44 ("x86/vdso32/syscall.S: Do not load __USER32_DS to %ss")

Cc Alexei Starovoitov <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Will Drewry <[email protected]>
---
 tools/testing/selftests/x86/Makefile          |   5 +-
 tools/testing/selftests/x86/run_x86_tests.sh  |   2 +
 tools/testing/selftests/x86/sysret_ss_attrs.c | 112 ++++++++++++++++++++++++++
 tools/testing/selftests/x86/thunks.S          |  67 +++++++++++++++
 4 files changed, 185 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/Makefile +4 -1
index ddf6356..9309097 100644
@@ -1,6 +1,6 @@
 .PHONY: all all_32 all_64 check_build32 clean run_tests
 
-TARGETS_C_BOTHBITS := sigreturn single_step_syscall
+TARGETS_C_BOTHBITS := sigreturn single_step_syscall sysret_ss_attrs
 
 BINARIES_32 := $(TARGETS_C_BOTHBITS:%=%_32)
 BINARIES_64 := $(TARGETS_C_BOTHBITS:%=%_64)
@@ -46,3 +46,6 @@ check_build32:
 	  echo "  yum install glibc-devel.*i686";			\
 	  exit 1;							\
 	fi
+
+# Some tests have additional dependencies.
+sysret_ss_attrs_64: thunks.S
tools/testing/selftests/x86/run_x86_tests.sh +2 -0
index 3fc19b3..d250342 100644
@@ -4,10 +4,12 @@
 # script here.
 ./sigreturn_32 || exit 1
 ./single_step_syscall_32 || exit 1
+./sysret_ss_attrs_32 || exit 1
 
 if [[ "$uname -p" -eq "x86_64" ]]; then
     ./sigreturn_64 || exit 1
     ./single_step_syscall_64 || exit 1
+    ./sysret_ss_attrs_64 || exit 1
 fi
 
 exit 0
tools/testing/selftests/x86/sysret_ss_attrs.c new file +112 -0

112 lines not on this page · raw message

tools/testing/selftests/x86/thunks.S new file +67 -0

67 lines not on this page · raw message