Skip to contentSkip to conversation

selftests/x86: fixes for !CONFIG_IA32_EMULATION and vsyscall=none

PATCH In review Dominik Brodowski 4 participants 24 messages Feb 11, 2018 – Feb 15, 2018

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

cover selftests/x86: fixes for !CONFIG_IA32_EMULATION and vsyscall=none

On systems with CONFIG_IA32_EMULATION disabled and vsyscall disabled, a couple of selftests fail spectacularly.

Also throw in a fix for the Makefile, which still wants to build the moved 5lvl test.

Dominik Brodowski (5):
selftests/x86: 5lvl test has been moved
selftests/x86: fix vDSO selftest segfault for vsyscall=none selftests/x86: do not rely on int $0x80 in test_mremap_vdso.c selftests/x86: do not rely on int $0x80 in single_step_syscall.c selftests/x86: disable tests requiring 32bit support on pure 64bit
systems

 tools/testing/selftests/x86/Makefile              | 24 +++++++----
 tools/testing/selftests/x86/single_step_syscall.c |  5 ++-
 tools/testing/selftests/x86/test_mremap_vdso.c    |  4 ++
 tools/testing/selftests/x86/test_vdso.c           | 50 +++++++++++++++++++----
 4 files changed, 67 insertions(+), 16 deletions(-)
Signature · 6 lines
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH 1/5 selftests/x86: 5lvl test has been moved

Fixes 235266b8e11c "selftests/vm: move 128TB mmap boundary test to generic directory"
Signed-off-by Dominik Brodowski <linux at dominikbrodowski.net>
---
 tools/testing/selftests/x86/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/x86/Makefile +1 -1
index 10ca46df1449..ce2615a2d105 100644
@@ -11,7 +11,7 @@ TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_sysc
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
 			test_FCMOV test_FCOMI test_FISTTP \
 			vdso_restorer
-TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip 5lvl
+TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
Signature · 6 lines
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

[tip:x86/urgent] selftests/x86: Fix build bug caused by the 5lvl test which has been moved to the VM directory

selftests/x86: Fix build bug caused by the 5lvl test which has been moved to the VM directory
Commit-ID:  92d22ce1a5f079a2c62d51d4084ece5926dd8ff2
Gitweb:     https://git.kernel.org/tip/92d22ce1a5f079a2c62d51d4084ece5926dd8ff2
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Sun, 11 Feb 2018 12:10:09 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 11 Feb 2018 12:24:47 +0100

selftests/x86: Fix build bug caused by the 5lvl test which has been moved to the VM directory

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 235266b8e11c "selftests/vm: move 128TB mmap boundary test to generic directory"
---
 tools/testing/selftests/x86/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/x86/Makefile +1 -1
index 10ca46d..ce2615a 100644
@@ -11,7 +11,7 @@ TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_sysc
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
 			test_FCMOV test_FCOMI test_FISTTP \
 			vdso_restorer
-TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip 5lvl
+TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
#3 lore raw

[tip:x86/pti] selftests/x86: Fix build bug caused by the 5lvl test which has been moved to the VM directory

In reply to Dominik Brodowski
selftests/x86: Fix build bug caused by the 5lvl test which has been moved to the VM directory
Commit-ID:  7f95122067ab26fb8344b2a9de64ffbd0fea0010
Gitweb:     https://git.kernel.org/tip/7f95122067ab26fb8344b2a9de64ffbd0fea0010
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Sun, 11 Feb 2018 12:10:09 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 13 Feb 2018 09:05:32 +0100

selftests/x86: Fix build bug caused by the 5lvl test which has been moved to the VM directory

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 235266b8e11c "selftests/vm: move 128TB mmap boundary test to generic directory"
---
 tools/testing/selftests/x86/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/x86/Makefile +1 -1
index 5d4f10a..91fbfa8 100644
@@ -11,7 +11,7 @@ TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_sysc
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
 			test_FCMOV test_FCOMI test_FISTTP \
 			vdso_restorer
-TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip 5lvl
+TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
#4 lore raw

PATCH 2/5 selftests/x86: fix vDSO selftest segfault for vsyscall=none

In reply to Dominik Brodowski

The vDSO selftest tries to execute a vsyscall unconditionally, even if it is not present on the test system (e.g. if booted with vsyscall=none or with CONFIG_LEGACY_VSYSCALL_NONE=y set. Fix this by copying (and tweaking) the vsyscall check from test_vsyscall.c

CC Andrew Lutomirski <luto at kernel.org>
Signed-off-by Dominik Brodowski <linux at dominikbrodowski.net>
---
 tools/testing/selftests/x86/test_vdso.c | 50 ++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 7 deletions(-)
tools/testing/selftests/x86/test_vdso.c +43 -7
index 29973cde06d3..558c8207e7b9 100644
@@ -28,18 +28,52 @@
 
 int nerrs = 0;
 
+typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
+
+getcpu_t vgetcpu;
+getcpu_t vdso_getcpu;
+
+static void *vsyscall_getcpu(void)
+{
 #ifdef __x86_64__
-# define VSYS(x) (x)
+	FILE *maps;
+	char line[128];
+	bool found = false;
+
+	maps = fopen("/proc/self/maps", "r");
+	if (!maps) /* might still be present, but ignore it here, as we test vDSO not vsyscall */
+		return NULL;
+
+	while (fgets(line, sizeof(line), maps)) {
+		char r, x;
+		void *start, *end;
+		char name[128];
+		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
+			   &start, &end, &r, &x, name) != 5)
+			continue;
+
+		if (strcmp(name, "[vsyscall]"))
+			continue;
+
+		/* assume entries are OK, as we test vDSO here not vsyscall */
+		found = true;
+		break;
+	}
+
+	fclose(maps);
+
+	if (!found) {
+		printf("Warning: failed to find vsyscall getcpu\n");
+		return NULL;
+	}
+	return (void *) (0xffffffffff600800);
 #else
