From bf39d18e640909b8b88318158bec1450bd178ebd Mon Sep 17 00:00:00 2001 From: Daniel McNeil Date: Thu, 15 Jul 2004 21:52:43 -0700 Subject: [PATCH] [PATCH] mmap PROT_NONE fix for NX patch This works around the current PROT_NONE problem from elf binaries that do not have the PT_GNU_STACK so that the do not have execute permission. The problem was that setting "def_flags" to include the VM_EXEC bit for compatibility reasons would also make PROT_NONE pages executable, which is obviously not correct. Signed-off-by: Daniel McNeil Signed-off-by: Linus Torvalds --- mm/mmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index f23ec33c8b7d5..cd8eec6bdb3ab 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -792,6 +792,12 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr, vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; + /* + * mm->def_flags might have VM_EXEC set, which PROT_NONE does NOT want. + */ + if (prot == PROT_NONE) + vm_flags &= ~VM_EXEC; + if (flags & MAP_LOCKED) { if (!capable(CAP_IPC_LOCK)) return -EPERM; -- 2.53.0