mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: + proc-put-check_mem_permission-before-__get_free_page-in-mem_read.patch added to -mm tree
       [not found] <201104252011.p3PKBFTD005857@imap1.linux-foundation.org>
@ 2011-04-25 22:01 ` Alexey Dobriyan
  0 siblings, 0 replies; only message in thread
From: Alexey Dobriyan @ 2011-04-25 22:01 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, bookjovi, kosaki.motohiro, wilsons

On Mon, Apr 25, 2011 at 01:11:15PM -0700, akpm@linux-foundation.org wrote:
> Subject: proc: put check_mem_permission before __get_free_page in mem_read
> From: Jovi Zhang <bookjovi@gmail.com>
> 
> It would be better to put check_mem_permission() before __get_free_page()
> in mem_read(), to be same as mem_write().

This can be done even more straightforward if you put task_struct right after
it isn't needed.

> --- a/fs/proc/base.c~proc-put-check_mem_permission-before-__get_free_page-in-mem_read
> +++ a/fs/proc/base.c
> @@ -831,23 +831,21 @@ static ssize_t mem_read(struct file * fi
>  	if (!task)
>  		goto out_no_task;
>  
> -	ret = -ENOMEM;
> -	page = (char *)__get_free_page(GFP_TEMPORARY);
> -	if (!page)
> -		goto out;
> -
>  	mm = check_mem_permission(task);
>  	ret = PTR_ERR(mm);
>  	if (IS_ERR(mm))
> -		goto out_free;
> +		goto out_task;
>  
>  	ret = -EIO;
> - 
>  	if (file->private_data != (void*)((long)current->self_exec_id))
> -		goto out_put;
> +		goto out_mm;
> +
> +	ret = -ENOMEM;
> +	page = (char *)__get_free_page(GFP_TEMPORARY);
> +	if (!page)
> +		goto out_mm;
>  
>  	ret = 0;
> - 
>  	while (count > 0) {
>  		int this_len, retval;
>  
> @@ -870,12 +868,10 @@ static ssize_t mem_read(struct file * fi
>  		count -= retval;
>  	}
>  	*ppos = src;
> -
> -out_put:
> -	mmput(mm);
> -out_free:
>  	free_page((unsigned long) page);
> -out:
> +out_mm:
> +	mmput(mm);
> +out_task:
>  	put_task_struct(task);
>  out_no_task:
>  	return ret;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-25 22:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <201104252011.p3PKBFTD005857@imap1.linux-foundation.org>
2011-04-25 22:01 ` + proc-put-check_mem_permission-before-__get_free_page-in-mem_read.patch added to -mm tree Alexey Dobriyan

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

Powered by JetHome