Skip to contentSkip to conversation

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

PATCH New Pengfei Xu 2 participants 5 messages Sep 27, 2019 – Sep 29, 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

Quoted 51 lines · Pengfei Xu

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 +6 -0
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 */

testcases/kernel/security/umip/umip_basic_test.c +2 -0
+               #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) {

testcases/kernel/security/umip/umip_basic_test.c +4 -0
+                               tst_res(TFAIL, "Got SIGSEGV\n\n");
+                               return;
+                       }
+                       tst_res(TPASS, "Didn't receive SIGSEGV, child

exited with %s\n\n",

testcases/kernel/security/umip/umip_basic_test.c +4 -0
+                               tst_strstatus(status));
+                               return;
+               #else
+                       tst_res(TINFO, "Linux kernel version is before
Quoted 2 lines

than v5.4");

Thank you for fixing this.

My concern is that if an LTS distro backports the patch(commit e86c2c8b93), then it will break this hardcode kernel-version comparing.

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

Quoted 7 lines
testcases/kernel/security/umip/umip_basic_test.c +4 -1
+               #endif
+       }
+
        if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
-               tst_res(TPASS, "Got SIGSEGV");
+               tst_res(TPASS, "Got SIGSEGV\n\n");

Why we need two '\n' here?

Quoted 14 lines
                return;
        }
testcases/kernel/security/umip/umip_basic_test.c +1 -2
-       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));
 }
 
--

2.14.1

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190929/3280a602/attachment.htm>
author
#2 lore raw

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

Hi Li Wang,

My feedback is as below, thanks!

Quoted 58 lines · Li Wang
Quoted 51 lines · Pengfei Xu

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 +6 -0
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 */

testcases/kernel/security/umip/umip_basic_test.c +2 -0
+               #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) {

testcases/kernel/security/umip/umip_basic_test.c +4 -0
+                               tst_res(TFAIL, "Got SIGSEGV\n\n");
+                               return;
+                       }
+                       tst_res(TPASS, "Didn't receive SIGSEGV, child

exited with %s\n\n",

testcases/kernel/security/umip/umip_basic_test.c +4 -0
+                               tst_strstatus(status));
+                               return;
+               #else
+                       tst_res(TINFO, "Linux kernel version is before
Quoted 2 lines

than v5.4");

Thank you for fixing this.

Quoted 4 lines

My concern is that if an LTS distro backports the patch(commit e86c2c8b93), then it will break this hardcode kernel-version comparing.

Ok, let's wait to confirm umip patch merged into Linux kernel main line, and then merge the patch into LTP. :)
Thanks for your advice!

Quoted 11 lines

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

Quoted 8 lines
testcases/kernel/security/umip/umip_basic_test.c +4 -1
+               #endif
+       }
+
        if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
-               tst_res(TPASS, "Got SIGSEGV");
+               tst_res(TPASS, "Got SIGSEGV\n\n");

Why we need two '\n' here?

Because it could help to split umip cases in LTP, there are 5 umip cases in LTP tests, and we could check each umip case easily in LTP log, like as below:

"

 # ./umip_basic_test
 tst_kconfig.c:62: INFO: Parsing kernel config '/lib/kernel/config-5.3.0-xsuper+'
 tst_test.c:1118: INFO: Timeout per run is 0h 05m 00s
 umip_basic_test.c:160: INFO: cpuinfo contains umip, CPU supports umip
 umip_basic_test.c:41: INFO: TEST sgdt, sgdt result save at [0x7fff930bda8e]
 umip_basic_test.c:132: INFO: Linux kernel version is before v5.4
 umip_basic_test.c:137: PASS: Got SIGSEGV

umip_basic_test.c:51: INFO: TEST sidt, sidt result save at [0x7fff930bda8e]

umip_basic_test.c:132: INFO: Linux kernel version is before v5.4 umip_basic_test.c:137: PASS: Got SIGSEGV

umip_basic_test.c:60: INFO: TEST sldt, sldt result save at [0x7fff930bda80]