-# define VSYS(x) 0
+	return NULL;
 #endif
+}
 
-typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
-
-const getcpu_t vgetcpu = (getcpu_t)VSYS(0xffffffffff600800);
-getcpu_t vdso_getcpu;
 
-void fill_function_pointers()
+static void fill_function_pointers()
 {
 	void *vdso = dlopen("linux-vdso.so.1",
 			    RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
@@ -54,6 +88,8 @@ void fill_function_pointers()
 	vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu");
 	if (!vdso_getcpu)
 		printf("Warning: failed to find getcpu in vDSO\n");
+
+	vgetcpu = (getcpu_t) vsyscall_getcpu();
 }
 
 static long sys_getcpu(unsigned * cpu, unsigned * node,
Signature · 6 lines
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

Re: [PATCH 2/5] selftests/x86: fix vDSO selftest segfault for vsyscall=none

tools/testing/selftests/x86/test_vdso.c line 52

Quoted 3 lines · Dominik Brodowski
tools/testing/selftests/x86/test_vdso.c +3 -0
+		char name[128];
+		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
+			   &start, &end, &r, &x, name) != 5)

So that's a buffer overflow waiting to happen, if a line in 'maps' gets too large, right?

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [PATCH 2/5] selftests/x86: fix vDSO selftest segfault for vsyscall=none

Quoted 9 lines · Ingo Molnar

tools/testing/selftests/x86/test_vdso.c line 52

Quoted 3 lines · Dominik Brodowski
tools/testing/selftests/x86/test_vdso.c +3 -0
+		char name[128];
+		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
+			   &start, &end, &r, &x, name) != 5)

So that's a buffer overflow waiting to happen, if a line in 'maps' gets too large, right?

... as does tools/testing/selftests/x86/test_vsyscall.c already now, right? Will fix both up with an additional patch.

But a more generic question: Is there a quick, easy but reliable test available in userspace to determine whether

	int $0x80
	vsyscall

is available on a given system, or will cause a segfault?

Thanks,
Dominik
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

Re: [PATCH 2/5] selftests/x86: fix vDSO selftest segfault for vsyscall=none

Quoted 11 lines · Dominik Brodowski
Quoted 9 lines · Ingo Molnar

tools/testing/selftests/x86/test_vdso.c line 52

Quoted 3 lines · Dominik Brodowski
tools/testing/selftests/x86/test_vdso.c +3 -0
+		char name[128];
+		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
+			   &start, &end, &r, &x, name) != 5)

So that's a buffer overflow waiting to happen, if a line in 'maps' gets too large, right?

Quoted 2 lines

... as does tools/testing/selftests/x86/test_vsyscall.c already now, right? Will fix both up with an additional patch.

Maybe no fix is needed after all: The fgets() call a few lines above limits "line" to 127 chars max. So "name" can't even get close to 128 chars, right?

	char line[128];
...
	while (fgets(line, sizeof(line), maps)) {

Thanks,
Dominik
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

Re: [PATCH 2/5] selftests/x86: fix vDSO selftest segfault for vsyscall=none

Quoted 15 lines · Dominik Brodowski
Quoted 11 lines · Dominik Brodowski
Quoted 9 lines · Ingo Molnar

tools/testing/selftests/x86/test_vdso.c line 52

Quoted 3 lines · Dominik Brodowski
tools/testing/selftests/x86/test_vdso.c +3 -0
+		char name[128];
+		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
+			   &start, &end, &r, &x, name) != 5)

So that's a buffer overflow waiting to happen, if a line in 'maps' gets too large, right?

Quoted 2 lines

... as does tools/testing/selftests/x86/test_vsyscall.c already now, right? Will fix both up with an additional patch.

Quoted 7 lines

Maybe no fix is needed after all: The fgets() call a few lines above limits "line" to 127 chars max. So "name" can't even get close to 128 chars, right?

	char line[128];
...
	while (fgets(line, sizeof(line), maps)) {

Yeah, probably - but still, this connection and the sscanf() guarantee is not obvious at first sight, so please improve this to derive from the same value (define a LINE_MAX size or such), plus maybe add a comment to the sscanf() line that this is safe because strlen(name) >= strlen(line).

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

PATCH 1/1 selftests/x86: clarify that there is no buffer overflow on sscanf usage

Suggested-by Ingo Molnar <mingo at kernel.org>
CC Andy Lutomirski <luto at kernel.org>
Signed-off-by Dominik Brodowski <linux at dominikbrodowski.net>

---

Quoted 4 lines

Yeah, probably - but still, this connection and the sscanf() guarantee is not obvious at first sight, so please improve this to derive from the same value (define a LINE_MAX size or such), plus maybe add a comment to the sscanf() line that this is safe because strlen(name) >= strlen(line).

Sounds reasonable. Patch (which applies on top of the five patches for selftests/x86 I sent out earlier today) is attached.

Thanks,
Dominik

tools/testing/selftests/x86/test_vdso.c +8 -3
index 558c8207e7b9..7ade625f10ed 100644
@@ -26,6 +26,9 @@
 # endif
 #endif
 
+/* max length of lines in /proc/self/maps - anything longer is skipped here */
+#define MAPS_LINE_LEN 128
+
 int nerrs = 0;
 
 typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
@@ -37,17 +40,19 @@ static void *vsyscall_getcpu(void)
 {
 #ifdef __x86_64__
 	FILE *maps;
-	char line[128];
+	char line[MAPS_LINE_LEN];
 	bool found = false;
 
 	maps = fopen("/proc/self/maps", "r");
 	if (!maps) /* might still be present, but ignore it here, as we test vDSO not vsyscall */
 		return NULL;
 
-	while (fgets(line, sizeof(line), maps)) {
+	while (fgets(line, MAPS_LINE_LEN, maps)) {
 		char r, x;
 		void *start, *end;
-		char name[128];
+		char name[MAPS_LINE_LEN];
+
+		/* sscanf is safe here as strlen(name) >= strlen(line) */
 		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
 			   &start, &end, &r, &x, name) != 5)
 			continue;
tools/testing/selftests/x86/test_vsyscall.c +8 -3
index 7a744fa7b786..ee92e4727f18 100644
@@ -33,6 +33,9 @@
 # endif
 #endif
 
+/* max length of lines in /proc/self/maps - anything longer is skipped here */
+#define MAPS_LINE_LEN 128
+
 static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
 		       int flags)
 {
@@ -98,7 +101,7 @@ static int init_vsys(void)
 #ifdef __x86_64__
 	int nerrs = 0;
 	FILE *maps;
-	char line[128];
+	char line[MAPS_LINE_LEN];
 	bool found = false;
 
 	maps = fopen("/proc/self/maps", "r");
@@ -108,10 +111,12 @@ static int init_vsys(void)
 		return 0;
 	}
 
-	while (fgets(line, sizeof(line), maps)) {
+	while (fgets(line, MAPS_LINE_LEN, maps)) {
 		char r, x;
 		void *start, *end;
-		char name[128];
+		char name[MAPS_LINE_LEN];
+
+		/* sscanf is safe here as strlen(name) >= strlen(line) */
 		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
 			   &start, &end, &r, &x, name) != 5)
 			continue;

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#10 lore raw

Re: [PATCH] selftests/x86: clarify that there is no buffer overflow on sscanf usage

Quoted 5 lines · Dominik Brodowski
Suggested-by Ingo Molnar <mingo at kernel.org>
CC Andy Lutomirski <luto at kernel.org>
Signed-off-by Dominik Brodowski <linux at dominikbrodowski.net>

Missing commit log. Please add one.

thanks,
-- Shuah

Quoted 80 lines

---

Quoted 4 lines

Yeah, probably - but still, this connection and the sscanf() guarantee is not obvious at first sight, so please improve this to derive from the same value (define a LINE_MAX size or such), plus maybe add a comment to the sscanf() line that this is safe because strlen(name) >= strlen(line).

Sounds reasonable. Patch (which applies on top of the five patches for selftests/x86 I sent out earlier today) is attached.

Thanks,
Dominik

tools/testing/selftests/x86/test_vdso.c +8 -3
index 558c8207e7b9..7ade625f10ed 100644
@@ -26,6 +26,9 @@
 # endif
 #endif
 
+/* max length of lines in /proc/self/maps - anything longer is skipped here */
+#define MAPS_LINE_LEN 128
+
 int nerrs = 0;
 
 typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
@@ -37,17 +40,19 @@ static void *vsyscall_getcpu(void)
 {
 #ifdef __x86_64__
 	FILE *maps;
-	char line[128];
+	char line[MAPS_LINE_LEN];
 	bool found = false;
 
 	maps = fopen("/proc/self/maps", "r");
 	if (!maps) /* might still be present, but ignore it here, as we test vDSO not vsyscall */
 		return NULL;
 
-	while (fgets(line, sizeof(line), maps)) {
+	while (fgets(line, MAPS_LINE_LEN, maps)) {
 		char r, x;
 		void *start, *end;
-		char name[128];
+		char name[MAPS_LINE_LEN];
+
+		/* sscanf is safe here as strlen(name) >= strlen(line) */
 		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
 			   &start, &end, &r, &x, name) != 5)
 			continue;
tools/testing/selftests/x86/test_vsyscall.c +4 -2
index 7a744fa7b786..ee92e4727f18 100644
@@ -33,6 +33,9 @@
 # endif
 #endif
 
+/* max length of lines in /proc/self/maps - anything longer is skipped here */
+#define MAPS_LINE_LEN 128
+
 static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
 		       int flags)
 {
@@ -98,7 +101,7 @@ static int init_vsys(void)
 #ifdef __x86_64__
 	int nerrs = 0;
 	FILE *maps;
-	char line[128];
+	char line[MAPS_LINE_LEN];
 	bool found = false;
 
 	maps = fopen("/proc/self/maps", "r");
@@ -108,10 +111,12 @@ static int init_vsys(void)
 		return 0;
 	}
 
-	while (fgets(line, sizeof(line), maps)) {

tools/testing/selftests/x86/test_vsyscall.c static int init_vsys(void) · line 122

Quoted 10 lines
tools/testing/selftests/x86/test_vsyscall.c +4 -1
+	while (fgets(line, MAPS_LINE_LEN, maps)) {
 		char r, x;
 		void *start, *end;
-		char name[128];
+		char name[MAPS_LINE_LEN];
+
+		/* sscanf is safe here as strlen(name) >= strlen(line) */
 		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
 			   &start, &end, &r, &x, name) != 5)
 			continue;

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

[tip:x86/pti] selftests/x86: Clean up and document sscanf() usage

In reply to Dominik Brodowski
selftests/x86: Clean up and document sscanf() usage
Commit-ID:  d8e92de8ef952bed88c56c7a44c02d8dcae0984e
Gitweb:     https://git.kernel.org/tip/d8e92de8ef952bed88c56c7a44c02d8dcae0984e
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Sun, 11 Feb 2018 21:59:24 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 13 Feb 2018 09:04:56 +0100

selftests/x86: Clean up and document sscanf() usage

Replace a couple of magically connected buffer length literal constants with a common definition that makes their relationship obvious. Also document why our sscanf() usage is safe.

No intended functional changes.

---
 tools/testing/selftests/x86/test_vdso.c     | 11 ++++++++---
 tools/testing/selftests/x86/test_vsyscall.c | 11 ++++++++---
 2 files changed, 16 insertions(+), 6 deletions(-)
tools/testing/selftests/x86/test_vdso.c +8 -3
index 558c820..2352590 100644
@@ -26,6 +26,9 @@
 # endif
 #endif
 
+/* max length of lines in /proc/self/maps - anything longer is skipped here */
+#define MAPS_LINE_LEN 128
+
 int nerrs = 0;
 
 typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
@@ -37,17 +40,19 @@ static void *vsyscall_getcpu(void)
 {
 #ifdef __x86_64__
 	FILE *maps;
-	char line[128];
+	char line[MAPS_LINE_LEN];
 	bool found = false;
 
 	maps = fopen("/proc/self/maps", "r");
 	if (!maps) /* might still be present, but ignore it here, as we test vDSO not vsyscall */
 		return NULL;
 
-	while (fgets(line, sizeof(line), maps)) {
+	while (fgets(line, MAPS_LINE_LEN, maps)) {
 		char r, x;
 		void *start, *end;
-		char name[128];
+		char name[MAPS_LINE_LEN];
+
+		/* sscanf() is safe here as strlen(name) >= strlen(line) */
 		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
 			   &start, &end, &r, &x, name) != 5)
 			continue;
tools/testing/selftests/x86/test_vsyscall.c +8 -3
index 7a744fa..be81621 100644
@@ -33,6 +33,9 @@
 # endif
 #endif
 
+/* max length of lines in /proc/self/maps - anything longer is skipped here */
+#define MAPS_LINE_LEN 128
+
 static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
 		       int flags)
 {
@@ -98,7 +101,7 @@ static int init_vsys(void)
 #ifdef __x86_64__
 	int nerrs = 0;
 	FILE *maps;
-	char line[128];
+	char line[MAPS_LINE_LEN];
 	bool found = false;
 
 	maps = fopen("/proc/self/maps", "r");
@@ -108,10 +111,12 @@ static int init_vsys(void)
 		return 0;
 	}
 
-	while (fgets(line, sizeof(line), maps)) {
+	while (fgets(line, MAPS_LINE_LEN, maps)) {
 		char r, x;
 		void *start, *end;
-		char name[128];
+		char name[MAPS_LINE_LEN];
+
+		/* sscanf() is safe here as strlen(name) >= strlen(line) */
 		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
 			   &start, &end, &r, &x, name) != 5)
 			continue;
#12 lore raw

[tip:x86/pti] selftests/x86: Fix vDSO selftest segfault for vsyscall=none

In reply to Dominik Brodowski
selftests/x86: Fix vDSO selftest segfault for vsyscall=none
Commit-ID:  198ee8e17502da2634f7366395db1d77630e0219
Gitweb:     https://git.kernel.org/tip/198ee8e17502da2634f7366395db1d77630e0219
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Sun, 11 Feb 2018 12:10:10 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 13 Feb 2018 09:04:55 +0100

selftests/x86: Fix vDSO selftest segfault for vsyscall=none

The vDSO selftest tries to execute a vsyscall unconditionally, even if it is not present on the test system (e.g. if booted with vsyscall=none or with CONFIG_LEGACY_VSYSCALL_NONE=y set. Fix this by copying (and tweaking) the vsyscall check from test_vsyscall.c

---
 tools/testing/selftests/x86/test_vdso.c | 50 ++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 7 deletions(-)
tools/testing/selftests/x86/test_vdso.c +43 -7
index 29973cd..558c820 100644
@@ -28,18 +28,52 @@
 
 int nerrs = 0;
 
+typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
+
+getcpu_t vgetcpu;
+getcpu_t vdso_getcpu;
+
+static void *vsyscall_getcpu(void)
+{
 #ifdef __x86_64__
-# define VSYS(x) (x)
+	FILE *maps;
+	char line[128];
+	bool found = false;
+
+	maps = fopen("/proc/self/maps", "r");
+	if (!maps) /* might still be present, but ignore it here, as we test vDSO not vsyscall */
+		return NULL;
+
+	while (fgets(line, sizeof(line), maps)) {
+		char r, x;
+		void *start, *end;
+		char name[128];
+		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",
+			   &start, &end, &r, &x, name) != 5)
+			continue;
+
+		if (strcmp(name, "[vsyscall]"))
+			continue;
+
+		/* assume entries are OK, as we test vDSO here not vsyscall */
+		found = true;
+		break;
+	}
+
+	fclose(maps);
+
+	if (!found) {
+		printf("Warning: failed to find vsyscall getcpu\n");
+		return NULL;
+	}
+	return (void *) (0xffffffffff600800);
 #else
-# define VSYS(x) 0
+	return NULL;
 #endif
+}
 
-typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
-
-const getcpu_t vgetcpu = (getcpu_t)VSYS(0xffffffffff600800);
-getcpu_t vdso_getcpu;
 
-void fill_function_pointers()
+static void fill_function_pointers()
 {
 	void *vdso = dlopen("linux-vdso.so.1",
 			    RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
@@ -54,6 +88,8 @@ void fill_function_pointers()
 	vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu");
 	if (!vdso_getcpu)
 		printf("Warning: failed to find getcpu in vDSO\n");
+
+	vgetcpu = (getcpu_t) vsyscall_getcpu();
 }
 
 static long sys_getcpu(unsigned * cpu, unsigned * node,
#13 lore raw

PATCH 3/5 selftests/x86: do not rely on int $0x80 in test_mremap_vdso.c

In reply to Dominik Brodowski

On 64bit builds, we should not rely on int $0x80 working (it only does if CONFIG_IA32_EMULATION is enabled). Without this patch, the move test may succeed, but the int $0x80 cause a segfault, resulting in a false negative output of this selftest.

CC Dmitry Safonov <dsafonov at virtuozzo.com>
CC Andy Lutomirski <luto at kernel.org>
Signed-off-by Dominik Brodowski <linux at dominikbrodowski.net>
---
 tools/testing/selftests/x86/test_mremap_vdso.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/x86/test_mremap_vdso.c +4 -0
index bf0d687c7db7..64f11c8d9b76 100644
@@ -90,8 +90,12 @@ int main(int argc, char **argv, char **envp)
 			vdso_size += PAGE_SIZE;
 		}
 
+#ifdef __i386__
 		/* Glibc is likely to explode now - exit with raw syscall */
 		asm volatile ("int $0x80" : : "a" (__NR_exit), "b" (!!ret));
+#else /* __x86_64__ */
+		syscall(SYS_exit, ret);
+#endif
 	} else {
 		int status;
 
Signature · 6 lines
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#14 lore raw

[tip:x86/urgent] selftests/x86: Do not rely on "int $0x80" in test_mremap_vdso.c

selftests/x86: Do not rely on "int $0x80" in test_mremap_vdso.c
Commit-ID:  484790d9ab02704c569d8c7205c630c08eee7822
Gitweb:     https://git.kernel.org/tip/484790d9ab02704c569d8c7205c630c08eee7822
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Sun, 11 Feb 2018 12:10:11 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 11 Feb 2018 12:24:47 +0100

selftests/x86: Do not rely on "int $0x80" in test_mremap_vdso.c

On 64-bit builds, we should not rely on "int $0x80" working (it only does if CONFIG_IA32_EMULATION=y is enabled).

Without this patch, the move test may succeed, but the "int $0x80" causes a segfault, resulting in a false negative output of this self-test.

---
 tools/testing/selftests/x86/test_mremap_vdso.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/x86/test_mremap_vdso.c +4 -0
index bf0d687..64f11c8 100644
@@ -90,8 +90,12 @@ int main(int argc, char **argv, char **envp)
 			vdso_size += PAGE_SIZE;
 		}
 
