public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stas Sergeev <stsp@aknet.ru>
To: Linux kernel <linux-kernel@vger.kernel.org>
Subject: question about MNT_NOEXEC and PROT_EXEC relation
Date: Thu, 21 Sep 2006 22:48:30 +0400	[thread overview]
Message-ID: <4512DE7E.9090602@aknet.ru> (raw)

[-- 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)

                 reply	other threads:[~2006-09-21 18:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4512DE7E.9090602@aknet.ru \
    --to=stsp@aknet.ru \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox