@@ -465,7 +465,7 @@ static void test_ptrace_write_gsbase(void)
465
465
wait (& status );
466
466
467
467
if (WSTOPSIG (status ) == SIGTRAP ) {
468
- unsigned long gs , base ;
468
+ unsigned long gs ;
469
469
unsigned long gs_offset = USER_REGS_OFFSET (gs );
470
470
unsigned long base_offset = USER_REGS_OFFSET (gs_base );
471
471
@@ -481,19 +481,28 @@ static void test_ptrace_write_gsbase(void)
481
481
err (1 , "PTRACE_POKEUSER" );
482
482
483
483
gs = ptrace (PTRACE_PEEKUSER , child , gs_offset , NULL );
484
- base = ptrace (PTRACE_PEEKUSER , child , base_offset , NULL );
485
484
486
485
/*
487
486
* In a non-FSGSBASE system, the nonzero selector will load
488
487
* GSBASE (again). But what is tested here is whether the
489
488
* selector value is changed or not by the GSBASE write in
490
489
* a ptracer.
491
490
*/
492
- if (gs == 0 && base == 0xFF ) {
493
- printf ("[OK]\tGS was reset as expected\n" );
494
- } else {
491
+ if (gs != * shared_scratch ) {
495
492
nerrs ++ ;
496
- printf ("[FAIL]\tGS=0x%lx, GSBASE=0x%lx (should be 0, 0xFF)\n" , gs , base );
493
+ printf ("[FAIL]\tGS changed to %lx\n" , gs );
494
+
495
+ /*
496
+ * On older kernels, poking a nonzero value into the
497
+ * base would zero the selector. On newer kernels,
498
+ * this behavior has changed -- poking the base
499
+ * changes only the base and, if FSGSBASE is not
500
+ * available, this may not effect.
501
+ */
502
+ if (gs == 0 )
503
+ printf ("\tNote: this is expected behavior on older kernels.\n" );
504
+ } else {
505
+ printf ("[OK]\tGS remained 0x%hx\n" , * shared_scratch );
497
506
}
498
507
}
499
508
0 commit comments