All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] selftests/x86: Minor fixes
@ 2020-11-02 19:51 Andy Lutomirski
  2020-11-02 19:51 ` [PATCH 1/2] selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests Andy Lutomirski
  2020-11-02 19:51 ` [PATCH 2/2] selftests/x86: Add missing .note.GNU-stack sections Andy Lutomirski
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Lutomirski @ 2020-11-02 19:51 UTC (permalink / raw)
  To: x86; +Cc: LKML, Andy Lutomirski

Two bugs fixed.

Andy Lutomirski (2):
  selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests
  selftests/x86: Add missing .note.GNU-stack sections

 tools/testing/selftests/x86/fsgsbase.c              | 12 ++++++++++--
 tools/testing/selftests/x86/raw_syscall_helper_32.S |  2 ++
 tools/testing/selftests/x86/thunks.S                |  2 ++
 3 files changed, 14 insertions(+), 2 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests
  2020-11-02 19:51 [PATCH 0/2] selftests/x86: Minor fixes Andy Lutomirski
@ 2020-11-02 19:51 ` Andy Lutomirski
  2020-11-24 13:02   ` [tip: x86/misc] " tip-bot2 for Andy Lutomirski
  2020-11-02 19:51 ` [PATCH 2/2] selftests/x86: Add missing .note.GNU-stack sections Andy Lutomirski
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Lutomirski @ 2020-11-02 19:51 UTC (permalink / raw)
  To: x86; +Cc: LKML, Andy Lutomirski

Setting GS to 1, 2, or 3 causes a nonsensical part of the IRET
microcode to change GS back to zero on a return from kernel mode to
user mode.  The result is that these tests fail randomly depending
on when interrupts happen.  Detect when this happens and let the
test pass.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 tools/testing/selftests/x86/fsgsbase.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c
index 7161cfc2e60b..8c780cce941d 100644
--- a/tools/testing/selftests/x86/fsgsbase.c
+++ b/tools/testing/selftests/x86/fsgsbase.c
@@ -392,8 +392,8 @@ static void set_gs_and_switch_to(unsigned long local,
 		local = read_base(GS);
 
 		/*
-		 * Signal delivery seems to mess up weird selectors.  Put it
-		 * back.
+		 * Signal delivery is quite likely to change a selector
+		 * of 1, 2, or 3 back to 0 due to IRET being defective.
 		 */
 		asm volatile ("mov %0, %%gs" : : "rm" (force_sel));
 	} else {
@@ -411,6 +411,14 @@ static void set_gs_and_switch_to(unsigned long local,
 	if (base == local && sel_pre_sched == sel_post_sched) {
 		printf("[OK]\tGS/BASE remained 0x%hx/0x%lx\n",
 		       sel_pre_sched, local);
+	} else if (base == local && sel_pre_sched >= 1 && sel_pre_sched <= 3 &&
+		   sel_post_sched == 0) {
+		/*
+		 * IRET is misdesigned and will squash selectors 1, 2, or 3
+		 * to zero.  Don't fail the test just because this happened.
+		 */
+		printf("[OK]\tGS/BASE changed from 0x%hx/0x%lx to 0x%hx/0x%lx because IRET is defective\n",
+		       sel_pre_sched, local, sel_post_sched, base);
 	} else {
 		nerrs++;
 		printf("[FAIL]\tGS/BASE changed from 0x%hx/0x%lx to 0x%hx/0x%lx\n",
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] selftests/x86: Add missing .note.GNU-stack sections
  2020-11-02 19:51 [PATCH 0/2] selftests/x86: Minor fixes Andy Lutomirski
  2020-11-02 19:51 ` [PATCH 1/2] selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests Andy Lutomirski
@ 2020-11-02 19:51 ` Andy Lutomirski
  2020-11-24 13:02   ` [tip: x86/misc] " tip-bot2 for Andy Lutomirski
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Lutomirski @ 2020-11-02 19:51 UTC (permalink / raw)
  To: x86; +Cc: LKML, Andy Lutomirski

Several of the x86 selftests end up with executable stacks because
the asm was missing the annotation that says that they are modern
and don't need executable stacks.  Add the annotations.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 tools/testing/selftests/x86/raw_syscall_helper_32.S | 2 ++
 tools/testing/selftests/x86/thunks.S                | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/tools/testing/selftests/x86/raw_syscall_helper_32.S b/tools/testing/selftests/x86/raw_syscall_helper_32.S
index 94410fa2b5ed..a10d36afdca0 100644
--- a/tools/testing/selftests/x86/raw_syscall_helper_32.S
+++ b/tools/testing/selftests/x86/raw_syscall_helper_32.S
@@ -45,3 +45,5 @@ int80_and_ret:
 
 	.type int80_and_ret, @function
 	.size int80_and_ret, .-int80_and_ret
+
+.section .note.GNU-stack,"",%progbits
diff --git a/tools/testing/selftests/x86/thunks.S b/tools/testing/selftests/x86/thunks.S
index 1bb5d62c16a4..a2d47d8344d4 100644
--- a/tools/testing/selftests/x86/thunks.S
+++ b/tools/testing/selftests/x86/thunks.S
@@ -57,3 +57,5 @@ call32_from_64:
 	ret
 
 .size call32_from_64, .-call32_from_64
+
+.section .note.GNU-stack,"",%progbits
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip: x86/misc] selftests/x86: Add missing .note.GNU-stack sections
  2020-11-02 19:51 ` [PATCH 2/2] selftests/x86: Add missing .note.GNU-stack sections Andy Lutomirski
@ 2020-11-24 13:02   ` tip-bot2 for Andy Lutomirski
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Andy Lutomirski @ 2020-11-24 13:02 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Andy Lutomirski, Borislav Petkov, x86, linux-kernel

