diff options
Diffstat (limited to 'arch/x86/kernel/ptrace_32.c')
-rw-r--r-- | arch/x86/kernel/ptrace_32.c | 723 |
1 files changed, 723 insertions, 0 deletions
diff --git a/arch/x86/kernel/ptrace_32.c b/arch/x86/kernel/ptrace_32.c new file mode 100644 index 000000000000..7c1b92522e95 --- /dev/null +++ b/arch/x86/kernel/ptrace_32.c | |||
@@ -0,0 +1,723 @@ | |||
1 | /* ptrace.c */ | ||
2 | /* By Ross Biro 1/23/92 */ | ||
3 | /* | ||
4 | * Pentium III FXSR, SSE support | ||
5 | * Gareth Hughes <gareth@valinux.com>, May 2000 | ||
6 | */ | ||
7 | |||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/sched.h> | ||
10 | #include <linux/mm.h> | ||
11 | #include <linux/smp.h> | ||
12 | #include <linux/errno.h> | ||
13 | #include <linux/ptrace.h> | ||
14 | #include <linux/user.h> | ||
15 | #include <linux/security.h> | ||
16 | #include <linux/audit.h> | ||
17 | #include <linux/seccomp.h> | ||
18 | #include <linux/signal.h> | ||
19 | |||
20 | #include <asm/uaccess.h> | ||
21 | #include <asm/pgtable.h> | ||
22 | #include <asm/system.h> | ||
23 | #include <asm/processor.h> | ||
24 | #include <asm/i387.h> | ||
25 | #include <asm/debugreg.h> | ||
26 | #include <asm/ldt.h> | ||
27 | #include <asm/desc.h> | ||
28 | |||
29 | /* | ||
30 | * does not yet catch signals sent when the child dies. | ||
31 | * in exit.c or in signal.c. | ||
32 | */ | ||
33 | |||
34 | /* | ||
35 | * Determines which flags the user has access to [1 = access, 0 = no access]. | ||
36 | * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), NT(14), IOPL(12-13), IF(9). | ||
37 | * Also masks reserved bits (31-22, 15, 5, 3, 1). | ||
38 | */ | ||
39 | #define FLAG_MASK 0x00050dd5 | ||
40 | |||
41 | /* set's the trap flag. */ | ||
42 | #define TRAP_FLAG 0x100 | ||
43 | |||
44 | /* | ||
45 | * Offset of eflags on child stack.. | ||
46 | */ | ||
47 | #define EFL_OFFSET offsetof(struct pt_regs, eflags) | ||
48 | |||
49 | static inline struct pt_regs *get_child_regs(struct task_struct *task) | ||
50 | { | ||
51 | void *stack_top = (void *)task->thread.esp0; | ||
52 | return stack_top - sizeof(struct pt_regs); | ||
53 | } | ||
54 | |||
55 | /* | ||
56 | * This routine will get a word off of the processes privileged stack. | ||
57 | * the offset is bytes into the pt_regs structure on the stack. | ||
58 | * This routine assumes that all the privileged stacks are in our | ||
59 | * data space. | ||
60 | */ | ||
61 | static inline int get_stack_long(struct task_struct *task, int offset) | ||
62 | { | ||
63 | unsigned char *stack; | ||
64 | |||
65 | stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs); | ||
66 | stack += offset; | ||
67 | return (*((int *)stack)); | ||
68 | } | ||
69 | |||
70 | /* | ||
71 | * This routine will put a word on the processes privileged stack. | ||
72 | * the offset is bytes into the pt_regs structure on the stack. | ||
73 | * This routine assumes that all the privileged stacks are in our | ||
74 | * data space. | ||
75 | */ | ||
76 | static inline int put_stack_long(struct task_struct *task, int offset, | ||
77 | unsigned long data) | ||
78 | { | ||
79 | unsigned char * stack; | ||
80 | |||
81 | stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs); | ||
82 | stack += offset; | ||
83 | *(unsigned long *) stack = data; | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | static int putreg(struct task_struct *child, | ||
88 | unsigned long regno, unsigned long value) | ||
89 | { | ||
90 | switch (regno >> 2) { | ||
91 | case GS: | ||
92 | if (value && (value & 3) != 3) | ||
93 | return -EIO; | ||
94 | child->thread.gs = value; | ||
95 | return 0; | ||
96 | case DS: | ||
97 | case ES: | ||
98 | case FS: | ||
99 | if (value && (value & 3) != 3) | ||
100 | return -EIO; | ||
101 | value &= 0xffff; | ||
102 | break; | ||
103 | case SS: | ||
104 | case CS: | ||
105 | if ((value & 3) != 3) | ||
106 | return -EIO; | ||
107 | value &= 0xffff; | ||
108 | break; | ||
109 | case EFL: | ||
110 | value &= FLAG_MASK; | ||
111 | value |= get_stack_long(child, EFL_OFFSET) & ~FLAG_MASK; | ||
112 | break; | ||
113 | } | ||
114 | if (regno > FS*4) | ||
115 | regno -= 1*4; | ||
116 | put_stack_long(child, regno, value); | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | static unsigned long getreg(struct task_struct *child, | ||
121 | unsigned long regno) | ||
122 | { | ||
123 | unsigned long retval = ~0UL; | ||
124 | |||
125 | switch (regno >> 2) { | ||
126 | case GS: | ||
127 | retval = child->thread.gs; | ||
128 | break; | ||
129 | case DS: | ||
130 | case ES: | ||
131 | case FS: | ||
132 | case SS: | ||
133 | case CS: | ||
134 | retval = 0xffff; | ||
135 | /* fall through */ | ||
136 | default: | ||
137 | if (regno > FS*4) | ||
138 | regno -= 1*4; | ||
139 | retval &= get_stack_long(child, regno); | ||
140 | } | ||
141 | return retval; | ||
142 | } | ||
143 | |||
144 | #define LDT_SEGMENT 4 | ||
145 | |||
146 | static unsigned long convert_eip_to_linear(struct task_struct *child, struct pt_regs *regs) | ||
147 | { | ||
148 | unsigned long addr, seg; | ||
149 | |||
150 | addr = regs->eip; | ||
151 | seg = regs->xcs & 0xffff; | ||
152 | if (regs->eflags & VM_MASK) { | ||
153 | addr = (addr & 0xffff) + (seg << 4); | ||
154 | return addr; | ||
155 | } | ||
156 | |||
157 | /* | ||
158 | * We'll assume that the code segments in the GDT | ||
159 | * are all zero-based. That is largely true: the | ||
160 | * TLS segments are used for data, and the PNPBIOS | ||
161 | * and APM bios ones we just ignore here. | ||
162 | */ | ||
163 | if (seg & LDT_SEGMENT) { | ||
164 | u32 *desc; | ||
165 | unsigned long base; | ||
166 | |||
167 | seg &= ~7UL; | ||
168 | |||
169 | down(&child->mm->context.sem); | ||
170 | if (unlikely((seg >> 3) >= child->mm->context.size)) | ||
171 | addr = -1L; /* bogus selector, access would fault */ | ||
172 | else { | ||
173 | desc = child->mm->context.ldt + seg; | ||
174 | base = ((desc[0] >> 16) | | ||
175 | ((desc[1] & 0xff) << 16) | | ||
176 | (desc[1] & 0xff000000)); | ||
177 | |||
178 | /* 16-bit code segment? */ | ||
179 | if (!((desc[1] >> 22) & 1)) | ||
180 | addr &= 0xffff; | ||
181 | addr += base; | ||
182 | } | ||
183 | up(&child->mm->context.sem); | ||
184 | } | ||
185 | return addr; | ||
186 | } | ||
187 | |||
188 | static inline int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs) | ||
189 | { | ||
190 | int i, copied; | ||
191 | unsigned char opcode[15]; | ||
192 | unsigned long addr = convert_eip_to_linear(child, regs); | ||
193 | |||
194 | copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0); | ||
195 | for (i = 0; i < copied; i++) { | ||
196 | switch (opcode[i]) { | ||
197 | /* popf and iret */ | ||
198 | case 0x9d: case 0xcf: | ||
199 | return 1; | ||
200 | /* opcode and address size prefixes */ | ||
201 | case 0x66: case 0x67: | ||
202 | continue; | ||
203 | /* irrelevant prefixes (segment overrides and repeats) */ | ||
204 | case 0x26: case 0x2e: | ||
205 | case 0x36: case 0x3e: | ||
206 | case 0x64: case 0x65: | ||
207 | case 0xf0: case 0xf2: case 0xf3: | ||
208 | continue; | ||
209 | |||
210 | /* | ||
211 | * pushf: NOTE! We should probably not let | ||
212 | * the user see the TF bit being set. But | ||
213 | * it's more pain than it's worth to avoid | ||
214 | * it, and a debugger could emulate this | ||
215 | * all in user space if it _really_ cares. | ||
216 | */ | ||
217 | case 0x9c: | ||
218 | default: | ||
219 | return 0; | ||
220 | } | ||
221 | } | ||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static void set_singlestep(struct task_struct *child) | ||
226 | { | ||
227 | struct pt_regs *regs = get_child_regs(child); | ||
228 | |||
229 | /* | ||
230 | * Always set TIF_SINGLESTEP - this guarantees that | ||
231 | * we single-step system calls etc.. This will also | ||
232 | * cause us to set TF when returning to user mode. | ||
233 | */ | ||
234 | set_tsk_thread_flag(child, TIF_SINGLESTEP); | ||
235 | |||
236 | /* | ||
237 | * If TF was already set, don't do anything else | ||
238 | */ | ||
239 | if (regs->eflags & TRAP_FLAG) | ||
240 | return; | ||
241 | |||
242 | /* Set TF on the kernel stack.. */ | ||
243 | regs->eflags |= TRAP_FLAG; | ||
244 | |||
245 | /* | ||
246 | * ..but if TF is changed by the instruction we will trace, | ||
247 | * don't mark it as being "us" that set it, so that we | ||
248 | * won't clear it by hand later. | ||
249 | */ | ||
250 | if (is_setting_trap_flag(child, regs)) | ||
251 | return; | ||
252 | |||
253 | child->ptrace |= PT_DTRACE; | ||
254 | } | ||
255 | |||
256 | static void clear_singlestep(struct task_struct *child) | ||
257 | { | ||
258 | /* Always clear TIF_SINGLESTEP... */ | ||
259 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | ||
260 | |||
261 | /* But touch TF only if it was set by us.. */ | ||
262 | if (child->ptrace & PT_DTRACE) { | ||
263 | struct pt_regs *regs = get_child_regs(child); | ||
264 | regs->eflags &= ~TRAP_FLAG; | ||
265 | child->ptrace &= ~PT_DTRACE; | ||
266 | } | ||
267 | } | ||
268 | |||
269 | /* | ||
270 | * Called by kernel/ptrace.c when detaching.. | ||
271 | * | ||
272 | * Make sure the single step bit is not set. | ||
273 | */ | ||
274 | void ptrace_disable(struct task_struct *child) | ||
275 | { | ||
276 | clear_singlestep(child); | ||
277 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); | ||
278 | } | ||
279 | |||
280 | /* | ||
281 | * Perform get_thread_area on behalf of the traced child. | ||
282 | */ | ||
283 | static int | ||
284 | ptrace_get_thread_area(struct task_struct *child, | ||
285 | int idx, struct user_desc __user *user_desc) | ||
286 | { | ||
287 | struct user_desc info; | ||
288 | struct desc_struct *desc; | ||
289 | |||
290 | /* | ||
291 | * Get the current Thread-Local Storage area: | ||
292 | */ | ||
293 | |||
294 | #define GET_BASE(desc) ( \ | ||
295 | (((desc)->a >> 16) & 0x0000ffff) | \ | ||
296 | (((desc)->b << 16) & 0x00ff0000) | \ | ||
297 | ( (desc)->b & 0xff000000) ) | ||
298 | |||
299 | #define GET_LIMIT(desc) ( \ | ||
300 | ((desc)->a & 0x0ffff) | \ | ||
301 | ((desc)->b & 0xf0000) ) | ||
302 | |||
303 | #define GET_32BIT(desc) (((desc)->b >> 22) & 1) | ||
304 | #define GET_CONTENTS(desc) (((desc)->b >> 10) & 3) | ||
305 | #define GET_WRITABLE(desc) (((desc)->b >> 9) & 1) | ||
306 | #define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1) | ||
307 | #define GET_PRESENT(desc) (((desc)->b >> 15) & 1) | ||
308 | #define GET_USEABLE(desc) (((desc)->b >> 20) & 1) | ||
309 | |||
310 | if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX) | ||
311 | return -EINVAL; | ||
312 | |||
313 | desc = child->thread.tls_array + idx - GDT_ENTRY_TLS_MIN; | ||
314 | |||
315 | info.entry_number = idx; | ||
316 | info.base_addr = GET_BASE(desc); | ||
317 | info.limit = GET_LIMIT(desc); | ||
318 | info.seg_32bit = GET_32BIT(desc); | ||
319 | info.contents = GET_CONTENTS(desc); | ||
320 | info.read_exec_only = !GET_WRITABLE(desc); | ||
321 | info.limit_in_pages = GET_LIMIT_PAGES(desc); | ||
322 | info.seg_not_present = !GET_PRESENT(desc); | ||
323 | info.useable = GET_USEABLE(desc); | ||
324 | |||
325 | if (copy_to_user(user_desc, &info, sizeof(info))) | ||
326 | return -EFAULT; | ||
327 | |||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | /* | ||
332 | * Perform set_thread_area on behalf of the traced child. | ||
333 | */ | ||
334 | static int | ||
335 | ptrace_set_thread_area(struct task_struct *child, | ||
336 | int idx, struct user_desc __user *user_desc) | ||
337 | { | ||
338 | struct user_desc info; | ||
339 | struct desc_struct *desc; | ||
340 | |||
341 | if (copy_from_user(&info, user_desc, sizeof(info))) | ||
342 | return -EFAULT; | ||
343 | |||
344 | if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX) | ||
345 | return -EINVAL; | ||
346 | |||
347 | desc = child->thread.tls_array + idx - GDT_ENTRY_TLS_MIN; | ||
348 | if (LDT_empty(&info)) { | ||
349 | desc->a = 0; | ||
350 | desc->b = 0; | ||
351 | } else { | ||
352 | desc->a = LDT_entry_a(&info); | ||
353 | desc->b = LDT_entry_b(&info); | ||
354 | } | ||
355 | |||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) | ||
360 | { | ||
361 | struct user * dummy = NULL; | ||
362 | int i, ret; | ||
363 | unsigned long __user *datap = (unsigned long __user *)data; | ||
364 | |||
365 | switch (request) { | ||
366 | /* when I and D space are separate, these will need to be fixed. */ | ||
367 | case PTRACE_PEEKTEXT: /* read word at location addr. */ | ||
368 | case PTRACE_PEEKDATA: | ||
369 | ret = generic_ptrace_peekdata(child, addr, data); | ||
370 | break; | ||
371 | |||
372 | /* read the word at location addr in the USER area. */ | ||
373 | case PTRACE_PEEKUSR: { | ||
374 | unsigned long tmp; | ||
375 | |||
376 | ret = -EIO; | ||
377 | if ((addr & 3) || addr < 0 || | ||
378 | addr > sizeof(struct user) - 3) | ||
379 | break; | ||
380 | |||
381 | tmp = 0; /* Default return condition */ | ||
382 | if(addr < FRAME_SIZE*sizeof(long)) | ||
383 | tmp = getreg(child, addr); | ||
384 | if(addr >= (long) &dummy->u_debugreg[0] && | ||
385 | addr <= (long) &dummy->u_debugreg[7]){ | ||
386 | addr -= (long) &dummy->u_debugreg[0]; | ||
387 | addr = addr >> 2; | ||
388 | tmp = child->thread.debugreg[addr]; | ||
389 | } | ||
390 | ret = put_user(tmp, datap); | ||
391 | break; | ||
392 | } | ||
393 | |||
394 | /* when I and D space are separate, this will have to be fixed. */ | ||
395 | case PTRACE_POKETEXT: /* write the word at location addr. */ | ||
396 | case PTRACE_POKEDATA: | ||
397 | ret = generic_ptrace_pokedata(child, addr, data); | ||
398 | break; | ||
399 | |||
400 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ | ||
401 | ret = -EIO; | ||
402 | if ((addr & 3) || addr < 0 || | ||
403 | addr > sizeof(struct user) - 3) | ||
404 | break; | ||
405 | |||
406 | if (addr < FRAME_SIZE*sizeof(long)) { | ||
407 | ret = putreg(child, addr, data); | ||
408 | break; | ||
409 | } | ||
410 | /* We need to be very careful here. We implicitly | ||
411 | want to modify a portion of the task_struct, and we | ||
412 | have to be selective about what portions we allow someone | ||
413 | to modify. */ | ||
414 | |||
415 | ret = -EIO; | ||
416 | if(addr >= (long) &dummy->u_debugreg[0] && | ||
417 | addr <= (long) &dummy->u_debugreg[7]){ | ||
418 | |||
419 | if(addr == (long) &dummy->u_debugreg[4]) break; | ||
420 | if(addr == (long) &dummy->u_debugreg[5]) break; | ||
421 | if(addr < (long) &dummy->u_debugreg[4] && | ||
422 | ((unsigned long) data) >= TASK_SIZE-3) break; | ||
423 | |||
424 | /* Sanity-check data. Take one half-byte at once with | ||
425 | * check = (val >> (16 + 4*i)) & 0xf. It contains the | ||
426 | * R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits | ||
427 | * 2 and 3 are LENi. Given a list of invalid values, | ||
428 | * we do mask |= 1 << invalid_value, so that | ||
429 | * (mask >> check) & 1 is a correct test for invalid | ||
430 | * values. | ||
431 | * | ||
432 | * R/Wi contains the type of the breakpoint / | ||
433 | * watchpoint, LENi contains the length of the watched | ||
434 | * data in the watchpoint case. | ||
435 | * | ||
436 | * The invalid values are: | ||
437 | * - LENi == 0x10 (undefined), so mask |= 0x0f00. | ||
438 | * - R/Wi == 0x10 (break on I/O reads or writes), so | ||
439 | * mask |= 0x4444. | ||
440 | * - R/Wi == 0x00 && LENi != 0x00, so we have mask |= | ||
441 | * 0x1110. | ||
442 | * | ||
443 | * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54. | ||
444 | * | ||
445 | * See the Intel Manual "System Programming Guide", | ||
446 | * 15.2.4 | ||
447 | * | ||
448 | * Note that LENi == 0x10 is defined on x86_64 in long | ||
449 | * mode (i.e. even for 32-bit userspace software, but | ||
450 | * 64-bit kernel), so the x86_64 mask value is 0x5454. | ||
451 | * See the AMD manual no. 24593 (AMD64 System | ||
452 | * Programming)*/ | ||
453 | |||
454 | if(addr == (long) &dummy->u_debugreg[7]) { | ||
455 | data &= ~DR_CONTROL_RESERVED; | ||
456 | for(i=0; i<4; i++) | ||
457 | if ((0x5f54 >> ((data >> (16 + 4*i)) & 0xf)) & 1) | ||
458 | goto out_tsk; | ||
459 | if (data) | ||
460 | set_tsk_thread_flag(child, TIF_DEBUG); | ||
461 | else | ||
462 | clear_tsk_thread_flag(child, TIF_DEBUG); | ||
463 | } | ||
464 | addr -= (long) &dummy->u_debugreg; | ||
465 | addr = addr >> 2; | ||
466 | child->thread.debugreg[addr] = data; | ||
467 | ret = 0; | ||
468 | } | ||
469 | break; | ||
470 | |||
471 | case PTRACE_SYSEMU: /* continue and stop at next syscall, which will not be executed */ | ||
472 | case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ | ||
473 | case PTRACE_CONT: /* restart after signal. */ | ||
474 | ret = -EIO; | ||
475 | if (!valid_signal(data)) | ||
476 | break; | ||
477 | if (request == PTRACE_SYSEMU) { | ||
478 | set_tsk_thread_flag(child, TIF_SYSCALL_EMU); | ||
479 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
480 | } else if (request == PTRACE_SYSCALL) { | ||
481 | set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
482 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); | ||
483 | } else { | ||
484 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); | ||
485 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
486 | } | ||
487 | child->exit_code = data; | ||
488 | /* make sure the single step bit is not set. */ | ||
489 | clear_singlestep(child); | ||
490 | wake_up_process(child); | ||
491 | ret = 0; | ||
492 | break; | ||
493 | |||
494 | /* | ||
495 | * make the child exit. Best I can do is send it a sigkill. | ||
496 | * perhaps it should be put in the status that it wants to | ||
497 | * exit. | ||
498 | */ | ||
499 | case PTRACE_KILL: | ||
500 | ret = 0; | ||
501 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ | ||
502 | break; | ||
503 | child->exit_code = SIGKILL; | ||
504 | /* make sure the single step bit is not set. */ | ||
505 | clear_singlestep(child); | ||
506 | wake_up_process(child); | ||
507 | break; | ||
508 | |||
509 | case PTRACE_SYSEMU_SINGLESTEP: /* Same as SYSEMU, but singlestep if not syscall */ | ||
510 | case PTRACE_SINGLESTEP: /* set the trap flag. */ | ||
511 | ret = -EIO; | ||
512 | if (!valid_signal(data)) | ||
513 | break; | ||
514 | |||
515 | if (request == PTRACE_SYSEMU_SINGLESTEP) | ||
516 | set_tsk_thread_flag(child, TIF_SYSCALL_EMU); | ||
517 | else | ||
518 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); | ||
519 | |||
520 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
521 | set_singlestep(child); | ||
522 | child->exit_code = data; | ||
523 | /* give it a chance to run. */ | ||
524 | wake_up_process(child); | ||
525 | ret = 0; | ||
526 | break; | ||
527 | |||
528 | case PTRACE_DETACH: | ||
529 | /* detach a process that was attached. */ | ||
530 | ret = ptrace_detach(child, data); | ||
531 | break; | ||
532 | |||
533 | case PTRACE_GETREGS: { /* Get all gp regs from the child. */ | ||
534 | if (!access_ok(VERIFY_WRITE, datap, FRAME_SIZE*sizeof(long))) { | ||
535 | ret = -EIO; | ||
536 | break; | ||
537 | } | ||
538 | for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) { | ||
539 | __put_user(getreg(child, i), datap); | ||
540 | datap++; | ||
541 | } | ||
542 | ret = 0; | ||
543 | break; | ||
544 | } | ||
545 | |||
546 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ | ||
547 | unsigned long tmp; | ||
548 | if (!access_ok(VERIFY_READ, datap, FRAME_SIZE*sizeof(long))) { | ||
549 | ret = -EIO; | ||
550 | break; | ||
551 | } | ||
552 | for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) { | ||
553 | __get_user(tmp, datap); | ||
554 | putreg(child, i, tmp); | ||
555 | datap++; | ||
556 | } | ||
557 | ret = 0; | ||
558 | break; | ||
559 | } | ||
560 | |||
561 | case PTRACE_GETFPREGS: { /* Get the child FPU state. */ | ||
562 | if (!access_ok(VERIFY_WRITE, datap, | ||
563 | sizeof(struct user_i387_struct))) { | ||
564 | ret = -EIO; | ||
565 | break; | ||
566 | } | ||
567 | ret = 0; | ||
568 | if (!tsk_used_math(child)) | ||
569 | init_fpu(child); | ||
570 | get_fpregs((struct user_i387_struct __user *)data, child); | ||
571 | break; | ||
572 | } | ||
573 | |||
574 | case PTRACE_SETFPREGS: { /* Set the child FPU state. */ | ||
575 | if (!access_ok(VERIFY_READ, datap, | ||
576 | sizeof(struct user_i387_struct))) { | ||
577 | ret = -EIO; | ||
578 | break; | ||
579 | } | ||
580 | set_stopped_child_used_math(child); | ||
581 | set_fpregs(child, (struct user_i387_struct __user *)data); | ||
582 | ret = 0; | ||
583 | break; | ||
584 | } | ||
585 | |||
586 | case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */ | ||
587 | if (!access_ok(VERIFY_WRITE, datap, | ||
588 | sizeof(struct user_fxsr_struct))) { | ||
589 | ret = -EIO; | ||
590 | break; | ||
591 | } | ||
592 | if (!tsk_used_math(child)) | ||
593 | init_fpu(child); | ||
594 | ret = get_fpxregs((struct user_fxsr_struct __user *)data, child); | ||
595 | break; | ||
596 | } | ||
597 | |||
598 | case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */ | ||
599 | if (!access_ok(VERIFY_READ, datap, | ||
600 | sizeof(struct user_fxsr_struct))) { | ||
601 | ret = -EIO; | ||
602 | break; | ||
603 | } | ||
604 | set_stopped_child_used_math(child); | ||
605 | ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data); | ||
606 | break; | ||
607 | } | ||
608 | |||
609 | case PTRACE_GET_THREAD_AREA: | ||
610 | ret = ptrace_get_thread_area(child, addr, | ||
611 | (struct user_desc __user *) data); | ||
612 | break; | ||
613 | |||
614 | case PTRACE_SET_THREAD_AREA: | ||
615 | ret = ptrace_set_thread_area(child, addr, | ||
616 | (struct user_desc __user *) data); | ||
617 | break; | ||
618 | |||
619 | default: | ||
620 | ret = ptrace_request(child, request, addr, data); | ||
621 | break; | ||
622 | } | ||
623 | out_tsk: | ||
624 | return ret; | ||
625 | } | ||
626 | |||
627 | void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code) | ||
628 | { | ||
629 | struct siginfo info; | ||
630 | |||
631 | tsk->thread.trap_no = 1; | ||
632 | tsk->thread.error_code = error_code; | ||
633 | |||
634 | memset(&info, 0, sizeof(info)); | ||
635 | info.si_signo = SIGTRAP; | ||
636 | info.si_code = TRAP_BRKPT; | ||
637 | |||
638 | /* User-mode eip? */ | ||
639 | info.si_addr = user_mode_vm(regs) ? (void __user *) regs->eip : NULL; | ||
640 | |||
641 | /* Send us the fakey SIGTRAP */ | ||
642 | force_sig_info(SIGTRAP, &info, tsk); | ||
643 | } | ||
644 | |||
645 | /* notification of system call entry/exit | ||
646 | * - triggered by current->work.syscall_trace | ||
647 | */ | ||
648 | __attribute__((regparm(3))) | ||
649 | int do_syscall_trace(struct pt_regs *regs, int entryexit) | ||
650 | { | ||
651 | int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU); | ||
652 | /* | ||
653 | * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall | ||
654 | * interception | ||
655 | */ | ||
656 | int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP); | ||
657 | int ret = 0; | ||
658 | |||
659 | /* do the secure computing check first */ | ||
660 | if (!entryexit) | ||
661 | secure_computing(regs->orig_eax); | ||
662 | |||
663 | if (unlikely(current->audit_context)) { | ||
664 | if (entryexit) | ||
665 | audit_syscall_exit(AUDITSC_RESULT(regs->eax), | ||
666 | regs->eax); | ||
667 | /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only | ||
668 | * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is | ||
669 | * not used, entry.S will call us only on syscall exit, not | ||
670 | * entry; so when TIF_SYSCALL_AUDIT is used we must avoid | ||
671 | * calling send_sigtrap() on syscall entry. | ||
672 | * | ||
673 | * Note that when PTRACE_SYSEMU_SINGLESTEP is used, | ||
674 | * is_singlestep is false, despite his name, so we will still do | ||
675 | * the correct thing. | ||
676 | */ | ||
677 | else if (is_singlestep) | ||
678 | goto out; | ||
679 | } | ||
680 | |||
681 | if (!(current->ptrace & PT_PTRACED)) | ||
682 | goto out; | ||
683 | |||
684 | /* If a process stops on the 1st tracepoint with SYSCALL_TRACE | ||
685 | * and then is resumed with SYSEMU_SINGLESTEP, it will come in | ||
686 | * here. We have to check this and return */ | ||
687 | if (is_sysemu && entryexit) | ||
688 | return 0; | ||
689 | |||
690 | /* Fake a debug trap */ | ||
691 | if (is_singlestep) | ||
692 | send_sigtrap(current, regs, 0); | ||
693 | |||
694 | if (!test_thread_flag(TIF_SYSCALL_TRACE) && !is_sysemu) | ||
695 | goto out; | ||
696 | |||
697 | /* the 0x80 provides a way for the tracing parent to distinguish | ||
698 | between a syscall stop and SIGTRAP delivery */ | ||
699 | /* Note that the debugger could change the result of test_thread_flag!*/ | ||
700 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80:0)); | ||
701 | |||
702 | /* | ||
703 | * this isn't the same as continuing with a signal, but it will do | ||
704 | * for normal use. strace only continues with a signal if the | ||
705 | * stopping signal is not SIGTRAP. -brl | ||
706 | */ | ||
707 | if (current->exit_code) { | ||
708 | send_sig(current->exit_code, current, 1); | ||
709 | current->exit_code = 0; | ||
710 | } | ||
711 | ret = is_sysemu; | ||
712 | out: | ||
713 | if (unlikely(current->audit_context) && !entryexit) | ||
714 | audit_syscall_entry(AUDIT_ARCH_I386, regs->orig_eax, | ||
715 | regs->ebx, regs->ecx, regs->edx, regs->esi); | ||
716 | if (ret == 0) | ||
717 | return 0; | ||
718 | |||
719 | regs->orig_eax = -1; /* force skip of syscall restarting */ | ||
720 | if (unlikely(current->audit_context)) | ||
721 | audit_syscall_exit(AUDITSC_RESULT(regs->eax), regs->eax); | ||
722 | return 1; | ||
723 | } | ||