Skip to content

Commit a5d25e0

Browse files
amlutosuryasaimadhu
authored andcommitted
selftests/x86: Add a syscall_arg_fault_64 test for negative GSBASE
If the kernel erroneously allows WRGSBASE and user code writes a negative value, paranoid_entry will get confused. Check for this by writing a negative value to GSBASE and doing SYSENTER with TF set. A successful run looks like: [RUN] SYSENTER with TF, invalid state, and GSBASE < 0 [SKIP] Illegal instruction A failed run causes a kernel hang, and I believe it's because we double-fault and then get a never ending series of page faults and, when we exhaust the double fault stack we double fault again, starting the process over. Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/f4f71efc91b9eae5e3dae21c9aee1c70cf5f370e.1590620529.git.luto@kernel.org
1 parent 5e7ec85 commit a5d25e0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tools/testing/selftests/x86/syscall_arg_fault.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static void sigsegv_or_sigbus(int sig, siginfo_t *info, void *ctx_void)
7272
if (ax != -EFAULT && ax != -ENOSYS) {
7373
printf("[FAIL]\tAX had the wrong value: 0x%lx\n",
7474
(unsigned long)ax);
75+
printf("\tIP = 0x%lx\n", (unsigned long)ctx->uc_mcontext.gregs[REG_IP]);
7576
n_errs++;
7677
} else {
7778
printf("[OK]\tSeems okay\n");
@@ -226,5 +227,30 @@ int main()
226227
}
227228
set_eflags(get_eflags() & ~X86_EFLAGS_TF);
228229

230+
#ifdef __x86_64__
231+
printf("[RUN]\tSYSENTER with TF, invalid state, and GSBASE < 0\n");
232+
233+
if (sigsetjmp(jmpbuf, 1) == 0) {
234+
sigtrap_consecutive_syscalls = 0;
235+
236+
asm volatile ("wrgsbase %%rax\n\t"
237+
:: "a" (0xffffffffffff0000UL));
238+
239+
set_eflags(get_eflags() | X86_EFLAGS_TF);
240+
asm volatile (
241+
"movl $-1, %%eax\n\t"
242+
"movl $-1, %%ebx\n\t"
243+
"movl $-1, %%ecx\n\t"
244+
"movl $-1, %%edx\n\t"
245+
"movl $-1, %%esi\n\t"
246+
"movl $-1, %%edi\n\t"
247+
"movl $-1, %%ebp\n\t"
248+
"movl $-1, %%esp\n\t"
249+
"sysenter"
250+
: : : "memory", "flags");
251+
}
252+
set_eflags(get_eflags() & ~X86_EFLAGS_TF);
253+
#endif
254+
229255
return 0;
230256
}

0 commit comments

Comments
 (0)