Skip to contentSkip to conversation

umip_basic_test.c: update umip basic test for new kernel v5.4

PATCH New Pengfei Xu 2 participants 3 messages Sep 27, 2019 – Oct 3, 2019

lore
Share & tools
lore

Pengfei Xu

author
#0 lore raw

PATCH 1/1 umip_basic_test.c: update umip basic test for new kernel v5.4

After linux kernel v5.4 mainline, 64bit SGDT SIDT SMSW will return dummy value and not trigger SIGSEGV due to kernel code change. For detailed kernel update info, you could check v5.4 commit:
x86/umip: Add emulation (spoofing) for UMIP covered instructions in 64-bit processes as well

---
 testcases/kernel/security/umip/umip_basic_test.c | 25 ++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
testcases/kernel/security/umip/umip_basic_test.c +23 -2
index 37850ef9f..278ae92f6 100644
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <sys/wait.h>
 #include <signal.h>
+#include <linux/version.h>
 
 #include "tst_test.h"
 #include "tst_safe_stdio.h"
@@ -112,11 +113,31 @@ static void verify_umip_instruction(unsigned int n)
 
 	SAFE_WAITPID(pid, &status, 0);
 
+	switch (n) {
+	case 0:
+	case 1:
+	case 3:
+		/* after linux kernel v5.4 mainline, 64bit SGDT SIDT SMSW will return
+		   dummy value and not trigger SIGSEGV due to kernel code change */
+		#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0)
+			tst_res(TINFO, "Linux kernel version is after than v5.4");
+			if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
+				tst_res(TFAIL, "Got SIGSEGV\n\n");
+				return;
+			}
+			tst_res(TPASS, "Didn't receive SIGSEGV, child exited with %s\n\n",
+				tst_strstatus(status));
+				return;
+		#else
+			tst_res(TINFO, "Linux kernel version is before than v5.4");
+		#endif
+	}
+
 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
-		tst_res(TPASS, "Got SIGSEGV");
+		tst_res(TPASS, "Got SIGSEGV\n\n");
 		return;
 	}
-	tst_res(TFAIL, "Didn't receive SIGSEGV, child exited with %s",
+	tst_res(TFAIL, "Didn't receive SIGSEGV, child exited with %s\n\n",
 		tst_strstatus(status));
 }
 
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/1 umip_basic_test.c: update umip basic test for new kernel v5.4

Hi!

testcases/kernel/security/umip/umip_basic_test.c static void verify_umip_instruction(unsigned int n) · line 122

Quoted 3 lines
testcases/kernel/security/umip/umip_basic_test.c +3 -0
+		/* after linux kernel v5.4 mainline, 64bit SGDT SIDT SMSW will return
+		   dummy value and not trigger SIGSEGV due to kernel code change */
+		#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0)

This is obviously wrong, the version you get here is the version from kernel headers that does not correspond to the kernel you are running on at all.

We do have tst_kvercmp() function in LTP that uses parses uname() output and returns if you are running on kernel newer/same/older as the version passed to that function. Use that one instead.

testcases/kernel/security/umip/umip_basic_test.c static void verify_umip_instruction(unsigned int n) · line 130

Quoted 8 lines
testcases/kernel/security/umip/umip_basic_test.c +8 -0
+			tst_res(TINFO, "Linux kernel version is after than v5.4");
+			if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
+				tst_res(TFAIL, "Got SIGSEGV\n\n");
+				return;
+			}
+			tst_res(TPASS, "Didn't receive SIGSEGV, child exited with %s\n\n",
+				tst_strstatus(status));
+				return;
				^
				Wrong indentation.

testcases/kernel/security/umip/umip_basic_test.c static void verify_umip_instruction(unsigned int n) · line 141

Quoted 13 lines
testcases/kernel/security/umip/umip_basic_test.c +7 -2
+		#else
+			tst_res(TINFO, "Linux kernel version is before than v5.4");
+		#endif
+	}
+
 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
-		tst_res(TPASS, "Got SIGSEGV");
+		tst_res(TPASS, "Got SIGSEGV\n\n");
 		return;
 	}
-	tst_res(TFAIL, "Didn't receive SIGSEGV, child exited with %s",
+	tst_res(TFAIL, "Didn't receive SIGSEGV, child exited with %s\n\n",
 		tst_strstatus(status));

Can you please avoid polluting output with useless newlines as well?

Quoted 8 lines

}

Signature · 5 lines
2.14.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 umip_basic_test.c: update umip basic test for new kernel v5.4

Hi Hrubis,

Thanks a lot for your comments! :)
BR.

Quoted 9 lines · Cyril Hrubis

Hi!

testcases/kernel/security/umip/umip_basic_test.c static void verify_umip_instruction(unsigned int n) · line 122

Quoted 3 lines
testcases/kernel/security/umip/umip_basic_test.c +3 -0
+		/* after linux kernel v5.4 mainline, 64bit SGDT SIDT SMSW will return
+		   dummy value and not trigger SIGSEGV due to kernel code change */
+		#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0)

This is obviously wrong, the version you get here is the version from kernel headers that does not correspond to the kernel you are running on at all.

Quoted 4 lines

We do have tst_kvercmp() function in LTP that uses parses uname() output and returns if you are running on kernel newer/same/older as the version passed to that function. Use that one instead.

Will use tst_kvercmp function, thanks.

Quoted 11 lines

testcases/kernel/security/umip/umip_basic_test.c static void verify_umip_instruction(unsigned int n) · line 130

Quoted 8 lines
testcases/kernel/security/umip/umip_basic_test.c +8 -0
+			tst_res(TINFO, "Linux kernel version is after than v5.4");
+			if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
+				tst_res(TFAIL, "Got SIGSEGV\n\n");
+				return;
+			}
+			tst_res(TPASS, "Didn't receive SIGSEGV, child exited with %s\n\n",
+				tst_strstatus(status));
+				return;
				^
				Wrong indentation.

Yes, will correct it.

Quoted 7 lines
Quoted 7 lines
testcases/kernel/security/umip/umip_basic_test.c +5 -1
+		#else
+			tst_res(TINFO, "Linux kernel version is before than v5.4");
+		#endif
+	}
+
 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
-		tst_res(TPASS, "Got SIGSEGV");
Quoted 10 lines

testcases/kernel/security/umip/umip_basic_test.c static void verify_umip_instruction(unsigned int n) · line 141

Quoted 6 lines
testcases/kernel/security/umip/umip_basic_test.c +2 -1
+		tst_res(TPASS, "Got SIGSEGV\n\n");
 		return;
 	}
-	tst_res(TFAIL, "Didn't receive SIGSEGV, child exited with %s",
+	tst_res(TFAIL, "Didn't receive SIGSEGV, child exited with %s\n\n",
 		tst_strstatus(status));

Can you please avoid polluting output with useless newlines as well?

Quoted 1 line

}

Ok, will avoid useless newlines.
Thanks for all comments, will correct them.

Quoted 11 lines
Quoted 7 lines
Signature · 6 lines
-- 
2.14.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]