Merge branch 'for-4.6-ns' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
[linux-2.6-block.git] / mm / mprotect.c
index f7cb3d4d9c2eb55d74738e374faa3bfa37251686..fa37c4cd973aa49b4deb227646fcdb2779f7cb24 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/migrate.h>
 #include <linux/perf_event.h>
 #include <linux/ksm.h>
+#include <linux/pkeys.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 #include <asm/cacheflush.h>
@@ -354,7 +355,7 @@ fail:
 SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
                unsigned long, prot)
 {
-       unsigned long vm_flags, nstart, end, tmp, reqprot;
+       unsigned long nstart, end, tmp, reqprot;
        struct vm_area_struct *vma, *prev;
        int error = -EINVAL;
        const int grows = prot & (PROT_GROWSDOWN|PROT_GROWSUP);
@@ -380,8 +381,6 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
        if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
                prot |= PROT_EXEC;
 
-       vm_flags = calc_vm_prot_bits(prot);
-
        down_write(&current->mm->mmap_sem);
 
        vma = find_vma(current->mm, start);
@@ -411,10 +410,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
 
        for (nstart = start ; ; ) {
                unsigned long newflags;
+               int pkey = arch_override_mprotect_pkey(vma, prot, -1);
 
                /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
 
-               newflags = vm_flags;
+               newflags = calc_vm_prot_bits(prot, pkey);
                newflags |= (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC));
 
                /* newflags >> 4 shift VM_MAY% in place of VM_% */