diff options
Diffstat (limited to 'fs/proc')
-rw-r--r-- | fs/proc/task_mmu.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 6dc0334815f7..4206454734e0 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, | |||
640 | 640 | ||
641 | ret = -EACCES; | 641 | ret = -EACCES; |
642 | if (!ptrace_may_attach(task)) | 642 | if (!ptrace_may_attach(task)) |
643 | goto out; | 643 | goto out_task; |
644 | 644 | ||
645 | ret = -EINVAL; | 645 | ret = -EINVAL; |
646 | /* file position must be aligned */ | 646 | /* file position must be aligned */ |
647 | if (*ppos % PM_ENTRY_BYTES) | 647 | if (*ppos % PM_ENTRY_BYTES) |
648 | goto out; | 648 | goto out_task; |
649 | 649 | ||
650 | ret = 0; | 650 | ret = 0; |
651 | mm = get_task_mm(task); | 651 | mm = get_task_mm(task); |
652 | if (!mm) | 652 | if (!mm) |
653 | goto out; | 653 | goto out_task; |
654 | 654 | ||
655 | ret = -ENOMEM; | 655 | ret = -ENOMEM; |
656 | uaddr = (unsigned long)buf & PAGE_MASK; | 656 | uaddr = (unsigned long)buf & PAGE_MASK; |
@@ -658,7 +658,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf, | |||
658 | pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE; | 658 | pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE; |
659 | pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL); | 659 | pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL); |
660 | if (!pages) | 660 | if (!pages) |
661 | goto out_task; | 661 | goto out_mm; |
662 | 662 | ||
663 | down_read(¤t->mm->mmap_sem); | 663 | down_read(¤t->mm->mmap_sem); |
664 | ret = get_user_pages(current, current->mm, uaddr, pagecount, | 664 | ret = get_user_pages(current, current->mm, uaddr, pagecount, |
@@ -668,6 +668,12 @@ static ssize_t pagemap_read(struct file *file, char __user *buf, | |||
668 | if (ret < 0) | 668 | if (ret < 0) |
669 | goto out_free; | 669 | goto out_free; |
670 | 670 | ||
671 | if (ret != pagecount) { | ||
672 | pagecount = ret; | ||
673 | ret = -EFAULT; | ||
674 | goto out_pages; | ||
675 | } | ||
676 | |||
671 | pm.out = buf; | 677 | pm.out = buf; |
672 | pm.end = buf + count; | 678 | pm.end = buf + count; |
673 | 679 | ||
@@ -699,15 +705,17 @@ static ssize_t pagemap_read(struct file *file, char __user *buf, | |||
699 | ret = pm.out - buf; | 705 | ret = pm.out - buf; |
700 | } | 706 | } |
701 | 707 | ||
708 | out_pages: | ||
702 | for (; pagecount; pagecount--) { | 709 | for (; pagecount; pagecount--) { |
703 | page = pages[pagecount-1]; | 710 | page = pages[pagecount-1]; |
704 | if (!PageReserved(page)) | 711 | if (!PageReserved(page)) |
705 | SetPageDirty(page); | 712 | SetPageDirty(page); |
706 | page_cache_release(page); | 713 | page_cache_release(page); |
707 | } | 714 | } |
708 | mmput(mm); | ||
709 | out_free: | 715 | out_free: |
710 | kfree(pages); | 716 | kfree(pages); |
717 | out_mm: | ||
718 | mmput(mm); | ||
711 | out_task: | 719 | out_task: |
712 | put_task_struct(task); | 720 | put_task_struct(task); |
713 | out: | 721 | out: |