Skip to content

Commit 5e7ec85

Browse files
ChangSeokBaeKAGA-KOKO
authored andcommitted
selftests/x86/fsgsbase: Test ptracer-induced GS base write with FSGSBASE
This validates that GS selector and base are independently preserved in ptrace commands. Suggested-by: Andy Lutomirski <[email protected]> Signed-off-by: Chang S. Bae <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Tony Luck <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 291fd83 commit 5e7ec85

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tools/testing/selftests/x86/fsgsbase.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static void test_ptrace_write_gsbase(void)
465465
wait(&status);
466466

467467
if (WSTOPSIG(status) == SIGTRAP) {
468-
unsigned long gs;
468+
unsigned long gs, base;
469469
unsigned long gs_offset = USER_REGS_OFFSET(gs);
470470
unsigned long base_offset = USER_REGS_OFFSET(gs_base);
471471

@@ -481,6 +481,7 @@ static void test_ptrace_write_gsbase(void)
481481
err(1, "PTRACE_POKEUSER");
482482

483483
gs = ptrace(PTRACE_PEEKUSER, child, gs_offset, NULL);
484+
base = ptrace(PTRACE_PEEKUSER, child, base_offset, NULL);
484485

485486
/*
486487
* In a non-FSGSBASE system, the nonzero selector will load
@@ -501,8 +502,14 @@ static void test_ptrace_write_gsbase(void)
501502
*/
502503
if (gs == 0)
503504
printf("\tNote: this is expected behavior on older kernels.\n");
505+
} else if (have_fsgsbase && (base != 0xFF)) {
506+
nerrs++;
507+
printf("[FAIL]\tGSBASE changed to %lx\n", base);
504508
} else {
505-
printf("[OK]\tGS remained 0x%hx\n", *shared_scratch);
509+
printf("[OK]\tGS remained 0x%hx", *shared_scratch);
510+
if (have_fsgsbase)
511+
printf(" and GSBASE changed to 0xFF");
512+
printf("\n");
506513
}
507514
}
508515

0 commit comments

Comments
 (0)