Skip to content

Commit 1461150

Browse files
thejhakpm00
authored andcommitted
mm: mark mas allocation in vms_abort_munmap_vmas as __GFP_NOFAIL
vms_abort_munmap_vmas() is a recovery path where, on entry, some VMAs have already been torn down halfway (in a way we can't undo) but are still present in the maple tree. At this point, we *must* remove the VMAs from the VMA tree, otherwise we get UAF. Because removing VMA tree nodes can require memory allocation, the existing code has an error path which tries to handle this by reattaching the VMAs; but that can't be done safely. A nicer way to fix it would probably be to preallocate enough maple tree nodes for the removal before the point of no return, or something like that; but for now, fix it the easy and kinda ugly way, by marking this allocation __GFP_NOFAIL. Link: https://lkml.kernel.org/r/[email protected] Fixes: 4f87153 ("mm: change failure of MAP_FIXED to restoring the gap on failure") Signed-off-by: Jann Horn <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1db2728 commit 1461150

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

mm/vma.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,9 @@ static inline void vms_abort_munmap_vmas(struct vma_munmap_struct *vms,
241241
* failure method of leaving a gap where the MAP_FIXED mapping failed.
242242
*/
243243
mas_set_range(mas, vms->start, vms->end - 1);
244-
if (unlikely(mas_store_gfp(mas, NULL, GFP_KERNEL))) {
245-
pr_warn_once("%s: (%d) Unable to abort munmap() operation\n",
246-
current->comm, current->pid);
247-
/* Leaving vmas detached and in-tree may hamper recovery */
248-
reattach_vmas(mas_detach);
249-
} else {
250-
/* Clean up the insertion of the unfortunate gap */
251-
vms_complete_munmap_vmas(vms, mas_detach);
252-
}
244+
mas_store_gfp(mas, NULL, GFP_KERNEL|__GFP_NOFAIL);
245+
/* Clean up the insertion of the unfortunate gap */
246+
vms_complete_munmap_vmas(vms, mas_detach);
253247
}
254248

255249
int

0 commit comments

Comments
 (0)