From: Fan Yang Date: Thu, 4 Jun 2020 10:22:07 +0000 (+0800) Subject: mm: Fix mremap not considering huge pmd devmap X-Git-Tag: archive/raspbian/5.7.6-1+rpi1^2^2~21 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=400fcc0b569a9944b0bee1f4e98a53d026b6bf49;p=linux.git mm: Fix mremap not considering huge pmd devmap Origin: https://git.kernel.org/linus/5bfea2d9b17f1034a68147a8b03b9789af5700f9 Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2020-10757 The original code in mm/mremap.c checks huge pmd by: if (is_swap_pmd(*old_pmd) || pmd_trans_huge(*old_pmd)) { However, a DAX mapped nvdimm is mapped as huge page (by default) but it is not transparent huge page (_PAGE_PSE | PAGE_DEVMAP). This commit changes the condition to include the case. This addresses CVE-2020-10757. Fixes: 5c7fb56e5e3f ("mm, dax: dax-pmd vs thp-pmd vs hugetlbfs-pmd") Cc: Reported-by: Fan Yang Signed-off-by: Fan Yang Tested-by: Fan Yang Tested-by: Dan Williams Reviewed-by: Dan Williams Acked-by: Kirill A. Shutemov Signed-off-by: Linus Torvalds Gbp-Pq: Topic bugfix/all Gbp-Pq: Name mm-Fix-mremap-not-considering-huge-pmd-devmap.patch --- diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 64a03f226ab..dca64a2dda9 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -256,6 +256,7 @@ static inline int pmd_large(pmd_t pte) } #ifdef CONFIG_TRANSPARENT_HUGEPAGE +/* NOTE: when predicate huge page, consider also pmd_devmap, or use pmd_large */ static inline int pmd_trans_huge(pmd_t pmd) { return (pmd_val(pmd) & (_PAGE_PSE|_PAGE_DEVMAP)) == _PAGE_PSE; diff --git a/mm/mremap.c b/mm/mremap.c index d28f08a36b9..3a097e02caf 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -266,7 +266,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma, new_pmd = alloc_new_pmd(vma->vm_mm, vma, new_addr); if (!new_pmd) break; - if (is_swap_pmd(*old_pmd) || pmd_trans_huge(*old_pmd)) { + if (is_swap_pmd(*old_pmd) || pmd_trans_huge(*old_pmd) || pmd_devmap(*old_pmd)) { if (extent == HPAGE_PMD_SIZE) { bool moved; /* See comment in move_ptes() */