mm: Fix mremap not considering huge pmd devmap
authorFan Yang <Fan_Yang@sjtu.edu.cn>
Thu, 4 Jun 2020 10:22:07 +0000 (18:22 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 Jun 2020 07:22:57 +0000 (09:22 +0200)
commit 5bfea2d9b17f1034a68147a8b03b9789af5700f9 upstream.

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: <stable@vger.kernel.org>
Reported-by: Fan Yang <Fan_Yang@sjtu.edu.cn>
Signed-off-by: Fan Yang <Fan_Yang@sjtu.edu.cn>
Tested-by: Fan Yang <Fan_Yang@sjtu.edu.cn>
Tested-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/include/asm/pgtable.h
mm/mremap.c

index 98a337e3835d68758297115cc6d9cbba8e5b657a..2f7a4018b6e48e7886f5dcec31e8ce0ac9c02338 100644 (file)
@@ -234,6 +234,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;
index 88ceeb4ef817e7c92286c3aab2b37e045a1f8022..3c7fcd5d579441bbe90c5310180229fe3bcecbdf 100644 (file)
@@ -223,7 +223,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() */