All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve Muckle <smuckle@google.com>
To: Shuah Khan <shuah@kernel.org>, Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kselftest@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@android.com,
	Steve Muckle <smuckle@google.com>
Subject: [PATCH] selftests: x86: add version check in test_syscall_vdso
Date: Thu, 28 Feb 2019 16:18:06 -0800	[thread overview]
Message-ID: <20190301001806.154271-1-smuckle@google.com> (raw)

Since 4.17 registers r8-r11 are not clobbered/zeroed by a 64-bit kernel
handling a 32-bit syscall and this behavior is enforced by the
test_syscall_vdso testcase. See commit 8bb2610bc496
("x86/entry/64/compat: Preserve r8-r11 in int $0x80").

Permit the old behavior in the testcase for kernels prior to 4.17.

Signed-off-by: Steve Muckle <smuckle@google.com>
---
 .../testing/selftests/x86/test_syscall_vdso.c | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/testing/selftests/x86/test_syscall_vdso.c b/tools/testing/selftests/x86/test_syscall_vdso.c
index c9c3281077bc..f7284dc4c32b 100644
--- a/tools/testing/selftests/x86/test_syscall_vdso.c
+++ b/tools/testing/selftests/x86/test_syscall_vdso.c
@@ -30,6 +30,7 @@
 #include <sys/time.h>
 #include <elf.h>
 #include <sys/ptrace.h>
+#include <sys/utsname.h>
 #include <sys/wait.h>
 
 #if !defined(__i386__)
@@ -71,6 +72,7 @@ struct regs64 {
 };
 struct regs64 regs64;
 int kernel_is_64bit;
+int clobber_ok;
 
 asm (
 	"	.pushsection .text\n"
@@ -130,6 +132,28 @@ void print_regs64(void)
 	printf("12:%016llx 13:%016llx 14:%016llx 15:%016llx\n", regs64.r12,  regs64.r13,  regs64.r14,  regs64.r15);
 }
 
+static void get_kernel_version(int *version, int *patchlevel)
+{
+	int ret, sublevel;
+	struct utsname utsname;
+
+	ret = uname(&utsname);
+	if (ret) {
+		perror("uname");
+		exit(1);
+	}
+
+	ret = sscanf(utsname.release, "%d.%d.%d", version, patchlevel,
+		     &sublevel);
+	if (ret < 0) {
+		perror("sscanf");
+		exit(1);
+	} else if (ret != 3) {
+		printf("Malformed kernel version %s\n", &utsname.release);
+		exit(1);
+	}
+}
+
 int check_regs64(void)
 {
 	int err = 0;
@@ -166,6 +190,8 @@ int check_regs64(void)
 			 * Historically (and probably unintentionally), they
 			 * were clobbered or zeroed.
 			 */
+			if (clobber_ok && *r64 == 0 && num <= 11)
+				continue;
 		}
 		printf("[FAIL]\tR%d has changed:%016llx\n", num, *r64);
 		err++;
