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 | { |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame^] | 42 | BUILD_BUG_ON(offsetof(struct pt_regs, ebx) != 0); |
| 43 | if (regno > FS) |
| 44 | --regno; |
| 45 | return ®s->ebx + 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) { |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 54 | case GS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | if (value && (value & 3) != 3) |
| 56 | return -EIO; |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 57 | child->thread.gs = value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | case DS: |
| 60 | case ES: |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 61 | case FS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Roland McGrath | e1f2877 | 2008-01-30 13:30:50 +0100 | [diff] [blame] | 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; |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame^] | 83 | value |= regs->eflags & ~FLAG_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | break; |
| 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 | e1f2877 | 2008-01-30 13:30:50 +0100 | [diff] [blame] | 97 | case EFL: |
| 98 | /* |
| 99 | * If the debugger set TF, hide it from the readout. |
| 100 | */ |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame^] | 101 | retval = regs->eflags; |
Roland McGrath | e1f2877 | 2008-01-30 13:30:50 +0100 | [diff] [blame] | 102 | if (test_tsk_thread_flag(child, TIF_FORCED_TF)) |
| 103 | retval &= ~X86_EFLAGS_TF; |
| 104 | break; |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 105 | case GS: |
| 106 | retval = child->thread.gs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | case DS: |
| 109 | case ES: |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 110 | case FS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | case SS: |
| 112 | case CS: |
| 113 | retval = 0xffff; |
| 114 | /* fall through */ |
| 115 | default: |
Roland McGrath | 62a97d4 | 2008-01-30 13:30:52 +0100 | [diff] [blame^] | 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 | /* |
| 122 | * Called by kernel/ptrace.c when detaching.. |
| 123 | * |
| 124 | * Make sure the single step bit is not set. |
| 125 | */ |
| 126 | void ptrace_disable(struct task_struct *child) |
| 127 | { |
Roland McGrath | 7f23234 | 2008-01-30 13:30:48 +0100 | [diff] [blame] | 128 | user_disable_single_step(child); |
Bodo Stroesser | ab1c23c | 2005-09-03 15:57:21 -0700 | [diff] [blame] | 129 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 132 | 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] | 133 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | struct user * dummy = NULL; |
| 135 | int i, ret; |
| 136 | unsigned long __user *datap = (unsigned long __user *)data; |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | switch (request) { |
| 139 | /* when I and D space are separate, these will need to be fixed. */ |
| 140 | case PTRACE_PEEKTEXT: /* read word at location addr. */ |
Alexey Dobriyan | 7664732 | 2007-07-17 04:03:43 -0700 | [diff] [blame] | 141 | case PTRACE_PEEKDATA: |
| 142 | ret = generic_ptrace_peekdata(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | /* read the word at location addr in the USER area. */ |
| 146 | case PTRACE_PEEKUSR: { |
| 147 | unsigned long tmp; |
| 148 | |
| 149 | ret = -EIO; |
| 150 | if ((addr & 3) || addr < 0 || |
| 151 | addr > sizeof(struct user) - 3) |
| 152 | break; |
| 153 | |
| 154 | tmp = 0; /* Default return condition */ |
| 155 | if(addr < FRAME_SIZE*sizeof(long)) |
| 156 | tmp = getreg(child, addr); |
| 157 | if(addr >= (long) &dummy->u_debugreg[0] && |
| 158 | addr <= (long) &dummy->u_debugreg[7]){ |
| 159 | addr -= (long) &dummy->u_debugreg[0]; |
| 160 | addr = addr >> 2; |
| 161 | tmp = child->thread.debugreg[addr]; |
| 162 | } |
| 163 | ret = put_user(tmp, datap); |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | /* when I and D space are separate, this will have to be fixed. */ |
| 168 | case PTRACE_POKETEXT: /* write the word at location addr. */ |
| 169 | case PTRACE_POKEDATA: |
Alexey Dobriyan | f284ce7 | 2007-07-17 04:03:44 -0700 | [diff] [blame] | 170 | ret = generic_ptrace_pokedata(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | break; |
| 172 | |
| 173 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ |
| 174 | ret = -EIO; |
| 175 | if ((addr & 3) || addr < 0 || |
| 176 | addr > sizeof(struct user) - 3) |
| 177 | break; |
| 178 | |
| 179 | if (addr < FRAME_SIZE*sizeof(long)) { |
| 180 | ret = putreg(child, addr, data); |
| 181 | break; |
| 182 | } |
| 183 | /* We need to be very careful here. We implicitly |
| 184 | want to modify a portion of the task_struct, and we |
| 185 | have to be selective about what portions we allow someone |
| 186 | to modify. */ |
| 187 | |
| 188 | ret = -EIO; |
| 189 | if(addr >= (long) &dummy->u_debugreg[0] && |
| 190 | addr <= (long) &dummy->u_debugreg[7]){ |
| 191 | |
| 192 | if(addr == (long) &dummy->u_debugreg[4]) break; |
| 193 | if(addr == (long) &dummy->u_debugreg[5]) break; |
| 194 | if(addr < (long) &dummy->u_debugreg[4] && |
| 195 | ((unsigned long) data) >= TASK_SIZE-3) break; |
| 196 | |
| 197 | /* Sanity-check data. Take one half-byte at once with |
| 198 | * check = (val >> (16 + 4*i)) & 0xf. It contains the |
| 199 | * R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits |
| 200 | * 2 and 3 are LENi. Given a list of invalid values, |
| 201 | * we do mask |= 1 << invalid_value, so that |
| 202 | * (mask >> check) & 1 is a correct test for invalid |
| 203 | * values. |
| 204 | * |
| 205 | * R/Wi contains the type of the breakpoint / |
| 206 | * watchpoint, LENi contains the length of the watched |
| 207 | * data in the watchpoint case. |
| 208 | * |
| 209 | * The invalid values are: |
| 210 | * - LENi == 0x10 (undefined), so mask |= 0x0f00. |
| 211 | * - R/Wi == 0x10 (break on I/O reads or writes), so |
| 212 | * mask |= 0x4444. |
| 213 | * - R/Wi == 0x00 && LENi != 0x00, so we have mask |= |
| 214 | * 0x1110. |
| 215 | * |
| 216 | * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54. |
| 217 | * |
| 218 | * See the Intel Manual "System Programming Guide", |
| 219 | * 15.2.4 |
| 220 | * |
| 221 | * Note that LENi == 0x10 is defined on x86_64 in long |
| 222 | * mode (i.e. even for 32-bit userspace software, but |
| 223 | * 64-bit kernel), so the x86_64 mask value is 0x5454. |
| 224 | * See the AMD manual no. 24593 (AMD64 System |
| 225 | * Programming)*/ |
| 226 | |
| 227 | if(addr == (long) &dummy->u_debugreg[7]) { |
| 228 | data &= ~DR_CONTROL_RESERVED; |
| 229 | for(i=0; i<4; i++) |
| 230 | if ((0x5f54 >> ((data >> (16 + 4*i)) & 0xf)) & 1) |
| 231 | goto out_tsk; |
Stephane Eranian | b3cf257 | 2006-07-09 21:12:39 -0400 | [diff] [blame] | 232 | if (data) |
| 233 | set_tsk_thread_flag(child, TIF_DEBUG); |
| 234 | else |
| 235 | clear_tsk_thread_flag(child, TIF_DEBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | addr -= (long) &dummy->u_debugreg; |
| 238 | addr = addr >> 2; |
| 239 | child->thread.debugreg[addr] = data; |
| 240 | ret = 0; |
| 241 | } |
| 242 | break; |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | case PTRACE_GETREGS: { /* Get all gp regs from the child. */ |
| 245 | if (!access_ok(VERIFY_WRITE, datap, FRAME_SIZE*sizeof(long))) { |
| 246 | ret = -EIO; |
| 247 | break; |
| 248 | } |
| 249 | for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) { |
| 250 | __put_user(getreg(child, i), datap); |
| 251 | datap++; |
| 252 | } |
| 253 | ret = 0; |
| 254 | break; |
| 255 | } |
| 256 | |
| 257 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ |
| 258 | unsigned long tmp; |
| 259 | if (!access_ok(VERIFY_READ, datap, FRAME_SIZE*sizeof(long))) { |
| 260 | ret = -EIO; |
| 261 | break; |
| 262 | } |
| 263 | for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) { |
| 264 | __get_user(tmp, datap); |
| 265 | putreg(child, i, tmp); |
| 266 | datap++; |
| 267 | } |
| 268 | ret = 0; |
| 269 | break; |
| 270 | } |
| 271 | |
| 272 | case PTRACE_GETFPREGS: { /* Get the child FPU state. */ |
| 273 | if (!access_ok(VERIFY_WRITE, datap, |
| 274 | sizeof(struct user_i387_struct))) { |
| 275 | ret = -EIO; |
| 276 | break; |
| 277 | } |
| 278 | ret = 0; |
| 279 | if (!tsk_used_math(child)) |
| 280 | init_fpu(child); |
| 281 | get_fpregs((struct user_i387_struct __user *)data, child); |
| 282 | break; |
| 283 | } |
| 284 | |
| 285 | case PTRACE_SETFPREGS: { /* Set the child FPU state. */ |
| 286 | if (!access_ok(VERIFY_READ, datap, |
| 287 | sizeof(struct user_i387_struct))) { |
| 288 | ret = -EIO; |
| 289 | break; |
| 290 | } |
| 291 | set_stopped_child_used_math(child); |
| 292 | set_fpregs(child, (struct user_i387_struct __user *)data); |
| 293 | ret = 0; |
| 294 | break; |
| 295 | } |
| 296 | |
| 297 | case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */ |
| 298 | if (!access_ok(VERIFY_WRITE, datap, |
| 299 | sizeof(struct user_fxsr_struct))) { |
| 300 | ret = -EIO; |
| 301 | break; |
| 302 | } |
| 303 | if (!tsk_used_math(child)) |
| 304 | init_fpu(child); |
| 305 | ret = get_fpxregs((struct user_fxsr_struct __user *)data, child); |
| 306 | break; |
| 307 | } |
| 308 | |
| 309 | case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */ |
| 310 | if (!access_ok(VERIFY_READ, datap, |
| 311 | sizeof(struct user_fxsr_struct))) { |
| 312 | ret = -EIO; |
| 313 | break; |
| 314 | } |
| 315 | set_stopped_child_used_math(child); |
| 316 | ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data); |
| 317 | break; |
| 318 | } |
| 319 | |
| 320 | case PTRACE_GET_THREAD_AREA: |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 321 | if (addr < 0) |
| 322 | return -EIO; |
| 323 | ret = do_get_thread_area(child, addr, |
| 324 | (struct user_desc __user *) data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | break; |
| 326 | |
| 327 | case PTRACE_SET_THREAD_AREA: |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 328 | if (addr < 0) |
| 329 | return -EIO; |
| 330 | ret = do_set_thread_area(child, addr, |
| 331 | (struct user_desc __user *) data, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | break; |
| 333 | |
| 334 | default: |
| 335 | ret = ptrace_request(child, request, addr, data); |
| 336 | break; |
| 337 | } |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 338 | out_tsk: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | return ret; |
| 340 | } |
| 341 | |
| 342 | void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code) |
| 343 | { |
| 344 | struct siginfo info; |
| 345 | |
| 346 | tsk->thread.trap_no = 1; |
| 347 | tsk->thread.error_code = error_code; |
| 348 | |
| 349 | memset(&info, 0, sizeof(info)); |
| 350 | info.si_signo = SIGTRAP; |
| 351 | info.si_code = TRAP_BRKPT; |
| 352 | |
| 353 | /* User-mode eip? */ |
Vincent Hanquez | fa1e1bd | 2005-06-23 00:08:44 -0700 | [diff] [blame] | 354 | info.si_addr = user_mode_vm(regs) ? (void __user *) regs->eip : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 356 | /* Send us the fake SIGTRAP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | force_sig_info(SIGTRAP, &info, tsk); |
| 358 | } |
| 359 | |
| 360 | /* notification of system call entry/exit |
| 361 | * - triggered by current->work.syscall_trace |
| 362 | */ |
| 363 | __attribute__((regparm(3))) |
Laurent Vivier | ed75e8d | 2005-09-03 15:57:18 -0700 | [diff] [blame] | 364 | int do_syscall_trace(struct pt_regs *regs, int entryexit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 366 | int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU); |
| 367 | /* |
| 368 | * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall |
| 369 | * interception |
| 370 | */ |
Bodo Stroesser | 1b38f00 | 2005-09-03 15:57:20 -0700 | [diff] [blame] | 371 | int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP); |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 372 | int ret = 0; |
Bodo Stroesser | 1b38f00 | 2005-09-03 15:57:20 -0700 | [diff] [blame] | 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /* do the secure computing check first */ |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 375 | if (!entryexit) |
| 376 | secure_computing(regs->orig_eax); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Bodo Stroesser | ab1c23c | 2005-09-03 15:57:21 -0700 | [diff] [blame] | 378 | if (unlikely(current->audit_context)) { |
| 379 | if (entryexit) |
Al Viro | 5411be5 | 2006-03-29 20:23:36 -0500 | [diff] [blame] | 380 | audit_syscall_exit(AUDITSC_RESULT(regs->eax), |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 381 | regs->eax); |
Bodo Stroesser | ab1c23c | 2005-09-03 15:57:21 -0700 | [diff] [blame] | 382 | /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only |
| 383 | * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is |
| 384 | * not used, entry.S will call us only on syscall exit, not |
| 385 | * entry; so when TIF_SYSCALL_AUDIT is used we must avoid |
| 386 | * calling send_sigtrap() on syscall entry. |
| 387 | * |
| 388 | * Note that when PTRACE_SYSEMU_SINGLESTEP is used, |
| 389 | * is_singlestep is false, despite his name, so we will still do |
| 390 | * the correct thing. |
| 391 | */ |
| 392 | else if (is_singlestep) |
| 393 | goto out; |
| 394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | if (!(current->ptrace & PT_PTRACED)) |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 397 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Bodo Stroesser | 1b38f00 | 2005-09-03 15:57:20 -0700 | [diff] [blame] | 399 | /* If a process stops on the 1st tracepoint with SYSCALL_TRACE |
| 400 | * and then is resumed with SYSEMU_SINGLESTEP, it will come in |
| 401 | * here. We have to check this and return */ |
| 402 | if (is_sysemu && entryexit) |
| 403 | return 0; |
Laurent Vivier | ed75e8d | 2005-09-03 15:57:18 -0700 | [diff] [blame] | 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | /* Fake a debug trap */ |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 406 | if (is_singlestep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | send_sigtrap(current, regs, 0); |
| 408 | |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 409 | if (!test_thread_flag(TIF_SYSCALL_TRACE) && !is_sysemu) |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 410 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | /* the 0x80 provides a way for the tracing parent to distinguish |
| 413 | between a syscall stop and SIGTRAP delivery */ |
Laurent Vivier | ed75e8d | 2005-09-03 15:57:18 -0700 | [diff] [blame] | 414 | /* Note that the debugger could change the result of test_thread_flag!*/ |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 415 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80:0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | /* |
| 418 | * this isn't the same as continuing with a signal, but it will do |
| 419 | * for normal use. strace only continues with a signal if the |
| 420 | * stopping signal is not SIGTRAP. -brl |
| 421 | */ |
| 422 | if (current->exit_code) { |
| 423 | send_sig(current->exit_code, current, 1); |
| 424 | current->exit_code = 0; |
| 425 | } |
Laurent Vivier | ed75e8d | 2005-09-03 15:57:18 -0700 | [diff] [blame] | 426 | ret = is_sysemu; |
Andrea Arcangeli | 4c7fc72 | 2005-09-09 13:01:51 -0700 | [diff] [blame] | 427 | out: |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 428 | if (unlikely(current->audit_context) && !entryexit) |
Al Viro | 5411be5 | 2006-03-29 20:23:36 -0500 | [diff] [blame] | 429 | audit_syscall_entry(AUDIT_ARCH_I386, regs->orig_eax, |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 430 | regs->ebx, regs->ecx, regs->edx, regs->esi); |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 431 | if (ret == 0) |
| 432 | return 0; |
| 433 | |
Bodo Stroesser | 1b38f00 | 2005-09-03 15:57:20 -0700 | [diff] [blame] | 434 | regs->orig_eax = -1; /* force skip of syscall restarting */ |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 435 | if (unlikely(current->audit_context)) |
Al Viro | 5411be5 | 2006-03-29 20:23:36 -0500 | [diff] [blame] | 436 | audit_syscall_exit(AUDITSC_RESULT(regs->eax), regs->eax); |
Bodo Stroesser | c8c86ce | 2005-09-03 15:57:19 -0700 | [diff] [blame] | 437 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |