public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] /proc/*/environ: wrong placing of ptrace_may_attach() check
@ 2007-05-28 13:41 Alexey Dobriyan
  2007-05-30  0:16 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2007-05-28 13:41 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, devel

Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru>
---

 fs/proc/base.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -204,12 +204,17 @@ static int proc_pid_environ(struct task_
 	int res = 0;
 	struct mm_struct *mm = get_task_mm(task);
 	if (mm) {
-		unsigned int len = mm->env_end - mm->env_start;
+		unsigned int len;
+
+		res = -ESRCH;
+		if (!ptrace_may_attach(task))
+			goto out;
+
+		len  = mm->env_end - mm->env_start;
 		if (len > PAGE_SIZE)
 			len = PAGE_SIZE;
 		res = access_process_vm(task, mm->env_start, buffer, len, 0);
-		if (!ptrace_may_attach(task))
-			res = -ESRCH;
+out:
 		mmput(mm);
 	}
 	return res;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] /proc/*/environ: wrong placing of ptrace_may_attach() check
  2007-05-28 13:41 [PATCH] /proc/*/environ: wrong placing of ptrace_may_attach() check Alexey Dobriyan
@ 2007-05-30  0:16 ` Andrew Morton
  2007-05-30  8:39   ` Alexey Dobriyan
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2007-05-30  0:16 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel, devel

On Mon, 28 May 2007 17:41:57 +0400
Alexey Dobriyan <adobriyan@sw.ru> wrote:

> Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru>

Better changelogs, please.

> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -204,12 +204,17 @@ static int proc_pid_environ(struct task_
>  	int res = 0;
>  	struct mm_struct *mm = get_task_mm(task);
>  	if (mm) {
> -		unsigned int len = mm->env_end - mm->env_start;
> +		unsigned int len;
> +
> +		res = -ESRCH;
> +		if (!ptrace_may_attach(task))
> +			goto out;
> +
> +		len  = mm->env_end - mm->env_start;
>  		if (len > PAGE_SIZE)
>  			len = PAGE_SIZE;
>  		res = access_process_vm(task, mm->env_start, buffer, len, 0);
> -		if (!ptrace_may_attach(task))
> -			res = -ESRCH;
> +out:
>  		mmput(mm);
>  	}
>  	return res;

What's wrong with the existing code?  It's a bit dopey-looking and can, I
guess, permit a task to cause a pagefault in an mm which it doesn't have
permission to read from.  But is there some more serious problem being
fixed here?

I shouldn't have to ask this stuff.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] /proc/*/environ: wrong placing of ptrace_may_attach() check
  2007-05-30  0:16 ` Andrew Morton
@ 2007-05-30  8:39   ` Alexey Dobriyan
  0 siblings, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2007-05-30  8:39 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, devel

On Tue, May 29, 2007 at 05:16:23PM -0700, Andrew Morton wrote:
> On Mon, 28 May 2007 17:41:57 +0400
> Alexey Dobriyan <adobriyan@sw.ru> wrote:

> > --- a/fs/proc/base.c
> > +++ b/fs/proc/base.c
> > @@ -204,12 +204,17 @@ static int proc_pid_environ(struct task_
> >  	int res = 0;
> >  	struct mm_struct *mm = get_task_mm(task);
> >  	if (mm) {
> > -		unsigned int len = mm->env_end - mm->env_start;
> > +		unsigned int len;
> > +
> > +		res = -ESRCH;
> > +		if (!ptrace_may_attach(task))
> > +			goto out;
> > +
> > +		len  = mm->env_end - mm->env_start;
> >  		if (len > PAGE_SIZE)
> >  			len = PAGE_SIZE;
> >  		res = access_process_vm(task, mm->env_start, buffer, len, 0);
> > -		if (!ptrace_may_attach(task))
> > -			res = -ESRCH;
> > +out:
> >  		mmput(mm);
> >  	}
> >  	return res;
>
> What's wrong with the existing code?  It's a bit dopey-looking and can, I
> guess, permit a task to cause a pagefault in an mm which it doesn't have
> permission to read from.  But is there some more serious problem being
> fixed here?

I think not, because environment will be copied from target task, stay
in kernel tmp buffer, but not copied to target buffer due to -ESRCH.
But such code is asking for problems.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-30  8:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-28 13:41 [PATCH] /proc/*/environ: wrong placing of ptrace_may_attach() check Alexey Dobriyan
2007-05-30  0:16 ` Andrew Morton
2007-05-30  8:39   ` Alexey Dobriyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox