From: Dave Hansen <[email protected]>
This is a cleanup. There should be functional changes in this patch. The pageattr code has the ability to find and change aliases mappings. It does this for requests by default unless the page protections being modified contain only the NX bit. But, this behavior is rather obscure and buried very deep within the infrastructure. Rather than doing it implicitly from NX, use the new CPA_NO_CHECK_ALIAS to do it more explicitly from the call site where NX is set. Signed-off-by: Dave Hansen <[email protected]> Cc: Kees Cook <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Juergen Gross <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Andi Kleen <[email protected]> --- b/arch/x86/mm/pageattr.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff -puN arch/x86/mm/pageattr.c~x86-pageattr-nx arch/x86/mm/pageattr.c --- a/arch/x86/mm/pageattr.c~x86-pageattr-nx 2018-08-02 15:04:48.032475796 -0700 +++ b/arch/x86/mm/pageattr.c 2018-08-02 15:04:48.036475796 -0700 @@ -1485,8 +1485,6 @@ static int change_page_attr_set_clr(unsi if (in_flag & (CPA_ARRAY | CPA_PAGES_ARRAY)) cpa.flags |= in_flag; - /* No alias checking for _NX bit modifications */ - checkalias = (pgprot_val(mask_set) | pgprot_val(mask_clr)) != _PAGE_NX; /* Never check aliases if the caller asks for it explicitly: */ if (checkalias && (in_flag & CPA_NO_CHECK_ALIAS)) checkalias = 0; @@ -1750,7 +1748,9 @@ int set_memory_x(unsigned long addr, int if (!(__supported_pte_mask & _PAGE_NX)) return 0; - return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_NX), 0); + /* NX is not required to be consistent across aliases. */ + return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_NX), + CPA_NO_CHECK_ALIAS); } EXPORT_SYMBOL(set_memory_x); @@ -1759,7 +1759,9 @@ int set_memory_nx(unsigned long addr, in if (!(__supported_pte_mask & _PAGE_NX)) return 0; - return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_NX), 0); + /* NX is not required to be consistent across aliases. */ + return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_NX), + CPA_NO_CHECK_ALIAS); } EXPORT_SYMBOL(set_memory_nx); _

