public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matt Mackall <mpm@selenic.com>
To: Marcelo Tosatti <marcelo@kvack.org>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] pagemap: proper read error handling
Date: Mon, 10 Mar 2008 13:32:42 -0500	[thread overview]
Message-ID: <1205173962.11669.61.camel@calx> (raw)
In-Reply-To: <20080308233555.GA21461@dmt>


On Sat, 2008-03-08 at 20:35 -0300, Marcelo Tosatti wrote:
> Fix pagemap_read() error handling by releasing acquired resources and
> checking for get_user_pages() partial failure.
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Thanks, Marcelo, this all looks good.

Signed-off-by: Matt Mackall <mpm@selenic.com>

> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 6dc0334..4206454 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -640,17 +640,17 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
>  
>  	ret = -EACCES;
>  	if (!ptrace_may_attach(task))
> -		goto out;
> +		goto out_task;
>  
>  	ret = -EINVAL;
>  	/* file position must be aligned */
>  	if (*ppos % PM_ENTRY_BYTES)
> -		goto out;
> +		goto out_task;
>  
>  	ret = 0;
>  	mm = get_task_mm(task);
>  	if (!mm)
> -		goto out;
> +		goto out_task;
>  
>  	ret = -ENOMEM;
>  	uaddr = (unsigned long)buf & PAGE_MASK;
> @@ -658,7 +658,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
>  	pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE;
>  	pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
>  	if (!pages)
> -		goto out_task;
> +		goto out_mm;
>  
>  	down_read(&current->mm->mmap_sem);
>  	ret = get_user_pages(current, current->mm, uaddr, pagecount,
> @@ -668,6 +668,12 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
>  	if (ret < 0)
>  		goto out_free;
>  
> +	if (ret != pagecount) {
> +		pagecount = ret;
> +		ret = -EFAULT;
> +		goto out_pages;
> +	}
> +
>  	pm.out = buf;
>  	pm.end = buf + count;
>  
> @@ -699,15 +705,17 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
>  			ret = pm.out - buf;
>  	}
>  
> +out_pages:
>  	for (; pagecount; pagecount--) {
>  		page = pages[pagecount-1];
>  		if (!PageReserved(page))
>  			SetPageDirty(page);
>  		page_cache_release(page);
>  	}
> -	mmput(mm);
>  out_free:
>  	kfree(pages);
> +out_mm:
> +	mmput(mm);
>  out_task:
>  	put_task_struct(task);
>  out:
-- 
Mathematics is the supreme nostalgia of our time.


      reply	other threads:[~2008-03-10 18:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-08 23:35 [PATCH] pagemap: proper read error handling Marcelo Tosatti
2008-03-10 18:32 ` Matt Mackall [this message]

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=1205173962.11669.61.camel@calx \
    --to=mpm@selenic.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo@kvack.org \
    /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