mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: miklos@szeredi.hu
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Cc: Christoph Hellwig <hch@infradead.org>
Subject: [patch 3/9] fix execute checking in permission()
Date: Thu, 09 Aug 2007 11:20:49 +0200	[thread overview]
Message-ID: <20070809092459.676107488@szeredi.hu> (raw)
In-Reply-To: <20070809092046.656183199@szeredi.hu>

[-- Attachment #1: permission_exec_fix.patch --]
[-- Type: text/plain, Size: 2515 bytes --]

From: Miklos Szeredi <mszeredi@suse.cz>

permission() checks that MAY_EXEC is only allowed on regular files if
at least one execute bit is set in the file mode.

generic_permission() already ensures this, so the extra check in
permission() is superfluous.

If the filesystem defines it's own ->permission() the check may still
be needed.  In this case move it after ->permission().  This is needed
because filesystems such as FUSE may need to refresh the inode
attributes before checking permissions.

This check should be moved inside ->permission(), but that's another
story.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---

Index: linux/fs/namei.c
===================================================================
--- linux.orig/fs/namei.c	2007-08-09 11:01:55.000000000 +0200
+++ linux/fs/namei.c	2007-08-09 11:04:22.000000000 +0200
@@ -227,10 +227,10 @@ int generic_permission(struct inode *ino
 
 int permission(struct inode *inode, int mask, struct nameidata *nd)
 {
-	umode_t mode = inode->i_mode;
 	int retval, submask;
 
 	if (mask & MAY_WRITE) {
+		umode_t mode = inode->i_mode;
 
 		/*
 		 * Nobody gets write access to a read-only fs.
@@ -246,22 +246,34 @@ int permission(struct inode *inode, int 
 			return -EACCES;
 	}
 
-
-	/*
-	 * MAY_EXEC on regular files requires special handling: We override
-	 * filesystem execute permissions if the mode bits aren't set or
-	 * the fs is mounted with the "noexec" flag.
-	 */
-	if ((mask & MAY_EXEC) && S_ISREG(mode) && (!(mode & S_IXUGO) ||
-			(nd && nd->mnt && (nd->mnt->mnt_flags & MNT_NOEXEC))))
-		return -EACCES;
+	if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
+		/*
+		 * MAY_EXEC on regular files is denied if the fs is mounted
+		 * with the "noexec" flag.
+		 */
+		if (nd && nd->mnt && (nd->mnt->mnt_flags & MNT_NOEXEC))
+			return -EACCES;
+	}
 
 	/* Ordinary permission routines do not understand MAY_APPEND. */
 	submask = mask & ~MAY_APPEND;
-	if (inode->i_op && inode->i_op->permission)
+	if (inode->i_op && inode->i_op->permission) {
 		retval = inode->i_op->permission(inode, submask, nd);
-	else
+		if (!retval) {
+			/*
+			 * Exec permission on a regular file is denied if none
+			 * of the execute bits are set.
+			 *
+			 * This check should be done by the ->permission()
+			 * method.
+			 */
+			if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode) &&
+			    !(inode->i_mode & S_IXUGO))
+				return -EACCES;
+		}
+	} else {
 		retval = generic_permission(inode, submask, NULL);
+	}
 	if (retval)
 		return retval;
 

--

  parent reply	other threads:[~2007-08-09  9:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-09  9:20 [patch 0/9] assorted fixes and cleanups miklos
2007-08-09  9:20 ` [patch 1/9] unprivileged mounts: fix subtype handling miklos
2007-08-09  9:20 ` [patch 2/9] VFS: check nanoseconds in utimensat miklos
2007-08-09  9:20 ` miklos [this message]
2007-08-09  9:20 ` [patch 4/9] exec: remove unnecessary check for MNT_NOEXEC miklos
2007-08-09  9:20 ` [patch 5/9] fuse: fix setting i_mode bits miklos
2007-08-09  9:20 ` [patch 6/9] fuse: clean up execute permission checking miklos
2007-08-09  9:20 ` [patch 7/9] clean out unused code in dentry pruning miklos
2007-08-09  9:20 ` [patch 8/9] UML: remove unnecessary hostfs_getattr() miklos
2007-08-09  9:20 ` [patch 9/9] fix warnings is revoked_inode.c miklos

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=20070809092459.676107488@szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=akpm@linux-foundation.org \
    --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

all inboxes | Powered by JetHome®