From 3b565b8c8115d396ca91e79552529d48092d8589 Mon Sep 17 00:00:00 2001 From: Khalid Aziz Date: Tue, 7 Mar 2017 11:26:10 -0700 Subject: [PATCH] sparc64: Do not retain old VM_SPARC_ADI flag when protection changes on page When protection on a memory page is changed with mprotect(), old arch-specific VM flags on the page are retained. This patch clears old VM_SPARC_ADI flag when protection is changed since mprotect() is potentially being invoked to disable ADI on the page. This code will add VM_SPARC_ADI flag back if the new protection includes it. Orabug: 25641371 Signed-off-by: Khalid Aziz Signed-off-by: Allen Pais --- include/linux/mm.h | 6 ++++++ mm/mprotect.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1f41995d06f3..c7d1f776cc7d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -165,6 +165,7 @@ extern unsigned int kobjsize(const void *objp); # define VM_GROWSUP VM_ARCH_1 #elif defined(CONFIG_SPARC64) # define VM_SPARC_ADI VM_ARCH_1 /* Uses ADI tag for access control */ +# define VM_ARCH_CLEAR VM_SPARC_ADI #elif !defined(CONFIG_MMU) # define VM_MAPPED_COPY VM_ARCH_1 /* T if mapped copy of data (nommu mmap) */ #endif @@ -200,6 +201,11 @@ extern unsigned int kobjsize(const void *objp); /* This mask defines which mm->def_flags a process can inherit its parent */ #define VM_INIT_DEF_MASK VM_NOHUGEPAGE +/* Arch-specific flags to clear when updating VM flags on protection change */ +#ifndef VM_ARCH_CLEAR +# define VM_ARCH_CLEAR VM_NONE +#endif + /* * mapping from the currently active vm_flags protection bits (the * low four bits) to a page protection mask.. diff --git a/mm/mprotect.c b/mm/mprotect.c index 88584838e704..826bb094c84d 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -396,7 +396,8 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, /* Here we know that vma->vm_start <= nstart < vma->vm_end. */ newflags = vm_flags; - newflags |= (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC)); + newflags |= (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC | + VM_ARCH_CLEAR)); /* newflags >> 4 shift VM_MAY% in place of VM_% */ if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) { -- 2.50.1