The following commit has been merged into the x86/misc branch of tip:

Commit-ID:     aeaaf005da1de075929e56562dced4a58238efc4
Gitweb:        https://git.kernel.org/tip/aeaaf005da1de075929e56562dced4a58238efc4
Author:        Andy Lutomirski <luto@kernel.org>
AuthorDate:    Mon, 02 Nov 2020 11:51:11 -08:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Tue, 24 Nov 2020 13:55:39 +01:00

selftests/x86: Add missing .note.GNU-stack sections

Several of the x86 selftests end up with executable stacks because
the asm was missing the annotation that says that they are modern
and don't need executable stacks.  Add the annotations.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/6f043c03e9e0e4557e1e975a63b07a4d18965a68.1604346596.git.luto@kernel.org
---
 tools/testing/selftests/x86/raw_syscall_helper_32.S | 2 ++
 tools/testing/selftests/x86/thunks.S                | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/tools/testing/selftests/x86/raw_syscall_helper_32.S b/tools/testing/selftests/x86/raw_syscall_helper_32.S
index 94410fa..a10d36a 100644
--- a/tools/testing/selftests/x86/raw_syscall_helper_32.S
+++ b/tools/testing/selftests/x86/raw_syscall_helper_32.S
@@ -45,3 +45,5 @@ int80_and_ret:
 
 	.type int80_and_ret, @function
 	.size int80_and_ret, .-int80_and_ret
+
+.section .note.GNU-stack,"",%progbits
diff --git a/tools/testing/selftests/x86/thunks.S b/tools/testing/selftests/x86/thunks.S
index 1bb5d62..a2d47d8 100644
--- a/tools/testing/selftests/x86/thunks.S
+++ b/tools/testing/selftests/x86/thunks.S
@@ -57,3 +57,5 @@ call32_from_64:
 	ret
 
 .size call32_from_64, .-call32_from_64
+
+.section .note.GNU-stack,"",%progbits

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip: x86/misc] selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests
  2020-11-02 19:51 ` [PATCH 1/2] selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests Andy Lutomirski
@ 2020-11-24 13:02   ` tip-bot2 for Andy Lutomirski
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Andy Lutomirski @ 2020-11-24 13:02 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Andy Lutomirski, Borislav Petkov, x86, linux-kernel

The following commit has been merged into the x86/misc branch of tip:

Commit-ID:     716572b0003ef67a4889bd7d85baf5099c5a0248
Gitweb:        https://git.kernel.org/tip/716572b0003ef67a4889bd7d85baf5099c5a0248
Author:        Andy Lutomirski <luto@kernel.org>
AuthorDate:    Mon, 02 Nov 2020 11:51:10 -08:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Tue, 24 Nov 2020 13:46:16 +01:00

selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests

Setting GS to 1, 2, or 3 causes a nonsensical part of the IRET microcode
to change GS back to zero on a return from kernel mode to user mode. The
result is that these tests fail randomly depending on when interrupts
happen. Detect when this happens and let the test pass.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/7567fd44a1d60a9424f25b19a998f12149993b0d.1604346596.git.luto@kernel.org
---
 tools/testing/selftests/x86/fsgsbase.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c
index 7161cfc..8c780cc 100644
--- a/tools/testing/selftests/x86/fsgsbase.c
+++ b/tools/testing/selftests/x86/fsgsbase.c
@@ -392,8 +392,8 @@ static void set_gs_and_switch_to(unsigned long local,
 		local = read_base(GS);
 
 		/*
-		 * Signal delivery seems to mess up weird selectors.  Put it
-		 * back.
+		 * Signal delivery is quite likely to change a selector
+		 * of 1, 2, or 3 back to 0 due to IRET being defective.
 		 */
 		asm volatile ("mov %0, %%gs" : : "rm" (force_sel));
 	} else {
@@ -411,6 +411,14 @@ static void set_gs_and_switch_to(unsigned long local,
 	if (base == local && sel_pre_sched == sel_post_sched) {
 		printf("[OK]\tGS/BASE remained 0x%hx/0x%lx\n",
 		       sel_pre_sched, local);
+	} else if (base == local && sel_pre_sched >= 1 && sel_pre_sched <= 3 &&
+		   sel_post_sched == 0) {
+		/*
+		 * IRET is misdesigned and will squash selectors 1, 2, or 3
+		 * to zero.  Don't fail the test just because this happened.
+		 */
+		printf("[OK]\tGS/BASE changed from 0x%hx/0x%lx to 0x%hx/0x%lx because IRET is defective\n",
+		       sel_pre_sched, local, sel_post_sched, base);
 	} else {
 		nerrs++;
 		printf("[FAIL]\tGS/BASE changed from 0x%hx/0x%lx to 0x%hx/0x%lx\n",

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-24 13:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-02 19:51 [PATCH 0/2] selftests/x86: Minor fixes Andy Lutomirski
2020-11-02 19:51 ` [PATCH 1/2] selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests Andy Lutomirski
2020-11-24 13:02   ` [tip: x86/misc] " tip-bot2 for Andy Lutomirski
2020-11-02 19:51 ` [PATCH 2/2] selftests/x86: Add missing .note.GNU-stack sections Andy Lutomirski
2020-11-24 13:02   ` [tip: x86/misc] " tip-bot2 for Andy Lutomirski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.