+#ifdef __i386__
 		/* Glibc is likely to explode now - exit with raw syscall */
 		asm volatile ("int $0x80" : : "a" (__NR_exit), "b" (!!ret));
+#else /* __x86_64__ */
+		syscall(SYS_exit, ret);
+#endif
 	} else {
 		int status;
 
#15 lore raw

[tip:x86/pti] selftests/x86: Do not rely on "int $0x80" in test_mremap_vdso.c

In reply to Dominik Brodowski
selftests/x86: Do not rely on "int $0x80" in test_mremap_vdso.c
Commit-ID:  2cbc0d66de0480449c75636f55697c7ff3af61fc
Gitweb:     https://git.kernel.org/tip/2cbc0d66de0480449c75636f55697c7ff3af61fc
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Sun, 11 Feb 2018 12:10:11 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 13 Feb 2018 09:05:37 +0100

selftests/x86: Do not rely on "int $0x80" in test_mremap_vdso.c

On 64-bit builds, we should not rely on "int $0x80" working (it only does if CONFIG_IA32_EMULATION=y is enabled).

Without this patch, the move test may succeed, but the "int $0x80" causes a segfault, resulting in a false negative output of this self-test.

---
 tools/testing/selftests/x86/test_mremap_vdso.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/x86/test_mremap_vdso.c +4 -0
index bf0d687..64f11c8 100644
@@ -90,8 +90,12 @@ int main(int argc, char **argv, char **envp)
 			vdso_size += PAGE_SIZE;
 		}
 
+#ifdef __i386__
 		/* Glibc is likely to explode now - exit with raw syscall */
 		asm volatile ("int $0x80" : : "a" (__NR_exit), "b" (!!ret));
