Skip to content

Commit 6c26bd4

Browse files
committed
mm/mmap: Fix error return in do_vmi_align_munmap()
If mas_store_gfp() in the gather loop failed, the 'error' variable that ultimately gets returned was not being set. In many cases, its original value of -ENOMEM was still in place, and that was fine. But if VMAs had been split at the start or end of the range, then 'error' could be zero. Change to the 'error = foo(); if (error) goto …' idiom to fix the bug. Also clean up a later case which avoided the same bug by *explicitly* setting error = -ENOMEM right before calling the function that might return -ENOMEM. In a final cosmetic change, move the 'Point of no return' comment to *after* the goto. That's been in the wrong place since the preallocation was removed, and this new error path was added. Fixes: 606c812 ("mm/mmap: Fix error path in do_vmi_align_munmap()") Signed-off-by: David Woodhouse <[email protected]> Cc: [email protected] Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]>
1 parent 6aeadf7 commit 6c26bd4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mm/mmap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,8 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma,
23872387
}
23882388
vma_start_write(next);
23892389
mas_set_range(&mas_detach, next->vm_start, next->vm_end - 1);
2390-
if (mas_store_gfp(&mas_detach, next, GFP_KERNEL))
2390+
error = mas_store_gfp(&mas_detach, next, GFP_KERNEL);
2391+
if (error)
23912392
goto munmap_gather_failed;
23922393
vma_mark_detached(next, true);
23932394
if (next->vm_flags & VM_LOCKED)
@@ -2436,12 +2437,12 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma,
24362437
BUG_ON(count != test_count);
24372438
}
24382439
#endif
2439-
/* Point of no return */
2440-
error = -ENOMEM;
24412440
vma_iter_set(vmi, start);
2442-
if (vma_iter_clear_gfp(vmi, start, end, GFP_KERNEL))
2441+
error = vma_iter_clear_gfp(vmi, start, end, GFP_KERNEL);
2442+
if (error)
24432443
goto clear_tree_failed;
24442444

2445+
/* Point of no return */
24452446
mm->locked_vm -= locked_vm;
24462447
mm->map_count -= count;
24472448
/*

0 commit comments

Comments
 (0)