FDPIC: Respect PT_GNU_STACK exec protection markings when creating NOMMU stack
authorMike Frysinger <vapier@gentoo.org>
Wed, 6 Jan 2010 17:23:17 +0000 (17:23 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 9 Feb 2010 12:50:49 +0000 (04:50 -0800)
commit944a638b7bb07f3ef9a33af60e5ea8465b7adfd1
tree72a01e79ecb53349054890729cec105a71ab4f44
parent0b3bf81197f05e1bf0ed93c5f2525030b127faaa
FDPIC: Respect PT_GNU_STACK exec protection markings when creating NOMMU stack

commit 04e4f2b18c8de1389d1e00fef0f42a8099910daf upstream.

The current code will load the stack size and protection markings, but
then only use the markings in the MMU code path.  The NOMMU code path
always passes PROT_EXEC to the mmap() call.  While this doesn't matter
to most people whilst the code is running, it will cause a pointless
icache flush when starting every FDPIC application.  Typically this
icache flush will be of a region on the order of 128KB in size, or may
be the entire icache, depending on the facilities available on the CPU.

In the case where the arch default behaviour seems to be desired
(EXSTACK_DEFAULT), we probe VM_STACK_FLAGS for VM_EXEC to determine
whether we should be setting PROT_EXEC or not.

For arches that support an MPU (Memory Protection Unit - an MMU without
the virtual mapping capability), setting PROT_EXEC or not will make an
important difference.

It should be noted that this change also affects the executability of
the brk region, since ELF-FDPIC has that share with the stack.  However,
this is probably irrelevant as NOMMU programs aren't likely to use the
brk region, preferring instead allocation via mmap().

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
arch/blackfin/include/asm/page.h
arch/frv/include/asm/page.h
fs/binfmt_elf_fdpic.c