+#else /* __x86_64__ */
+		syscall(SYS_exit, ret);
+#endif
 	} else {
 		int status;
 
#16 lore raw

PATCH 4/5 selftests/x86: do not rely on int $0x80 in single_step_syscall.c

In reply to Dominik Brodowski

On 64bit builds, we should not rely on int $0x80 working (it only does if CONFIG_IA32_EMULATION is enabled). To keep the "Set TF and check int80" test running on 64bit installs with CONFIG_IA32_EMULATION enabled, build this test only if we can also build 32bit binaries (which should be a good approximation for that).

CC Dmitry Safonov <dsafonov at virtuozzo.com>
CC Andy Lutomirski <luto at kernel.org>
Signed-off-by Dominik Brodowski <linux at dominikbrodowski.net>
---
 tools/testing/selftests/x86/Makefile              | 2 ++
 tools/testing/selftests/x86/single_step_syscall.c | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/Makefile +2 -0
index ce2615a2d105..371ae715c506 100644
@@ -40,12 +40,14 @@ endef
 ifeq ($(CAN_BUILD_I386),1)
 all: all_32
 TEST_PROGS += $(BINARIES_32)
+EXTRA_CFLAGS += -DCAN_BUILD_32
 $(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t))))
 endif
 
 ifeq ($(CAN_BUILD_X86_64),1)
 all: all_64
 TEST_PROGS += $(BINARIES_64)
+EXTRA_CFLAGS += -DCAN_BUILD_64
 $(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t))))
 endif
 
tools/testing/selftests/x86/single_step_syscall.c +4 -1
index a48da95c18fd..ddfdd635de16 100644
@@ -119,7 +119,9 @@ static void check_result(void)
 
 int main()
 {
+#ifdef CAN_BUILD_32
 	int tmp;
+#endif
 
 	sethandler(SIGTRAP, sigtrap, 0);
 
@@ -139,12 +141,13 @@ int main()
 		      : : "c" (post_nop) : "r11");
 	check_result();
 #endif
-
+#ifdef CAN_BUILD_32
 	printf("[RUN]\tSet TF and check int80\n");
 	set_eflags(get_eflags() | X86_EFLAGS_TF);
 	asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid)
 			: INT80_CLOBBERS);
 	check_result();
