Skip to content

Commit f5d09de

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: use aligned address in copy_user_gigantic_page()
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/20241028145656.932941-2-wangkefeng.wang@huawei.com Fixes: 530dd99 ("mm: memory: improve copy_user_large_folio()") Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Reviewed-by: David Hildenbrand <david@redhat.com> Cc: Huang Ying <ying.huang@intel.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 8aca2bc commit f5d09de

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
@@ -5340,7 +5340,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
53405340
break;
53415341
}
53425342
ret = copy_user_large_folio(new_folio, pte_folio,
5343-
ALIGN_DOWN(addr, sz), dst_vma);
5343+
addr, dst_vma);
53445344
folio_put(pte_folio);
53455345
if (ret) {
53465346
folio_put(new_folio);
@@ -6643,8 +6643,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
66436643
*foliop = NULL;
66446644
goto out;
66456645
}
6646-
ret = copy_user_large_folio(folio, *foliop,
6647-
ALIGN_DOWN(dst_addr, size), dst_vma);
6646+
ret = copy_user_large_folio(folio, *foliop, dst_addr, dst_vma);
66486647
folio_put(*foliop);
66496648
*foliop = NULL;
66506649
if (ret) {

mm/memory.c

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

68546854
static int copy_user_gigantic_page(struct folio *dst, struct folio *src,
6855-
unsigned long addr,
6855+
unsigned long addr_hint,
68566856
struct vm_area_struct *vma,
68576857
unsigned int nr_pages)
68586858
{
6859-
int i;
6859+
unsigned long addr = ALIGN_DOWN(addr_hint, folio_size(dst));
68606860
struct page *dst_page;
68616861
struct page *src_page;
6862+
int i;
68626863

68636864
for (i = 0; i < nr_pages; i++) {
68646865
dst_page = folio_page(dst, i);

0 commit comments

Comments
 (0)