Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1146619ybg; Thu, 4 Jun 2020 02:10:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXkHSUMAsyShxST7xZZpUoSzI7VrJEm+xFuLHFOxFh9rrgtpFTSZNmuWPC4PdwCwgGYRZz X-Received: by 2002:a17:906:a2c5:: with SMTP id by5mr3007521ejb.492.1591261809696; Thu, 04 Jun 2020 02:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591261809; cv=none; d=google.com; s=arc-20160816; b=K9FkvFWqLfdUC7TyDvBi8Oeh2dx0Pz/2/GJ2uPue5Z46m93nLzzNR6w9axdqw8YIEl 2zTqYDopPQw0XA6PVs8k1U+dmlMno/xbwrOymaeLvNihN7SYznbXAascu8RrBwlQSzpN fSqbTMWLytl7YxmR838PLssi5h2D3Tr8V9hXfXK9jQR/PUsK9yI/QQlHrpauRhfl7a3+ oPEN4+coQjZ0FcpM+1RC7m/VdbVNMc4Rny9dLbyukllwM4rhSvM1bKmV/6dEFkWwsEMY /o2gLo3Nri6jrrHeiJhz1qD0ZRxJLW+lWJZ3cBtJbz8t9+fYyGkcY4jOr+84sbWg/hHv obgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:date:message-id:subject:mime-version :content-transfer-encoding:from; bh=vxCdUzSCiU3kqmIOJ6vVcJRLJttFKPqVWD7Yy/w4Jmw=; b=brbpmyaWrF/PXxDMDHNCV94sq86QKxVmo9FlhZ1D6udz4r2/KBdzFCAhquDQsXBVW/ baoOA9YIN/7bbkQjahAhYe/NDyZ/nqJeuVRWf7lvavLeErBcsEbljEzq1dAzO1IWNBtd rXhi0XK+eTxc02aeHdDVJ3/XrLUlnYP+bW1LLe7aDAKQkuLr81NbJFp6mG6Gj4kGAEl8 +SGtUJAHr3sDWw62rkqx1lbnc7KZ3Yd5WGizj9aquLk7JYM3TCD/d+yMNYmfv8mJt5nZ 7znE95Ix8yGC9+TvGzN/uN3U/znYElkdZ94GQ9qP+LiubKiVjyZhVSqpgOXgrioSxm2x XYcw== 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 63si1118762edj.314.2020.06.04.02.09.46; Thu, 04 Jun 2020 02:10:09 -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 S1728388AbgFDJHC convert rfc822-to-8bit (ORCPT + 99 others); Thu, 4 Jun 2020 05:07:02 -0400 Received: from smtp180.sjtu.edu.cn ([202.120.2.180]:54656 "EHLO smtp180.sjtu.edu.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728089AbgFDJHC (ORCPT ); Thu, 4 Jun 2020 05:07:02 -0400 X-Greylist: delayed 350 seconds by postgrey-1.27 at vger.kernel.org; Thu, 04 Jun 2020 05:07:01 EDT Received: from proxy01.sjtu.edu.cn (smtp185.sjtu.edu.cn [202.120.2.185]) by smtp180.sjtu.edu.cn (Postfix) with ESMTPS id 8617F1008CA2F for ; Thu, 4 Jun 2020 17:01:08 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by proxy01.sjtu.edu.cn (Postfix) with ESMTP id 7CC8F20426A48 for ; Thu, 4 Jun 2020 17:01:08 +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 XFgF8pTuBOzj for ; Thu, 4 Jun 2020 17:01:08 +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 5490820426998 for ; Thu, 4 Jun 2020 17:01:07 +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: Subject: [PATCH v3] mm: Fix mremap not considering huge pmd devmap Message-Id: Date: Thu, 4 Jun 2020 17:01:07 +0800 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 Hi, 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