+#endif
 
 	/*
 	 * This test is particularly interesting if fast syscalls use
Signature · 6 lines
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

[tip:x86/urgent] selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c

selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c
Commit-ID:  16db357ce126ea41ba7089a569fe5ed934b2e974
Gitweb:     https://git.kernel.org/tip/16db357ce126ea41ba7089a569fe5ed934b2e974
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Sun, 11 Feb 2018 12:10:12 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 11 Feb 2018 12:24:47 +0100

selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c

On 64-bit builds, we should not rely on "int $0x80" working (it only does if CONFIG_IA32_EMULATION=y is enabled). To keep the "Set TF and check int80" test running on 64-bit installs with CONFIG_IA32_EMULATION=y enabled, build this test only if we can also build 32-bit binaries (which should be a good approximation for that).

---
 tools/testing/selftests/x86/Makefile              | 2 ++
 tools/testing/selftests/x86/single_step_syscall.c | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/Makefile +2 -0
index ce2615a..371ae71 100644
@@ -40,12 +40,14 @@ endef
 ifeq ($(CAN_BUILD_I386),1)
 all: all_32
 TEST_PROGS += $(BINARIES_32)
+EXTRA_CFLAGS += -DCAN_BUILD_32
 $(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t))))
 endif
 
 ifeq ($(CAN_BUILD_X86_64),1)
 all: all_64
 TEST_PROGS += $(BINARIES_64)
+EXTRA_CFLAGS += -DCAN_BUILD_64
 $(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t))))
 endif
 
tools/testing/selftests/x86/single_step_syscall.c +4 -1
index a48da95..ddfdd63 100644
@@ -119,7 +119,9 @@ static void check_result(void)
 
 int main()
 {
+#ifdef CAN_BUILD_32
 	int tmp;
+#endif
 
 	sethandler(SIGTRAP, sigtrap, 0);
 
@@ -139,12 +141,13 @@ int main()
 		      : : "c" (post_nop) : "r11");
 	check_result();
 #endif
-
+#ifdef CAN_BUILD_32
 	printf("[RUN]\tSet TF and check int80\n");
 	set_eflags(get_eflags() | X86_EFLAGS_TF);
 	asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid)
 			: INT80_CLOBBERS);
 	check_result();
+#endif
 
 	/*
 	 * This test is particularly interesting if fast syscalls use
#18 lore raw

[tip:x86/pti] selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c

In reply to Dominik Brodowski
selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c
Commit-ID:  9e2b962d35d746bca8b51902807553191ccb06b2
Gitweb:     https://git.kernel.org/tip/9e2b962d35d746bca8b51902807553191ccb06b2
Author:     Ingo Molnar <[email protected]>
AuthorDate: Tue, 13 Feb 2018 09:13:21 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 13 Feb 2018 09:13:21 +0100

selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c

On 64-bit builds, we should not rely on "int $0x80" working (it only does if CONFIG_IA32_EMULATION=y is enabled). To keep the "Set TF and check int80" test running on 64-bit installs with CONFIG_IA32_EMULATION=y enabled, build this test only if we can also build 32-bit binaries (which should be a good approximation for that).

---
 tools/testing/selftests/x86/Makefile              | 2 ++
 tools/testing/selftests/x86/single_step_syscall.c | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/Makefile +2 -0
index 91fbfa8..73b8ef6 100644
@@ -30,11 +30,13 @@ CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
 ifeq ($(CAN_BUILD_I386),1)
 all: all_32
 TEST_PROGS += $(BINARIES_32)
+EXTRA_CFLAGS += -DCAN_BUILD_32
 endif
 
 ifeq ($(CAN_BUILD_X86_64),1)
 all: all_64
 TEST_PROGS += $(BINARIES_64)
+EXTRA_CFLAGS += -DCAN_BUILD_64
 endif
 
 all_32: $(BINARIES_32)
tools/testing/selftests/x86/single_step_syscall.c +4 -1
index a48da95..ddfdd63 100644
@@ -119,7 +119,9 @@ static void check_result(void)
 
 int main()
 {
+#ifdef CAN_BUILD_32
 	int tmp;
+#endif
 
 	sethandler(SIGTRAP, sigtrap, 0);
 
@@ -139,12 +141,13 @@ int main()
 		      : : "c" (post_nop) : "r11");
 	check_result();
 #endif
-
+#ifdef CAN_BUILD_32
 	printf("[RUN]\tSet TF and check int80\n");
 	set_eflags(get_eflags() | X86_EFLAGS_TF);
 	asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid)
 			: INT80_CLOBBERS);
 	check_result();
+#endif
 
 	/*
 	 * This test is particularly interesting if fast syscalls use
#19 lore raw

[tip:x86/pti] selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c

In reply to Dominik Brodowski
selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c
Commit-ID:  4105c69703cdeba76f384b901712c9397b04e9c2
Gitweb:     https://git.kernel.org/tip/4105c69703cdeba76f384b901712c9397b04e9c2
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Tue, 13 Feb 2018 09:13:21 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 15 Feb 2018 01:15:48 +0100

selftests/x86: Do not rely on "int $0x80" in single_step_syscall.c

On 64-bit builds, we should not rely on "int $0x80" working (it only does if CONFIG_IA32_EMULATION=y is enabled). To keep the "Set TF and check int80" test running on 64-bit installs with CONFIG_IA32_EMULATION=y enabled, build this test only if we can also build 32-bit binaries (which should be a good approximation for that).

---
 tools/testing/selftests/x86/Makefile              | 2 ++
 tools/testing/selftests/x86/single_step_syscall.c | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/Makefile +2 -0
index 91fbfa8..73b8ef6 100644
@@ -30,11 +30,13 @@ CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
 ifeq ($(CAN_BUILD_I386),1)
 all: all_32
 TEST_PROGS += $(BINARIES_32)
+EXTRA_CFLAGS += -DCAN_BUILD_32
 endif
 
 ifeq ($(CAN_BUILD_X86_64),1)
 all: all_64
 TEST_PROGS += $(BINARIES_64)
+EXTRA_CFLAGS += -DCAN_BUILD_64
 endif
 
 all_32: $(BINARIES_32)
tools/testing/selftests/x86/single_step_syscall.c +4 -1
index a48da95..ddfdd63 100644
@@ -119,7 +119,9 @@ static void check_result(void)
 
 int main()
 {
+#ifdef CAN_BUILD_32
 	int tmp;
+#endif
 
 	sethandler(SIGTRAP, sigtrap, 0);
 
@@ -139,12 +141,13 @@ int main()
 		      : : "c" (post_nop) : "r11");
 	check_result();
 #endif
-
+#ifdef CAN_BUILD_32
 	printf("[RUN]\tSet TF and check int80\n");
 	set_eflags(get_eflags() | X86_EFLAGS_TF);
 	asm volatile ("int $0x80" : "=a" (tmp) : "a" (SYS_getpid)
 			: INT80_CLOBBERS);
 	check_result();
+#endif
 
 	/*
 	 * This test is particularly interesting if fast syscalls use
#20 lore raw

PATCH 5/5 selftests/x86: disable tests requiring 32bit support on pure 64bit systems

In reply to Dominik Brodowski

The ldt_gdt and ptrace_syscall selftests, even in their 64bit variant, use hard-coded 32bit syscall numbers and call int $0x80. This will fail on 64bit systems with CONFIG_IA32_EMULATION disabled. Therefore, do not build these tests if we cannot build 32bit binaries (which should be a good approximation for CONFIG_IA32_EMULATION being enabled).

CC Dmitry Safonov <dsafonov at virtuozzo.com>
CC Andy Lutomirski <luto at kernel.org>
Signed-off-by Dominik Brodowski <linux at dominikbrodowski.net>
---
 tools/testing/selftests/x86/Makefile | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/testing/selftests/x86/Makefile +13 -7
index 371ae715c506..d744991c0f4f 100644
@@ -5,16 +5,26 @@ include ../lib.mk
 
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
-TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_syscall test_mremap_vdso \
-			check_initial_reg_state sigreturn ldt_gdt iopl mpx-mini-test ioperm \
+UNAME_M := $(shell uname -m)
+CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
+CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
+
+TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
+			check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \
 			protection_keys test_vdso test_vsyscall
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
 			test_FCMOV test_FCOMI test_FISTTP \
 			vdso_restorer
 TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
+# Some selftests require 32bit support enabled also on 64bit systems
+TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
 
-TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
+TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
+ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
+TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
+endif
+
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
 BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
 
@@ -23,10 +33,6 @@ BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
 
 CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
 
-UNAME_M := $(shell uname -m)
-CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
-CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
-
 define gen-target-rule-32
 $(1) $(1)_32: $(OUTPUT)/$(1)_32
 .PHONY: $(1) $(1)_32
Signature · 6 lines
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#21 lore raw

[tip:x86/urgent] selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems

selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems
Commit-ID:  29469471c10759d81b699aa0b9f02d9a71071be5
Gitweb:     https://git.kernel.org/tip/29469471c10759d81b699aa0b9f02d9a71071be5
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Sun, 11 Feb 2018 12:10:13 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 11 Feb 2018 12:24:47 +0100

selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems

The ldt_gdt and ptrace_syscall selftests, even in their 64-bit variant, use hard-coded 32-bit syscall numbers and call "int $0x80".

This will fail on 64-bit systems with CONFIG_IA32_EMULATION=y disabled.

Therefore, do not build these tests if we cannot build 32-bit binaries (which should be a good approximation for CONFIG_IA32_EMULATION=y being enabled).

---
 tools/testing/selftests/x86/Makefile | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/testing/selftests/x86/Makefile +13 -7
index 371ae71..d744991 100644
@@ -5,16 +5,26 @@ include ../lib.mk
 
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
-TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_syscall test_mremap_vdso \
-			check_initial_reg_state sigreturn ldt_gdt iopl mpx-mini-test ioperm \
+UNAME_M := $(shell uname -m)
+CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
+CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
+
+TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
+			check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \
 			protection_keys test_vdso test_vsyscall
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
 			test_FCMOV test_FCOMI test_FISTTP \
 			vdso_restorer
 TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
+# Some selftests require 32bit support enabled also on 64bit systems
+TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
 
-TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
+TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
+ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
+TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
+endif
+
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
 BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
 
@@ -23,10 +33,6 @@ BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
 
 CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
 
-UNAME_M := $(shell uname -m)
-CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
-CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
-
 define gen-target-rule-32
 $(1) $(1)_32: $(OUTPUT)/$(1)_32
 .PHONY: $(1) $(1)_32
#22 lore raw

[tip:x86/pti] selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems

In reply to Dominik Brodowski
selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems
Commit-ID:  d09a04140a61e82e938534b0c3983e8d90d5c54d
Gitweb:     https://git.kernel.org/tip/d09a04140a61e82e938534b0c3983e8d90d5c54d
Author:     Ingo Molnar <[email protected]>
AuthorDate: Tue, 13 Feb 2018 09:15:19 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 13 Feb 2018 09:15:19 +0100

selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems

The ldt_gdt and ptrace_syscall selftests, even in their 64-bit variant, use hard-coded 32-bit syscall numbers and call "int $0x80".

This will fail on 64-bit systems with CONFIG_IA32_EMULATION=y disabled.

Therefore, do not build these tests if we cannot build 32-bit binaries (which should be a good approximation for CONFIG_IA32_EMULATION=y being enabled).

---
 tools/testing/selftests/x86/Makefile | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/testing/selftests/x86/Makefile +13 -7
index 73b8ef6..aa6e2d7 100644
@@ -5,16 +5,26 @@ include ../lib.mk
 
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
-TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_syscall test_mremap_vdso \
-			check_initial_reg_state sigreturn ldt_gdt iopl mpx-mini-test ioperm \
+UNAME_M := $(shell uname -m)
+CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
+CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
+
+TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
+			check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \
 			protection_keys test_vdso test_vsyscall
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
 			test_FCMOV test_FCOMI test_FISTTP \
 			vdso_restorer
 TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
+# Some selftests require 32bit support enabled also on 64bit systems
+TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
 
-TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
+TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
+ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
+TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
+endif
+
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
 BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
 
@@ -23,10 +33,6 @@ BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
 
 CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
 
-UNAME_M := $(shell uname -m)
-CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
-CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
-
 ifeq ($(CAN_BUILD_I386),1)
 all: all_32
 TEST_PROGS += $(BINARIES_32)
#23 lore raw

[tip:x86/pti] selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems

In reply to Dominik Brodowski
selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems
Commit-ID:  9279ddf23ce78ff2676e8e8e19fec0f022c26d04
Gitweb:     https://git.kernel.org/tip/9279ddf23ce78ff2676e8e8e19fec0f022c26d04
Author:     Dominik Brodowski <[email protected]>
AuthorDate: Tue, 13 Feb 2018 09:15:19 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 15 Feb 2018 01:15:48 +0100

selftests/x86: Disable tests requiring 32-bit support on pure 64-bit systems

The ldt_gdt and ptrace_syscall selftests, even in their 64-bit variant, use hard-coded 32-bit syscall numbers and call "int $0x80".

This will fail on 64-bit systems with CONFIG_IA32_EMULATION=y disabled.

Therefore, do not build these tests if we cannot build 32-bit binaries (which should be a good approximation for CONFIG_IA32_EMULATION=y being enabled).

---
 tools/testing/selftests/x86/Makefile | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/testing/selftests/x86/Makefile +13 -7
index 73b8ef6..aa6e2d7 100644
@@ -5,16 +5,26 @@ include ../lib.mk
 
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
-TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_syscall test_mremap_vdso \
-			check_initial_reg_state sigreturn ldt_gdt iopl mpx-mini-test ioperm \
+UNAME_M := $(shell uname -m)
+CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
+CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
+
+TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
+			check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \
 			protection_keys test_vdso test_vsyscall
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
 			test_FCMOV test_FCOMI test_FISTTP \
 			vdso_restorer
 TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
+# Some selftests require 32bit support enabled also on 64bit systems
+TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
 
-TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
+TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
+ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
+TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
+endif
+
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
 BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
 
@@ -23,10 +33,6 @@ BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
 
 CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
 
-UNAME_M := $(shell uname -m)
-CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
-CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
-
 ifeq ($(CAN_BUILD_I386),1)
 all: all_32
 TEST_PROGS += $(BINARIES_32)