Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 26540
b: refs/heads/master
c: 9d21f09
h: refs/heads/master
v: v3
  • Loading branch information
Linus Torvalds committed May 8, 2006
1 parent acc9b6c commit 341b662
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 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: 74fae122eb9f0db8b8718b9851c31c2f374fb134
refs/heads/master: 9d21f09ca03d1142f1988001f228d02581d8986c
39 changes: 21 additions & 18 deletions trunk/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ int ptrace_may_attach(struct task_struct *task)
int ptrace_attach(struct task_struct *task)
{
int retval;
task_lock(task);

retval = -EPERM;
if (task->pid <= 1)
goto bad;
goto out;
if (task->tgid == current->tgid)
goto bad;
goto out;

write_lock_irq(&tasklist_lock);
task_lock(task);

/* the same process cannot be attached many times */
if (task->ptrace & PT_PTRACED)
goto bad;
Expand All @@ -166,17 +170,15 @@ int ptrace_attach(struct task_struct *task)
? PT_ATTACHED : 0);
if (capable(CAP_SYS_PTRACE))
task->ptrace |= PT_PTRACE_CAP;
task_unlock(task);

write_lock_irq(&tasklist_lock);
__ptrace_link(task, current);
write_unlock_irq(&tasklist_lock);

force_sig_specific(SIGSTOP, task);
return 0;

bad:
write_unlock_irq(&tasklist_lock);
task_unlock(task);
out:
return retval;
}

Expand Down Expand Up @@ -417,21 +419,22 @@ int ptrace_request(struct task_struct *child, long request,
*/
int ptrace_traceme(void)
{
int ret;
int ret = -EPERM;

/*
* Are we already being traced?
*/
if (current->ptrace & PT_PTRACED)
return -EPERM;
ret = security_ptrace(current->parent, current);
if (ret)
return -EPERM;
/*
* Set the ptrace bit in the process ptrace flags.
*/
current->ptrace |= PT_PTRACED;
return 0;
task_lock(current);
if (!(current->ptrace & PT_PTRACED)) {
ret = security_ptrace(current->parent, current);
/*
* Set the ptrace bit in the process ptrace flags.
*/
if (!ret)
current->ptrace |= PT_PTRACED;
}
task_unlock(current);
return ret;
}

/**
Expand Down

0 comments on commit 341b662

Please sign in to comment.