aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Arcangeli <aarcange@redhat.com>2011-10-31 20:08:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-31 20:30:47 -0400
commitebed48460be5abd86d9a24fa7c66378e58109f30 (patch)
tree721d935953c58ac014e3d00ea1092ab480ea3356
parent6661672053aee709d93f5dbd7887c789364c11d4 (diff)
mremap: check for overflow using deltas
Using "- 1" relies on the old_end to be page aligned and PAGE_SIZE > 1, those are reasonable requirements but the check remains obscure and it looks more like an off by one error than an overflow check. This I feel will improve readability. Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Acked-by: Johannes Weiner <jweiner@redhat.com> Acked-by: Mel Gorman <mgorman@suse.de> Acked-by: Rik van Riel <riel@redhat.com> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/mremap.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/mm/mremap.c b/mm/mremap.c
index 506fa44403df..195e866568e0 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -141,9 +141,10 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
141 for (; old_addr < old_end; old_addr += extent, new_addr += extent) { 141 for (; old_addr < old_end; old_addr += extent, new_addr += extent) {
142 cond_resched(); 142 cond_resched();
143 next = (old_addr + PMD_SIZE) & PMD_MASK; 143 next = (old_addr + PMD_SIZE) & PMD_MASK;
144 if (next - 1 > old_end) 144 /* even if next overflowed, extent below will be ok */
145 next = old_end;
146 extent = next - old_addr; 145 extent = next - old_addr;
146 if (extent > old_end - old_addr)
147 extent = old_end - old_addr;
147 old_pmd = get_old_pmd(vma->vm_mm, old_addr); 148 old_pmd = get_old_pmd(vma->vm_mm, old_addr);
148 if (!old_pmd) 149 if (!old_pmd)
149 continue; 150 continue;