Skip to content

Commit d08af0a

Browse files
jpemartinstorvalds
authored andcommitted
mm/hugetlb: fix refs calculation from unaligned @vaddr
Commit 82e5d37 ("mm/hugetlb: refactor subpage recording") refactored the count of subpages but missed an edge case when @vaddr is not aligned to PAGE_SIZE e.g. when close to vma->vm_end. It would then errousnly set @refs to 0 and record_subpages_vmas() wouldn't set the @pages array element to its value, consequently causing the reported null-deref by syzbot. Fix it by aligning down @vaddr by PAGE_SIZE in @refs calculation. Link: https://lkml.kernel.org/r/[email protected] Fixes: 82e5d37 ("mm/hugetlb: refactor subpage recording") Reported-by: [email protected] Signed-off-by: Joao Martins <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b3b2177 commit d08af0a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mm/hugetlb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,8 +5440,9 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
54405440
continue;
54415441
}
54425442

5443-
refs = min3(pages_per_huge_page(h) - pfn_offset,
5444-
(vma->vm_end - vaddr) >> PAGE_SHIFT, remainder);
5443+
/* vaddr may not be aligned to PAGE_SIZE */
5444+
refs = min3(pages_per_huge_page(h) - pfn_offset, remainder,
5445+
(vma->vm_end - ALIGN_DOWN(vaddr, PAGE_SIZE)) >> PAGE_SHIFT);
54455446

54465447
if (pages || vmas)
54475448
record_subpages_vmas(mem_map_offset(page, pfn_offset),

0 commit comments

Comments
 (0)