Skip to content

Commit cb12d61

Browse files
Kefeng Wanggregkh
authored andcommitted
mm: use aligned address in copy_user_gigantic_page()
commit f5d09de upstream. In current kernel, hugetlb_wp() calls copy_user_large_folio() with the fault address. Where the fault address may be not aligned with the huge page size. Then, copy_user_large_folio() may call copy_user_gigantic_page() with the address, while copy_user_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 copy_user_gigantic_page(). Link: https://lkml.kernel.org/r/[email protected] Fixes: 530dd99 ("mm: memory: improve copy_user_large_folio()") Signed-off-by: Kefeng Wang <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Cc: Huang Ying <[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 b79b6fe commit cb12d61

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

mm/hugetlb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5333,7 +5333,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
53335333
break;
53345334
}
53355335
ret = copy_user_large_folio(new_folio, pte_folio,
5336-
ALIGN_DOWN(addr, sz), dst_vma);
5336+
addr, dst_vma);
53375337
folio_put(pte_folio);
53385338
if (ret) {
53395339
folio_put(new_folio);
@@ -6632,8 +6632,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
66326632
*foliop = NULL;
66336633
goto out;
66346634
}
6635-
ret = copy_user_large_folio(folio, *foliop,
6636-
ALIGN_DOWN(dst_addr, size), dst_vma);
6635+
ret = copy_user_large_folio(folio, *foliop, dst_addr, dst_vma);
66376636
folio_put(*foliop);
66386637
*foliop = NULL;
66396638
if (ret) {

mm/memory.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6817,13 +6817,14 @@ void folio_zero_user(struct folio *folio, unsigned long addr_hint)
68176817
}
68186818

68196819
static int copy_user_gigantic_page(struct folio *dst, struct folio *src,
6820-
unsigned long addr,
6820+
unsigned long addr_hint,
68216821
struct vm_area_struct *vma,
68226822
unsigned int nr_pages)
68236823
{
6824-
int i;
6824+
unsigned long addr = ALIGN_DOWN(addr_hint, folio_size(dst));
68256825
struct page *dst_page;
68266826
struct page *src_page;
6827+
int i;
68276828

68286829
for (i = 0; i < nr_pages; i++) {
68296830
dst_page = folio_page(dst, i);

0 commit comments

Comments
 (0)