hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/testing/selftests/x86/sigreturn.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * sigreturn.c - tests for x86 sigreturn(2) and exit-to-userspace
34 * 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.
135 *
146 * This is a series of tests that exercises the sigreturn(2) syscall and
157 * the IRET / SYSRET paths in the kernel.
....@@ -459,6 +451,19 @@
459451 ctx->uc_mcontext.gregs[REG_SP] = (unsigned long)0x8badf00d5aadc0deULL;
460452 ctx->uc_mcontext.gregs[REG_CX] = 0;
461453
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
+
462467 memcpy(&requested_regs, &ctx->uc_mcontext.gregs, sizeof(gregset_t));
463468 requested_regs[REG_CX] = *ssptr(ctx); /* The asm code does this. */
464469