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