Skip to content

Commit 8aca2bc

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: use aligned address in clear_gigantic_page()
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/20241028145656.932941-1-wangkefeng.wang@huawei.com Fixes: 78fefd0 ("mm: memory: convert clear_huge_page() to folio_zero_user()") Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Reviewed-by: "Huang, Ying" <ying.huang@intel.com> Reviewed-by: David Hildenbrand <david@redhat.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Muchun Song <muchun.song@linux.dev> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent dad2dc9 commit 8aca2bc

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
@@ -825,7 +825,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
825825
error = PTR_ERR(folio);
826826
goto out;
827827
}
828-
folio_zero_user(folio, ALIGN_DOWN(addr, hpage_size));
828+
folio_zero_user(folio, addr);
829829
__folio_mark_uptodate(folio);
830830
error = hugetlb_add_to_page_cache(folio, mapping, index);
831831
if (unlikely(error)) {

mm/memory.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6815,9 +6815,10 @@ static inline int process_huge_page(
68156815
return 0;
68166816
}
68176817

6818-
static void clear_gigantic_page(struct folio *folio, unsigned long addr,
6818+
static void clear_gigantic_page(struct folio *folio, unsigned long addr_hint,
68196819
unsigned int nr_pages)
68206820
{
6821+
unsigned long addr = ALIGN_DOWN(addr_hint, folio_size(folio));
68216822
int i;
68226823

68236824
might_sleep();

0 commit comments

Comments
 (0)