@@ -385,6 +411,7 @@ int main(int argc, char **argv, char **envp)
 {
 	int exitcode = 0;
 	int cs;
+	int version, patchlevel;
 
 	asm("\n"
 	"	movl	%%cs, %%eax\n"
@@ -394,6 +421,9 @@ int main(int argc, char **argv, char **envp)
 	if (!kernel_is_64bit)
 		printf("[NOTE]\tNot a 64-bit kernel, won't test R8..R15 leaks\n");
 
+	get_kernel_version(&version, &patchlevel);
+	clobber_ok = version < 4 || (version == 4 && patchlevel < 17);
+
 	/* This only works for non-static builds:
 	 * syscall_addr = dlsym(dlopen("linux-gate.so.1", RTLD_NOW), "__kernel_vsyscall");
 	 */
-- 
2.21.0.352.gf09ad66450-goog


WARNING: multiple messages have this Message-ID (diff)
From: smuckle at google.com (Steve Muckle)
Subject: [PATCH] selftests: x86: add version check in test_syscall_vdso
Date: Thu, 28 Feb 2019 16:18:06 -0800	[thread overview]
Message-ID: <20190301001806.154271-1-smuckle@google.com> (raw)

Since 4.17 registers r8-r11 are not clobbered/zeroed by a 64-bit kernel
handling a 32-bit syscall and this behavior is enforced by the
test_syscall_vdso testcase. See commit 8bb2610bc496
("x86/entry/64/compat: Preserve r8-r11 in int $0x80").

Permit the old behavior in the testcase for kernels prior to 4.17.

Signed-off-by: Steve Muckle <smuckle at google.com>
---
 .../testing/selftests/x86/test_syscall_vdso.c | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/testing/selftests/x86/test_syscall_vdso.c b/tools/testing/selftests/x86/test_syscall_vdso.c
index c9c3281077bc..f7284dc4c32b 100644
--- a/tools/testing/selftests/x86/test_syscall_vdso.c
+++ b/tools/testing/selftests/x86/test_syscall_vdso.c
@@ -30,6 +30,7 @@
 #include <sys/time.h>
 #include <elf.h>
 #include <sys/ptrace.h>
+#include <sys/utsname.h>
 #include <sys/wait.h>
 
 #if !defined(__i386__)
@@ -71,6 +72,7 @@ struct regs64 {
 };
 struct regs64 regs64;
 int kernel_is_64bit;
+int clobber_ok;
 
 asm (
 	"	.pushsection .text\n"
@@ -130,6 +132,28 @@ void print_regs64(void)
 	printf("12:%016llx 13:%016llx 14:%016llx 15:%016llx\n", regs64.r12,  regs64.r13,  regs64.r14,  regs64.r15);
 }
 
+static void get_kernel_version(int *version, int *patchlevel)
+{
+	int ret, sublevel;
+	struct utsname utsname;
+
+	ret = uname(&utsname);
+	if (ret) {
+		perror("uname");
+		exit(1);
+	}
+
+	ret = sscanf(utsname.release, "%d.%d.%d", version, patchlevel,
+		     &sublevel);
+	if (ret < 0) {
+		perror("sscanf");
+		exit(1);
+	} else if (ret != 3) {
+		printf("Malformed kernel version %s\n", &utsname.release);
+		exit(1);
+	}
+}
+
 int check_regs64(void)
 {
 	int err = 0;
@@ -166,6 +190,8 @@ int check_regs64(void)
 			 * Historically (and probably unintentionally), they
 			 * were clobbered or zeroed.
 			 */
+			if (clobber_ok && *r64 == 0 && num <= 11)
+				continue;
 		}
 		printf("[FAIL]\tR%d has changed:%016llx\n", num, *r64);
 		err++;
@@ -385,6 +411,7 @@ int main(int argc, char **argv, char **envp)
 {
 	int exitcode = 0;
 	int cs;
+	int version, patchlevel;
 
 	asm("\n"
 	"	movl	%%cs, %%eax\n"
@@ -394,6 +421,9 @@ int main(int argc, char **argv, char **envp)
 	if (!kernel_is_64bit)
 		printf("[NOTE]\tNot a 64-bit kernel, won't test R8..R15 leaks\n");
 
+	get_kernel_version(&version, &patchlevel);
+	clobber_ok = version < 4 || (version == 4 && patchlevel < 17);
+
 	/* This only works for non-static builds:
 	 * syscall_addr = dlsym(dlopen("linux-gate.so.1", RTLD_NOW), "__kernel_vsyscall");
 	 */
-- 
2.21.0.352.gf09ad66450-goog

WARNING: multiple messages have this Message-ID (diff)
From: smuckle@google.com (Steve Muckle)
Subject: [PATCH] selftests: x86: add version check in test_syscall_vdso
Date: Thu, 28 Feb 2019 16:18:06 -0800	[thread overview]
Message-ID: <20190301001806.154271-1-smuckle@google.com> (raw)
Message-ID: <20190301001806.XHIVKxj4RgowChljlLCpIjA7BHHNf99hD64jB6hJ37c@z> (raw)

Since 4.17 registers r8-r11 are not clobbered/zeroed by a 64-bit kernel
handling a 32-bit syscall and this behavior is enforced by the
test_syscall_vdso testcase. See commit 8bb2610bc496
("x86/entry/64/compat: Preserve r8-r11 in int $0x80").

Permit the old behavior in the testcase for kernels prior to 4.17.

Signed-off-by: Steve Muckle <smuckle at google.com>
---
 .../testing/selftests/x86/test_syscall_vdso.c | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/testing/selftests/x86/test_syscall_vdso.c b/tools/testing/selftests/x86/test_syscall_vdso.c
index c9c3281077bc..f7284dc4c32b 100644
--- a/tools/testing/selftests/x86/test_syscall_vdso.c
+++ b/tools/testing/selftests/x86/test_syscall_vdso.c
@@ -30,6 +30,7 @@
 #include <sys/time.h>
 #include <elf.h>
 #include <sys/ptrace.h>
+#include <sys/utsname.h>
 #include <sys/wait.h>
 
 #if !defined(__i386__)
@@ -71,6 +72,7 @@ struct regs64 {
 };
 struct regs64 regs64;
 int kernel_is_64bit;
+int clobber_ok;
 
 asm (
 	"	.pushsection .text\n"
@@ -130,6 +132,28 @@ void print_regs64(void)
 	printf("12:%016llx 13:%016llx 14:%016llx 15:%016llx\n", regs64.r12,  regs64.r13,  regs64.r14,  regs64.r15);
 }
 
+static void get_kernel_version(int *version, int *patchlevel)
+{
+	int ret, sublevel;
+	struct utsname utsname;
+
+	ret = uname(&utsname);
+	if (ret) {
+		perror("uname");
+		exit(1);
+	}
+
+	ret = sscanf(utsname.release, "%d.%d.%d", version, patchlevel,
+		     &sublevel);
+	if (ret < 0) {
+		perror("sscanf");
+		exit(1);
+	} else if (ret != 3) {
+		printf("Malformed kernel version %s\n", &utsname.release);
+		exit(1);
+	}
+}
+
 int check_regs64(void)
 {
 	int err = 0;
@@ -166,6 +190,8 @@ int check_regs64(void)
 			 * Historically (and probably unintentionally), they
 			 * were clobbered or zeroed.
 			 */
+			if (clobber_ok && *r64 == 0 && num <= 11)
+				continue;
 		}
 		printf("[FAIL]\tR%d has changed:%016llx\n", num, *r64);
 		err++;
@@ -385,6 +411,7 @@ int main(int argc, char **argv, char **envp)
 {
 	int exitcode = 0;
 	int cs;
+	int version, patchlevel;
 
 	asm("\n"
 	"	movl	%%cs, %%eax\n"
@@ -394,6 +421,9 @@ int main(int argc, char **argv, char **envp)
 	if (!kernel_is_64bit)
 		printf("[NOTE]\tNot a 64-bit kernel, won't test R8..R15 leaks\n");
 
+	get_kernel_version(&version, &patchlevel);
+	clobber_ok = version < 4 || (version == 4 && patchlevel < 17);
+
 	/* This only works for non-static builds:
 	 * syscall_addr = dlsym(dlopen("linux-gate.so.1", RTLD_NOW), "__kernel_vsyscall");
 	 */
-- 
2.21.0.352.gf09ad66450-goog

             reply	other threads:[~2019-03-01  0:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-01  0:18 Steve Muckle [this message]
2019-03-01  0:18 ` [PATCH] selftests: x86: add version check in test_syscall_vdso Steve Muckle
2019-03-01  0:18 ` smuckle
2019-03-01 19:59 ` Andy Lutomirski
2019-03-01 19:59   ` Andy Lutomirski
2019-03-01 19:59   ` luto
2019-03-02  9:10   ` Greg KH
2019-03-02  9:10     ` Greg KH
2019-03-02  9:10     ` gregkh
2019-03-02 18:31     ` shuah
2019-03-02 18:31       ` shuah
2019-03-02 18:31       ` shuah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190301001806.154271-1-smuckle@google.com \
    --to=smuckle@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.