Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 16946
b: refs/heads/master
c: 6b9c7ed
h: refs/heads/master
v: v3
  • Loading branch information
Christoph Hellwig authored and Linus Torvalds committed Jan 9, 2006
1 parent 8ae23c3 commit b0de759
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 242 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6b34350f490b2c8508717541ec1fd2bbaadded94
refs/heads/master: 6b9c7ed84837753a436415097063232422e29a35
24 changes: 5 additions & 19 deletions trunk/arch/alpha/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,30 +265,16 @@ do_sys_ptrace(long request, long pid, long addr, long data,
lock_kernel();
DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n",
request, pid, addr, data));
ret = -EPERM;
if (request == PTRACE_TRACEME) {
/* are we already being traced? */
if (current->ptrace & PT_PTRACED)
goto out_notsk;
ret = security_ptrace(current->parent, current);
if (ret)
goto out_notsk;
/* set the ptrace bit in the process ptrace flags. */
current->ptrace |= PT_PTRACED;
ret = 0;
ret = ptrace_traceme();
goto out_notsk;
}
if (pid == 1) /* you may not mess with init */
goto out_notsk;

ret = -ESRCH;
read_lock(&tasklist_lock);
child = find_task_by_pid(pid);
if (child)
get_task_struct(child);
read_unlock(&tasklist_lock);
if (!child)
child = ptrace_get_task_struct(pid);
if (IS_ERR(child)) {
ret = PTR_ERR(child);
goto out_notsk;
}

