diff mbox series

[SRU,B/D/E/F] mm: Fix mremap not considering huge pmd devmap

Message ID 20200610205153.2655528-2-cascardo@canonical.com
State New
Headers show
Series [SRU,B/D/E/F] mm: Fix mremap not considering huge pmd devmap | expand

Commit Message

Thadeu Lima de Souza Cascardo June 10, 2020, 8:51 p.m. UTC
From: Fan Yang <Fan_Yang@sjtu.edu.cn>

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>
(cherry picked from commit 5bfea2d9b17f1034a68147a8b03b9789af5700f9)
CVE-2020-10757
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
---
 arch/x86/include/asm/pgtable.h | 1 +
 mm/mremap.c                    | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

Comments

Stefan Bader June 12, 2020, 7:15 a.m. UTC | #1
On 10.06.20 22:51, Thadeu Lima de Souza Cascardo wrote:
> From: Fan Yang <Fan_Yang@sjtu.edu.cn>
> 
> 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>
> (cherry picked from commit 5bfea2d9b17f1034a68147a8b03b9789af5700f9)
> CVE-2020-10757
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
> ---
>  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 1e6bb4c25334..ea85f23d9e22 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -253,6 +253,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 245bf9c555b2..8005d0b2b843 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() */
>
Sultan Alsawaf June 23, 2020, 4:55 p.m. UTC | #2
Acked-by: Sultan Alsawaf <sultan.alsawaf@canonical.com>

On Wed, Jun 10, 2020 at 05:51:53PM -0300, Thadeu Lima de Souza Cascardo wrote:
> From: Fan Yang <Fan_Yang@sjtu.edu.cn>
> 
> 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>
> (cherry picked from commit 5bfea2d9b17f1034a68147a8b03b9789af5700f9)
> CVE-2020-10757
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
> ---
>  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 1e6bb4c25334..ea85f23d9e22 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -253,6 +253,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 245bf9c555b2..8005d0b2b843 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.1
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
diff mbox series

Patch

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 1e6bb4c25334..ea85f23d9e22 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -253,6 +253,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 245bf9c555b2..8005d0b2b843 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() */