mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: bookjovi@gmail.com, Andrew Morton <akpm@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	David Rientjes <rientjes@google.com>,
	Stephen Wilson <wilsons@start.ca>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] proc: put check_mem_permission before __get_free_page in mem_read
Date: Tue, 26 Apr 2011 13:19:41 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LSU.2.00.1104261317400.9533@sister.anvils> (raw)
In-Reply-To: <20110426141449.F37C.A69D9226@jp.fujitsu.com>

On Tue, 26 Apr 2011, KOSAKI Motohiro wrote:
> 
> From 74f827ce74e1c4f846905e940edfa5f639b5a2ce Mon Sep 17 00:00:00 2001
> From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Date: Tue, 26 Apr 2011 13:57:02 +0900
> Subject: [PATCH] [PATCH] proc: put check_mem_permission after __get_free_page in mem_write
> 
> It should be better if put check_mem_permission after __get_free_page
> in mem_write, to be same as function mem_read.
> 
> Hugh Dickins explained the reason.
> 
>     check_mem_permission gets a reference to the mm.  If we __get_free_page
>     after check_mem_permission, imagine what happens if the system is out
>     of memory, and the mm we're looking at is selected for killing by the
>     OOM killer: while we wait in __get_free_page for more memory, no memory
>     is freed from the selected mm because it cannot reach exit_mmap while
>     we hold that reference.
> 
> 
> Reported-by: Jovi Zhang <bookjovi@gmail.com>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Stephen Wilson <wilsons@start.ca>

Thank you, yes!

Acked-by: Hugh Dickins <hughd@google.com>

> ---
>  fs/proc/base.c |   16 +++++++++-------
>  1 files changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 4deef2e..e93be6e 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -894,20 +894,20 @@ static ssize_t mem_write(struct file * file, const char __user *buf,
>  	if (!task)
>  		goto out_no_task;
>  
> +	copied = -ENOMEM;
> +	page = (char *)__get_free_page(GFP_TEMPORARY);
> +	if (!page)
> +		goto out_task;
> +
>  	mm = check_mem_permission(task);
>  	copied = PTR_ERR(mm);
>  	if (IS_ERR(mm))
> -		goto out_task;
> +		goto out_free;
>  
>  	copied = -EIO;
>  	if (file->private_data != (void *)((long)current->self_exec_id))
>  		goto out_mm;
>  
> -	copied = -ENOMEM;
> -	page = (char *)__get_free_page(GFP_TEMPORARY);
> -	if (!page)
> -		goto out_mm;
> -
>  	copied = 0;
>  	while (count > 0) {
>  		int this_len, retval;
> @@ -929,9 +929,11 @@ static ssize_t mem_write(struct file * file, const char __user *buf,
>  		count -= retval;			
>  	}
>  	*ppos = dst;
> -	free_page((unsigned long) page);
> +
>  out_mm:
>  	mmput(mm);
> +out_free:
> +	free_page((unsigned long) page);
>  out_task:
>  	put_task_struct(task);
>  out_no_task:
> -- 
> 1.7.3.1

  parent reply	other threads:[~2011-04-26 20:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-18  0:20 bookjovi
2011-04-24 15:33 ` KOSAKI Motohiro
2011-04-25 14:31 ` Stephen Wilson
2011-04-26  3:56 ` Hugh Dickins
2011-04-26  5:12   ` KOSAKI Motohiro
2011-04-26  5:50     ` [PATCH] proc: fix pagemap_read() error case (was Re: [PATCH] proc: put check_mem_permission before __get_free_page in mem_read) KOSAKI Motohiro
2011-04-26 16:44       ` Stephen Wilson
2011-04-26 20:44       ` Hugh Dickins
2011-04-28  1:45         ` KOSAKI Motohiro
2011-04-26 16:03     ` [PATCH] proc: put check_mem_permission before __get_free_page in mem_read Stephen Wilson
2011-04-26 20:19     ` Hugh Dickins [this message]
2011-04-26  8:55   ` Jovi Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.00.1104261317400.9533@sister.anvils \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=bookjovi@gmail.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wilsons@start.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®