public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* question about MNT_NOEXEC and PROT_EXEC relation
@ 2006-09-21 18:48 Stas Sergeev
  0 siblings, 0 replies; only message in thread
From: Stas Sergeev @ 2006-09-21 18:48 UTC (permalink / raw)
  To: Linux kernel

[-- Attachment #1: Type: text/plain, Size: 1462 bytes --]

Hi.

My question is inspired by the recent change in debian
scripts that resulted tmpfs to be mounted with "noexec".
That broke a few packages, namely UML and dosemu, see here:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=386945

Right now the kernel checks the MNT_NOEXEC flag and if it
is set, it rejects the PROT_EXEC file-based mappings.
My question is simple: why?

I have googled for an answer but failed to find any.
I have only found the related commit:
http://linux.bkbits.net:8080/linux-2.6/patch@1.1371.76.3
and some "post-factum" discussion:
http://lists.grok.org.uk/pipermail/full-disclosure/2004-January/015871.html
but the original discussion that preceeded the patch, I
was not able to find.

I can see the following problems with that approach:
1. It rejects both the MAP_SHARED and MAP_PRIVATE mappings.
How can it be usefull to reject the MAP_PRIVATE mapping, if
the one can just do the MAP_ANONYMOUS mapping with PROT_EXEC
set, and then simply read() the binary in?
2. It doesn't prevent mprotect() to be used to set PROT_EXEC
later on.
3. It doesn't check the file mode for the execute permission,
yet it checks MNT_NOEXEC - is this consistent?
4. It prevents tmpfs from being mounted with "noexec", and so,
in my eyes, doesn't add to security at all, and now also makes
some problems for debian.

Can someone please give a brief explanation of why such a
check is usefull? Or, in other words, why the attached patch
cannot be applied?


[-- Attachment #2: mapx.diff --]
[-- Type: text/plain, Size: 1256 bytes --]

--- a/mm/mmap.c	2006-01-25 15:02:24.000000000 +0300
+++ b/mm/mmap.c	2006-09-21 13:19:15.000000000 +0400
@@ -899,10 +899,6 @@
 
 		if (!file->f_op || !file->f_op->mmap)
 			return -ENODEV;
-
-		if ((prot & PROT_EXEC) &&
-		    (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
-			return -EPERM;
 	}
 	/*
 	 * Does the application expect PROT_READ to imply PROT_EXEC?
@@ -911,8 +907,7 @@
 	 *  mounted, in which case we dont add PROT_EXEC.)
 	 */
 	if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
-		if (!(file && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC)))
-			prot |= PROT_EXEC;
+		prot |= PROT_EXEC;
 
 	if (!len)
 		return -EINVAL;
--- a/mm/nommu.c	2006-04-12 09:37:34.000000000 +0400
+++ b/mm/nommu.c	2006-09-21 13:21:32.000000000 +0400
@@ -493,13 +493,7 @@
 				capabilities &= ~BDI_CAP_MAP_DIRECT;
 		}
 
-		/* handle executable mappings and implied executable
-		 * mappings */
-		if (file->f_vfsmnt->mnt_flags & MNT_NOEXEC) {
-			if (prot & PROT_EXEC)
-				return -EPERM;
-		}
-		else if ((prot & PROT_READ) && !(prot & PROT_EXEC)) {
+		if ((prot & PROT_READ) && !(prot & PROT_EXEC)) {
 			/* handle implication of PROT_EXEC by PROT_READ */
 			if (current->personality & READ_IMPLIES_EXEC) {
 				if (capabilities & BDI_CAP_EXEC_MAP)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-09-21 18:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-21 18:48 question about MNT_NOEXEC and PROT_EXEC relation Stas Sergeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox