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>
Acked-by: Matt Mackall <mpm@selenic.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
ret = -EACCES;
if (!ptrace_may_attach(task))
ret = -EACCES;
if (!ptrace_may_attach(task))
ret = -EINVAL;
/* file position must be aligned */
if (*ppos % PM_ENTRY_BYTES)
ret = -EINVAL;
/* file position must be aligned */
if (*ppos % PM_ENTRY_BYTES)
ret = 0;
mm = get_task_mm(task);
if (!mm)
ret = 0;
mm = get_task_mm(task);
if (!mm)
ret = -ENOMEM;
uaddr = (unsigned long)buf & PAGE_MASK;
ret = -ENOMEM;
uaddr = (unsigned long)buf & PAGE_MASK;
pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE;
pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
if (!pages)
pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE;
pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
if (!pages)
down_read(¤t->mm->mmap_sem);
ret = get_user_pages(current, current->mm, uaddr, pagecount,
down_read(¤t->mm->mmap_sem);
ret = get_user_pages(current, current->mm, uaddr, pagecount,
if (ret < 0)
goto out_free;
if (ret < 0)
goto out_free;
+ if (ret != pagecount) {
+ pagecount = ret;
+ ret = -EFAULT;
+ goto out_pages;
+ }
+
pm.out = buf;
pm.end = buf + count;
pm.out = buf;
pm.end = buf + count;
for (; pagecount; pagecount--) {
page = pages[pagecount-1];
if (!PageReserved(page))
SetPageDirty(page);
page_cache_release(page);
}
for (; pagecount; pagecount--) {
page = pages[pagecount-1];
if (!PageReserved(page))
SetPageDirty(page);
page_cache_release(page);
}
out_task:
put_task_struct(task);
out:
out_task:
put_task_struct(task);
out: