Skip to content

Commit

Permalink
selftests/x86/fsgsbase: Test ptracer-induced GS base write with FSGSBASE
Browse files Browse the repository at this point in the history
This validates that GS selector and base are independently preserved in
ptrace commands.

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200528201402.1708239-17-sashal@kernel.org
  • Loading branch information
Chang S. Bae authored and Thomas Gleixner committed Jun 18, 2020
1 parent 291fd83 commit 5e7ec85
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tools/testing/selftests/x86/fsgsbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static void test_ptrace_write_gsbase(void)
wait(&status);

if (WSTOPSIG(status) == SIGTRAP) {
unsigned long gs;
unsigned long gs, base;
unsigned long gs_offset = USER_REGS_OFFSET(gs);
unsigned long base_offset = USER_REGS_OFFSET(gs_base);

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

gs = ptrace(PTRACE_PEEKUSER, child, gs_offset, NULL);
base = ptrace(PTRACE_PEEKUSER, child, base_offset, NULL);

/*
* In a non-FSGSBASE system, the nonzero selector will load
Expand All @@ -501,8 +502,14 @@ static void test_ptrace_write_gsbase(void)
*/
if (gs == 0)
printf("\tNote: this is expected behavior on older kernels.\n");
} else if (have_fsgsbase && (base != 0xFF)) {
nerrs++;
printf("[FAIL]\tGSBASE changed to %lx\n", base);
} else {
printf("[OK]\tGS remained 0x%hx\n", *shared_scratch);
printf("[OK]\tGS remained 0x%hx", *shared_scratch);
if (have_fsgsbase)
printf(" and GSBASE changed to 0xFF");
printf("\n");
}
}

Expand Down

0 comments on commit 5e7ec85

Please sign in to comment.