Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1340119
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [RFC][PATCH 3/7] x86, pkeys: make mprotect_key() mask off additional vm_flags |
| Date | 2016-02-23 02:20 +0100 |
| Message-ID | <r59NU-6nf-9@gated-at.bofh.it> (permalink) |
| References | <r59NU-6nf-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Dave Hansen <dave.hansen@linux.intel.com>
Today, mprotect() takes 4 bits of data: PROT_READ/WRITE/EXEC/NONE.
Three of those bits: READ/WRITE/EXEC get translated directly in to
vma->vm_flags by calc_vm_prot_bits(). If a bit is unset in
mprotect()'s 'prot' argument then it must be cleared in vma->vm_flags
during the mprotect() call.
We do this clearing today by first calculating the VMA flags we
want set, then clearing the ones we do not want to inherit from
the original VMA:
vm_flags = calc_vm_prot_bits(prot, key);
...
newflags = vm_flags;
newflags |= (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC));
However, we *also* want to mask off the original VMA's vm_flags in
which we store the protection key.
To do that, this patch adds a new macro:
ARCH_VM_PKEY_FLAGS
which allows the architecture to specify additional bits that it would
like cleared. We use that to ensure that the VM_PKEY_BIT* bits get
cleared.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-mm@kvack.org
Cc: x86@kernel.org
Cc: torvalds@linux-foundation.org
Cc: akpm@linux-foundation.org
---
b/arch/x86/include/asm/pkeys.h | 2 ++
b/include/linux/pkeys.h | 1 +
b/mm/mprotect.c | 10 +++++++++-
3 files changed, 12 insertions(+), 1 deletion(-)
diff -puN arch/x86/include/asm/pkeys.h~pkeys-85a-mask-off-correct-vm_flags arch/x86/include/asm/pkeys.h
--- a/arch/x86/include/asm/pkeys.h~pkeys-85a-mask-off-correct-vm_flags 2016-02-22 17:09:23.727314024 -0800
+++ b/arch/x86/include/asm/pkeys.h 2016-02-22 17:09:23.733314297 -0800
@@ -38,4 +38,6 @@ static inline int arch_override_mprotect
extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
unsigned long init_val);
+#define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | VM_PKEY_BIT3)
+
#endif /*_ASM_X86_PKEYS_H */
diff -puN include/linux/pkeys.h~pkeys-85a-mask-off-correct-vm_flags include/linux/pkeys.h
--- a/include/linux/pkeys.h~pkeys-85a-mask-off-correct-vm_flags 2016-02-22 17:09:23.728314069 -0800
+++ b/include/linux/pkeys.h 2016-02-22 17:09:23.733314297 -0800
@@ -16,6 +16,7 @@
#define execute_only_pkey(mm) (0)
#define arch_override_mprotect_pkey(vma, prot, pkey) (0)
#define PKEY_DEDICATED_EXECUTE_ONLY 0
+#define ARCH_VM_PKEY_FLAGS 0
#endif /* ! CONFIG_ARCH_HAS_PKEYS */
/*
diff -puN mm/mprotect.c~pkeys-85a-mask-off-correct-vm_flags mm/mprotect.c
--- a/mm/mprotect.c~pkeys-85a-mask-off-correct-vm_flags 2016-02-22 17:09:23.730314160 -0800
+++ b/mm/mprotect.c 2016-02-22 17:09:23.733314297 -0800
@@ -417,9 +417,17 @@ static int do_mprotect_pkey(unsigned lon
/* Here we know that vma->vm_start <= nstart < vma->vm_end. */
+ /*
+ * Each mprotect() call explicitly passes r/w/x permissions.
+ * If a permission is not passed to mprotect(), it must be
+ * cleared from the VMA.
+ */
+ unsigned long mask_off_old_flags = VM_READ | VM_WRITE | VM_EXEC;
+ mask_off_old_flags |= ARCH_VM_PKEY_FLAGS;
+
vma_pkey = arch_override_mprotect_pkey(vma, prot, pkey);
newflags = calc_vm_prot_bits(prot, vma_pkey);
- newflags |= (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC));
+ newflags |= (vma->vm_flags & ~mask_off_old_flags);
/* newflags >> 4 shift VM_MAY% in place of VM_% */
if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
_
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[RFC][PATCH 0/7] System Calls for Memory Protection Keys Dave Hansen <dave@sr71.net> - 2016-02-23 02:20 +0100
[RFC][PATCH 3/7] x86, pkeys: make mprotect_key() mask off additional vm_flags Dave Hansen <dave@sr71.net> - 2016-02-23 02:20 +0100
[RFC][PATCH 1/7] x86, pkeys: Documentation Dave Hansen <dave@sr71.net> - 2016-02-23 02:20 +0100
[RFC][PATCH 6/7] x86, pkeys: add pkey set/get syscalls Dave Hansen <dave@sr71.net> - 2016-02-23 02:20 +0100
Re: [RFC][PATCH 6/7] x86, pkeys: add pkey set/get syscalls Ingo Molnar <mingo@kernel.org> - 2016-02-23 07:50 +0100
[RFC][PATCH 4/7] x86: wire up mprotect_key() system call Dave Hansen <dave@sr71.net> - 2016-02-23 02:20 +0100
[RFC][PATCH 7/7] pkeys: add details of system call use to Documentation/ Dave Hansen <dave@sr71.net> - 2016-02-23 02:20 +0100
Re: [RFC][PATCH 7/7] pkeys: add details of system call use to Documentation/ Ingo Molnar <mingo@kernel.org> - 2016-02-23 07:40 +0100
[RFC][PATCH 2/7] mm: implement new pkey_mprotect() system call Dave Hansen <dave@sr71.net> - 2016-02-23 02:20 +0100
[RFC][PATCH 5/7] x86, pkeys: allocation/free syscalls Dave Hansen <dave@sr71.net> - 2016-02-23 02:20 +0100
Re: [RFC][PATCH 0/7] System Calls for Memory Protection Keys "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-03-03 09:20 +0100
Re: [RFC][PATCH 0/7] System Calls for Memory Protection Keys Dave Hansen <dave@sr71.net> - 2016-03-04 00:50 +0100
csiph-web