umip_basic_test.c:137: PASS: Got SIGSEGV

umip_basic_test.c:69: INFO: TEST smsw, smsw result save at [0x7fff930bda80]

umip_basic_test.c:132: INFO: Linux kernel version is before v5.4 umip_basic_test.c:137: PASS: Got SIGSEGV
"
Thanks! :)

Quoted 20 lines
Quoted 15 lines
                return;
        }
testcases/kernel/security/umip/umip_basic_test.c +1 -2
-       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));
 }
 
--

2.14.1

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 2 lines
Regards,
Li Wang
#3 lore raw

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

Hi Pengfei,

Pengfei Xu <[email protected]> wrote:

...

Quoted 9 lines
Quoted 2 lines

My concern is that if an LTS distro backports the patch(commit

e86c2c8b93),

Quoted 3 lines

then it will break this hardcode kernel-version comparing.

Ok, let's wait to confirm umip patch merged into Linux kernel main line, and then merge the patch into LTP. :)

Sorry, I'm not talking merge time. I mean we have to consider more kernel distros(RHEL, SLES, Ubuntu) when writing/amending LTP test.

Imagine that, if RHEL8(kernel base on v4.18) backports the kernel patch(x86/umip: Add emulation (spoofing) for UMIP covered instructions in 64-bit processes) and what will happen after applying your patch in this umip_basic_test.c test? It will fail since that kernel version is less than 5.4. We probably need to find a way to solve this issue.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
testcases/kernel/security/umip/umip_basic_test.c +4 -1
+               #endif
+       }
+
        if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
-               tst_res(TPASS, "Got SIGSEGV");
+               tst_res(TPASS, "Got SIGSEGV\n\n");
Quoted 5 lines
Quoted 2 lines

Why we need two '\n' here?

Because it could help to split umip cases in LTP, there are 5 umip cases in LTP tests, and we could check each umip case easily in LTP log,

It is unnecessary because each test shows TINFO before testing.
e.g "umip_basic_test.c:41: INFO: TEST sgdt, sgdt result save at
[0x7fff930bda8e]"

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190929/35835499/attachment.htm>
author
#4 lore raw

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

Hi Li Wang,

Quoted 15 lines · Li Wang

Hi Pengfei,

Pengfei Xu <[email protected]> wrote:

...

Quoted 9 lines
Quoted 2 lines

My concern is that if an LTS distro backports the patch(commit

e86c2c8b93),

Quoted 3 lines

then it will break this hardcode kernel-version comparing.

Ok, let's wait to confirm umip patch merged into Linux kernel main line, and then merge the patch into LTP. :)

Quoted 9 lines

Sorry, I'm not talking merge time. I mean we have to consider more kernel distros(RHEL, SLES, Ubuntu) when writing/amending LTP test.

Imagine that, if RHEL8(kernel base on v4.18) backports the kernel patch(x86/umip: Add emulation (spoofing) for UMIP covered instructions in 64-bit processes) and what will happen after applying your patch in this umip_basic_test.c test? It will fail since that kernel version is less than 5.4. We probably need to find a way to solve this issue.

Ok, got it, we need consider one better way for it. :) Thanks for advice!

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

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

Quoted 8 lines
testcases/kernel/security/umip/umip_basic_test.c +4 -1
+               #endif
+       }
+
        if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
-               tst_res(TPASS, "Got SIGSEGV");
+               tst_res(TPASS, "Got SIGSEGV\n\n");

Why we need two '\n' here?

Quoted 8 lines
Quoted 3 lines

Because it could help to split umip cases in LTP, there are 5 umip cases in LTP tests, and we could check each umip case easily in LTP log,

It is unnecessary because each test shows TINFO before testing.
e.g "umip_basic_test.c:41: INFO: TEST sgdt, sgdt result save at
[0x7fff930bda8e]"

Ok thanks! :)

Quoted 3 lines
Signature · 2 lines
Regards,
Li Wang