Skip to content

Commit

Permalink
nommu: fix error handling in do_mmap_pgoff()
Browse files Browse the repository at this point in the history
Fix the error handling in do_mmap_pgoff().  If do_mmap_shared_file() or
do_mmap_private() fail, we jump to the error_put_region label at which
point we cann __put_nommu_region() on the region - but we haven't yet
added the region to the tree, and so __put_nommu_region() may BUG
because the region tree is empty or it may corrupt the region tree.

To get around this, we can afford to add the region to the region tree
before calling do_mmap_shared_file() or do_mmap_private() as we keep
nommu_region_sem write-locked, so no-one can race with us by seeing a
transient region.

Signed-off-by: David Howells <[email protected]>
Acked-by: Pekka Enberg <[email protected]>
Acked-by: Paul Mundt <[email protected]>
Cc: Mel Gorman <[email protected]>
Acked-by: Greg Ungerer <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
dhowells authored and torvalds committed Sep 5, 2009
1 parent 4e49627 commit a190887
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ unsigned long do_mmap_pgoff(struct file *file,
}

vma->vm_region = region;
add_nommu_region(region);

/* set up the mapping */
if (file && vma->vm_flags & VM_SHARED)
Expand All @@ -1361,8 +1362,6 @@ unsigned long do_mmap_pgoff(struct file *file,
if (ret < 0)
goto error_put_region;

add_nommu_region(region);

/* okay... we have a mapping; now we have to register it */
result = vma->vm_start;

Expand Down

0 comments on commit a190887

Please sign in to comment.