4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Dan Williams <dan.j.willi...@intel.com>

commit ef947b2529f918d9606533eb9c32b187ed6a5ede upstream.

gup_pte_range() fails to check pte_allows_gup() before translating a DAX
pte entry, pte_devmap(), to a page.  This allows writes to read-only
mappings, and bypasses the DAX cacheline dirty tracking due to missed
'mkwrite' faults.  The gup_huge_pmd() path and the gup_huge_pud() path
correctly check pte_allows_gup() before checking for _devmap() entries.

Fixes: 3565fce3a659 ("mm, x86: get_user_pages() for dax mappings")
Link: 
http://lkml.kernel.org/r/148804251312.36605.12665024794196605053.st...@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Ross Zwisler <ross.zwis...@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.willi...@intel.com>
Reported-by: Dave Hansen <dave.han...@linux.intel.com>
Reported-by: Ross Zwisler <ross.zwis...@linux.intel.com>
Cc: Xiong Zhou <xz...@redhat.com>
Cc: Ingo Molnar <mi...@redhat.com>
Cc: "H. Peter Anvin" <h...@zytor.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Signed-off-by: Andrew Morton <a...@linux-foundation.org>
Signed-off-by: Linus Torvalds <torva...@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>

---
 arch/x86/mm/gup.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/arch/x86/mm/gup.c
+++ b/arch/x86/mm/gup.c
@@ -120,6 +120,11 @@ static noinline int gup_pte_range(pmd_t
                        return 0;
                }
 
+               if (!pte_allows_gup(pte_val(pte), write)) {
+                       pte_unmap(ptep);
+                       return 0;
+               }
+
                if (pte_devmap(pte)) {
                        pgmap = get_dev_pagemap(pte_pfn(pte), pgmap);
                        if (unlikely(!pgmap)) {
@@ -127,8 +132,7 @@ static noinline int gup_pte_range(pmd_t
                                pte_unmap(ptep);
                                return 0;
                        }
-               } else if (!pte_allows_gup(pte_val(pte), write) ||
-                          pte_special(pte)) {
+               } else if (pte_special(pte)) {
                        pte_unmap(ptep);
                        return 0;
                }


Reply via email to