diff --git a/arch/alpha/kernel/asm-offsets.c b/arch/alpha/kernel/asm-offsets.c index c1f42cb25d3bd13d1c81c0dafc0d6178a2966b94..79b9b27166a3d2b52f938646331391f5d538291f 100644 --- a/arch/alpha/kernel/asm-offsets.c +++ b/arch/alpha/kernel/asm-offsets.c @@ -7,6 +7,7 @@ #include <linux/types.h> #include <linux/stddef.h> #include <linux/sched.h> +#include <linux/ptrace.h> #include <asm/io.h> #define DEFINE(sym, val) \ diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c index f9934af388ed73ee22bbe204e32644c2874c82c8..c6d707e5bdf33fdd50a142cb5e3447b53df6b2ad 100644 --- a/arch/i386/kernel/process.c +++ b/arch/i386/kernel/process.c @@ -36,6 +36,7 @@ #include <linux/mc146818rtc.h> #include <linux/module.h> #include <linux/kallsyms.h> +#include <linux/ptrace.h> #include <asm/uaccess.h> #include <asm/pgtable.h> diff --git a/arch/i386/kernel/traps.c b/arch/i386/kernel/traps.c index 234ced527110e4a6f1a990d2e7f056fe0a510de4..bca393dbee668c74edd94f157a18f54928bba398 100644 --- a/arch/i386/kernel/traps.c +++ b/arch/i386/kernel/traps.c @@ -24,6 +24,7 @@ #include <linux/interrupt.h> #include <linux/highmem.h> #include <linux/kallsyms.h> +#include <linux/ptrace.h> #ifdef CONFIG_EISA #include <linux/ioport.h> diff --git a/arch/i386/kernel/vm86.c b/arch/i386/kernel/vm86.c index 269cf00ddf4eb05028665dffd15a0a9661e03627..ea5b776be20242720e0ebc54901a6844c86dbaf8 100644 --- a/arch/i386/kernel/vm86.c +++ b/arch/i386/kernel/vm86.c @@ -40,6 +40,7 @@ #include <linux/smp.h> #include <linux/smp_lock.h> #include <linux/highmem.h> +#include <linux/ptrace.h> #include <asm/uaccess.h> #include <asm/pgalloc.h> diff --git a/arch/i386/math-emu/fpu_entry.c b/arch/i386/math-emu/fpu_entry.c index c37a93bea50b4b6213d727e827d62ed0992c15a2..baebe5c08da7522cac347f28cfc1d0c0d7fc35cd 100644 --- a/arch/i386/math-emu/fpu_entry.c +++ b/arch/i386/math-emu/fpu_entry.c @@ -25,6 +25,7 @@ +---------------------------------------------------------------------------*/ #include <linux/signal.h> +#include <linux/ptrace.h> #include <asm/uaccess.h> #include <asm/desc.h> diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c index 65860c3865a51f61defd586334b9ad05ffd524d6..3fa05f5351b42e48a54a720df6dd7d2427a6a7f3 100644 --- a/arch/m68k/kernel/traps.c +++ b/arch/m68k/kernel/traps.c @@ -29,6 +29,7 @@ #include <linux/string.h> #include <linux/linkage.h> #include <linux/init.h> +#include <linux/ptrace.h> #include <asm/setup.h> #include <asm/fpu.h> diff --git a/arch/m68knommu/kernel/asm-offsets.c b/arch/m68knommu/kernel/asm-offsets.c index 8c81e421a0301f5f36d6dd11a138be67d3627371..c803fe64e2ce4f2589dddfa7aefae7f2d0274e46 100644 --- a/arch/m68knommu/kernel/asm-offsets.c +++ b/arch/m68knommu/kernel/asm-offsets.c @@ -11,6 +11,7 @@ #include <linux/stddef.h> #include <linux/sched.h> #include <linux/kernel_stat.h> +#include <linux/ptrace.h> #include <asm/bootinfo.h> #include <asm/irq.h> #include <asm/hardirq.h> diff --git a/arch/m68knommu/kernel/traps.c b/arch/m68knommu/kernel/traps.c index 45283b564eb839d8dac7b1c2b8ce424b0556f0a1..7373bbf38db600de5db7aef0ac5f70faa6c0e27e 100644 --- a/arch/m68knommu/kernel/traps.c +++ b/arch/m68knommu/kernel/traps.c @@ -27,6 +27,7 @@ #include <linux/string.h> #include <linux/linkage.h> #include <linux/init.h> +#include <linux/ptrace.h> #include <asm/setup.h> #include <asm/fpu.h> diff --git a/arch/mips/kernel/irixsig.c b/arch/mips/kernel/irixsig.c index cc687306faccf66fef6b78a907cddea3c0322711..088f746119c65b075280e6141a88eafaf82b6b08 100644 --- a/arch/mips/kernel/irixsig.c +++ b/arch/mips/kernel/irixsig.c @@ -12,6 +12,7 @@ #include <linux/smp.h> #include <linux/smp_lock.h> #include <linux/time.h> +#include <linux/ptrace.h> #include <asm/ptrace.h> #include <asm/uaccess.h> diff --git a/arch/mips/kernel/sysmips.c b/arch/mips/kernel/sysmips.c index f8664242b8d7d4575705ddd5514799f8282e7eea..5a21cd0083e95187889b522c0bb912e7252636d9 100644 --- a/arch/mips/kernel/sysmips.c +++ b/arch/mips/kernel/sysmips.c @@ -16,6 +16,7 @@ #include <linux/sched.h> #include <linux/string.h> #include <linux/utsname.h> +#include <linux/ptrace.h> #include <asm/cachectl.h> #include <asm/pgalloc.h> diff --git a/arch/parisc/hpux/fs.c b/arch/parisc/hpux/fs.c index afe8ae65540f0dac44c138ceddc109a4093c4111..c22c789091e15ea8e69be150b82e45363e4d38dd 100644 --- a/arch/parisc/hpux/fs.c +++ b/arch/parisc/hpux/fs.c @@ -9,6 +9,7 @@ #include <linux/file.h> #include <linux/smp_lock.h> #include <linux/slab.h> +#include <linux/ptrace.h> #include <asm/errno.h> #include <asm/uaccess.h> diff --git a/arch/parisc/kernel/sys_parisc32.c b/arch/parisc/kernel/sys_parisc32.c index 3e2d0013d34007b092e94613a4e1df37fa0be8f7..4d6a5cf7dd21d50d09c2b8d8ad5cbc7955f9068c 100644 --- a/arch/parisc/kernel/sys_parisc32.c +++ b/arch/parisc/kernel/sys_parisc32.c @@ -53,6 +53,7 @@ #include <linux/binfmts.h> #include <linux/namei.h> #include <linux/vfs.h> +#include <linux/ptrace.h> #include <asm/types.h> #include <asm/uaccess.h> diff --git a/arch/ppc64/kernel/process.c b/arch/ppc64/kernel/process.c index c81d2cd0277276705940199a9aa97de98fb5e4a4..3b40722bd7033a716c6f6f5e8343687bdfdb8dad 100644 --- a/arch/ppc64/kernel/process.c +++ b/arch/ppc64/kernel/process.c @@ -31,6 +31,7 @@ #include <linux/init.h> #include <linux/init_task.h> #include <linux/prctl.h> +#include <linux/ptrace.h> #include <asm/pgtable.h> #include <asm/uaccess.h> diff --git a/arch/ppc64/kernel/sys_ppc32.c b/arch/ppc64/kernel/sys_ppc32.c index b8a0424c0e6cc0723be48b666720f9b5f7e4eaea..b5ddbaac34deefbfbaec17c7082a83d32c59a3e1 100644 --- a/arch/ppc64/kernel/sys_ppc32.c +++ b/arch/ppc64/kernel/sys_ppc32.c @@ -58,6 +58,7 @@ #include <linux/dnotify.h> #include <linux/security.h> #include <linux/compat.h> +#include <linux/ptrace.h> #include <asm/types.h> #include <asm/ipc.h> diff --git a/arch/s390x/kernel/linux32.c b/arch/s390x/kernel/linux32.c index fce07ff5aae3d414d4118f0cc4a951041c88f922..fc87ddddf6874718fc04aec84a6197cf7c38e26d 100644 --- a/arch/s390x/kernel/linux32.c +++ b/arch/s390x/kernel/linux32.c @@ -58,6 +58,7 @@ #include <linux/binfmts.h> #include <linux/compat.h> #include <linux/vfs.h> +#include <linux/ptrace.h> #include <asm/types.h> #include <asm/ipc.h> diff --git a/arch/sh/kernel/process.c b/arch/sh/kernel/process.c index 62fdca125d9d1bf217a294356130dec0d6303a17..7f3653647f6b99d2339a98004d4bac914131eb6c 100644 --- a/arch/sh/kernel/process.c +++ b/arch/sh/kernel/process.c @@ -15,6 +15,7 @@ #include <linux/mm.h> #include <linux/slab.h> #include <linux/a.out.h> +#include <linux/ptrace.h> #include <asm/io.h> #include <asm/uaccess.h> diff --git a/arch/sparc64/kernel/sys_sparc32.c b/arch/sparc64/kernel/sys_sparc32.c index 1f2fb2b35849d30fb20719dc9dfcccc1e5d86631..eadc30630cd83211c3e130e417a70019eb3266f7 100644 --- a/arch/sparc64/kernel/sys_sparc32.c +++ b/arch/sparc64/kernel/sys_sparc32.c @@ -54,6 +54,7 @@ #include <linux/compat.h> #include <linux/vfs.h> #include <linux/netfilter_ipv4/ip_tables.h> +#include <linux/ptrace.h> #include <asm/types.h> #include <asm/ipc.h> diff --git a/arch/um/kernel/exec_kern.c b/arch/um/kernel/exec_kern.c index eaae628fa90258b142ea1efc79e807ac0d9ff0f1..a6be6b542b4aec56fde051585fae06d4c3787983 100644 --- a/arch/um/kernel/exec_kern.c +++ b/arch/um/kernel/exec_kern.c @@ -5,6 +5,7 @@ #include "linux/slab.h" #include "linux/smp_lock.h" +#include "linux/ptrace.h" #include "asm/ptrace.h" #include "asm/pgtable.h" #include "asm/tlbflush.h" diff --git a/arch/um/kernel/signal_kern.c b/arch/um/kernel/signal_kern.c index cc9ab3416c9ae84514a0fa659f6c8e0848e12019..6e13847edb7584ed12a05ab644390993aa1ba848 100644 --- a/arch/um/kernel/signal_kern.c +++ b/arch/um/kernel/signal_kern.c @@ -14,6 +14,7 @@ #include "linux/slab.h" #include "linux/tty.h" #include "linux/binfmts.h" +#include "linux/ptrace.h" #include "asm/signal.h" #include "asm/uaccess.h" #include "asm/unistd.h" diff --git a/arch/um/kernel/skas/process_kern.c b/arch/um/kernel/skas/process_kern.c index 01ccfb478ebde77be272d6b2704fdc5474fbf69e..e0ea56be1daeeb7af8327a170c254c8584cb9403 100644 --- a/arch/um/kernel/skas/process_kern.c +++ b/arch/um/kernel/skas/process_kern.c @@ -5,6 +5,7 @@ #include "linux/sched.h" #include "linux/slab.h" +#include "linux/ptrace.h" #include "kern_util.h" #include "time_user.h" #include "signal_user.h" diff --git a/arch/um/kernel/tt/process_kern.c b/arch/um/kernel/tt/process_kern.c index 6e8bb62bf77be891b8d04bd24e99b8192a4212cd..b4a855f44adc01645cd5149f3fcfe8fea2b5297d 100644 --- a/arch/um/kernel/tt/process_kern.c +++ b/arch/um/kernel/tt/process_kern.c @@ -7,6 +7,7 @@ #include "linux/signal.h" #include "linux/kernel.h" #include "linux/interrupt.h" +#include "linux/ptrace.h" #include "asm/system.h" #include "asm/pgalloc.h" #include "asm/ptrace.h" diff --git a/arch/um/kernel/tt/syscall_kern.c b/arch/um/kernel/tt/syscall_kern.c index 7401449b1a2e147513ef5847eeb016d05057d3f4..1b71f9ce51843193d9aa33be1a1b8ff07f043ab8 100644 --- a/arch/um/kernel/tt/syscall_kern.c +++ b/arch/um/kernel/tt/syscall_kern.c @@ -6,6 +6,7 @@ #include "linux/types.h" #include "linux/utime.h" #include "linux/sys.h" +#include "linux/ptrace.h" #include "asm/unistd.h" #include "asm/ptrace.h" #include "asm/uaccess.h" diff --git a/arch/v850/kernel/asm-consts.c b/arch/v850/kernel/asm-consts.c index 44e042344612f310a1a5bc3bbe5e9e345e3954fa..666930d9cea658d022c0241c0af797c8da8a4f81 100644 --- a/arch/v850/kernel/asm-consts.c +++ b/arch/v850/kernel/asm-consts.c @@ -11,6 +11,7 @@ #include <linux/stddef.h> #include <linux/sched.h> #include <linux/kernel_stat.h> +#include <linux/ptrace.h> #include <asm/irq.h> #include <asm/hardirq.h> #include <asm/errno.h> diff --git a/arch/x86_64/ia32/sys_ia32.c b/arch/x86_64/ia32/sys_ia32.c index 3849c0ad3ec096757eaceb69521ded69ffc8a555..a7d36b41c5934ea025134eb273bbb74c6ec96186 100644 --- a/arch/x86_64/ia32/sys_ia32.c +++ b/arch/x86_64/ia32/sys_ia32.c @@ -59,6 +59,7 @@ #include <linux/aio_abi.h> #include <linux/compat.h> #include <linux/vfs.h> +#include <linux/ptrace.h> #include <asm/mman.h> #include <asm/types.h> #include <asm/uaccess.h> diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index a369757dc78cd281f7c1a845e1ed965a579219e9..91d24995dfcfce46f6140ed6ac547bd7b230c658 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c @@ -24,6 +24,7 @@ #include <linux/binfmts.h> #include <linux/personality.h> #include <linux/init.h> +#include <linux/ptrace.h> #include <asm/system.h> #include <asm/uaccess.h> diff --git a/fs/proc/base.c b/fs/proc/base.c index 164fb87ea678aa1a85d5b22dc633260006dc1cb1..cfb54c010ef91fc16f779a1a7350f27b46df211e 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -31,6 +31,7 @@ #include <linux/kallsyms.h> #include <linux/mount.h> #include <linux/security.h> +#include <linux/ptrace.h> /* * For hysterical raisins we keep the same inumbers as in the old procfs. diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index 706b420fb5c9cc9a43707576af4b53524eea30f2..5d44a953f42347dcb12bf48fccbb5368b1fad9db 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h @@ -3,8 +3,6 @@ /* ptrace.h */ /* structs and defines to help the user use the ptrace system call. */ -#include <linux/compiler.h> - /* has the defines to get at the registers. */ #define PTRACE_TRACEME 0 @@ -38,6 +36,8 @@ #define PTRACE_O_TRACEVFORKDONE 0x00000020 #define PTRACE_O_TRACEEXIT 0x00000040 +#define PTRACE_O_MASK 0x0000007f + /* Wait extended result codes for the above trace options. */ #define PTRACE_EVENT_FORK 1 #define PTRACE_EVENT_VFORK 2 @@ -47,7 +47,27 @@ #define PTRACE_EVENT_EXIT 6 #include <asm/ptrace.h> -#include <linux/sched.h> + +#ifdef __KERNEL__ +/* + * Ptrace flags + */ + +#define PT_PTRACED 0x00000001 +#define PT_DTRACE 0x00000002 /* delayed trace (used on m68k, i386) */ +#define PT_TRACESYSGOOD 0x00000004 +#define PT_PTRACE_CAP 0x00000008 /* ptracer can follow suid-exec */ +#define PT_TRACE_FORK 0x00000010 +#define PT_TRACE_VFORK 0x00000020 +#define PT_TRACE_CLONE 0x00000040 +#define PT_TRACE_EXEC 0x00000080 +#define PT_TRACE_VFORK_DONE 0x00000100 +#define PT_TRACE_EXIT 0x00000200 + +#define PT_TRACE_MASK 0x000003f4 + +#include <linux/compiler.h> /* For unlikely. */ +#include <linux/sched.h> /* For struct task_struct. */ extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char *dst, int len); extern int ptrace_writedata(struct task_struct *tsk, char * src, unsigned long dst, int len); @@ -58,11 +78,11 @@ extern int ptrace_check_attach(struct task_struct *task, int kill); extern int ptrace_request(struct task_struct *child, long request, long addr, long data); extern void ptrace_notify(int exit_code); extern void __ptrace_link(struct task_struct *child, - struct task_struct *new_parent); + struct task_struct *new_parent); extern void __ptrace_unlink(struct task_struct *child); static inline void ptrace_link(struct task_struct *child, - struct task_struct *new_parent) + struct task_struct *new_parent) { if (unlikely(child->ptrace)) __ptrace_link(child, new_parent); @@ -72,5 +92,6 @@ static inline void ptrace_unlink(struct task_struct *child) if (unlikely(child->ptrace)) __ptrace_unlink(child); } +#endif #endif diff --git a/include/linux/sched.h b/include/linux/sched.h index d3cd5e31e8f95f3de945c4fdc18cb9da039e1530..cfa6fd4d86dacce61a5367a6412c720b7aba8cf0 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -446,21 +446,6 @@ do { if (atomic_dec_and_test(&(tsk)->usage)) __put_task_struct(tsk); } while(0) #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ #define PF_KSWAPD 0x00040000 /* I am kswapd */ -/* - * Ptrace flags - */ - -#define PT_PTRACED 0x00000001 -#define PT_DTRACE 0x00000002 /* delayed trace (used on m68k, i386) */ -#define PT_TRACESYSGOOD 0x00000004 -#define PT_PTRACE_CAP 0x00000008 /* ptracer can follow suid-exec */ -#define PT_TRACE_FORK 0x00000010 -#define PT_TRACE_VFORK 0x00000020 -#define PT_TRACE_CLONE 0x00000040 -#define PT_TRACE_EXEC 0x00000080 -#define PT_TRACE_VFORK_DONE 0x00000100 -#define PT_TRACE_EXIT 0x00000200 - #if CONFIG_SMP extern void set_cpus_allowed(task_t *p, unsigned long new_mask); #else diff --git a/kernel/exit.c b/kernel/exit.c index 0523eb305c1777ce9b2c31393068a18a102c5678..d2d7c72f1e81e10fe0bcd847c7d683ad4e4d4483 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -694,10 +694,8 @@ static void exit_notify(struct task_struct *tsk) * only has special meaning to our real parent. */ if (tsk->exit_signal != -1) { - if (tsk->parent == tsk->real_parent) - do_notify_parent(tsk, tsk->exit_signal); - else - do_notify_parent(tsk, SIGCHLD); + int signal = tsk->parent == tsk->real_parent ? tsk->exit_signal : SIGCHLD; + do_notify_parent(tsk, signal); } tsk->state = TASK_ZOMBIE; @@ -731,8 +729,10 @@ NORET_TYPE void do_exit(long code) profile_exit_task(tsk); - if (unlikely(current->ptrace & PT_TRACE_EXIT)) + if (unlikely(current->ptrace & PT_TRACE_EXIT)) { + current->ptrace_message = code; ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP); + } acct_process(code); __exit_mm(tsk); diff --git a/kernel/ptrace.c b/kernel/ptrace.c index f67675f3d9d3bdfe0cc90660a6517655278caf49..287b81b65c348aeaca1e644d769d33fd20afcb35 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -252,49 +252,30 @@ int ptrace_writedata(struct task_struct *tsk, char * src, unsigned long dst, int static int ptrace_setoptions(struct task_struct *child, long data) { + child->ptrace &= ~PT_TRACE_MASK; + if (data & PTRACE_O_TRACESYSGOOD) child->ptrace |= PT_TRACESYSGOOD; - else - child->ptrace &= ~PT_TRACESYSGOOD; if (data & PTRACE_O_TRACEFORK) child->ptrace |= PT_TRACE_FORK; - else - child->ptrace &= ~PT_TRACE_FORK; if (data & PTRACE_O_TRACEVFORK) child->ptrace |= PT_TRACE_VFORK; - else - child->ptrace &= ~PT_TRACE_VFORK; if (data & PTRACE_O_TRACECLONE) child->ptrace |= PT_TRACE_CLONE; - else - child->ptrace &= ~PT_TRACE_CLONE; if (data & PTRACE_O_TRACEEXEC) child->ptrace |= PT_TRACE_EXEC; - else - child->ptrace &= ~PT_TRACE_EXEC; if (data & PTRACE_O_TRACEVFORKDONE) child->ptrace |= PT_TRACE_VFORK_DONE; - else - child->ptrace &= ~PT_TRACE_VFORK_DONE; if (data & PTRACE_O_TRACEEXIT) child->ptrace |= PT_TRACE_EXIT; - else - child->ptrace &= ~PT_TRACE_EXIT; - - if ((data & (PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEFORK - | PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE - | PTRACE_O_TRACEEXEC | PTRACE_O_TRACEEXIT - | PTRACE_O_TRACEVFORKDONE)) - != data) - return -EINVAL; - return 0; + return (data & ~PTRACE_O_MASK) ? -EINVAL : 0; } static int ptrace_getsiginfo(struct task_struct *child, long data) diff --git a/kernel/signal.c b/kernel/signal.c index d0d09cfbe8632b50a32f38599c6aa02990f2874a..b8fc6a05c03157f9990329fe04599f518f4890df 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -19,6 +19,7 @@ #include <linux/tty.h> #include <linux/binfmts.h> #include <linux/security.h> +#include <linux/ptrace.h> #include <asm/param.h> #include <asm/uaccess.h> #include <asm/siginfo.h> diff --git a/security/capability.c b/security/capability.c index 5909732acdfc2efb715130c77e86b6690f13b2aa..09882ecc997d0010fd07000b158a184e2944a525 100644 --- a/security/capability.c +++ b/security/capability.c @@ -18,6 +18,7 @@ #include <linux/smp_lock.h> #include <linux/skbuff.h> #include <linux/netlink.h> +#include <linux/ptrace.h> int cap_capable (struct task_struct *tsk, int cap) {