diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2005-09-06 18:18:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-07 19:57:43 -0400 |
commit | ab8d11beb46f0bd0617e04205c01f5c1fe845b61 (patch) | |
tree | 33b5aa5b63268b8f4d1428d74547fd351bb37113 /fs/proc/base.c | |
parent | 5e21ccb136047e556acf0fdf227cab5db05c1c25 (diff) |
[PATCH] remove duplicated code from proc and ptrace
Extract common code used by ptrace_attach() and may_ptrace_attach()
into a separate function.
Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
Cc: <viro@parcelfarce.linux.theplanet.co.uk>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r-- | fs/proc/base.c | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 24eed139e54e..84751f3f52d5 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -346,33 +346,6 @@ static int proc_root_link(struct inode *inode, struct dentry **dentry, struct vf | |||
346 | (task->state == TASK_STOPPED || task->state == TASK_TRACED) && \ | 346 | (task->state == TASK_STOPPED || task->state == TASK_TRACED) && \ |
347 | security_ptrace(current,task) == 0)) | 347 | security_ptrace(current,task) == 0)) |
348 | 348 | ||
349 | static int may_ptrace_attach(struct task_struct *task) | ||
350 | { | ||
351 | int retval = 0; | ||
352 | |||
353 | task_lock(task); | ||
354 | |||
355 | if (!task->mm) | ||
356 | goto out; | ||
357 | if (((current->uid != task->euid) || | ||
358 | (current->uid != task->suid) || | ||
359 | (current->uid != task->uid) || | ||
360 | (current->gid != task->egid) || | ||
361 | (current->gid != task->sgid) || | ||
362 | (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE)) | ||
363 | goto out; | ||
364 | rmb(); | ||
365 | if (task->mm->dumpable != 1 && !capable(CAP_SYS_PTRACE)) | ||
366 | goto out; | ||
367 | if (security_ptrace(current, task)) | ||
368 | goto out; | ||
369 | |||
370 | retval = 1; | ||
371 | out: | ||
372 | task_unlock(task); | ||
373 | return retval; | ||
374 | } | ||
375 | |||
376 | static int proc_pid_environ(struct task_struct *task, char * buffer) | 349 | static int proc_pid_environ(struct task_struct *task, char * buffer) |
377 | { | 350 | { |
378 | int res = 0; | 351 | int res = 0; |
@@ -382,7 +355,7 @@ static int proc_pid_environ(struct task_struct *task, char * buffer) | |||
382 | if (len > PAGE_SIZE) | 355 | if (len > PAGE_SIZE) |
383 | len = PAGE_SIZE; | 356 | len = PAGE_SIZE; |
384 | res = access_process_vm(task, mm->env_start, buffer, len, 0); | 357 | res = access_process_vm(task, mm->env_start, buffer, len, 0); |
385 | if (!may_ptrace_attach(task)) | 358 | if (!ptrace_may_attach(task)) |
386 | res = -ESRCH; | 359 | res = -ESRCH; |
387 | mmput(mm); | 360 | mmput(mm); |
388 | } | 361 | } |
@@ -685,7 +658,7 @@ static ssize_t mem_read(struct file * file, char __user * buf, | |||
685 | int ret = -ESRCH; | 658 | int ret = -ESRCH; |
686 | struct mm_struct *mm; | 659 | struct mm_struct *mm; |
687 | 660 | ||
688 | if (!MAY_PTRACE(task) || !may_ptrace_attach(task)) | 661 | if (!MAY_PTRACE(task) || !ptrace_may_attach(task)) |
689 | goto out; | 662 | goto out; |
690 | 663 | ||
691 | ret = -ENOMEM; | 664 | ret = -ENOMEM; |
@@ -711,7 +684,7 @@ static ssize_t mem_read(struct file * file, char __user * buf, | |||
711 | 684 | ||
712 | this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; | 685 | this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; |
713 | retval = access_process_vm(task, src, page, this_len, 0); | 686 | retval = access_process_vm(task, src, page, this_len, 0); |
714 | if (!retval || !MAY_PTRACE(task) || !may_ptrace_attach(task)) { | 687 | if (!retval || !MAY_PTRACE(task) || !ptrace_may_attach(task)) { |
715 | if (!ret) | 688 | if (!ret) |
716 | ret = -EIO; | 689 | ret = -EIO; |
717 | break; | 690 | break; |
@@ -749,7 +722,7 @@ static ssize_t mem_write(struct file * file, const char * buf, | |||
749 | struct task_struct *task = proc_task(file->f_dentry->d_inode); | 722 | struct task_struct *task = proc_task(file->f_dentry->d_inode); |
750 | unsigned long dst = *ppos; | 723 | unsigned long dst = *ppos; |
751 | 724 | ||
752 | if (!MAY_PTRACE(task) || !may_ptrace_attach(task)) | 725 | if (!MAY_PTRACE(task) || !ptrace_may_attach(task)) |
753 | return -ESRCH; | 726 | return -ESRCH; |
754 | 727 | ||
755 | page = (char *)__get_free_page(GFP_USER); | 728 | page = (char *)__get_free_page(GFP_USER); |