pagemap: proper read error handling
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>
This commit is contained in:
parent
b500ce8d24
commit
fb39380b8d
|
@ -640,17 +640,17 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
|
||||||
|
|
||||||
ret = -EACCES;
|
ret = -EACCES;
|
||||||
if (!ptrace_may_attach(task))
|
if (!ptrace_may_attach(task))
|
||||||
goto out;
|
goto out_task;
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
/* file position must be aligned */
|
/* file position must be aligned */
|
||||||
if (*ppos % PM_ENTRY_BYTES)
|
if (*ppos % PM_ENTRY_BYTES)
|
||||||
goto out;
|
goto out_task;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
mm = get_task_mm(task);
|
mm = get_task_mm(task);
|
||||||
if (!mm)
|
if (!mm)
|
||||||
goto out;
|
goto out_task;
|
||||||
|
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
uaddr = (unsigned long)buf & PAGE_MASK;
|
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;
|
pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE;
|
||||||
pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
|
pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
|
||||||
if (!pages)
|
if (!pages)
|
||||||
goto out_task;
|
goto out_mm;
|
||||||
|
|
||||||
down_read(¤t->mm->mmap_sem);
|
down_read(¤t->mm->mmap_sem);
|
||||||
ret = get_user_pages(current, current->mm, uaddr, pagecount,
|
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)
|
if (ret < 0)
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
|
||||||
|
if (ret != pagecount) {
|
||||||
|
pagecount = ret;
|
||||||
|
ret = -EFAULT;
|
||||||
|
goto out_pages;
|
||||||
|
}
|
||||||
|
|
||||||
pm.out = buf;
|
pm.out = buf;
|
||||||
pm.end = buf + count;
|
pm.end = buf + count;
|
||||||
|
|
||||||
|
@ -699,15 +705,17 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
|
||||||
ret = pm.out - buf;
|
ret = pm.out - buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_pages:
|
||||||
for (; pagecount; pagecount--) {
|
for (; pagecount; pagecount--) {
|
||||||
page = pages[pagecount-1];
|
page = pages[pagecount-1];
|
||||||
if (!PageReserved(page))
|
if (!PageReserved(page))
|
||||||
SetPageDirty(page);
|
SetPageDirty(page);
|
||||||
page_cache_release(page);
|
page_cache_release(page);
|
||||||
}
|
}
|
||||||
mmput(mm);
|
|
||||||
out_free:
|
out_free:
|
||||||
kfree(pages);
|
kfree(pages);
|
||||||
|
out_mm:
|
||||||
|
mmput(mm);
|
||||||
out_task:
|
out_task:
|
||||||
put_task_struct(task);
|
put_task_struct(task);
|
||||||
out:
|
out:
|
||||||
|
|
Loading…
Reference in New Issue