linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH prototype] [2/8] Add support to override mmap exec write protection with O_FORCEWRITE
Date: Tue, 18 Mar 2008 02:09:36 +0100 (CET)	[thread overview]
Message-ID: <20080318010936.489811B41E1@basil.firstfloor.org> (raw)
In-Reply-To: <20080318209.039112899@firstfloor.org>

pbitmaps need to write to files mapped as executable, so add 
a way to bypass the normal write protection using a new O_FORCEWRITE
flag.

Right now the flag can be set from user space too. If have not
made up my mind if that is a good or a bad thing (I don't think
it has any real security implications). Probably it's more bad
than good. 

Signed-off-by: Andi Kleen <andi@firstfloor.org>

---
 fs/namei.c                  |    9 +++++++--
 fs/open.c                   |    2 +-
 include/asm-generic/fcntl.h |    4 ++++
 include/linux/fs.h          |    1 +
 4 files changed, 13 insertions(+), 3 deletions(-)

Index: linux/fs/namei.c
===================================================================
--- linux.orig/fs/namei.c
+++ linux/fs/namei.c
@@ -334,10 +334,10 @@ int file_permission(struct file *file, i
  * the inode->i_lock spinlock.
  */
 
-int get_write_access(struct inode * inode)
+int __get_write_access(struct inode * inode, int flags)
 {
 	spin_lock(&inode->i_lock);
-	if (atomic_read(&inode->i_writecount) < 0) {
+	if (atomic_read(&inode->i_writecount) < 0 && !(flags&O_FORCEWRITE)) {
 		spin_unlock(&inode->i_lock);
 		return -ETXTBSY;
 	}
@@ -347,6 +347,11 @@ int get_write_access(struct inode * inod
 	return 0;
 }
 
+int get_write_access(struct inode * inode)
+{
+	return __get_write_access(inode, 0);
+}
+
 int deny_write_access(struct file * file)
 {
 	struct inode *inode = file->f_path.dentry->d_inode;
Index: linux/fs/open.c
===================================================================
--- linux.orig/fs/open.c
+++ linux/fs/open.c
@@ -742,7 +742,7 @@ static struct file *__dentry_open(struct
 				FMODE_PREAD | FMODE_PWRITE;
 	inode = dentry->d_inode;
 	if (f->f_mode & FMODE_WRITE) {
-		error = get_write_access(inode);
+		error = __get_write_access(inode, f->f_flags & O_FORCEWRITE);
 		if (error)
 			goto cleanup_file;
 	}
Index: linux/include/linux/fs.h
===================================================================
--- linux.orig/include/linux/fs.h
+++ linux/include/linux/fs.h
@@ -1720,6 +1720,7 @@ extern int generic_permission(struct ino
 		int (*check_acl)(struct inode *, int));
 
 extern int get_write_access(struct inode *);
+extern int __get_write_access(struct inode *i, int flags);
 extern int deny_write_access(struct file *);
 static inline void put_write_access(struct inode * inode)
 {
Index: linux/include/asm-generic/fcntl.h
===================================================================
--- linux.orig/include/asm-generic/fcntl.h
+++ linux/include/asm-generic/fcntl.h
@@ -54,6 +54,10 @@
 #ifndef O_NDELAY
 #define O_NDELAY	O_NONBLOCK
 #endif
+/* ignore ETXTBSY -- should probably hide it from user space */
+#ifndef O_FORCEWRITE
+#define O_FORCEWRITE    02000000
+#endif
 
 #define F_DUPFD		0	/* dup */
 #define F_GETFD		1	/* get close_on_exec */

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2008-03-18  1:09 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-18  1:09 [PATCH prototype] [0/8] Predictive bitmaps for ELF executables Andi Kleen
2008-03-18  1:09 ` [PATCH prototype] [1/8] Give ELF shdr types a name Andi Kleen
2008-03-18  1:09 ` Andi Kleen [this message]
2008-03-18  1:09 ` [PATCH prototype] [3/8] Make readahead max pinned value a sysctl Andi Kleen
2008-03-18  1:09 ` [PATCH prototype] [4/8] Add readahead function to read-ahead based on a bitmap Andi Kleen
2008-03-18  1:09 ` [PATCH prototype] [5/8] Add ELF constants for pbitmaps Andi Kleen
2008-03-18  1:09 ` [PATCH prototype] [6/8] Core predictive bitmap engine Andi Kleen
2008-03-18  1:09 ` [PATCH prototype] [7/8] Add the sysctls to control pbitmaps Andi Kleen
2008-03-18  1:09 ` [PATCH prototype] [8/8] Add mmap_full_slurp support Andi Kleen
2008-03-18  7:36 ` [PATCH prototype] [0/8] Predictive bitmaps for ELF executables Andrew Morton
2008-03-18 14:18   ` Andi Kleen
2008-03-18 16:57     ` Andrew Morton
2008-03-18 17:20       ` Andi Kleen
2008-03-18 17:44         ` Andrew Morton
2008-03-19  8:32           ` Andi Kleen
2008-03-19  9:04             ` Andrew Morton
2008-03-19 22:45               ` Ulrich Drepper
2008-03-19 23:12                 ` Andrew Morton
2008-03-20  0:09                   ` David Miller, Andrew Morton
2008-03-20  9:00                 ` Andi Kleen
2008-03-21 17:15                   ` Ulrich Drepper
2008-03-21 17:26                     ` Andi Kleen
2008-03-22  4:36                       ` Ulrich Drepper
2008-03-22  7:17                         ` Andi Kleen
2008-03-22  7:24                           ` Nicholas Miell
2008-03-22  9:10                             ` Andi Kleen
2008-03-22 10:16                               ` Nicholas Miell
2008-03-22 14:29                                 ` Andi Kleen
2008-03-23 13:25                                   ` Pavel Machek
2008-03-23 17:08                                     ` Andi Kleen
2008-03-24 16:24                                       ` Pavel Machek
2008-03-24  4:20                               ` Ulrich Drepper
2008-03-24  5:16                                 ` Nicholas Miell
2008-03-24  5:26                                   ` Andi Kleen
2008-03-24 19:42                                   ` Ulrich Drepper
2008-03-24 21:47                                     ` Nicholas Miell
2008-03-25  7:54                                     ` Andi Kleen
2008-03-26 18:15                                       ` Ulrich Drepper
2008-03-26 18:54                                         ` Andi Kleen
2008-03-22  4:38                       ` Ulrich Drepper
2008-03-20  0:15               ` Diego Calleja

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=20080318010936.489811B41E1@basil.firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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