Skip to content

Commit b79b6fe

Browse files
Kefeng Wanggregkh
authored andcommitted
mm: use aligned address in clear_gigantic_page()
commit 8aca2bc upstream. In current kernel, hugetlb_no_page() calls folio_zero_user() with the fault address. Where the fault address may be not aligned with the huge page size. Then, folio_zero_user() may call clear_gigantic_page() with the address, while clear_gigantic_page() requires the address to be huge page size aligned. So, this may cause memory corruption or information leak, addtional, use more obvious naming 'addr_hint' instead of 'addr' for clear_gigantic_page(). Link: https://lkml.kernel.org/r/[email protected] Fixes: 78fefd0 ("mm: memory: convert clear_huge_page() to folio_zero_user()") Signed-off-by: Kefeng Wang <[email protected]> Reviewed-by: "Huang, Ying" <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Muchun Song <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent eb90418 commit b79b6fe

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

fs/hugetlbfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
893893
error = PTR_ERR(folio);
894894
goto out;
895895
}
896-
folio_zero_user(folio, ALIGN_DOWN(addr, hpage_size));
896+
folio_zero_user(folio, addr);
897897
__folio_mark_uptodate(folio);
898898
error = hugetlb_add_to_page_cache(folio, mapping, index);
899899
if (unlikely(error)) {

mm/memory.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6780,9 +6780,10 @@ static inline int process_huge_page(
67806780
return 0;
67816781
}
67826782

6783-
static void clear_gigantic_page(struct folio *folio, unsigned long addr,
6783+
static void clear_gigantic_page(struct folio *folio, unsigned long addr_hint,
67846784
unsigned int nr_pages)
67856785
{
6786+
unsigned long addr = ALIGN_DOWN(addr_hint, folio_size(folio));
67866787
int i;
67876788

67886789
might_sleep();

0 commit comments

Comments
 (0)