blob: e83cc67155ac253cbbec207b8ef246bc55f0a408 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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 * x86-64 port 2000-2002 Andi Kleen
8 */
9
10#include <linux/kernel.h>
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/errno.h>
15#include <linux/ptrace.h>
16#include <linux/user.h>
17#include <linux/security.h>
18#include <linux/audit.h>
19#include <linux/seccomp.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070020#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/uaccess.h>
23#include <asm/pgtable.h>
24#include <asm/system.h>
25#include <asm/processor.h>
26#include <asm/i387.h>
27#include <asm/debugreg.h>
28#include <asm/ldt.h>
29#include <asm/desc.h>
30#include <asm/proto.h>
31#include <asm/ia32.h>
32
33/*
34 * does not yet catch signals sent when the child dies.
35 * in exit.c or in signal.c.
36 */
37
Chuck Ebbert60923df2006-01-11 22:46:03 +010038/*
39 * Determines which flags the user has access to [1 = access, 0 = no access].
40 * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), IOPL(12-13), IF(9).
41 * Also masks reserved bits (63-22, 15, 5, 3, 1).
42 */
43#define FLAG_MASK 0x54dd5UL
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/* set's the trap flag. */
46#define TRAP_FLAG 0x100UL
47
48/*
49 * eflags and offset of eflags on child stack..
50 */
51#define EFLAGS offsetof(struct pt_regs, eflags)
52#define EFL_OFFSET ((int)(EFLAGS-sizeof(struct pt_regs)))
53
54/*
55 * this routine will get a word off of the processes privileged stack.
56 * the offset is how far from the base addr as stored in the TSS.
57 * this routine assumes that all the privileged stacks are in our
58 * data space.
59 */
60static inline unsigned long get_stack_long(struct task_struct *task, int offset)
61{
62 unsigned char *stack;
63
64 stack = (unsigned char *)task->thread.rsp0;
65 stack += offset;
66 return (*((unsigned long *)stack));
67}
68
69/*
70 * this routine will put a word on the processes privileged stack.
71 * the offset is how far from the base addr as stored in the TSS.
72 * this routine assumes that all the privileged stacks are in our
73 * data space.
74 */
75static inline long put_stack_long(struct task_struct *task, int offset,
76 unsigned long data)
77{
78 unsigned char * stack;
79
80 stack = (unsigned char *) task->thread.rsp0;
81 stack += offset;
82 *(unsigned long *) stack = data;
83 return 0;
84}
85
Andi Kleene502cdd2005-04-16 15:24:58 -070086#define LDT_SEGMENT 4
87
88unsigned long convert_rip_to_linear(struct task_struct *child, struct pt_regs *regs)
89{
90 unsigned long addr, seg;
91
92 addr = regs->rip;
93 seg = regs->cs & 0xffff;
94
95 /*
96 * We'll assume that the code segments in the GDT
97 * are all zero-based. That is largely true: the
98 * TLS segments are used for data, and the PNPBIOS
99 * and APM bios ones we just ignore here.
100 */
101 if (seg & LDT_SEGMENT) {
102 u32 *desc;
103 unsigned long base;
104
Roland McGrath29eb5112007-07-16 01:03:16 -0700105 seg &= ~7UL;
Andi Kleene502cdd2005-04-16 15:24:58 -0700106
Roland McGrath29eb5112007-07-16 01:03:16 -0700107 down(&child->mm->context.sem);
108 if (unlikely((seg >> 3) >= child->mm->context.size))
109 addr = -1L; /* bogus selector, access would fault */
110 else {
111 desc = child->mm->context.ldt + seg;
112 base = ((desc[0] >> 16) |
113 ((desc[1] & 0xff) << 16) |
114 (desc[1] & 0xff000000));
115
116 /* 16-bit code segment? */
117 if (!((desc[1] >> 22) & 1))
118 addr &= 0xffff;
119 addr += base;
120 }
Andi Kleene502cdd2005-04-16 15:24:58 -0700121 up(&child->mm->context.sem);
122 }
Roland McGrath29eb5112007-07-16 01:03:16 -0700123
Andi Kleene502cdd2005-04-16 15:24:58 -0700124 return addr;
125}
126
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200127static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
Andi Kleene502cdd2005-04-16 15:24:58 -0700128{
129 int i, copied;
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200130 unsigned char opcode[15];
Andi Kleene502cdd2005-04-16 15:24:58 -0700131 unsigned long addr = convert_rip_to_linear(child, regs);
132
133 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
134 for (i = 0; i < copied; i++) {
135 switch (opcode[i]) {
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200136 /* popf and iret */
137 case 0x9d: case 0xcf:
Andi Kleene502cdd2005-04-16 15:24:58 -0700138 return 1;
139
140 /* CHECKME: 64 65 */
141
142 /* opcode and address size prefixes */
143 case 0x66: case 0x67:
144 continue;
145 /* irrelevant prefixes (segment overrides and repeats) */
146 case 0x26: case 0x2e:
147 case 0x36: case 0x3e:
148 case 0x64: case 0x65:
Chuck Ebbertd4d35852006-09-26 10:52:32 +0200149 case 0xf2: case 0xf3:
Andi Kleene502cdd2005-04-16 15:24:58 -0700150 continue;
151
Andi Kleene502cdd2005-04-16 15:24:58 -0700152 case 0x40 ... 0x4f:
Chuck Ebberta752d712006-09-26 10:52:32 +0200153 if (regs->cs != __USER_CS)
154 /* 32-bit mode: register increment */
155 return 0;
156 /* 64-bit mode: REX prefix */
Andi Kleene502cdd2005-04-16 15:24:58 -0700157 continue;
158
Chuck Ebbertd4d35852006-09-26 10:52:32 +0200159 /* CHECKME: f2, f3 */
Andi Kleene502cdd2005-04-16 15:24:58 -0700160
161 /*
162 * pushf: NOTE! We should probably not let
163 * the user see the TF bit being set. But
164 * it's more pain than it's worth to avoid
165 * it, and a debugger could emulate this
166 * all in user space if it _really_ cares.
167 */
168 case 0x9c:
169 default:
170 return 0;
171 }
172 }
173 return 0;
174}
175
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700176static void set_singlestep(struct task_struct *child)
177{
Al Virobb049232006-01-12 01:05:38 -0800178 struct pt_regs *regs = task_pt_regs(child);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700179
180 /*
181 * Always set TIF_SINGLESTEP - this guarantees that
182 * we single-step system calls etc.. This will also
183 * cause us to set TF when returning to user mode.
184 */
185 set_tsk_thread_flag(child, TIF_SINGLESTEP);
186
187 /*
188 * If TF was already set, don't do anything else
189 */
190 if (regs->eflags & TRAP_FLAG)
191 return;
192
193 /* Set TF on the kernel stack.. */
194 regs->eflags |= TRAP_FLAG;
195
Andi Kleene502cdd2005-04-16 15:24:58 -0700196 /*
197 * ..but if TF is changed by the instruction we will trace,
198 * don't mark it as being "us" that set it, so that we
199 * won't clear it by hand later.
Andi Kleene502cdd2005-04-16 15:24:58 -0700200 */
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200201 if (is_setting_trap_flag(child, regs))
Andi Kleene502cdd2005-04-16 15:24:58 -0700202 return;
203
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700204 child->ptrace |= PT_DTRACE;
205}
206
207static void clear_singlestep(struct task_struct *child)
208{
209 /* Always clear TIF_SINGLESTEP... */
210 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
211
212 /* But touch TF only if it was set by us.. */
213 if (child->ptrace & PT_DTRACE) {
Al Virobb049232006-01-12 01:05:38 -0800214 struct pt_regs *regs = task_pt_regs(child);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700215 regs->eflags &= ~TRAP_FLAG;
216 child->ptrace &= ~PT_DTRACE;
217 }
218}
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/*
221 * Called by kernel/ptrace.c when detaching..
222 *
223 * Make sure the single step bit is not set.
224 */
225void ptrace_disable(struct task_struct *child)
226{
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700227 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229
230static int putreg(struct task_struct *child,
231 unsigned long regno, unsigned long value)
232{
233 unsigned long tmp;
234
235 /* Some code in the 64bit emulation may not be 64bit clean.
236 Don't take any chances. */
237 if (test_tsk_thread_flag(child, TIF_IA32))
238 value &= 0xffffffff;
239 switch (regno) {
240 case offsetof(struct user_regs_struct,fs):
241 if (value && (value & 3) != 3)
242 return -EIO;
243 child->thread.fsindex = value & 0xffff;
244 return 0;
245 case offsetof(struct user_regs_struct,gs):
246 if (value && (value & 3) != 3)
247 return -EIO;
248 child->thread.gsindex = value & 0xffff;
249 return 0;
250 case offsetof(struct user_regs_struct,ds):
251 if (value && (value & 3) != 3)
252 return -EIO;
253 child->thread.ds = value & 0xffff;
254 return 0;
255 case offsetof(struct user_regs_struct,es):
256 if (value && (value & 3) != 3)
257 return -EIO;
258 child->thread.es = value & 0xffff;
259 return 0;
260 case offsetof(struct user_regs_struct,ss):
261 if ((value & 3) != 3)
262 return -EIO;
263 value &= 0xffff;
264 return 0;
265 case offsetof(struct user_regs_struct,fs_base):
Suresh Siddha84929802005-06-21 17:14:32 -0700266 if (value >= TASK_SIZE_OF(child))
Andi Kleenf6b8d472005-05-16 21:53:30 -0700267 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 child->thread.fs = value;
269 return 0;
270 case offsetof(struct user_regs_struct,gs_base):
Suresh Siddha84929802005-06-21 17:14:32 -0700271 if (value >= TASK_SIZE_OF(child))
Andi Kleenf6b8d472005-05-16 21:53:30 -0700272 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 child->thread.gs = value;
274 return 0;
275 case offsetof(struct user_regs_struct, eflags):
276 value &= FLAG_MASK;
277 tmp = get_stack_long(child, EFL_OFFSET);
278 tmp &= ~FLAG_MASK;
279 value |= tmp;
280 break;
281 case offsetof(struct user_regs_struct,cs):
282 if ((value & 3) != 3)
283 return -EIO;
284 value &= 0xffff;
285 break;
286 }
287 put_stack_long(child, regno - sizeof(struct pt_regs), value);
288 return 0;
289}
290
291static unsigned long getreg(struct task_struct *child, unsigned long regno)
292{
293 unsigned long val;
294 switch (regno) {
295 case offsetof(struct user_regs_struct, fs):
296 return child->thread.fsindex;
297 case offsetof(struct user_regs_struct, gs):
298 return child->thread.gsindex;
299 case offsetof(struct user_regs_struct, ds):
300 return child->thread.ds;
301 case offsetof(struct user_regs_struct, es):
302 return child->thread.es;
303 case offsetof(struct user_regs_struct, fs_base):
304 return child->thread.fs;
305 case offsetof(struct user_regs_struct, gs_base):
306 return child->thread.gs;
307 default:
308 regno = regno - sizeof(struct pt_regs);
309 val = get_stack_long(child, regno);
310 if (test_tsk_thread_flag(child, TIF_IA32))
311 val &= 0xffffffff;
312 return val;
313 }
314
315}
316
Christoph Hellwig481bed42005-11-07 00:59:47 -0800317long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 long i, ret;
320 unsigned ui;
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 switch (request) {
323 /* when I and D space are separate, these will need to be fixed. */
324 case PTRACE_PEEKTEXT: /* read word at location addr. */
Alexey Dobriyan76647322007-07-17 04:03:43 -0700325 case PTRACE_PEEKDATA:
326 ret = generic_ptrace_peekdata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 /* read the word at location addr in the USER area. */
330 case PTRACE_PEEKUSR: {
331 unsigned long tmp;
332
333 ret = -EIO;
334 if ((addr & 7) ||
335 addr > sizeof(struct user) - 7)
336 break;
337
338 switch (addr) {
Andi Kleenc4d1fcf2005-05-20 14:27:56 -0700339 case 0 ... sizeof(struct user_regs_struct) - sizeof(long):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 tmp = getreg(child, addr);
341 break;
342 case offsetof(struct user, u_debugreg[0]):
343 tmp = child->thread.debugreg0;
344 break;
345 case offsetof(struct user, u_debugreg[1]):
346 tmp = child->thread.debugreg1;
347 break;
348 case offsetof(struct user, u_debugreg[2]):
349 tmp = child->thread.debugreg2;
350 break;
351 case offsetof(struct user, u_debugreg[3]):
352 tmp = child->thread.debugreg3;
353 break;
354 case offsetof(struct user, u_debugreg[6]):
355 tmp = child->thread.debugreg6;
356 break;
357 case offsetof(struct user, u_debugreg[7]):
358 tmp = child->thread.debugreg7;
359 break;
360 default:
361 tmp = 0;
362 break;
363 }
364 ret = put_user(tmp,(unsigned long __user *) data);
365 break;
366 }
367
368 /* when I and D space are separate, this will have to be fixed. */
369 case PTRACE_POKETEXT: /* write the word at location addr. */
370 case PTRACE_POKEDATA:
Alexey Dobriyanf284ce72007-07-17 04:03:44 -0700371 ret = generic_ptrace_pokedata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 break;
373
374 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
Suresh Siddha84929802005-06-21 17:14:32 -0700375 {
376 int dsize = test_tsk_thread_flag(child, TIF_IA32) ? 3 : 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 ret = -EIO;
378 if ((addr & 7) ||
379 addr > sizeof(struct user) - 7)
380 break;
381
382 switch (addr) {
Andi Kleenc4d1fcf2005-05-20 14:27:56 -0700383 case 0 ... sizeof(struct user_regs_struct) - sizeof(long):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 ret = putreg(child, addr, data);
385 break;
386 /* Disallows to set a breakpoint into the vsyscall */
387 case offsetof(struct user, u_debugreg[0]):
Suresh Siddha84929802005-06-21 17:14:32 -0700388 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 child->thread.debugreg0 = data;
390 ret = 0;
391 break;
392 case offsetof(struct user, u_debugreg[1]):
Suresh Siddha84929802005-06-21 17:14:32 -0700393 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 child->thread.debugreg1 = data;
395 ret = 0;
396 break;
397 case offsetof(struct user, u_debugreg[2]):
Suresh Siddha84929802005-06-21 17:14:32 -0700398 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 child->thread.debugreg2 = data;
400 ret = 0;
401 break;
402 case offsetof(struct user, u_debugreg[3]):
Suresh Siddha84929802005-06-21 17:14:32 -0700403 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 child->thread.debugreg3 = data;
405 ret = 0;
406 break;
407 case offsetof(struct user, u_debugreg[6]):
408 if (data >> 32)
409 break;
410 child->thread.debugreg6 = data;
411 ret = 0;
412 break;
413 case offsetof(struct user, u_debugreg[7]):
414 /* See arch/i386/kernel/ptrace.c for an explanation of
415 * this awkward check.*/
Jan Beulich893efca2006-03-25 16:29:19 +0100416 data &= ~DR_CONTROL_RESERVED;
417 for(i=0; i<4; i++)
418 if ((0x5554 >> ((data >> (16 + 4*i)) & 0xf)) & 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 break;
420 if (i == 4) {
Stephane Eraniand3a4f482006-09-26 10:52:28 +0200421 child->thread.debugreg7 = data;
422 if (data)
423 set_tsk_thread_flag(child, TIF_DEBUG);
424 else
425 clear_tsk_thread_flag(child, TIF_DEBUG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 ret = 0;
Stephane Eraniand3a4f482006-09-26 10:52:28 +0200427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 break;
429 }
430 break;
Suresh Siddha84929802005-06-21 17:14:32 -0700431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700433 case PTRACE_CONT: /* restart after signal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700436 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 break;
438 if (request == PTRACE_SYSCALL)
439 set_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
440 else
441 clear_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
442 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
443 child->exit_code = data;
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700444 /* make sure the single step bit is not set. */
445 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 wake_up_process(child);
447 ret = 0;
448 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450#ifdef CONFIG_IA32_EMULATION
451 /* This makes only sense with 32bit programs. Allow a
452 64bit debugger to fully examine them too. Better
453 don't use it against 64bit processes, use
454 PTRACE_ARCH_PRCTL instead. */
455 case PTRACE_SET_THREAD_AREA: {
456 struct user_desc __user *p;
457 int old;
458 p = (struct user_desc __user *)data;
459 get_user(old, &p->entry_number);
460 put_user(addr, &p->entry_number);
461 ret = do_set_thread_area(&child->thread, p);
462 put_user(old, &p->entry_number);
463 break;
464 case PTRACE_GET_THREAD_AREA:
465 p = (struct user_desc __user *)data;
466 get_user(old, &p->entry_number);
467 put_user(addr, &p->entry_number);
468 ret = do_get_thread_area(&child->thread, p);
469 put_user(old, &p->entry_number);
470 break;
471 }
472#endif
473 /* normal 64bit interface to access TLS data.
474 Works just like arch_prctl, except that the arguments
475 are reversed. */
476 case PTRACE_ARCH_PRCTL:
477 ret = do_arch_prctl(child, data, addr);
478 break;
479
480/*
481 * make the child exit. Best I can do is send it a sigkill.
482 * perhaps it should be put in the status that it wants to
483 * exit.
484 */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700485 case PTRACE_KILL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 ret = 0;
487 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
488 break;
489 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
490 child->exit_code = SIGKILL;
491 /* make sure the single step bit is not set. */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700492 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 wake_up_process(child);
494 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700496 case PTRACE_SINGLESTEP: /* set the trap flag. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700498 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 break;
500 clear_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700501 set_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 child->exit_code = data;
503 /* give it a chance to run. */
504 wake_up_process(child);
505 ret = 0;
506 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 case PTRACE_DETACH:
509 /* detach a process that was attached. */
510 ret = ptrace_detach(child, data);
511 break;
512
513 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
514 if (!access_ok(VERIFY_WRITE, (unsigned __user *)data,
515 sizeof(struct user_regs_struct))) {
516 ret = -EIO;
517 break;
518 }
519 ret = 0;
520 for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) {
521 ret |= __put_user(getreg(child, ui),(unsigned long __user *) data);
522 data += sizeof(long);
523 }
524 break;
525 }
526
527 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
528 unsigned long tmp;
529 if (!access_ok(VERIFY_READ, (unsigned __user *)data,
530 sizeof(struct user_regs_struct))) {
531 ret = -EIO;
532 break;
533 }
534 ret = 0;
535 for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) {
Andi Kleenf49481b2007-02-13 13:26:24 +0100536 ret = __get_user(tmp, (unsigned long __user *) data);
537 if (ret)
538 break;
539 ret = putreg(child, ui, tmp);
540 if (ret)
541 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 data += sizeof(long);
543 }
544 break;
545 }
546
547 case PTRACE_GETFPREGS: { /* Get the child extended FPU state. */
548 if (!access_ok(VERIFY_WRITE, (unsigned __user *)data,
549 sizeof(struct user_i387_struct))) {
550 ret = -EIO;
551 break;
552 }
553 ret = get_fpregs((struct user_i387_struct __user *)data, child);
554 break;
555 }
556
557 case PTRACE_SETFPREGS: { /* Set the child extended FPU state. */
558 if (!access_ok(VERIFY_READ, (unsigned __user *)data,
559 sizeof(struct user_i387_struct))) {
560 ret = -EIO;
561 break;
562 }
563 set_stopped_child_used_math(child);
564 ret = set_fpregs(child, (struct user_i387_struct __user *)data);
565 break;
566 }
567
568 default:
569 ret = ptrace_request(child, request, addr, data);
570 break;
571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return ret;
573}
574
575static void syscall_trace(struct pt_regs *regs)
576{
577
578#if 0
579 printk("trace %s rip %lx rsp %lx rax %d origrax %d caller %lx tiflags %x ptrace %x\n",
580 current->comm,
581 regs->rip, regs->rsp, regs->rax, regs->orig_rax, __builtin_return_address(0),
582 current_thread_info()->flags, current->ptrace);
583#endif
584
585 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
586 ? 0x80 : 0));
587 /*
588 * this isn't the same as continuing with a signal, but it will do
589 * for normal use. strace only continues with a signal if the
590 * stopping signal is not SIGTRAP. -brl
591 */
592 if (current->exit_code) {
593 send_sig(current->exit_code, current, 1);
594 current->exit_code = 0;
595 }
596}
597
598asmlinkage void syscall_trace_enter(struct pt_regs *regs)
599{
600 /* do the secure computing check first */
601 secure_computing(regs->orig_rax);
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (test_thread_flag(TIF_SYSCALL_TRACE)
604 && (current->ptrace & PT_PTRACED))
605 syscall_trace(regs);
2fd6f582005-04-29 16:08:28 +0100606
David Woodhouse488f2ea2005-05-03 14:11:02 +0100607 if (unlikely(current->audit_context)) {
608 if (test_thread_flag(TIF_IA32)) {
Al Viro5411be52006-03-29 20:23:36 -0500609 audit_syscall_entry(AUDIT_ARCH_I386,
David Woodhouse488f2ea2005-05-03 14:11:02 +0100610 regs->orig_rax,
611 regs->rbx, regs->rcx,
612 regs->rdx, regs->rsi);
613 } else {
Al Viro5411be52006-03-29 20:23:36 -0500614 audit_syscall_entry(AUDIT_ARCH_X86_64,
David Woodhouse488f2ea2005-05-03 14:11:02 +0100615 regs->orig_rax,
616 regs->rdi, regs->rsi,
617 regs->rdx, regs->r10);
618 }
619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
621
622asmlinkage void syscall_trace_leave(struct pt_regs *regs)
623{
624 if (unlikely(current->audit_context))
Al Viro5411be52006-03-29 20:23:36 -0500625 audit_syscall_exit(AUDITSC_RESULT(regs->rax), regs->rax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 if ((test_thread_flag(TIF_SYSCALL_TRACE)
628 || test_thread_flag(TIF_SINGLESTEP))
629 && (current->ptrace & PT_PTRACED))
630 syscall_trace(regs);
631}