[PATCH consolidate sys_ptrace
Subsystems (11)
[Let's try again now that sys_ptrace returns long everywhere mainline..]
The sys_ptrace boilerplate code (everything outside the big switch statement for the arch-specific requests) is shared by most architectures. This patch moves it to kernel/ptrace.c and leaves the arch-specific code as arch_ptrace.
Some architectures have a too different ptrace so we have to exclude them. They continue to keep their implementations. For sh64 I had to add a sh64_ptrace wrapper because it does some initialization on the first call. For um I removed an ifdefed SUBARCH_PTRACE_SPECIAL block, but SUBARCH_PTRACE_SPECIAL isn't defined anywhere in the tree.
arch/arm/kernel/ptrace.c +1 -48
@@ -648,7 +648,7 @@#endif -static int do_ptrace (int request,struct task_struct *child,long addr,long data) +long arch_ptrace (struct task_struct *child,long request,long addr,long data) {unsigned long tmp;int ret;
@@ -782,53 +782,6 @@return ret; } -asmlinkage int sys_ptrace(long request, long pid, long addr, long data) -{ -struct task_struct *child; -int ret; - -lock_kernel (); - ret = -EPERM ; -if (request ==PTRACE_TRACEME ) { -/* are we already being traced? */ -if (current->ptrace &PT_PTRACED ) - goto out; - ret =security_ptrace (current->parent, current); -if (ret) - goto out; -/* set the ptrace bit in the process flags. */ - current->ptrace |=PT_PTRACED ; - ret =0 ; - goto out; - } - ret = -ESRCH ; -read_lock (&tasklist_lock); - child =find_task_by_pid (pid); -if (child) -get_task_struct (child); -read_unlock (&tasklist_lock); -if (!child) - goto out; - - ret = -EPERM ; -if (pid ==1 )/* you may not mess with init */ - goto out_tsk; - -if (request ==PTRACE_ATTACH ) { - ret =ptrace_attach (child); - goto out_tsk; - } - ret =ptrace_check_attach (child, request ==PTRACE_KILL ); -if (ret ==0 ) - ret =do_ptrace (request, child, addr, data); - -out_tsk: -put_task_struct (child); -out: -unlock_kernel (); -return ret; -} - asmlinkage void syscall_trace(int why, struct pt_regs *regs) {unsigned long ip;
arch/arm26/kernel/ptrace.c +1 -48
61 lines not on this page · raw message
arch/frv/kernel/ptrace.c +1 -42
59 lines not on this page · raw message
arch/h8300/kernel/ptrace.c +1 -38
@@ -57,43 +57,10 @@h8300_disable_trace (child); } -asmlinkage int sys_ptrace(long request, long pid, long addr, long data) +long arch_ptrace (struct task_struct *child,long request,long addr,long data) { -struct task_struct *child;int ret; -lock_kernel (); - ret = -EPERM ; -if (request ==PTRACE_TRACEME ) { -/* are we already being traced? */ -if (current->ptrace &PT_PTRACED ) - goto out; -/* set the ptrace bit in the process flags. */ - current->ptrace |=PT_PTRACED ; - ret =0 ; - goto out; - } - ret = -ESRCH ; -read_lock (&tasklist_lock); - child =find_task_by_pid (pid); -if (child) -get_task_struct (child); -read_unlock (&tasklist_lock); -if (!child) - goto out; - - ret = -EPERM ; -if (pid ==1 )/* you may not mess with init */ - goto out_tsk; - -if (request ==PTRACE_ATTACH ) { - ret =ptrace_attach (child); - goto out_tsk; - } - ret =ptrace_check_attach (child, request ==PTRACE_KILL ); -if (ret <0 ) - goto out_tsk; -switch (request) {case PTRACE_PEEKTEXT :/* read word at location addr. */ case PTRACE_PEEKDATA : {
@@ -251,10 +218,6 @@ ret = -EIO ;break ; } -out_tsk: -put_task_struct (child); -out: -unlock_kernel ();return ret; }
arch/i386/kernel/ptrace.c +2 -42
61 lines not on this page · raw message
arch/m68knommu/kernel/ptrace.c +1 -38
@@ -101,43 +101,10 @@put_reg (child,PT_SR , tmp); } -asmlinkage int sys_ptrace(long request, long pid, long addr, long data) +long arch_ptrace(truct task_struct *child, long request, long addr, long data) { -struct task_struct *child;int ret; -lock_kernel (); - ret = -EPERM ; -if (request ==PTRACE_TRACEME ) { -/* are we already being traced? */ -if (current->ptrace &PT_PTRACED ) - goto out; -/* set the ptrace bit in the process flags. */ - current->ptrace |=PT_PTRACED ; - ret =0 ; - goto out; - } - ret = -ESRCH ; -read_lock (&tasklist_lock); - child =find_task_by_pid (pid); -if (child) -get_task_struct (child); -read_unlock (&tasklist_lock); -if (!child) - goto out; - - ret = -EPERM ; -if (pid ==1 )/* you may not mess with init */ - goto out_tsk; - -if (request ==PTRACE_ATTACH ) { - ret =ptrace_attach (child); - goto out_tsk; - } - ret =ptrace_check_attach (child, request ==PTRACE_KILL ); -if (ret <0 ) - goto out_tsk; -switch (request) {/* when I and D space are separate, these will need to be fixed. */ case PTRACE_PEEKTEXT :/* read word at location addr. */
@@ -357,10 +324,6 @@ ret = -EIO ;break ; } -out_tsk: -put_task_struct (child); -out: -unlock_kernel ();return ret; }
arch/mips/kernel/ptrace.c +1 -46
62 lines not on this page · raw message
arch/ppc/kernel/ptrace.c +2 -41
58 lines not on this page · raw message
arch/ppc64/kernel/ptrace.c +2 -41
58 lines not on this page · raw message
arch/sh/kernel/ptrace.c +2 -42
60 lines not on this page · raw message
arch/v850/kernel/ptrace.c +1 -40
56 lines not on this page · raw message
arch/x86_64/kernel/ptrace.c +1 -42
59 lines not on this page · raw message
arch/xtensa/kernel/ptrace.c +2 -53
70 lines not on this page · raw message
kernel/ptrace.c +82 -0
85 lines not on this page · raw message
arch/cris/arch-v10/kernel/ptrace.c +2 -49
67 lines not on this page · raw message
arch/cris/arch-v32/kernel/ptrace.c +2 -49
67 lines not on this page · raw message
arch/um/kernel/ptrace.c +2 -48
65 lines not on this page · raw message
include/asm-alpha/ptrace.h +3 -0
@@ -67,6 +67,9 @@ };#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +#define user_mode (regs) (((regs)->ps & 8) != 0)#define instruction_pointer (regs) ((regs)->pc)#define profile_pc (regs) instruction_pointer(regs)
include/asm-arm/unistd.h +0 -1
@@ -542,7 +542,6 @@ asmlinkage int sys_fork(struct pt_regs *regs); asmlinkage int sys_vfork(struct pt_regs *regs); asmlinkage int sys_pipe(unsigned long *fildes); -asmlinkage int sys_ptrace(long request, long pid, long addr, long data);struct sigaction ; asmlinkage long sys_rt_sigaction(int sig, const struct sigaction __user *act,
include/asm-arm26/unistd.h +0 -1
@@ -480,7 +480,6 @@ asmlinkage int sys_fork(struct pt_regs *regs); asmlinkage int sys_vfork(struct pt_regs *regs); asmlinkage int sys_pipe(unsigned long *fildes); -asmlinkage int sys_ptrace(long request, long pid, long addr, long data);struct sigaction ; asmlinkage long sys_rt_sigaction(int sig, const struct sigaction __user *act,
include/asm-cris/unistd.h +0 -1
@@ -367,7 +367,6 @@ asmlinkage int sys_vfork(long r10, long r11, long r12, long r13,long mof,long srp,struct pt_regs *regs); asmlinkage int sys_pipe(unsigned long __user *fildes); -asmlinkage int sys_ptrace(long request, long pid, long addr, long data);struct sigaction ; asmlinkage long sys_rt_sigaction(int sig, const struct sigaction __user *act,
include/asm-h8300/unistd.h +0 -1
@@ -528,7 +528,6 @@ asmlinkage int sys_execve(char *name, char **argv, char **envp,int dummy, ...); asmlinkage int sys_pipe(unsigned long *fildes); -asmlinkage int sys_ptrace(long request, long pid, long addr, long data);struct sigaction ; asmlinkage long sys_rt_sigaction(int sig, const struct sigaction __user *act,
include/asm-i386/unistd.h +0 -1
@@ -448,7 +448,6 @@ asmlinkage int sys_fork(struct pt_regs regs); asmlinkage int sys_vfork(struct pt_regs regs); asmlinkage int sys_pipe(unsigned long __user *fildes); -asmlinkage int sys_ptrace(long request, long pid, long addr, long data);asmlinkage long sys_iopl (unsigned long unused);struct sigaction ; asmlinkage long sys_rt_sigaction(int sig,
include/asm-ia64/ptrace.h +3 -0
@@ -227,6 +227,9 @@ };#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +/* * We use the ia64_psr(regs)->ri to determine which of the three * instructions in bundle (16 bytes) took the sample. Generate
include/asm-m32r/ptrace.h +3 -0
@@ -145,6 +145,9 @@#define PTRACE_O_TRACESYSGOOD 0x00000001#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +#if defined(CONFIG_ISA_M32R2 ) || defined(CONFIG_CHIP_VDEC2 )#define user_mode (regs) ((M32R_PSW_BPM & (regs)->psw) != 0)#elif defined(CONFIG_ISA_M32R )
include/asm-m68knommu/unistd.h +0 -1
@@ -504,7 +504,6 @@ unsigned long fd, unsigned long pgoff); asmlinkage int sys_execve(char *name, char **argv, char **envp); asmlinkage int sys_pipe(unsigned long *fildes); -asmlinkage int sys_ptrace(long request, long pid, long addr, long data);struct pt_regs ; int sys_request_irq(unsigned int, irqreturn_t (*)(int, void *, struct pt_regs *),
include/asm-mips/unistd.h +0 -1
@@ -1164,7 +1164,6 @@ unsigned long fd, unsigned long pgoff); asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs); asmlinkage int sys_pipe(nabi_no_regargs struct pt_regs regs); -asmlinkage int sys_ptrace(long request, long pid, long addr, long data);struct sigaction ; asmlinkage long sys_rt_sigaction(int sig, const struct sigaction __user *act,
include/asm-parisc/ptrace.h +3 -0
@@ -45,6 +45,9 @@#define PTRACE_SINGLEBLOCK 12/* resume execution until next branch */ #ifdef __KERNEL__ +#define __ARCH_SYS_PTRACE 1 + +/* XXX should we use iaoq[1] or iaoq[0] ? */ #define user_mode (regs) (((regs)->iaoq[0] & 3) ? 1 : 0)#define user_space (regs) (((regs)->iasq[1] != 0) ? 1 : 0)
include/asm-ppc/unistd.h +0 -1
@@ -469,7 +469,6 @@int sys_vfork (int p1,int p2,int p3,int p4,int p5,int p6,struct pt_regs *regs);int sys_pipe (int __user *fildes); -int sys_ptrace (long request,long pid,long addr,long data);struct sigaction ; long sys_rt_sigaction(int sig, const struct sigaction __user *act,
include/asm-ppc64/unistd.h +0 -1
@@ -467,7 +467,6 @@ unsigned long p4, unsigned long p5, unsigned long p6, struct pt_regs *regs);int sys_pipe (int __user *fildes); -int sys_ptrace (long request,long pid,long addr,long data);struct sigaction ;long sys_rt_sigaction (int sig,const struct sigaction __user *act,struct sigaction __user *oact,size_t sigsetsize);
include/asm-sh/unistd.h +0 -1
@@ -503,7 +503,6 @@ asmlinkage int sys_pipe(unsigned long r4, unsigned long r5,unsigned long r6,unsigned long r7,struct pt_regs regs); -asmlinkage int sys_ptrace(long request, long pid, long addr, long data); asmlinkage ssize_t sys_pread_wrapper(unsigned int fd, char *buf,size_t count,long dummy,loff_t pos); asmlinkage ssize_t sys_pwrite_wrapper(unsigned int fd, const char *buf,
include/asm-sparc/ptrace.h +3 -0
@@ -60,6 +60,9 @@#define STACKFRAME_SZ sizeof(struct sparc_stackf)#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +#define user_mode (regs) (!((regs)->psr & PSR_PS))#define instruction_pointer (regs) ((regs)->pc)unsigned long profile_pc (struct pt_regs *);
include/asm-sparc64/ptrace.h +3 -0
@@ -94,6 +94,9 @@#define STACKFRAME32_SZ sizeof(struct sparc_stackf32)#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +#define force_successful_syscall_return () \ do { current_thread_info()->syscall_noerror = 1; \ } while (0)
include/asm-v850/unistd.h +0 -1
@@ -452,7 +452,6 @@struct pt_regs ;int sys_execve (char *name,char **argv,char **envp,struct pt_regs *regs);int sys_pipe (int *fildes); -int sys_ptrace (long request,long pid,long addr,long data);struct sigaction ; asmlinkage long sys_rt_sigaction(int sig, const struct sigaction __user *act,
include/asm-x86_64/unistd.h +0 -2
@@ -780,8 +780,6 @@#include <linux/types.h> #include <asm/ptrace.h> -asmlinkage long sys_ptrace (long request,long pid, -unsigned long addr,long data);asmlinkage long sys_iopl (unsigned int level,struct pt_regs *regs);asmlinkage long sys_ioperm (unsigned long from,unsigned long num,int turn_on);struct sigaction ;
include/linux/ptrace.h +2 -0
@@ -76,6 +76,8 @@#include <linux/compiler.h> /* For unlikely. */ #include <linux/sched.h> /* For struct task_struct. */ + +extern long arch_ptrace (struct task_struct *child,long request,long addr,long data);extern int ptrace_readdata (struct task_struct *tsk,unsigned long src,char __user *dst,int len);extern int ptrace_writedata (struct task_struct *tsk,char __user *src,unsigned long dst,int len);extern int ptrace_attach (struct task_struct *tsk);
arch/sh64/kernel/ptrace.c +27 -56
107 lines not on this page · raw message
arch/sh64/kernel/syscalls.S +1 -1
@@ -46,7 +46,7 @@ .long sys_setuid16 .long sys_getuid16 .long sys_stime /* 25 */ - .long sys_ptrace + .long sh64_ptrace .long sys_alarm .long sys_fstat .long sys_pause
include/asm-m68k/ptrace.h +1 -0
@@ -65,6 +65,7 @@#define PTRACE_SETFPREGS 15#ifdef __KERNEL__ +#define __ARCH_SYS_PTRACE 1#ifndef PS_S #define PS_S (0x2000)
include/asm-s390/ptrace.h +2 -0
@@ -468,6 +468,8 @@ };#ifdef __KERNEL__ +#define __ARCH_SYS_PTRACE 1 +#define user_mode (regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)#define instruction_pointer (regs) ((regs)->psw.addr & PSW_ADDR_INSN)#define profile_pc (regs) instruction_pointer(regs)
arch/ia64/ia32/sys_ia32.c +1 -0
@@ -50,6 +50,7 @@#include <linux/compat.h> #include <linux/vfs.h> #include <linux/mman.h> +#include <linux/syscalls.h> #include <asm/intrinsics.h> #include <asm/semaphore.h>
include/linux/syscalls.h +4 -0
@@ -60,6 +60,7 @@#include <asm/semaphore.h> #include <asm/siginfo.h> #include <asm/signal.h> +#include <asm/ptrace.h> /* for __ARCH_SYS_PTRACE */ #include <linux/quota.h> #include <linux/key.h>
@@ -477,6 +478,9 @@ unsigned long off, unsigned long len, void __user *buf); +#ifndef __ARCH_SYS_PTRACE +asmlinkage long sys_ptrace (long request,long pid,long addr,long data); +#endif asmlinkage long sys_prctl (int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5);asmlinkage long sys_swapon (const char __user *specialfile,int swap_flags);
Quoted 7 lines · Christoph Hellwig
[Let's try again now that
sys_ptracereturns long everywhere mainline..]The
sys_ptraceboilerplate code (everything outside the big switch statement for the arch-specific requests) is shared by most architectures. This patch moves it tokernel/ptrace.cand leaves the arch-specific code asarch_ptrace.
Quoted 5 lines
Some architectures have a too different ptrace so we have to exclude them. They continue to keep their implementations. For sh64 I had to add a
sh64_ptracewrapper because it does some initialization on the first call. For um I removed an ifdefedSUBARCH_PTRACE_SPECIALblock, butSUBARCH_PTRACE_SPECIALisn't defined anywhere in the tree.
Umm, it might be a good idea to actually send the current patch instead of the old one. I really should write this text from scratch instead of copying it :)
arch/arm/kernel/ptrace.c +1 -48
@@ -648,7 +648,7 @@#endif -static int do_ptrace (int request,struct task_struct *child,long addr,long data) +long arch_ptrace (struct task_struct *child,long request,long addr,long data) {unsigned long tmp;int ret;
@@ -782,53 +782,6 @@return ret; } -asmlinkage long sys_ptrace (long request,long pid,long addr,long data) -{ -struct task_struct *child; -int ret; - -lock_kernel (); - ret = -EPERM ; -if (request ==PTRACE_TRACEME ) { -/* are we already being traced? */ -if (current->ptrace &PT_PTRACED ) - goto out; - ret =security_ptrace (current->parent, current); -if (ret) - goto out; -/* set the ptrace bit in the process flags. */ - current->ptrace |=PT_PTRACED ; - ret =0 ; - goto out; - } - ret = -ESRCH ; -read_lock (&tasklist_lock); - child =find_task_by_pid (pid); -if (child) -get_task_struct (child); -read_unlock (&tasklist_lock); -if (!child) - goto out; - - ret = -EPERM ; -if (pid ==1 )/* you may not mess with init */ - goto out_tsk; - -if (request ==PTRACE_ATTACH ) { - ret =ptrace_attach (child); - goto out_tsk; - } - ret =ptrace_check_attach (child, request ==PTRACE_KILL ); -if (ret ==0 ) - ret =do_ptrace (request, child, addr, data); - -out_tsk: -put_task_struct (child); -out: -unlock_kernel (); -return ret; -} - asmlinkage void syscall_trace(int why, struct pt_regs *regs) {unsigned long ip;
arch/arm26/kernel/ptrace.c +1 -48
61 lines not on this page · raw message
arch/frv/kernel/ptrace.c +1 -42
59 lines not on this page · raw message
arch/h8300/kernel/ptrace.c +1 -38
@@ -57,43 +57,10 @@h8300_disable_trace (child); } -asmlinkage long sys_ptrace (long request,long pid,long addr,long data) +long arch_ptrace (struct task_struct *child,long request,long addr,long data) { -struct task_struct *child;int ret; -lock_kernel (); - ret = -EPERM ; -if (request ==PTRACE_TRACEME ) { -/* are we already being traced? */ -if (current->ptrace &PT_PTRACED ) - goto out; -/* set the ptrace bit in the process flags. */ - current->ptrace |=PT_PTRACED ; - ret =0 ; - goto out; - } - ret = -ESRCH ; -read_lock (&tasklist_lock); - child =find_task_by_pid (pid); -if (child) -get_task_struct (child); -read_unlock (&tasklist_lock); -if (!child) - goto out; - - ret = -EPERM ; -if (pid ==1 )/* you may not mess with init */ - goto out_tsk; - -if (request ==PTRACE_ATTACH ) { - ret =ptrace_attach (child); - goto out_tsk; - } - ret =ptrace_check_attach (child, request ==PTRACE_KILL ); -if (ret <0 ) - goto out_tsk; -switch (request) {case PTRACE_PEEKTEXT :/* read word at location addr. */ case PTRACE_PEEKDATA : {
@@ -251,10 +218,6 @@ ret = -EIO ;break ; } -out_tsk: -put_task_struct (child); -out: -unlock_kernel ();return ret; }
arch/i386/kernel/ptrace.c +2 -42
61 lines not on this page · raw message
arch/m68knommu/kernel/ptrace.c +1 -38
@@ -101,43 +101,10 @@put_reg (child,PT_SR , tmp); } -asmlinkage long sys_ptrace (long request,long pid,long addr,long data) +long arch_ptrace(truct task_struct *child, long request, long addr, long data) { -struct task_struct *child;int ret; -lock_kernel (); - ret = -EPERM ; -if (request ==PTRACE_TRACEME ) { -/* are we already being traced? */ -if (current->ptrace &PT_PTRACED ) - goto out; -/* set the ptrace bit in the process flags. */ - current->ptrace |=PT_PTRACED ; - ret =0 ; - goto out; - } - ret = -ESRCH ; -read_lock (&tasklist_lock); - child =find_task_by_pid (pid); -if (child) -get_task_struct (child); -read_unlock (&tasklist_lock); -if (!child) - goto out; - - ret = -EPERM ; -if (pid ==1 )/* you may not mess with init */ - goto out_tsk; - -if (request ==PTRACE_ATTACH ) { - ret =ptrace_attach (child); - goto out_tsk; - } - ret =ptrace_check_attach (child, request ==PTRACE_KILL ); -if (ret <0 ) - goto out_tsk; -switch (request) {/* when I and D space are separate, these will need to be fixed. */ case PTRACE_PEEKTEXT :/* read word at location addr. */
@@ -357,10 +324,6 @@ ret = -EIO ;break ; } -out_tsk: -put_task_struct (child); -out: -unlock_kernel ();return ret; }
arch/mips/kernel/ptrace.c +5 -50
88 lines not on this page · raw message
arch/sh/kernel/ptrace.c +2 -42
60 lines not on this page · raw message
arch/v850/kernel/ptrace.c +2 -41
58 lines not on this page · raw message
arch/x86_64/kernel/ptrace.c +1 -42
59 lines not on this page · raw message
arch/xtensa/kernel/ptrace.c +2 -53
70 lines not on this page · raw message
kernel/ptrace.c +82 -0
85 lines not on this page · raw message
arch/cris/arch-v10/kernel/ptrace.c +2 -49
67 lines not on this page · raw message
arch/cris/arch-v32/kernel/ptrace.c +2 -49
67 lines not on this page · raw message
arch/um/kernel/ptrace.c +2 -48
65 lines not on this page · raw message
include/asm-alpha/ptrace.h +3 -0
@@ -67,6 +67,9 @@ };#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +#define user_mode (regs) (((regs)->ps & 8) != 0)#define instruction_pointer (regs) ((regs)->pc)#define profile_pc (regs) instruction_pointer(regs)
include/asm-ia64/ptrace.h +3 -0
@@ -229,6 +229,9 @@ };#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +/* * We use the ia64_psr(regs)->ri to determine which of the three * instructions in bundle (16 bytes) took the sample. Generate
include/asm-m32r/ptrace.h +3 -0
@@ -145,6 +145,9 @@#define PTRACE_O_TRACESYSGOOD 0x00000001#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +#if defined(CONFIG_ISA_M32R2 ) || defined(CONFIG_CHIP_VDEC2 )#define user_mode (regs) ((M32R_PSW_BPM & (regs)->psw) != 0)#elif defined(CONFIG_ISA_M32R )
include/asm-sparc/ptrace.h +3 -0
@@ -60,6 +60,9 @@#define STACKFRAME_SZ sizeof(struct sparc_stackf)#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +#define user_mode (regs) (!((regs)->psr & PSR_PS))#define instruction_pointer (regs) ((regs)->pc)unsigned long profile_pc (struct pt_regs *);
include/asm-sparc64/ptrace.h +3 -0
@@ -94,6 +94,9 @@#define STACKFRAME32_SZ sizeof(struct sparc_stackf32)#ifdef __KERNEL__ + +#define __ARCH_SYS_PTRACE 1 +#define force_successful_syscall_return () \ do { current_thread_info()->syscall_noerror = 1; \ } while (0)
include/linux/ptrace.h +2 -0
@@ -78,6 +78,8 @@#include <linux/compiler.h> /* For unlikely. */ #include <linux/sched.h> /* For struct task_struct. */ + +extern long arch_ptrace (struct task_struct *child,long request,long addr,long data);extern int ptrace_readdata (struct task_struct *tsk,unsigned long src,char __user *dst,int len);extern int ptrace_writedata (struct task_struct *tsk,char __user *src,unsigned long dst,int len);extern int ptrace_attach (struct task_struct *tsk);
arch/sh64/kernel/ptrace.c +27 -56
107 lines not on this page · raw message
arch/sh64/kernel/syscalls.S +1 -1
@@ -46,7 +46,7 @@ .long sys_setuid16 .long sys_getuid16 .long sys_stime /* 25 */ - .long sys_ptrace + .long sh64_ptrace .long sys_alarm .long sys_fstat .long sys_pause
include/asm-s390/ptrace.h +2 -0
@@ -468,6 +468,8 @@ };#ifdef __KERNEL__ +#define __ARCH_SYS_PTRACE 1 +#define user_mode (regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)#define instruction_pointer (regs) ((regs)->psw.addr & PSW_ADDR_INSN)#define profile_pc (regs) instruction_pointer(regs)
arch/m68k/kernel/ptrace.c +3 -44
65 lines not on this page · raw message
arch/parisc/kernel/ptrace.c +4 -46
77 lines not on this page · raw message
arch/powerpc/kernel/ptrace.c +2 -41
58 lines not on this page · raw message
Paul Mackerras
Acked-byQuoted 6 lines · Christoph Hellwig
Quoted 5 lines
Some architectures have a too different ptrace so we have to exclude them. They continue to keep their implementations. For sh64 I had to add a
sh64_ptracewrapper because it does some initialization on the first call. For um I removed an ifdefedSUBARCH_PTRACE_SPECIALblock, butSUBARCH_PTRACE_SPECIALisn't defined anywhere in the tree.
Quoted 6 lines
Umm, it might be a good idea to actually send the current patch instead of the old one. I really should write this text from scratch instead of copying it :)
Signed-off-by Christoph Hellwig <[email protected]>
On Tue, 01 Nov 2005 06:12:21 +0100, Christoph Hellwig wrote:
<snip>
Quoted 5 lines
Index:
linux-2.6/kernel/ptrace.c
===================================================================
kernel/ptrace.c line 415
Quoted 10 lines
kernel/ptrace.c +7
-0@@ -406,3 +406,85 @@return ret; } + +#ifndef __ARCH_SYS_PTRACE +static int ptrace_get_task_struct (long request,long pid, +struct task_struct **childp) +{ +struct task_struct *child; +int ret;
This "ret" is basically unused and should go away
Quoted 5 lines
kernel/ptrace.c +5
-0+ +/* +* Callers use child == NULL as an indication to exit early even +* when the return value is 0, so make sure it is non-NULL here. +*/
kernel/ptrace.c line 430
Quoted 10 lines
kernel/ptrace.c +10
-0+ *childp =NULL ; + +if (request ==PTRACE_TRACEME ) { +/* +* Are we already being traced? +*/ +if (current->ptrace &PT_PTRACED ) +return -EPERM ; + ret =security_ptrace (current->parent, current); +if (ret)
if (security_ptrace(current->parent, current))
Quoted 5 lines
kernel/ptrace.c +5
-0+return -EPERM ; +/* +* Set the ptrace bit in the process ptrace flags. +*/ + current->ptrace |=PT_PTRACED ;
kernel/ptrace.c line 445
Quoted 10 lines
kernel/ptrace.c +10
-0+return 0 ; + } + +/* +* You may not mess with init +*/ +if (pid ==1 ) +return -EPERM ; + + ret = -ESRCH ;
Not needed (anymore)
kernel/ptrace.c line 457
Quoted 12 lines
kernel/ptrace.c +12
-0+read_lock (&tasklist_lock); + child =find_task_by_pid (pid); +if (child) +get_task_struct (child); +read_unlock (&tasklist_lock); +if (!child) +return -ESRCH ; + + *childp = child; +return 0 ; +} +
Best,
Norbert
Quoted 6 lines · Christoph Hellwig
Umm, it might be a good idea to actually send the current patch instead of the old one. I really should write this text from scratch instead of copying it :)
Signed-off-by Christoph Hellwig <[email protected]>
Ralf
David Howells
Acked-byQuoted 4 lines · Christoph Hellwig
Quoted 4 lines
The
sys_ptraceboilerplate code (everything outside the big switch statement for the arch-specific requests) is shared by most architectures. This patch moves it tokernel/ptrace.cand leaves the arch-specific code asarch_ptrace.
Looks okay to me. I do have a concern about all the extra indirections we're acquiring by this mad rush to centralise everything. It's going to slow things down and consume more stack space. Is there any way we can:
(1) Make a sys_ptrace() *jump* to arch_ptrace() instead of calling it, thus obviating the extra return step.
(2) Drop the use of lock_kernel().
Otherwise, the patch looks valid:
David
Quoted 8 lines · David Howells
Quoted 4 lines · Christoph Hellwig
Quoted 4 lines
The
sys_ptraceboilerplate code (everything outside the big switch statement for the arch-specific requests) is shared by most architectures. This patch moves it tokernel/ptrace.cand leaves the arch-specific code asarch_ptrace.
Quoted 8 lines
Looks okay to me. I do have a concern about all the extra indirections we're acquiring by this mad rush to centralise everything. It's going to slow things down and consume more stack space. Is there any way we can:
(1) Make a
sys_ptrace()*jump* toarch_ptrace()instead of calling it, thus obviating the extra return step.(2) Drop the use of
lock_kernel().
If we can remove the lock_kernel() and move the final put_task_struct() into each arch_ptrace() then we can end sys_ptrace() with
return arch_ptrace(....);
and with luck, gcc will convert it into a tailcall for us.
It's probably not the first place to start doing such optimisation tho.
Quoted 10 lines · Andrew Morton <akpm <at> osdl.org> writes:
Quoted 7 lines · David Howells <dhowells <at> redhat.com> wrote:
Christoph Hellwig <hch <at> lst.de> wrote:
(1) Make a
sys_ptrace()*jump* toarch_ptrace()instead of calling it, thus obviating the extra return step.
Quoted 6 lines
If we can remove the
lock_kernel()and move the finalput_task_struct()into eacharch_ptrace()then we can endsys_ptrace()withreturn arch_ptrace(....);and with luck, gcc will convert it into a tailcall for us.
Yep, it can do it, especially if CONFIG_REGPARM is enabled.
Quoted 1 line
It's probably not the first place to start doing such optimisation tho.
Boys, you risk being burned. I'm sorry I'll have to teach you a lesson. I'm especially sorry because I had to learn it the hard way...
prevent_tail_call is there for a reason (grep for it in kernel/exit.c)
* If you do:
int do_foo(params...) {
...
}
asmlinkage int sys_foo(params...) {
return do_foo(a_new_param, params...);
}* and do_foo and sys_foo have different prototypes (such as in the example or in the patch),
THEN
GCC can reorder/change parameters of sys_foo on the stack, to make them match the do_foo call.
Since those parameters are afterwards restored into userspace registers (which are supposed to be unchanged), we get userspace breakage.
But only if userspace uses the registers afterwards, and if it calls with int 0x80 (there's no restoring otherwise, or something such).
I know this because I did once this exact error, and it was very hard to diagnose (actually, it was in a UML-patch and I got breakage in UML). Also, it was triggered only when CONFIG_REGPARM is enabled. If needed, I can point out real examples (but you already should know).
Quoted 11 lines · David Howells
Quoted 4 lines · Christoph Hellwig
Quoted 4 lines
The
sys_ptraceboilerplate code (everything outside the big switch statement for the arch-specific requests) is shared by most architectures. This patch moves it tokernel/ptrace.cand leaves the arch-specific code asarch_ptrace.Looks okay to me. I do have a concern about all the extra indirections we're acquiring by this mad rush to centralise everything. It's going to slow things down and consume more stack space. Is there any way we can:
Quoted 6 lines
(1) Make a
sys_ptrace()*jump* toarch_ptrace()instead of calling it, thus obviating the extra return step.(2) Drop the use of
lock_kernel().Otherwise, the patch looks valid:
As BKL usage indicates this is a real slowpath. No one cares about one function call or less here.
Russell King
Acked-byQuoted 14 lines · Christoph Hellwig
Quoted 7 lines · Christoph Hellwig
[Let's try again now that
sys_ptracereturns long everywhere mainline..]The
sys_ptraceboilerplate code (everything outside the big switch statement for the arch-specific requests) is shared by most architectures. This patch moves it tokernel/ptrace.cand leaves the arch-specific code asarch_ptrace.Quoted 5 lines
Some architectures have a too different ptrace so we have to exclude them. They continue to keep their implementations. For sh64 I had to add a
sh64_ptracewrapper because it does some initialization on the first call. For um I removed an ifdefedSUBARCH_PTRACE_SPECIALblock, butSUBARCH_PTRACE_SPECIALisn't defined anywhere in the tree.
Quoted 6 lines
Umm, it might be a good idea to actually send the current patch instead of the old one. I really should write this text from scratch instead of copying it :)
Signed-off-by Christoph Hellwig <[email protected]>
Thanks Christoph.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of: 2.6 Serial core
Paul Mundt
Acked-byQuoted 7 lines · Christoph Hellwig
Quoted 5 lines · Christoph Hellwig
Some architectures have a too different ptrace so we have to exclude them. They continue to keep their implementations. For sh64 I had to add a
sh64_ptracewrapper because it does some initialization on the first call. For um I removed an ifdefedSUBARCH_PTRACE_SPECIALblock, butSUBARCH_PTRACE_SPECIALisn't defined anywhere in the tree.
Quoted 7 lines
Umm, it might be a good idea to actually send the current patch instead of the old one. I really should write this text from scratch instead of copying it :)
Signed-off-by Christoph Hellwig <[email protected]>
sh and sh64 bits look fine, thanks.