Print this page
11530 badseg test creates cores
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/test/os-tests/tests/i386/badseg.c
+++ new/usr/src/test/os-tests/tests/i386/badseg_exec.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 - * Copyright 2018 Joyent, Inc.
13 + * Copyright 2019 Joyent, Inc.
14 14 */
15 15
16 16 #include <stdlib.h>
17 17 #include <ucontext.h>
18 18 #include <sys/wait.h>
19 19 #include <unistd.h>
20 20 #include <sys/regset.h>
21 +#include <sys/resource.h>
22 +#include <err.h>
21 23
22 24 /*
23 25 * Load a bunch of bad selectors into the seg regs: this will typically cause
24 26 * the child process to core dump, but it shouldn't panic the kernel...
25 27 *
26 28 * It's especially interesting to run this on CPU0.
27 29 */
28 30
29 31 unsigned short selector;
30 32
31 33 static void badds(void)
32 34 {
33 35 __asm__ volatile("movw %0, %%ds" : : "r" (selector));
34 36 }
35 37
36 38 static void bades(void)
37 39 {
38 40 __asm__ volatile("movw %0, %%es" : : "r" (selector));
39 41 }
40 42
41 43 static void badfs(void)
42 44 {
43 45 __asm__ volatile("movw %0, %%fs" : : "r" (selector));
44 46 }
45 47
46 48 static void badgs(void)
47 49 {
48 50 __asm__ volatile("movw %0, %%gs" : : "r" (selector));
49 51 }
50 52
51 53 static void badss(void)
52 54 {
53 55 __asm__ volatile("movw %0, %%ss" : : "r" (selector));
54 56 }
55 57
56 58 static void
57 59 resetseg(uint_t seg)
58 60 {
59 61 ucontext_t ucp;
60 62 volatile int done = 0;
61 63
62 64 int rc = getcontext(&ucp);
63 65 if (done) {
64 66 (void) getcontext(&ucp);
65 67 return;
66 68 }
67 69
68 70 if (rc == 0) {
69 71 done = 1;
70 72 ucp.uc_mcontext.gregs[seg] = selector;
71 73 (void) setcontext(&ucp);
72 74 }
73 75 abort();
74 76 }
75 77
76 78 static void
77 79 resetcs(void)
78 80 {
79 81 return (resetseg(CS));
80 82 }
81 83
82 84 static void
83 85 resetds(void)
84 86 {
85 87 return (resetseg(DS));
86 88 }
87 89
88 90 static void
89 91 resetes(void)
90 92 {
91 93 return (resetseg(ES));
92 94 }
93 95
94 96 static void
95 97 resetfs(void)
96 98 {
97 99 return (resetseg(FS));
98 100 }
99 101
100 102 static void
101 103 resetgs(void)
102 104 {
103 105 return (resetseg(GS));
104 106 }
105 107
106 108 static void
107 109 resetss(void)
108 110 {
109 111 return (resetseg(SS));
↓ open down ↓ |
79 lines elided |
↑ open up ↑ |
110 112 }
111 113
112 114 static void
113 115 inchild(void (*func)())
114 116 {
115 117 pid_t pid;
116 118
117 119 switch ((pid = fork())) {
118 120 case 0:
119 121 func();
120 - exit(0);
122 + exit(EXIT_SUCCESS);
121 123 case -1:
122 - exit(1);
124 + exit(EXIT_FAILURE);
123 125 default:
124 126 (void) waitpid(pid, NULL, 0);
125 127 return;
126 128 }
127 129
128 130 }
129 131
130 132 int
131 133 main(int argc, char *argv[])
132 134 {
135 + struct rlimit rl = { 0, };
136 +
137 + if (setrlimit(RLIMIT_CORE, &rl) != 0) {
138 + err(EXIT_FAILURE, "failed to disable cores");
139 + }
140 +
133 141 for (selector = 0; selector < 8194; selector++) {
134 142 inchild(resetcs);
135 143 inchild(resetds);
136 144 inchild(resetes);
137 145 inchild(resetfs);
138 146 inchild(resetgs);
139 147 inchild(resetss);
140 148 inchild(badds);
141 149 inchild(bades);
142 150 inchild(badfs);
143 151 inchild(badgs);
144 152 inchild(badss);
145 153 }
146 154
147 - exit(0);
155 + exit(EXIT_SUCCESS);
148 156 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX