| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * sigreturn.c - tests for x86 sigreturn(2) and exit-to-userspace |
|---|
| 3 | 4 | * Copyright (c) 2014-2015 Andrew Lutomirski |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms and conditions of the GNU General Public License, |
|---|
| 7 | | - * version 2, as published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope it will be useful, but |
|---|
| 10 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 12 | | - * General Public License for more details. |
|---|
| 13 | 5 | * |
|---|
| 14 | 6 | * This is a series of tests that exercises the sigreturn(2) syscall and |
|---|
| 15 | 7 | * the IRET / SYSRET paths in the kernel. |
|---|
| .. | .. |
|---|
| 459 | 451 | ctx->uc_mcontext.gregs[REG_SP] = (unsigned long)0x8badf00d5aadc0deULL; |
|---|
| 460 | 452 | ctx->uc_mcontext.gregs[REG_CX] = 0; |
|---|
| 461 | 453 | |
|---|
| 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 | + |
|---|
| 462 | 467 | memcpy(&requested_regs, &ctx->uc_mcontext.gregs, sizeof(gregset_t)); |
|---|
| 463 | 468 | requested_regs[REG_CX] = *ssptr(ctx); /* The asm code does this. */ |
|---|
| 464 | 469 | |
|---|