Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* By Ross Biro 1/23/92 */ |
| 2 | /* |
| 3 | * Pentium III FXSR, SSE support |
| 4 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
| 5 | */ |
| 6 | |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/sched.h> |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/errno.h> |
| 12 | #include <linux/ptrace.h> |
| 13 | #include <linux/user.h> |
| 14 | #include <linux/security.h> |
| 15 | #include <linux/audit.h> |
| 16 | #include <linux/seccomp.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 17 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include <asm/uaccess.h> |
| 20 | #include <asm/pgtable.h> |
| 21 | #include <asm/system.h> |
| 22 | #include <asm/processor.h> |
| 23 | #include <asm/i387.h> |
| 24 | #include <asm/debugreg.h> |
| 25 | #include <asm/ldt.h> |
| 26 | #include <asm/desc.h> |
| 27 | |
| 28 | /* |
| 29 | * does not yet catch signals sent when the child dies. |
| 30 | * in exit.c or in signal.c. |
| 31 | */ |
| 32 | |
Chuck Ebbert | 9f155b9 | 2006-01-05 23:11:29 -0500 | [diff] [blame] | 33 | /* |
| 34 | * Determines which flags the user has access to [1 = access, 0 = no access]. |
Chuck Ebbert | 3c36c6a | 2006-03-23 02:59:39 -0800 | [diff] [blame] | 35 | * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), NT(14), IOPL(12-13), IF(9). |
Chuck Ebbert | 9f155b9 | 2006-01-05 23:11:29 -0500 | [diff] [blame] | 36 | * Also masks reserved bits (31-22, 15, 5, 3, 1). |
| 37 | */ |
Chuck Ebbert | 3c36c6a | 2006-03-23 02:59:39 -0800 | [diff] [blame] | 38 | #define FLAG_MASK 0x00050dd5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 40 | static long *pt_regs_access(struct pt_regs *regs, unsigned long regno) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 42 | BUILD_BUG_ON(offsetof(struct pt_regs, bx) != 0); |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 43 | if (regno > FS) |
| 44 | --regno; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 45 | return ®s->bx + regno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static int putreg(struct task_struct *child, |
| 49 | unsigned long regno, unsigned long value) |
| 50 | { |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 51 | struct pt_regs *regs = task_pt_regs(child); |
| 52 | regno >>= 2; |
| 53 | switch (regno) { |
Roland McGrath | 9e714be | 2008-01-30 13:30:58 +0100 | [diff] [blame^] | 54 | case GS: |
| 55 | if (value && (value & 3) != 3) |
| 56 | return -EIO; |
| 57 | child->thread.gs = value; |
| 58 | return 0; |
| 59 | case DS: |
| 60 | case ES: |
| 61 | case FS: |
| 62 | if (value && (value & 3) != 3) |
| 63 | return -EIO; |
| 64 | value &= 0xffff; |
| 65 | break; |
| 66 | case SS: |
| 67 | case CS: |
| 68 | if ((value & 3) != 3) |
| 69 | return -EIO; |
| 70 | value &= 0xffff; |
| 71 | break; |
| 72 | case EFL: |
| 73 | value &= FLAG_MASK; |
| 74 | /* |
| 75 | * If the user value contains TF, mark that |
| 76 | * it was not "us" (the debugger) that set it. |
| 77 | * If not, make sure it stays set if we had. |
| 78 | */ |
| 79 | if (value & X86_EFLAGS_TF) |
| 80 | clear_tsk_thread_flag(child, TIF_FORCED_TF); |
| 81 | else if (test_tsk_thread_flag(child, TIF_FORCED_TF)) |
| 82 | value |= X86_EFLAGS_TF; |
| 83 | value |= regs->flags & ~FLAG_MASK; |
| 84 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 86 | *pt_regs_access(regs, regno) = value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | return 0; |
| 88 | } |
| 89 | |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 90 | static unsigned long getreg(struct task_struct *child, unsigned long regno) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 92 | struct pt_regs *regs = task_pt_regs(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | unsigned long retval = ~0UL; |
| 94 | |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 95 | regno >>= 2; |
| 96 | switch (regno) { |
Roland McGrath | 9e714be | 2008-01-30 13:30:58 +0100 | [diff] [blame^] | 97 | case EFL: |
| 98 | /* |
| 99 | * If the debugger set TF, hide it from the readout. |
| 100 | */ |
| 101 | retval = regs->flags; |
| 102 | if (test_tsk_thread_flag(child, TIF_FORCED_TF)) |
| 103 | retval &= ~X86_EFLAGS_TF; |
| 104 | break; |
| 105 | case GS: |
| 106 | retval = child->thread.gs; |
| 107 | break; |
| 108 | case DS: |
| 109 | case ES: |
| 110 | case FS: |
| 111 | case SS: |
| 112 | case CS: |
| 113 | retval = 0xffff; |
| 114 | /* fall through */ |
| 115 | default: |
| 116 | retval &= *pt_regs_access(regs, regno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | return retval; |
| 119 | } |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | /* |
Roland McGrath | d9771e8 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 122 | * This function is trivial and will be inlined by the compiler. |
| 123 | * Having it separates the implementation details of debug |
| 124 | * registers from the interface details of ptrace. |
| 125 | */ |
| 126 | static unsigned long ptrace_get_debugreg(struct task_struct *child, int n) |
| 127 | { |
| 128 | return child->thread.debugreg[n]; |
| 129 | } |
| 130 | |
| 131 | static int ptrace_set_debugreg(struct task_struct *child, |
| 132 | int n, unsigned long data) |
| 133 | { |
| 134 | if (unlikely(n == 4 || n == 5)) |
| 135 | return -EIO; |
| 136 | |
| 137 | if (n < 4 && unlikely(data >= TASK_SIZE - 3)) |
| 138 | return -EIO; |
| 139 | |
| 140 | if (n == 7) { |
| 141 | /* |
| 142 | * Sanity-check data. Take one half-byte at once with |
| 143 | * check = (val >> (16 + 4*i)) & 0xf. It contains the |
| 144 | * R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits |
| 145 | * 2 and 3 are LENi. Given a list of invalid values, |
| 146 | * we do mask |= 1 << invalid_value, so that |
| 147 | * (mask >> check) & 1 is a correct test for invalid |
| 148 | * values. |
| 149 | * |
| 150 | * R/Wi contains the type of the breakpoint / |
| 151 | * watchpoint, LENi contains the length of the watched |
| 152 | * data in the watchpoint case. |
| 153 | * |
| 154 | * The invalid values are: |
| 155 | * - LENi == 0x10 (undefined), so mask |= 0x0f00. |
| 156 | * - R/Wi == 0x10 (break on I/O reads or writes), so |
| 157 | * mask |= 0x4444. |
| 158 | * - R/Wi == 0x00 && LENi != 0x00, so we have mask |= |
| 159 | * 0x1110. |
| 160 | * |
| 161 | * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54. |
| 162 | * |
| 163 | * See the Intel Manual "System Programming Guide", |
| 164 | * 15.2.4 |
| 165 | * |
| 166 | * Note that LENi == 0x10 is defined on x86_64 in long |
| 167 | * mode (i.e. even for 32-bit userspace software, but |
| 168 | * 64-bit kernel), so the x86_64 mask value is 0x5454. |
| 169 | * See the AMD manual no. 24593 (AMD64 System Programming) |
| 170 | */ |
| 171 | int i; |
| 172 | data &= ~DR_CONTROL_RESERVED; |
| 173 | for (i = 0; i < 4; i++) |
| 174 | if ((0x5f54 >> ((data >> (16 + 4*i)) & 0xf)) & 1) |
| 175 | return -EIO; |
| 176 | if (data) |
| 177 | set_tsk_thread_flag(child, TIF_DEBUG); |
| 178 | else |
| 179 | clear_tsk_thread_flag(child, TIF_DEBUG); |
| 180 | } |
| 181 | |
| 182 | child->thread.debugreg[n] = data; |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | * Called by kernel/ptrace.c when detaching.. |
| 189 | * |
| 190 | * Make sure the single step bit is not set. |
| 191 | */ |
| 192 | void ptrace_disable(struct task_struct *child) |
Roland McGrath | 9e714be | 2008-01-30 13:30:58 +0100 | [diff] [blame^] | 193 | { |
Roland McGrath | 7f23234 | 2008-01-30 13:30:48 +0100 | [diff] [blame] | 194 | user_disable_single_step(child); |
Bodo Stroesser | ab1c23c | 2005-09-03 15:57:21 -0700 | [diff] [blame] | 195 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 198 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | struct user * dummy = NULL; |
| 201 | int i, ret; |
| 202 | unsigned long __user *datap = (unsigned long __user *)data; |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | switch (request) { |
| 205 | /* when I and D space are separate, these will need to be fixed. */ |
Roland McGrath | 9e714be | 2008-01-30 13:30:58 +0100 | [diff] [blame^] | 206 | case PTRACE_PEEKTEXT: /* read word at location addr. */ |
Alexey Dobriyan | 7664732 | 2007-07-17 04:03:43 -0700 | [diff] [blame] | 207 | case PTRACE_PEEKDATA: |
| 208 | ret = generic_ptrace_peekdata(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /* read the word at location addr in the USER area. */ |
| 212 | case PTRACE_PEEKUSR: { |
| 213 | unsigned long tmp; |
| 214 | |
| 215 | ret = -EIO; |
Roland McGrath | 9e714be | 2008-01-30 13:30:58 +0100 | [diff] [blame^] | 216 | if ((addr & 3) || addr < 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | addr > sizeof(struct user) - 3) |
| 218 | break; |
| 219 | |
| 220 | tmp = 0; /* Default return condition */ |
| 221 | if(addr < FRAME_SIZE*sizeof(long)) |
| 222 | tmp = getreg(child, addr); |
| 223 | if(addr >= (long) &dummy->u_debugreg[0] && |
| 224 | addr <= (long) &dummy->u_debugreg[7]){ |
| 225 | addr -= (long) &dummy->u_debugreg[0]; |
| 226 | addr = addr >> 2; |
Roland McGrath | d9771e8 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 227 | tmp = ptrace_get_debugreg(child, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | ret = put_user(tmp, datap); |
| 230 | break; |
| 231 | } |
| 232 | |
| 233 | /* when I and D space are separate, this will have to be fixed. */ |
| 234 | case PTRACE_POKETEXT: /* write the word at location addr. */ |
| 235 | case PTRACE_POKEDATA: |
Alexey Dobriyan | f284ce7 | 2007-07-17 04:03:44 -0700 | [diff] [blame] | 236 | ret = generic_ptrace_pokedata(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | break; |
| 238 | |
| 239 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ |
| 240 | ret = -EIO; |
Roland McGrath | 9e714be | 2008-01-30 13:30:58 +0100 | [diff] [blame^] | 241 | if ((addr & 3) || addr < 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | addr > sizeof(struct user) - 3) |
| 243 | break; |
| 244 | |
| 245 | if (addr < FRAME_SIZE*sizeof(long)) { |
| 246 | ret = putreg(child, addr, data); |
| 247 | break; |
| 248 | } |
| 249 | /* We need to be very careful here. We implicitly |
| 250 | want to modify a portion of the task_struct, and we |
| 251 | have to be selective about what portions we allow someone |
| 252 | to modify. */ |
| 253 | |
| 254 | ret = -EIO; |
| 255 | if(addr >= (long) &dummy->u_debugreg[0] && |
| 256 | addr <= (long) &dummy->u_debugreg[7]){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | addr -= (long) &dummy->u_debugreg; |
| 258 | addr = addr >> 2; |
Roland McGrath | d9771e8 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 259 | ret = ptrace_set_debugreg(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | break; |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | case PTRACE_GETREGS: { /* Get all gp regs from the child. */ |
| 264 | if (!access_ok(VERIFY_WRITE, datap, FRAME_SIZE*sizeof(long))) { |
| 265 | ret = -EIO; |
| 266 | break; |
| 267 | } |
| 268 | for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) { |
| 269 | __put_user(getreg(child, i), datap); |
| 270 | datap++; |
| 271 | } |
| 272 | ret = 0; |
| 273 | break; |
| 274 | } |
| 275 | |
| 276 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ |
| 277 | unsigned long tmp; |
| 278 | if (!access_ok(VERIFY_READ, datap, FRAME_SIZE*sizeof(long))) { |
| 279 | ret = -EIO; |
| 280 | break; |
| 281 | } |
| 282 | for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) { |
| 283 | __get_user(tmp, datap); |
| 284 | putreg(child, i, tmp); |
| 285 | datap++; |
| 286 | } |
| 287 | ret = 0; |
| 288 | break; |
| 289 | } |
| 290 | |
| 291 | case PTRACE_GETFPREGS: { /* Get the child FPU state. */ |
| 292 | if (!access_ok(VERIFY_WRITE, datap, |
| 293 | sizeof(struct user_i387_struct))) { |
| 294 | ret = -EIO; |
| 295 | break; |
| 296 | } |
| 297 | ret = 0; |
| 298 | if (!tsk_used_math(child)) |
| 299 | init_fpu(child); |
| 300 | get_fpregs((struct user_i387_struct __user *)data, child); |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | case PTRACE_SETFPREGS: { /* Set the child FPU state. */ |
| 305 | if (!access_ok(VERIFY_READ, datap, |
| 306 | sizeof(struct user_i387_struct))) { |
| 307 | ret = -EIO; |
| 308 | break; |
| 309 | } |
| 310 | set_stopped_child_used_math(child); |
| 311 | set_fpregs(child, (struct user_i387_struct __user *)data); |
| 312 | ret = 0; |
| 313 | break; |
| 314 | } |
| 315 | |
| 316 | case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */ |
| 317 | if (!access_ok(VERIFY_WRITE, datap, |
| 318 | sizeof(struct user_fxsr_struct))) { |
| 319 | ret = -EIO; |
| 320 | break; |
| 321 | } |
| 322 | if (!tsk_used_math(child)) |
| 323 | init_fpu(child); |
| 324 | ret = get_fpxregs((struct user_fxsr_struct __user *)data, child); |
| 325 | break; |
| 326 | } |
| 327 | |
| 328 | case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */ |
| 329 | if (!access_ok(VERIFY_READ, datap, |
| 330 | sizeof(struct user_fxsr_struct))) { |
| 331 | ret = -EIO; |
| 332 | break; |
| 333 | } |
| 334 | set_stopped_child_used_math(child); |
| 335 | ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data); |
| 336 | break; |
| 337 | } |
| 338 | |
| 339 | case PTRACE_GET_THREAD_AREA: |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 340 | if (addr < 0) |
| 341 | return -EIO; |
| 342 | ret = do_get_thread_area(child, addr, |
| 343 | (struct user_desc __user *) data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | break; |
| 345 | |
| 346 | case PTRACE_SET_THREAD_AREA: |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 347 | if (addr < 0) |
| 348 | return -EIO; |
| 349 | ret = do_set_thread_area(child, addr, |
| 350 | (struct user_desc __user *) data, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | break; |
| 352 | |
| 353 | default: |
| 354 | ret = ptrace_request(child, request, addr, data); |
| 355 | break; |
| 356 | } |
Roland McGrath | d9771e8 | 2008-01-30 13:30:52 +0100 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code) |
| 362 | { |
| 363 | struct siginfo info; |
| 364 | |
| 365 | tsk->thread.trap_no = 1; |
| 366 | tsk->thread.error_code = error_code; |
| 367 | |
| 368 | memset(&info, 0, sizeof(info)); |
| 369 | info.si_signo = SIGTRAP; |
| 370 | info.si_code = TRAP_BRKPT; |
| 371 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 372 | /* User-mode ip? */ |
| 373 | info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 375 | /* Send us the fake SIGTRAP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | force_sig_info(SIGTRAP, &info, tsk); |
| 377 | } |
| 378 | |
| 379 | /* notification of system call entry/exit |
| 380 | * - triggered by current->work.syscall_trace |
| 381 | */ |
| 382 | __attribute__((regparm(3))) |
Laurent Vivier | ed75e8d | 2005-09-03 15:57:18 -0700 | [diff] [blame] | 383 | int do_syscall_trace(struct pt_regs *regs, int entryexit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 385 | int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU); |
| 386 | /* |
| 387 | * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall |
| 388 | * interception |
| 389 | */ |
Bodo Stroesser | 1b38f00 | 2005-09-03 15:57:20 -0700 | [diff] [blame] | 390 | int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP); |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 391 | int ret = 0; |
Bodo Stroesser | 1b38f00 | 2005-09-03 15:57:20 -0700 | [diff] [blame] | 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | /* do the secure computing check first */ |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 394 | if (!entryexit) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 395 | secure_computing(regs->orig_ax); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Bodo Stroesser | ab1c23c | 2005-09-03 15:57:21 -0700 | [diff] [blame] | 397 | if (unlikely(current->audit_context)) { |
| 398 | if (entryexit) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 399 | audit_syscall_exit(AUDITSC_RESULT(regs->ax), |
| 400 | regs->ax); |
Bodo Stroesser | ab1c23c | 2005-09-03 15:57:21 -0700 | [diff] [blame] | 401 | /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only |
| 402 | * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is |
| 403 | * not used, entry.S will call us only on syscall exit, not |
| 404 | * entry; so when TIF_SYSCALL_AUDIT is used we must avoid |
| 405 | * calling send_sigtrap() on syscall entry. |
| 406 | * |
| 407 | * Note that when PTRACE_SYSEMU_SINGLESTEP is used, |
| 408 | * is_singlestep is false, despite his name, so we will still do |
| 409 | * the correct thing. |
| 410 | */ |
| 411 | else if (is_singlestep) |
| 412 | goto out; |
| 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | if (!(current->ptrace & PT_PTRACED)) |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 416 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Bodo Stroesser | 1b38f00 | 2005-09-03 15:57:20 -0700 | [diff] [blame] | 418 | /* If a process stops on the 1st tracepoint with SYSCALL_TRACE |
| 419 | * and then is resumed with SYSEMU_SINGLESTEP, it will come in |
| 420 | * here. We have to check this and return */ |
| 421 | if (is_sysemu && entryexit) |
| 422 | return 0; |
Laurent Vivier | ed75e8d | 2005-09-03 15:57:18 -0700 | [diff] [blame] | 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /* Fake a debug trap */ |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 425 | if (is_singlestep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | send_sigtrap(current, regs, 0); |
| 427 | |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 428 | if (!test_thread_flag(TIF_SYSCALL_TRACE) && !is_sysemu) |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 429 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | /* the 0x80 provides a way for the tracing parent to distinguish |
| 432 | between a syscall stop and SIGTRAP delivery */ |
Laurent Vivier | ed75e8d | 2005-09-03 15:57:18 -0700 | [diff] [blame] | 433 | /* Note that the debugger could change the result of test_thread_flag!*/ |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 434 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80:0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * this isn't the same as continuing with a signal, but it will do |
| 438 | * for normal use. strace only continues with a signal if the |
| 439 | * stopping signal is not SIGTRAP. -brl |
| 440 | */ |
| 441 | if (current->exit_code) { |
| 442 | send_sig(current->exit_code, current, 1); |
| 443 | current->exit_code = 0; |
| 444 | } |
Laurent Vivier | ed75e8d | 2005-09-03 15:57:18 -0700 | [diff] [blame] | 445 | ret = is_sysemu; |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 446 | out: |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 447 | if (unlikely(current->audit_context) && !entryexit) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 448 | audit_syscall_entry(AUDIT_ARCH_I386, regs->orig_ax, |
| 449 | regs->bx, regs->cx, regs->dx, regs->si); |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 450 | if (ret == 0) |
| 451 | return 0; |
| 452 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 453 | regs->orig_ax = -1; /* force skip of syscall restarting */ |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 454 | if (unlikely(current->audit_context)) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 455 | audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax); |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 456 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |