Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) |
| 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
| 6 | #include <stdio.h> |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdarg.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <unistd.h> |
| 12 | #include <signal.h> |
| 13 | #include <sched.h> |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 14 | #include <fcntl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <setjmp.h> |
| 17 | #include <sys/time.h> |
| 18 | #include <sys/wait.h> |
| 19 | #include <sys/mman.h> |
| 20 | #include <asm/unistd.h> |
| 21 | #include <asm/page.h> |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 22 | #include <sys/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "user_util.h" |
| 24 | #include "kern_util.h" |
| 25 | #include "user.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "signal_kern.h" |
| 27 | #include "signal_user.h" |
| 28 | #include "sysdep/ptrace.h" |
| 29 | #include "sysdep/sigcontext.h" |
| 30 | #include "irq_user.h" |
| 31 | #include "ptrace_user.h" |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 32 | #include "mem_user.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "time_user.h" |
| 34 | #include "init.h" |
| 35 | #include "os.h" |
| 36 | #include "uml-config.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include "choose-mode.h" |
| 38 | #include "mode.h" |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 39 | #include "tempfile.h" |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 40 | #include "kern_constants.h" |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #ifdef UML_CONFIG_MODE_SKAS |
| 43 | #include "skas.h" |
| 44 | #include "skas_ptrace.h" |
| 45 | #include "registers.h" |
| 46 | #endif |
| 47 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 48 | static int ptrace_child(void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | int ret; |
| 51 | int pid = os_getpid(), ppid = getppid(); |
| 52 | int sc_result; |
| 53 | |
| 54 | if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){ |
| 55 | perror("ptrace"); |
| 56 | os_kill_process(pid, 0); |
| 57 | } |
| 58 | os_stop_process(pid); |
| 59 | |
| 60 | /*This syscall will be intercepted by the parent. Don't call more than |
| 61 | * once, please.*/ |
| 62 | sc_result = os_getpid(); |
| 63 | |
| 64 | if (sc_result == pid) |
| 65 | ret = 1; /*Nothing modified by the parent, we are running |
| 66 | normally.*/ |
| 67 | else if (sc_result == ppid) |
| 68 | ret = 0; /*Expected in check_ptrace and check_sysemu when they |
| 69 | succeed in modifying the stack frame*/ |
| 70 | else |
| 71 | ret = 2; /*Serious trouble! This could be caused by a bug in |
| 72 | host 2.6 SKAS3/2.6 patch before release -V6, together |
| 73 | with a bug in the UML code itself.*/ |
| 74 | _exit(ret); |
| 75 | } |
| 76 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 77 | static int start_ptraced_child(void **stack_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 79 | void *stack; |
| 80 | unsigned long sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | int pid, n, status; |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 82 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 83 | stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, |
| 84 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 85 | if(stack == MAP_FAILED) |
| 86 | panic("check_ptrace : mmap failed, errno = %d", errno); |
| 87 | sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *); |
| 88 | pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | if(pid < 0) |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 90 | panic("start_ptraced_child : clone failed, errno = %d", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
| 92 | if(n < 0) |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 93 | panic("check_ptrace : clone failed, errno = %d", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) |
| 95 | panic("check_ptrace : expected SIGSTOP, got status = %d", |
| 96 | status); |
| 97 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 98 | *stack_out = stack; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | return(pid); |
| 100 | } |
| 101 | |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 102 | /* When testing for SYSEMU support, if it is one of the broken versions, we |
| 103 | * must just avoid using sysemu, not panic, but only if SYSEMU features are |
| 104 | * broken. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | * So only for SYSEMU features we test mustpanic, while normal host features |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 106 | * must work anyway! |
| 107 | */ |
| 108 | static int stop_ptraced_child(int pid, void *stack, int exitcode, |
| 109 | int mustpanic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | int status, n, ret = 0; |
| 112 | |
| 113 | if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 114 | panic("check_ptrace : ptrace failed, errno = %d", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | CATCH_EINTR(n = waitpid(pid, &status, 0)); |
| 116 | if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) { |
| 117 | int exit_with = WEXITSTATUS(status); |
| 118 | if (exit_with == 2) |
| 119 | printk("check_ptrace : child exited with status 2. " |
| 120 | "Serious trouble happening! Try updating your " |
| 121 | "host skas patch!\nDisabling SYSEMU support."); |
| 122 | printk("check_ptrace : child exited with exitcode %d, while " |
| 123 | "expecting %d; status 0x%x", exit_with, |
| 124 | exitcode, status); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 125 | if (mustpanic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | panic("\n"); |
| 127 | else |
| 128 | printk("\n"); |
| 129 | ret = -1; |
| 130 | } |
| 131 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 132 | if(munmap(stack, PAGE_SIZE) < 0) |
| 133 | panic("check_ptrace : munmap failed, errno = %d", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return ret; |
| 135 | } |
| 136 | |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 137 | int ptrace_faultinfo = 1; |
| 138 | int proc_mm = 1; |
| 139 | |
| 140 | static int __init skas0_cmd_param(char *str, int* add) |
| 141 | { |
| 142 | ptrace_faultinfo = proc_mm = 0; |
| 143 | return 0; |
| 144 | } |
| 145 | |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 146 | __uml_setup("skas0", skas0_cmd_param, |
| 147 | "skas0\n" |
| 148 | " Disables SKAS3 usage, so that SKAS0 is used, unless \n" |
| 149 | " you specify mode=tt.\n\n"); |
| 150 | |
| 151 | static int force_sysemu_disabled = 0; |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | static int __init nosysemu_cmd_param(char *str, int* add) |
| 154 | { |
| 155 | force_sysemu_disabled = 1; |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | __uml_setup("nosysemu", nosysemu_cmd_param, |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 160 | "nosysemu\n" |
| 161 | " Turns off syscall emulation patch for ptrace (SYSEMU) on.\n" |
| 162 | " SYSEMU is a performance-patch introduced by Laurent Vivier. It changes\n" |
| 163 | " behaviour of ptrace() and helps reducing host context switch rate.\n" |
| 164 | " To make it working, you need a kernel patch for your host, too.\n" |
| 165 | " See http://perso.wanadoo.fr/laurent.vivier/UML/ for further \n" |
| 166 | " information.\n\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | static void __init check_sysemu(void) |
| 169 | { |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 170 | void *stack; |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 171 | int pid, n, status, count=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | printk("Checking syscall emulation patch for ptrace..."); |
| 174 | sysemu_supported = 0; |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 175 | pid = start_ptraced_child(&stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0) |
| 178 | goto fail; |
| 179 | |
| 180 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
| 181 | if (n < 0) |
| 182 | panic("check_sysemu : wait failed, errno = %d", errno); |
| 183 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP)) |
| 184 | panic("check_sysemu : expected SIGTRAP, " |
| 185 | "got status = %d", status); |
| 186 | |
| 187 | n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, |
| 188 | os_getpid()); |
| 189 | if(n < 0) |
| 190 | panic("check_sysemu : failed to modify system " |
| 191 | "call return, errno = %d", errno); |
| 192 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 193 | if (stop_ptraced_child(pid, stack, 0, 0) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | goto fail_stopped; |
| 195 | |
| 196 | sysemu_supported = 1; |
| 197 | printk("OK\n"); |
| 198 | set_using_sysemu(!force_sysemu_disabled); |
| 199 | |
| 200 | printk("Checking advanced syscall emulation patch for ptrace..."); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 201 | pid = start_ptraced_child(&stack); |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 202 | |
| 203 | if(ptrace(PTRACE_OLDSETOPTIONS, pid, 0, |
| 204 | (void *) PTRACE_O_TRACESYSGOOD) < 0) |
| 205 | panic("check_ptrace: PTRACE_OLDSETOPTIONS failed, errno = %d", |
| 206 | errno); |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | while(1){ |
| 209 | count++; |
| 210 | if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0) |
| 211 | goto fail; |
| 212 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
| 213 | if(n < 0) |
| 214 | panic("check_ptrace : wait failed, errno = %d", errno); |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 215 | if(WIFSTOPPED(status) && (WSTOPSIG(status) == (SIGTRAP|0x80))){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | if (!count) |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 217 | panic("check_ptrace : SYSEMU_SINGLESTEP " |
| 218 | "doesn't singlestep"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, |
| 220 | os_getpid()); |
| 221 | if(n < 0) |
| 222 | panic("check_sysemu : failed to modify system " |
| 223 | "call return, errno = %d", errno); |
| 224 | break; |
| 225 | } |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 226 | else if(WIFSTOPPED(status) && (WSTOPSIG(status) == SIGTRAP)) |
| 227 | count++; |
| 228 | else |
| 229 | panic("check_ptrace : expected SIGTRAP or " |
| 230 | "(SIGTRAP|0x80), got status = %d", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 232 | if (stop_ptraced_child(pid, stack, 0, 0) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | goto fail_stopped; |
| 234 | |
| 235 | sysemu_supported = 2; |
| 236 | printk("OK\n"); |
| 237 | |
| 238 | if ( !force_sysemu_disabled ) |
| 239 | set_using_sysemu(sysemu_supported); |
| 240 | return; |
| 241 | |
| 242 | fail: |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 243 | stop_ptraced_child(pid, stack, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | fail_stopped: |
| 245 | printk("missing\n"); |
| 246 | } |
| 247 | |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 248 | static void __init check_ptrace(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 250 | void *stack; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | int pid, syscall, n, status; |
| 252 | |
| 253 | printk("Checking that ptrace can change system call numbers..."); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 254 | pid = start_ptraced_child(&stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 256 | if(ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0) |
| 257 | panic("check_ptrace: PTRACE_OLDSETOPTIONS failed, errno = %d", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | while(1){ |
| 260 | if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 261 | panic("check_ptrace : ptrace failed, errno = %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | errno); |
| 263 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
| 264 | if(n < 0) |
| 265 | panic("check_ptrace : wait failed, errno = %d", errno); |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 266 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != (SIGTRAP|0x80))) |
| 267 | panic("check_ptrace : expected (SIGTRAP|0x80), " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | "got status = %d", status); |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | syscall = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_NR_OFFSET, |
| 271 | 0); |
| 272 | if(syscall == __NR_getpid){ |
| 273 | n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET, |
| 274 | __NR_getppid); |
| 275 | if(n < 0) |
| 276 | panic("check_ptrace : failed to modify system " |
| 277 | "call, errno = %d", errno); |
| 278 | break; |
| 279 | } |
| 280 | } |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 281 | stop_ptraced_child(pid, stack, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | printk("OK\n"); |
| 283 | check_sysemu(); |
| 284 | } |
| 285 | |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 286 | extern int create_tmp_file(unsigned long len); |
| 287 | |
| 288 | static void check_tmpexec(void) |
| 289 | { |
| 290 | void *addr; |
| 291 | int err, fd = create_tmp_file(UM_KERN_PAGE_SIZE); |
| 292 | |
| 293 | addr = mmap(NULL, UM_KERN_PAGE_SIZE, |
| 294 | PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); |
| 295 | printf("Checking PROT_EXEC mmap in /tmp..."); |
| 296 | fflush(stdout); |
| 297 | if(addr == MAP_FAILED){ |
| 298 | err = errno; |
| 299 | perror("failed"); |
| 300 | if(err == EPERM) |
| 301 | printf("/tmp must be not mounted noexec\n"); |
| 302 | exit(1); |
| 303 | } |
| 304 | printf("OK\n"); |
| 305 | munmap(addr, UM_KERN_PAGE_SIZE); |
| 306 | |
| 307 | close(fd); |
| 308 | } |
| 309 | |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 310 | void os_early_checks(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 312 | check_ptrace(); |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 313 | |
| 314 | /* Need to check this early because mmapping happens before the |
| 315 | * kernel is running. |
| 316 | */ |
| 317 | check_tmpexec(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Bodo Stroesser | d9838d8 | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 320 | static int __init noprocmm_cmd_param(char *str, int* add) |
| 321 | { |
| 322 | proc_mm = 0; |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | __uml_setup("noprocmm", noprocmm_cmd_param, |
| 327 | "noprocmm\n" |
| 328 | " Turns off usage of /proc/mm, even if host supports it.\n" |
| 329 | " To support /proc/mm, the host needs to be patched using\n" |
| 330 | " the current skas3 patch.\n\n"); |
| 331 | |
| 332 | static int __init noptracefaultinfo_cmd_param(char *str, int* add) |
| 333 | { |
| 334 | ptrace_faultinfo = 0; |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | __uml_setup("noptracefaultinfo", noptracefaultinfo_cmd_param, |
| 339 | "noptracefaultinfo\n" |
| 340 | " Turns off usage of PTRACE_FAULTINFO, even if host supports\n" |
| 341 | " it. To support PTRACE_FAULTINFO, the host needs to be patched\n" |
| 342 | " using the current skas3 patch.\n\n"); |
| 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | #ifdef UML_CONFIG_MODE_SKAS |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 345 | static inline void check_skas3_ptrace_support(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
| 347 | struct ptrace_faultinfo fi; |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 348 | void *stack; |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 349 | int pid, n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | printf("Checking for the skas3 patch in the host..."); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 352 | pid = start_ptraced_child(&stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); |
| 355 | if (n < 0) { |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 356 | ptrace_faultinfo = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | if(errno == EIO) |
| 358 | printf("not found\n"); |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 359 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | perror("not found"); |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 361 | } |
| 362 | else { |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 363 | if (!ptrace_faultinfo) |
| 364 | printf("found but disabled on command line\n"); |
| 365 | else |
| 366 | printf("found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | init_registers(pid); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 370 | stop_ptraced_child(pid, stack, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | int can_do_skas(void) |
| 374 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | printf("Checking for /proc/mm..."); |
| 376 | if (os_access("/proc/mm", OS_ACC_W_OK) < 0) { |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 377 | proc_mm = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | printf("not found\n"); |
Gennady Sharapov | 60d339f6 | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 379 | } |
| 380 | else { |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 381 | if (!proc_mm) |
| 382 | printf("found but disabled on command line\n"); |
| 383 | else |
| 384 | printf("found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 387 | check_skas3_ptrace_support(); |
| 388 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | #else |
| 391 | int can_do_skas(void) |
| 392 | { |
| 393 | return(0); |
| 394 | } |
| 395 | #endif |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 396 | |
| 397 | int have_devanon = 0; |
| 398 | |
| 399 | void check_devanon(void) |
| 400 | { |
| 401 | int fd; |
| 402 | |
| 403 | printk("Checking for /dev/anon on the host..."); |
| 404 | fd = open("/dev/anon", O_RDWR); |
| 405 | if(fd < 0){ |
| 406 | printk("Not available (open failed with errno %d)\n", errno); |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | printk("OK\n"); |
| 411 | have_devanon = 1; |
| 412 | } |
| 413 | |
| 414 | int __init parse_iomem(char *str, int *add) |
| 415 | { |
| 416 | struct iomem_region *new; |
| 417 | struct uml_stat buf; |
| 418 | char *file, *driver; |
| 419 | int fd, err, size; |
| 420 | |
| 421 | driver = str; |
| 422 | file = strchr(str,','); |
| 423 | if(file == NULL){ |
| 424 | printf("parse_iomem : failed to parse iomem\n"); |
| 425 | goto out; |
| 426 | } |
| 427 | *file = '\0'; |
| 428 | file++; |
| 429 | fd = os_open_file(file, of_rdwr(OPENFLAGS()), 0); |
| 430 | if(fd < 0){ |
| 431 | os_print_error(fd, "parse_iomem - Couldn't open io file"); |
| 432 | goto out; |
| 433 | } |
| 434 | |
| 435 | err = os_stat_fd(fd, &buf); |
| 436 | if(err < 0){ |
| 437 | os_print_error(err, "parse_iomem - cannot stat_fd file"); |
| 438 | goto out_close; |
| 439 | } |
| 440 | |
| 441 | new = malloc(sizeof(*new)); |
| 442 | if(new == NULL){ |
| 443 | perror("Couldn't allocate iomem_region struct"); |
| 444 | goto out_close; |
| 445 | } |
| 446 | |
| 447 | size = (buf.ust_size + UM_KERN_PAGE_SIZE) & ~(UM_KERN_PAGE_SIZE - 1); |
| 448 | |
| 449 | *new = ((struct iomem_region) { .next = iomem_regions, |
| 450 | .driver = driver, |
| 451 | .fd = fd, |
| 452 | .size = size, |
| 453 | .phys = 0, |
| 454 | .virt = 0 }); |
| 455 | iomem_regions = new; |
| 456 | iomem_size += new->size + UM_KERN_PAGE_SIZE; |
| 457 | |
| 458 | return(0); |
| 459 | out_close: |
| 460 | os_close_file(fd); |
| 461 | out: |
| 462 | return(1); |
| 463 | } |
| 464 | |