if (request == PTRACE_ATTACH) {
ret = ptrace_attach(child);
Expand Down
16 changes: 5 additions & 11 deletions trunk/arch/ia64/ia32/sys_ia32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1761,21 +1761,15 @@ sys32_ptrace (int request, pid_t pid, unsigned int addr, unsigned int data)

lock_kernel();
if (request == PTRACE_TRACEME) {
ret = sys_ptrace(request, pid, addr, data);
ret = ptrace_traceme();
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)
child = ptrace_get_task_struct(pid);
if (IS_ERR(child)) {
ret = PTR_ERR(child);
goto out;
ret = -EPERM;
if (pid == 1) /* no messing around with init! */
goto out_tsk;
}

if (request == PTRACE_ATTACH) {
ret = sys_ptrace(request, pid, addr, data);
Expand Down
9 changes: 1 addition & 8 deletions trunk/arch/ia64/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1422,14 +1422,7 @@ sys_ptrace (long request, pid_t pid, unsigned long addr, unsigned long data)
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;
current->ptrace |= PT_PTRACED;
ret = 0;
ret = ptrace_traceme();
goto out;
}

Expand Down
22 changes: 5 additions & 17 deletions trunk/arch/m32r/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,28 +762,16 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
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;
ret = ptrace_traceme();
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 */
child = ptrace_get_task_struct(pid);
if (IS_ERR(child)) {
ret = PTR_ERR(child);
goto out;
}

if (request == PTRACE_ATTACH) {
ret = ptrace_attach(child);
Expand Down
26 changes: 6 additions & 20 deletions trunk/arch/mips/kernel/ptrace32.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,16 @@ asmlinkage int sys32_ptrace(int request, int pid, int addr, int data)
(unsigned long) data);
#endif
lock_kernel();
ret = -EPERM;
if (request == PTRACE_TRACEME) {
/* are we already being traced? */
if (current->ptrace & PT_PTRACED)
goto out;
if ((ret = security_ptrace(current->parent, current)))
goto out;
/* set the ptrace bit in the process flags. */
current->ptrace |= PT_PTRACED;
ret = 0;
ret = ptrace_traceme();
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;
child = ptrace_get_task_struct(pid);
if (IS_ERR(child)) {
ret = PTR_ERR(child);
goto out;
}

if (request == PTRACE_ATTACH) {
ret = ptrace_attach(child);
Expand Down
28 changes: 7 additions & 21 deletions trunk/arch/powerpc/kernel/ptrace32.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,19 @@ long compat_sys_ptrace(int request, int pid, unsigned long addr,
unsigned long data)
{
struct task_struct *child;
int ret = -EPERM;
int ret;

lock_kernel();
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;
ret = ptrace_traceme();
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;
child = ptrace_get_task_struct(pid);
if (IS_ERR(child)) {
ret = PTR_ERR(child);
goto out;
}

if (request == PTRACE_ATTACH) {
ret = ptrace_attach(child);
Expand Down
29 changes: 6 additions & 23 deletions trunk/arch/s390/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,35 +712,18 @@ sys_ptrace(long request, long pid, long addr, long data)
int ret;

lock_kernel();

if (request == PTRACE_TRACEME) {
/* are we already being traced? */
ret = -EPERM;
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;
goto out;
ret = ptrace_traceme();
goto out;
}

ret = -EPERM;
if (pid == 1) /* you may not mess with init */
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)
child = ptrace_get_task_struct(pid);
if (IS_ERR(child)) {
ret = PTR_ERR(child);
goto out;
}

ret = do_ptrace(child, request, addr, data);

put_task_struct(child);
out:
unlock_kernel();
Expand Down
35 changes: 6 additions & 29 deletions trunk/arch/sparc/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,40 +286,17 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
s, (int) request, (int) pid, addr, data, addr2);
}
#endif
if (request == PTRACE_TRACEME) {
int my_ret;

/* are we already being traced? */
if (current->ptrace & PT_PTRACED) {
pt_error_return(regs, EPERM);
goto out;
}
my_ret = security_ptrace(current->parent, current);
if (my_ret) {
pt_error_return(regs, -my_ret);
goto out;
}

/* set the ptrace bit in the process flags. */
current->ptrace |= PT_PTRACED;
if (request == PTRACE_TRACEME) {
ret = ptrace_traceme();
pt_succ_return(regs, 0);
goto out;
}
#ifndef ALLOW_INIT_TRACING
if (pid == 1) {
/* Can't dork with init. */
pt_error_return(regs, EPERM);
goto out;
}
#endif
read_lock(&tasklist_lock);
child = find_task_by_pid(pid);
if (child)
get_task_struct(child);
read_unlock(&tasklist_lock);

if (!child) {
pt_error_return(regs, ESRCH);
child = ptrace_get_task_struct(pid);
if (IS_ERR(child)) {
ret = PTR_ERR(child);
pt_error_return(regs, -ret);
goto out;
}

Expand Down
34 changes: 5 additions & 29 deletions trunk/arch/sparc64/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,39 +198,15 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
}
#endif
if (request == PTRACE_TRACEME) {
int ret;

/* are we already being traced? */
if (current->ptrace & PT_PTRACED) {
pt_error_return(regs, EPERM);
goto out;
}
ret = security_ptrace(current->parent, current);
if (ret) {
pt_error_return(regs, -ret);
goto out;
}

/* set the ptrace bit in the process flags. */
current->ptrace |= PT_PTRACED;
ret = ptrace_traceme();
pt_succ_return(regs, 0);
goto out;
}
#ifndef ALLOW_INIT_TRACING
if (pid == 1) {
/* Can't dork with init. */
pt_error_return(regs, EPERM);
goto out;
}
#endif
read_lock(&tasklist_lock);
child = find_task_by_pid(pid);
if (child)
get_task_struct(child);
read_unlock(&tasklist_lock);

if (!child) {
pt_error_return(regs, ESRCH);
child = ptrace_get_task_struct(pid);
if (IS_ERR(child)) {
ret = PTR_ERR(child);
pt_error_return(regs, -ret);
goto out;
}

Expand Down
44 changes: 11 additions & 33 deletions trunk/arch/x86_64/ia32/ptrace32.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,36 +196,6 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val)

#undef R32

static struct task_struct *find_target(int request, int pid, int *err)
{
struct task_struct *child;

*err = -EPERM;
if (pid == 1)
return NULL;

*err = -ESRCH;
read_lock(&tasklist_lock);
child = find_task_by_pid(pid);
if (child)
get_task_struct(child);
read_unlock(&tasklist_lock);
if (child) {
*err = -EPERM;
if (child->pid == 1)
goto out;
*err = ptrace_check_attach(child, request == PTRACE_KILL);
if (*err < 0)
goto out;
return child;
}
out:
if (child)
put_task_struct(child);
return NULL;

}

asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
{
struct task_struct *child;
Expand Down Expand Up @@ -254,9 +224,16 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
break;
}

child = find_target(request, pid, &ret);
if (!child)
return ret;
if (request == PTRACE_TRACEME)
return ptrace_traceme();

child = ptrace_get_task_struct(pid);
if (IS_ERR(child))
return PTR_ERR(child);

ret = ptrace_check_attach(child, request == PTRACE_KILL);
if (ret < 0)
goto out;

childregs = (struct pt_regs *)(child->thread.rsp0 - sizeof(struct pt_regs));

Expand Down Expand Up @@ -373,6 +350,7 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
break;
}

out:
put_task_struct(child);
return ret;
}
Expand Down
Loading

0 comments on commit b0de759

Please sign in to comment.