Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 7435
b: refs/heads/master
c: ab8d11b
h: refs/heads/master
i:
  7433: 0bccd09
  7431: 5338d05
v: v3
  • Loading branch information
Miklos Szeredi authored and Linus Torvalds committed Sep 7, 2005
1 parent 3159b7e commit db2783a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 45 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: 5e21ccb136047e556acf0fdf227cab5db05c1c25
refs/heads/master: ab8d11beb46f0bd0617e04205c01f5c1fe845b61
35 changes: 4 additions & 31 deletions trunk/fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,33 +346,6 @@ static int proc_root_link(struct inode *inode, struct dentry **dentry, struct vf
(task->state == TASK_STOPPED || task->state == TASK_TRACED) && \
security_ptrace(current,task) == 0))

static int may_ptrace_attach(struct task_struct *task)
{
int retval = 0;

task_lock(task);

if (!task->mm)
goto out;
if (((current->uid != task->euid) ||
(current->uid != task->suid) ||
(current->uid != task->uid) ||
(current->gid != task->egid) ||
(current->gid != task->sgid) ||
(current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
goto out;
rmb();
if (task->mm->dumpable != 1 && !capable(CAP_SYS_PTRACE))
goto out;
if (security_ptrace(current, task))
goto out;

retval = 1;
out:
task_unlock(task);
return retval;
}

static int proc_pid_environ(struct task_struct *task, char * buffer)
{
int res = 0;
Expand All @@ -382,7 +355,7 @@ static int proc_pid_environ(struct task_struct *task, char * buffer)
if (len > PAGE_SIZE)
len = PAGE_SIZE;
res = access_process_vm(task, mm->env_start, buffer, len, 0);
if (!may_ptrace_attach(task))
if (!ptrace_may_attach(task))
res = -ESRCH;
mmput(mm);
}
Expand Down Expand Up @@ -685,7 +658,7 @@ static ssize_t mem_read(struct file * file, char __user * buf,
int ret = -ESRCH;
struct mm_struct *mm;

if (!MAY_PTRACE(task) || !may_ptrace_attach(task))
if (!MAY_PTRACE(task) || !ptrace_may_attach(task))
goto out;

ret = -ENOMEM;
Expand All @@ -711,7 +684,7 @@ static ssize_t mem_read(struct file * file, char __user * buf,

this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
retval = access_process_vm(task, src, page, this_len, 0);
if (!retval || !MAY_PTRACE(task) || !may_ptrace_attach(task)) {
if (!retval || !MAY_PTRACE(task) || !ptrace_may_attach(task)) {
if (!ret)
ret = -EIO;
break;
Expand Down Expand Up @@ -749,7 +722,7 @@ static ssize_t mem_write(struct file * file, const char * buf,
struct task_struct *task = proc_task(file->f_dentry->d_inode);
unsigned long dst = *ppos;

if (!MAY_PTRACE(task) || !may_ptrace_attach(task))
if (!MAY_PTRACE(task) || !ptrace_may_attach(task))
return -ESRCH;

page = (char *)__get_free_page(GFP_USER);
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extern void __ptrace_link(struct task_struct *child,
struct task_struct *new_parent);
extern void __ptrace_unlink(struct task_struct *child);
extern void ptrace_untrace(struct task_struct *child);
extern int ptrace_may_attach(struct task_struct *task);

static inline void ptrace_link(struct task_struct *child,
struct task_struct *new_parent)
Expand Down
41 changes: 28 additions & 13 deletions trunk/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ int ptrace_check_attach(struct task_struct *child, int kill)
return ret;
}

static int may_attach(struct task_struct *task)
{
if (!task->mm)
return -EPERM;
if (((current->uid != task->euid) ||
(current->uid != task->suid) ||
(current->uid != task->uid) ||
(current->gid != task->egid) ||
(current->gid != task->sgid) ||
(current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
return -EPERM;
smp_rmb();
if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE))
return -EPERM;

return security_ptrace(current, task);
}

int ptrace_may_attach(struct task_struct *task)
{
int err;
task_lock(task);
err = may_attach(task);
task_unlock(task);
return !err;
}

int ptrace_attach(struct task_struct *task)
{
int retval;
Expand All @@ -127,22 +154,10 @@ int ptrace_attach(struct task_struct *task)
goto bad;
if (task == current)
goto bad;
if (!task->mm)
goto bad;
if(((current->uid != task->euid) ||
(current->uid != task->suid) ||
(current->uid != task->uid) ||
(current->gid != task->egid) ||
(current->gid != task->sgid) ||
(current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
goto bad;
smp_rmb();
if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE))
goto bad;
/* the same process cannot be attached many times */
if (task->ptrace & PT_PTRACED)
goto bad;
retval = security_ptrace(current, task);
retval = may_attach(task);
if (retval)
goto bad;

Expand Down

0 comments on commit db2783a

Please sign in to comment.