Re: +proc-put-check_mem_permission-before-__get_free_page-in-mem_read.patch addedto -mm tree
From: Alexey Dobriyan
Date: Mon Apr 25 2011 - 18:01:26 EST
On Mon, Apr 25, 2011 at 01:11:15PM -0700, akpm@xxxxxxxxxxxxxxxxxxxx wrote:
> Subject: proc: put check_mem_permission before __get_free_page in mem_read
> From: Jovi Zhang <bookjovi@xxxxxxxxx>
>
> 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;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/