Skip to content

Commit 9aacdd3

Browse files
mjkravetztorvalds
authored andcommitted
fs/hugetlbfs/inode.c: fix bugs in hugetlb_vmtruncate_list()
Hillf Danton noticed bugs in the hugetlb_vmtruncate_list routine. The argument end is of type pgoff_t. It was being converted to a vaddr offset and passed to unmap_hugepage_range. However, end was also being used as an argument to the vma_interval_tree_foreach controlling loop. In addition, the conversion of end to vaddr offset was incorrect. hugetlb_vmtruncate_list is called as part of a file truncate or fallocate hole punch operation. When truncating a hugetlbfs file, this bug could prevent some pages from being unmapped. This is possible if there are multiple vmas mapping the file, and there is a sufficiently sized hole between the mappings. The size of the hole between two vmas (A,B) must be such that the starting virtual address of B is greater than (ending virtual address of A << PAGE_SHIFT). In this case, the pages in B would not be unmapped. If pages are not properly unmapped during truncate, the following BUG is hit: kernel BUG at fs/hugetlbfs/inode.c:428! In the fallocate hole punch case, this bug could prevent pages from being unmapped as in the truncate case. However, for hole punch the result is that unmapped pages will not be removed during the operation. For hole punch, it is also possible that more pages than desired will be unmapped. This unnecessary unmapping will cause page faults to reestablish the mappings on subsequent page access. Fixes: 1bfad99 (" hugetlbfs: hugetlb_vmtruncate_list() needs to take a range")Reported-by: Hillf Danton <[email protected]> Signed-off-by: Mike Kravetz <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Dave Hansen <[email protected]> Cc: <[email protected]> [4.3] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9f8bdb3 commit 9aacdd3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

fs/hugetlbfs/inode.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ hugetlb_vmdelete_list(struct rb_root *root, pgoff_t start, pgoff_t end)
463463
*/
464464
vma_interval_tree_foreach(vma, root, start, end ? end : ULONG_MAX) {
465465
unsigned long v_offset;
466+
unsigned long v_end;
466467

467468
/*
468469
* Can the expression below overflow on 32-bit arches?
@@ -475,15 +476,17 @@ hugetlb_vmdelete_list(struct rb_root *root, pgoff_t start, pgoff_t end)
475476
else
476477
v_offset = 0;
477478

478-
if (end) {
479-
end = ((end - start) << PAGE_SHIFT) +
480-
vma->vm_start + v_offset;
481-
if (end > vma->vm_end)
482-
end = vma->vm_end;
483-
} else
484-
end = vma->vm_end;
479+
if (!end)
480+
v_end = vma->vm_end;
481+
else {
482+
v_end = ((end - vma->vm_pgoff) << PAGE_SHIFT)
483+
+ vma->vm_start;
484+
if (v_end > vma->vm_end)
485+
v_end = vma->vm_end;
486+
}
485487

486-
unmap_hugepage_range(vma, vma->vm_start + v_offset, end, NULL);
488+
unmap_hugepage_range(vma, vma->vm_start + v_offset, v_end,
489+
NULL);
487490
}
488491
}
489492

0 commit comments

Comments
 (0)