Skip to content

Commit c9129cf

Browse files
sohilmehhansendc
authored andcommitted
selftests/x86: Update the negative vsyscall tests to expect a #GP
Some of the vsyscall selftests expect a #PF when vsyscalls are disabled. However, with LASS enabled, an invalid access results in a SIGSEGV due to a #GP instead of a #PF. One such negative test fails because it is expecting X86_PF_INSTR to be set. Update the failing test to expect either a #GP or a #PF. Also, update the printed messages to show the trap number (denoting the type of fault) instead of assuming a #PF. Signed-off-by: Sohil Mehta <sohil.mehta@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251118182911.2983253-8-sohil.mehta%40intel.com
1 parent 42fea0a commit c9129cf

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

tools/testing/selftests/x86/test_vsyscall.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,13 @@ static void test_getcpu(int cpu)
308308
#ifdef __x86_64__
309309

310310
static jmp_buf jmpbuf;
311-
static volatile unsigned long segv_err;
311+
static volatile unsigned long segv_err, segv_trapno;
312312

313313
static void sigsegv(int sig, siginfo_t *info, void *ctx_void)
314314
{
315315
ucontext_t *ctx = (ucontext_t *)ctx_void;
316316

317+
segv_trapno = ctx->uc_mcontext.gregs[REG_TRAPNO];
317318
segv_err = ctx->uc_mcontext.gregs[REG_ERR];
318319
siglongjmp(jmpbuf, 1);
319320
}
@@ -336,7 +337,8 @@ static void test_vsys_r(void)
336337
else if (can_read)
337338
ksft_test_result_pass("We have read access\n");
338339
else
339-
ksft_test_result_pass("We do not have read access: #PF(0x%lx)\n", segv_err);
340+
ksft_test_result_pass("We do not have read access (trap=%ld, error=0x%lx)\n",
341+
segv_trapno, segv_err);
340342
}
341343

342344
static void test_vsys_x(void)
@@ -347,7 +349,7 @@ static void test_vsys_x(void)
347349
return;
348350
}
349351

350-
ksft_print_msg("Make sure that vsyscalls really page fault\n");
352+
ksft_print_msg("Make sure that vsyscalls really cause a fault\n");
351353

352354
bool can_exec;
353355
if (sigsetjmp(jmpbuf, 1) == 0) {
@@ -358,13 +360,14 @@ static void test_vsys_x(void)
358360
}
359361

360362
if (can_exec)
361-
ksft_test_result_fail("Executing the vsyscall did not page fault\n");
362-
else if (segv_err & (1 << 4)) /* INSTR */
363-
ksft_test_result_pass("Executing the vsyscall page failed: #PF(0x%lx)\n",
364-
segv_err);
363+
ksft_test_result_fail("Executing the vsyscall did not fault\n");
364+
/* #GP or #PF (with X86_PF_INSTR) */
365+
else if ((segv_trapno == 13) || ((segv_trapno == 14) && (segv_err & (1 << 4))))
366+
ksft_test_result_pass("Executing the vsyscall page failed (trap=%ld, error=0x%lx)\n",
367+
segv_trapno, segv_err);
365368
else
366-
ksft_test_result_fail("Execution failed with the wrong error: #PF(0x%lx)\n",
367-
segv_err);
369+
ksft_test_result_fail("Execution failed with the wrong error (trap=%ld, error=0x%lx)\n",
370+
segv_trapno, segv_err);
368371
}
369372

370373
/*

0 commit comments

Comments
 (0)