Add Intel umip(User Mode Instruction Prevention) basic function tests
PATCH v4 1/1 Add Intel umip(User Mode Instruction Prevention) basic function tests
umip is a security feature present in new Intel Processors. Intel CPU like ICE lake or newer is required.
When umip enabled, it prevents the execution of certain instructions and situation as below:
when Current Privilege Level (CPL) is greater than 0, user space applications could not access to system-wide settings such as the global and local descriptor tables, the segment selectors to the current task state and the local descriptor table.
umip is enabled by default at boot.
umip will protect below instructions in user mode:
* SGDT - Store Global Descriptor Table
* SIDT - Store Interrupt Descriptor Table
* SLDT - Store Local Descriptor Table
* SMSW - Store Machine Status Word
* STR - Store Task Register
If CPU not support umip, you still could comment cpuinfo check code to verify anyway.
--- runtest/secure_umip | 2 + testcases/kernel/security/umip/.gitignore | 1 + testcases/kernel/security/umip/Makefile | 7 + testcases/kernel/security/umip/umip_gp_test.c | 212 ++++++++++++++++++++++++++ 4 files changed, 222 insertions(+) create mode 100644 runtest/secure_umip create mode 100644 testcases/kernel/security/umip/.gitignore create mode 100644 testcases/kernel/security/umip/Makefile create mode 100644 testcases/kernel/security/umip/umip_gp_test.c
runtest/secure_umip new file +2 -0
@@ -0,0 +1,2 @@ +#DESCRIPTION: CPU security feature UMIP test +umip_instruction_test umip_gp_test
testcases/kernel/security/umip/.gitignore new file +1 -0
@@ -0,0 +1 @@ +umip_gp_test
testcases/kernel/security/umip/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/security/umip/umip_gp_test.c new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.14.1
PATCH v4 1/1 Add Intel umip(User Mode Instruction Prevention) basic function tests
Hi!
Quoted 5 lines
testcases/kernel/security/umip/umip_gp_test.c new file +5
-0+static void sig_handler (int signal) +{ +int exp_sigsegv =11 ; + +if (exp_sigsegv == signal) {
testcases/kernel/security/umip/umip_gp_test.c line 169
Quoted 10 lines
testcases/kernel/security/umip/umip_gp_test.c new file +10
-0+ sigsegv_cnt++; +tst_res (TPASS ,"Received SIGSEGV signal:%d, num:%d" , + signal, sigsegv_cnt); +// signal handler by app, kernel will not kill, need exit +exit (EXIT_VALUE ); + }else { +tst_res (TWARN ,"Received unexpected signal:%d" , signal); +SAFE_KILL (pid,SIGINT ); + } +}
I think I already tried to explain that signal handler runs asynchronously to the rest of the code and that calling anything else than a few signal-async-safe functions may cause undefined behavior, which mostly translates to deadlocks.
Why can't we write the test as:
static void asm_sgdt(void)
{
unsigned char val[GDT_LEN];
tst_res(TINFO, "TEST sgdt, sgdt result save at [%p]", val);
asm volatile("sgdt %0\n" : "=m" (val));
exit(0);
}...
static void do_test(unsigned int n)
{
int pid, status;
pid = SAFE_FORK();
if (!pid) {
switch (n) {
case 0:
asm_sgdt();
break;
...
}
}
SAFE_WAITPID(pid, &status, 0);
if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
tst_res(TPASS, "Got SIGSEGV");
return;
}
tst_res(TFAIL, "Child exitted with %s", tst_strstatus(status));
}Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/1 Add Intel umip(User Mode Instruction Prevention) basic function tests
Hi Cyril,
Thanks for your advice.
I make it complex and contain potential risk.
BR.
Quoted 23 lines · Cyril Hrubis
Hi!
I think I already tried to explain that signal handler runs asynchronously to the rest of the code and that calling anything else than a few signal-async-safe functions may cause undefined behavior, which mostly translates to deadlocks.
Why can't we write the test as:
SAFE_WAITPID(pid, &status, 0); if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) { tst_res(TPASS, "Got SIGSEGV"); return; } tst_res(TFAIL, "Child exitted with %s", tst_strstatus(status)); }Signature · 2 lines
Cyril Hrubis [email protected]