Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1196257ybg; Thu, 4 Jun 2020 03:40:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVBpV6tjNh3s+yaHGwExhbqQkBkJ05QNQxM1qjVuEkS1lLwzKXcKKp+lT99xUYt8DbCeTy X-Received: by 2002:a17:906:9a02:: with SMTP id ai2mr3176707ejc.97.1591267250602; Thu, 04 Jun 2020 03:40:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591267250; cv=none; d=google.com; s=arc-20160816; b=lhLb230RGpEueNIZPxgh52sbEiOHASSYZ0skHgij9t9y1JK02IlYSjdjEt9RiOqvEu qnn+1TO2qgIpHUqCpBZYW/nI84VXdqxfXjtXMEYW/QgHp1PKgKK53rAbNIQ2q/h6+Gvo rd1ctjlCGWyLTx3eq3/BJ17VsEQOe5D7L+kF4eVy2YyQJfEFrs8N38SJwo8ifuNWPGUg ZBeD24ZyeYOvUZqMKNzLRb4Mi8ag3mQZr/H5Lg70piEOgVdn8eDUz8o50iIsDlWykFeU iam/amgzNmHQFtZK4e2jiKQxh3hH+MKC4y0l7eburO7pC2I2I+oho8TuzD1Q4M+knMyw ugng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:cc:date:message-id:subject :mime-version:content-transfer-encoding:from; bh=jHUG0wTLKD1BilUrDJpNnbdim/2ZQ5IxA/oYi2LNh4U=; b=ym+exQzDd3xVTBkPoxCU8QRIuXK2PJhJY8WL9LAfav2m7l6TuyPMKOhkkORQEgz4/k HQMXsOgGbNkywU2xlqxKFyikmKn5hkCiMSUUAAiVejHYqm7Bi6P5eh+x/GibLFAX8Igs BwfmvVOXXngM7V+TB+3voa2ukN6FtXEpGCXu0yoIZmurBdK9gcatWD1QvmhLWj66DaHE JVF6NFSOIcNnfGdigqUUJDj446xV87vlWgHOPEcsk36oxDC3U8o8CQEicfIV1k6JDzmS yWT52NZ2nJobcaVfDtAjzR5e3WT+D/mD8rIhkOA6huMQLZ1Xy5rwfzzfUNIM/JkEBCcD dkkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de28si1466315edb.492.2020.06.04.03.40.27; Thu, 04 Jun 2020 03:40:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728214AbgFDKWT convert rfc822-to-8bit (ORCPT + 99 others); Thu, 4 Jun 2020 06:22:19 -0400 Received: from smtp180.sjtu.edu.cn ([202.120.2.180]:56320 "EHLO smtp180.sjtu.edu.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726236AbgFDKWT (ORCPT ); Thu, 4 Jun 2020 06:22:19 -0400 Received: from proxy01.sjtu.edu.cn (smtp185.sjtu.edu.cn [202.120.2.185]) by smtp180.sjtu.edu.cn (Postfix) with ESMTPS id 16D4B1008CA21; Thu, 4 Jun 2020 18:22:16 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by proxy01.sjtu.edu.cn (Postfix) with ESMTP id D103220426A63; Thu, 4 Jun 2020 18:22:15 +0800 (CST) X-Virus-Scanned: amavisd-new at proxy01.sjtu.edu.cn Received: from proxy01.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy01.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id b4y9uFH9wMra; Thu, 4 Jun 2020 18:22:15 +0800 (CST) Received: from fans-air.ipads-lab.se.sjtu.edu.cn (unknown [202.120.40.82]) (Authenticated sender: Fan_Yang@sjtu.edu.cn) by proxy01.sjtu.edu.cn (Postfix) with ESMTPSA id 9EA9920426A59; Thu, 4 Jun 2020 18:22:08 +0800 (CST) From: Fan Yang Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8BIT Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: [PATCH v3] mm: Fix mremap not considering huge pmd devmap Message-Id: Date: Thu, 4 Jun 2020 18:22:07 +0800 Cc: "Williams, Dan J" , "Kirill A. Shutemov" , Linus Torvalds To: linux-kernel@vger.kernel.org X-Mailer: Apple Mail (2.3608.80.23.2.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changelog v2->v3: - Added "Acked-by: Kirill..." Changelog v1->v2: - Removed some paragraph in commit msg, removed the comment in mm/mremap.c, and added a NOTE in where pmd_trans_huge is defined. - Added "Reviewed-by: Dan..." - Added "Fixes: 5c7fb56e5e3f..." - Added "Cc: " --- arch/x86/include/asm/pgtable.h | 1 + mm/mremap.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 4d02e64af1b3..19cdeebfbde6 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -257,6 +257,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 6aa6ea605068..57b1f999f789 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() */ -- 2.25.4