aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/kernel/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/kernel/process.c')
-rw-r--r--arch/um/kernel/process.c83
1 files changed, 54 insertions, 29 deletions
diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
index c45a60e9c92d..67acd92c5322 100644
--- a/arch/um/kernel/process.c
+++ b/arch/um/kernel/process.c
@@ -131,7 +131,7 @@ int start_fork_tramp(void *thread_arg, unsigned long temp_stack,
131 return(arg.pid); 131 return(arg.pid);
132} 132}
133 133
134static int ptrace_child(void) 134static int ptrace_child(void *arg)
135{ 135{
136 int ret; 136 int ret;
137 int pid = os_getpid(), ppid = getppid(); 137 int pid = os_getpid(), ppid = getppid();
@@ -160,16 +160,20 @@ static int ptrace_child(void)
160 _exit(ret); 160 _exit(ret);
161} 161}
162 162
163static int start_ptraced_child(void) 163static int start_ptraced_child(void **stack_out)
164{ 164{
165 void *stack;
166 unsigned long sp;
165 int pid, n, status; 167 int pid, n, status;
166 168
167 pid = fork(); 169 stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
168 if(pid == 0) 170 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
169 ptrace_child(); 171 if(stack == MAP_FAILED)
170 172 panic("check_ptrace : mmap failed, errno = %d", errno);
173 sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
174 pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL);
171 if(pid < 0) 175 if(pid < 0)
172 panic("check_ptrace : fork failed, errno = %d", errno); 176 panic("check_ptrace : clone failed, errno = %d", errno);
173 CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); 177 CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
174 if(n < 0) 178 if(n < 0)
175 panic("check_ptrace : wait failed, errno = %d", errno); 179 panic("check_ptrace : wait failed, errno = %d", errno);
@@ -177,6 +181,7 @@ static int start_ptraced_child(void)
177 panic("check_ptrace : expected SIGSTOP, got status = %d", 181 panic("check_ptrace : expected SIGSTOP, got status = %d",
178 status); 182 status);
179 183
184 *stack_out = stack;
180 return(pid); 185 return(pid);
181} 186}
182 187
@@ -184,12 +189,12 @@ static int start_ptraced_child(void)
184 * just avoid using sysemu, not panic, but only if SYSEMU features are broken. 189 * just avoid using sysemu, not panic, but only if SYSEMU features are broken.
185 * So only for SYSEMU features we test mustpanic, while normal host features 190 * So only for SYSEMU features we test mustpanic, while normal host features
186 * must work anyway!*/ 191 * must work anyway!*/
187static int stop_ptraced_child(int pid, int exitcode, int mustexit) 192static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic)
188{ 193{
189 int status, n, ret = 0; 194 int status, n, ret = 0;
190 195
191 if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) 196 if(ptrace(PTRACE_CONT, pid, 0, 0) < 0)
192 panic("stop_ptraced_child : ptrace failed, errno = %d", errno); 197 panic("check_ptrace : ptrace failed, errno = %d", errno);
193 CATCH_EINTR(n = waitpid(pid, &status, 0)); 198 CATCH_EINTR(n = waitpid(pid, &status, 0));
194 if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) { 199 if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) {
195 int exit_with = WEXITSTATUS(status); 200 int exit_with = WEXITSTATUS(status);
@@ -200,24 +205,40 @@ static int stop_ptraced_child(int pid, int exitcode, int mustexit)
200 printk("check_ptrace : child exited with exitcode %d, while " 205 printk("check_ptrace : child exited with exitcode %d, while "
201 "expecting %d; status 0x%x", exit_with, 206 "expecting %d; status 0x%x", exit_with,
202 exitcode, status); 207 exitcode, status);
203 if (mustexit) 208 if (mustpanic)
204 panic("\n"); 209 panic("\n");
205 else 210 else
206 printk("\n"); 211 printk("\n");
207 ret = -1; 212 ret = -1;
208 } 213 }
209 214
215 if(munmap(stack, PAGE_SIZE) < 0)
216 panic("check_ptrace : munmap failed, errno = %d", errno);
210 return ret; 217 return ret;
211} 218}
212 219
213static int force_sysemu_disabled = 0; 220static int force_sysemu_disabled = 0;
214 221
222int ptrace_faultinfo = 1;
223int proc_mm = 1;
224
225static int __init skas0_cmd_param(char *str, int* add)
226{
227 ptrace_faultinfo = proc_mm = 0;
228 return 0;
229}
230
215static int __init nosysemu_cmd_param(char *str, int* add) 231static int __init nosysemu_cmd_param(char *str, int* add)
216{ 232{
217 force_sysemu_disabled = 1; 233 force_sysemu_disabled = 1;
218 return 0; 234 return 0;
219} 235}
220 236
237__uml_setup("skas0", skas0_cmd_param,
238 "skas0\n"
239 " Disables SKAS3 usage, so that SKAS0 is used, unless you \n"
240 " specify mode=tt.\n\n");
241
221__uml_setup("nosysemu", nosysemu_cmd_param, 242__uml_setup("nosysemu", nosysemu_cmd_param,
222 "nosysemu\n" 243 "nosysemu\n"
223 " Turns off syscall emulation patch for ptrace (SYSEMU) on.\n" 244 " Turns off syscall emulation patch for ptrace (SYSEMU) on.\n"
@@ -228,11 +249,12 @@ __uml_setup("nosysemu", nosysemu_cmd_param,
228 249
229static void __init check_sysemu(void) 250static void __init check_sysemu(void)
230{ 251{
252 void *stack;
231 int pid, syscall, n, status, count=0; 253 int pid, syscall, n, status, count=0;
232 254
233 printk("Checking syscall emulation patch for ptrace..."); 255 printk("Checking syscall emulation patch for ptrace...");
234 sysemu_supported = 0; 256 sysemu_supported = 0;
235 pid = start_ptraced_child(); 257 pid = start_ptraced_child(&stack);
236 258
237 if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0) 259 if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0)
238 goto fail; 260 goto fail;
@@ -250,7 +272,7 @@ static void __init check_sysemu(void)
250 panic("check_sysemu : failed to modify system " 272 panic("check_sysemu : failed to modify system "
251 "call return, errno = %d", errno); 273 "call return, errno = %d", errno);
252 274
253 if (stop_ptraced_child(pid, 0, 0) < 0) 275 if (stop_ptraced_child(pid, stack, 0, 0) < 0)
254 goto fail_stopped; 276 goto fail_stopped;
255 277
256 sysemu_supported = 1; 278 sysemu_supported = 1;
@@ -258,7 +280,7 @@ static void __init check_sysemu(void)
258 set_using_sysemu(!force_sysemu_disabled); 280 set_using_sysemu(!force_sysemu_disabled);
259 281
260 printk("Checking advanced syscall emulation patch for ptrace..."); 282 printk("Checking advanced syscall emulation patch for ptrace...");
261 pid = start_ptraced_child(); 283 pid = start_ptraced_child(&stack);
262 while(1){ 284 while(1){
263 count++; 285 count++;
264 if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0) 286 if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0)
@@ -283,7 +305,7 @@ static void __init check_sysemu(void)
283 break; 305 break;
284 } 306 }
285 } 307 }
286 if (stop_ptraced_child(pid, 0, 0) < 0) 308 if (stop_ptraced_child(pid, stack, 0, 0) < 0)
287 goto fail_stopped; 309 goto fail_stopped;
288 310
289 sysemu_supported = 2; 311 sysemu_supported = 2;
@@ -294,17 +316,18 @@ static void __init check_sysemu(void)
294 return; 316 return;
295 317
296fail: 318fail:
297 stop_ptraced_child(pid, 1, 0); 319 stop_ptraced_child(pid, stack, 1, 0);
298fail_stopped: 320fail_stopped:
299 printk("missing\n"); 321 printk("missing\n");
300} 322}
301 323
302void __init check_ptrace(void) 324void __init check_ptrace(void)
303{ 325{
326 void *stack;
304 int pid, syscall, n, status; 327 int pid, syscall, n, status;
305 328
306 printk("Checking that ptrace can change system call numbers..."); 329 printk("Checking that ptrace can change system call numbers...");
307 pid = start_ptraced_child(); 330 pid = start_ptraced_child(&stack);
308 331
309 if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0) 332 if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0)
310 panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno); 333 panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno);
@@ -331,7 +354,7 @@ void __init check_ptrace(void)
331 break; 354 break;
332 } 355 }
333 } 356 }
334 stop_ptraced_child(pid, 0, 1); 357 stop_ptraced_child(pid, stack, 0, 1);
335 printk("OK\n"); 358 printk("OK\n");
336 check_sysemu(); 359 check_sysemu();
337} 360}
@@ -359,22 +382,22 @@ void forward_pending_sigio(int target)
359 kill(target, SIGIO); 382 kill(target, SIGIO);
360} 383}
361 384
362int ptrace_faultinfo = 0;
363int proc_mm = 1;
364
365extern void *__syscall_stub_start, __syscall_stub_end; 385extern void *__syscall_stub_start, __syscall_stub_end;
366 386
367#ifdef UML_CONFIG_MODE_SKAS 387#ifdef UML_CONFIG_MODE_SKAS
388
368static inline void check_skas3_ptrace_support(void) 389static inline void check_skas3_ptrace_support(void)
369{ 390{
370 struct ptrace_faultinfo fi; 391 struct ptrace_faultinfo fi;
392 void *stack;
371 int pid, n; 393 int pid, n;
372 394
373 printf("Checking for the skas3 patch in the host..."); 395 printf("Checking for the skas3 patch in the host...");
374 pid = start_ptraced_child(); 396 pid = start_ptraced_child(&stack);
375 397
376 n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); 398 n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
377 if (n < 0) { 399 if (n < 0) {
400 ptrace_faultinfo = 0;
378 if(errno == EIO) 401 if(errno == EIO)
379 printf("not found\n"); 402 printf("not found\n");
380 else { 403 else {
@@ -382,12 +405,14 @@ static inline void check_skas3_ptrace_support(void)
382 } 405 }
383 } 406 }
384 else { 407 else {
385 ptrace_faultinfo = 1; 408 if (!ptrace_faultinfo)
386 printf("found\n"); 409 printf("found but disabled on command line\n");
410 else
411 printf("found\n");
387 } 412 }
388 413
389 init_registers(pid); 414 init_registers(pid);
390 stop_ptraced_child(pid, 1, 1); 415 stop_ptraced_child(pid, stack, 1, 1);
391} 416}
392 417
393int can_do_skas(void) 418int can_do_skas(void)
@@ -396,13 +421,13 @@ int can_do_skas(void)
396 if (os_access("/proc/mm", OS_ACC_W_OK) < 0) { 421 if (os_access("/proc/mm", OS_ACC_W_OK) < 0) {
397 proc_mm = 0; 422 proc_mm = 0;
398 printf("not found\n"); 423 printf("not found\n");
399 goto out; 424 } else {
400 } 425 if (!proc_mm)
401 else { 426 printf("found but disabled on command line\n");
402 printf("found\n"); 427 else
428 printf("found\n");
403 } 429 }
404 430
405out:
406 check_skas3_ptrace_support(); 431 check_skas3_ptrace_support();
407 return 1; 432 return 1;
408} 433}