Skip to content

Commit 4d2fa82

Browse files
amlutoPeter Zijlstra
authored andcommitted
selftests/x86/sigreturn/32: Invalidate DS and ES when abusing the kernel
If the kernel accidentally uses DS or ES while the user values are loaded, it will work fine for sane userspace. In the interest of simulating maximally insane userspace, make sigreturn_32 zero out DS and ES for the nasty parts so that inadvertent use of these segments will crash. Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected]
1 parent 8caa016 commit 4d2fa82

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/testing/selftests/x86/sigreturn.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,19 @@ static void sigusr1(int sig, siginfo_t *info, void *ctx_void)
451451
ctx->uc_mcontext.gregs[REG_SP] = (unsigned long)0x8badf00d5aadc0deULL;
452452
ctx->uc_mcontext.gregs[REG_CX] = 0;
453453

454+
#ifdef __i386__
455+
/*
456+
* Make sure the kernel doesn't inadvertently use DS or ES-relative
457+
* accesses in a region where user DS or ES is loaded.
458+
*
459+
* Skip this for 64-bit builds because long mode doesn't care about
460+
* DS and ES and skipping it increases test coverage a little bit,
461+
* since 64-bit kernels can still run the 32-bit build.
462+
*/
463+
ctx->uc_mcontext.gregs[REG_DS] = 0;
464+
ctx->uc_mcontext.gregs[REG_ES] = 0;
465+
#endif
466+
454467
memcpy(&requested_regs, &ctx->uc_mcontext.gregs, sizeof(gregset_t));
455468
requested_regs[REG_CX] = *ssptr(ctx); /* The asm code does this. */
456469

0 commit comments

Comments
 (0)