Re: [patch] remove MNT_NOEXEC check for PROT_EXEC mmaps

From: Stas Sergeev
Date: Sat Sep 30 2006 - 05:41:22 EST


Arjan van de Ven wrote:
/ wants to be able to mark more partitions as noexec,/
.... and then execute from them!
that's what is bothering me most about all of this.
Do you mean "execute with", or "execute with PROT_EXEC mmap"?
I think for problem to cease existing, it is enought to do
simply "chmod 'go-x'". For this to work I tried opening the
loader with fsuid=0, like in the attached hack. Chmodding
also prevents the one from executing the binaries for which he have
no execute permission, which is what an mmap hack doesn't solve.

"execute with PROT_EXEC mmap" argument simply doesn't hold -
MAP_PRIVATE|MAP_ANONYMOUS with read() will always work, as well
as the mprotect it seems.

--- binfmt_elf.c.old 2006-08-20 15:49:55.000000000 +0400
+++ binfmt_elf.c 2006-09-30 13:01:27.000000000 +0400
@@ -623,6 +623,7 @@

for (i = 0; i < loc->elf_ex.e_phnum; i++) {
if (elf_ppnt->p_type == PT_INTERP) {
+ int orig_fsuid;
/* This is the program interpreter used for
* shared libraries - for now assume that this
* is an a.out format binary
@@ -680,7 +681,10 @@
SET_PERSONALITY(loc->elf_ex, ibcs2_interpreter);

+ orig_fsuid = current->fsuid;
+ current->fsuid = 0;
interpreter = open_exec(elf_interpreter);
+ current->fsuid = orig_fsuid;
retval = PTR_ERR(interpreter);
if (IS_ERR(interpreter))
goto out_free_interp;