mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: vaurora@redhat.com, neilb@suse.de, viro@zeniv.linux.org.uk,
	jblunck@suse.de, hch@infradead.org
Subject: [PATCH 1/5] vfs: implement open "forwarding"
Date: Thu, 26 Aug 2010 20:33:41 +0200	[thread overview]
Message-ID: <20100826183459.657502358@szeredi.hu> (raw)
In-Reply-To: <20100826183340.027591901@szeredi.hu>

[-- Attachment #1: vfs-open-redirect.patch --]
[-- Type: text/plain, Size: 2648 bytes --]

From: Miklos Szeredi <mszeredi@suse.cz>

Add a new file operation f_op->open_other().  This acts just like
f_op->open() except the return value can be another open struct file
pointer.  In that case the original file is discarded and the
replacement file is used instead.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---
 fs/open.c          |   23 +++++++++++++++++------
 include/linux/fs.h |    1 +
 2 files changed, 18 insertions(+), 6 deletions(-)

Index: linux-2.6/fs/open.c
===================================================================
--- linux-2.6.orig/fs/open.c	2010-08-19 09:45:50.000000000 +0200
+++ linux-2.6/fs/open.c	2010-08-19 09:46:27.000000000 +0200
@@ -657,6 +657,7 @@ static struct file *__dentry_open(struct
 					const struct cred *cred)
 {
 	struct inode *inode;
+	struct file *ret;
 	int error;
 
 	f->f_mode = OPEN_FMODE(f->f_flags) | FMODE_LSEEK |
@@ -664,6 +665,7 @@ static struct file *__dentry_open(struct
 	inode = dentry->d_inode;
 	if (f->f_mode & FMODE_WRITE) {
 		error = __get_file_write_access(inode, mnt);
+		ret = ERR_PTR(error);
 		if (error)
 			goto cleanup_file;
 		if (!special_file(inode->i_mode))
@@ -678,15 +680,24 @@ static struct file *__dentry_open(struct
 	file_sb_list_add(f, inode->i_sb);
 
 	error = security_dentry_open(f, cred);
+	ret = ERR_PTR(error);
 	if (error)
 		goto cleanup_all;
 
-	if (!open && f->f_op)
-		open = f->f_op->open;
-	if (open) {
-		error = open(inode, f);
-		if (error)
+	if (!open && f->f_op && f->f_op->open_other) {
+		/* NULL means keep f, non-error non-null means replace */
+		ret = f->f_op->open_other(f);
+		if (IS_ERR(ret) || ret != NULL)
 			goto cleanup_all;
+	} else {
+		if (!open && f->f_op)
+			open = f->f_op->open;
+		if (open) {
+			error = open(inode, f);
+			ret = ERR_PTR(error);
+			if (error)
+				goto cleanup_all;
+		}
 	}
 	ima_counts_get(f);
 
@@ -728,7 +739,7 @@ cleanup_file:
 	put_filp(f);
 	dput(dentry);
 	mntput(mnt);
-	return ERR_PTR(error);
+	return ret;
 }
 
 /**
Index: linux-2.6/include/linux/fs.h
===================================================================
--- linux-2.6.orig/include/linux/fs.h	2010-08-19 09:46:15.000000000 +0200
+++ linux-2.6/include/linux/fs.h	2010-08-19 09:46:27.000000000 +0200
@@ -1494,6 +1494,7 @@ struct file_operations {
 	long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
 	int (*mmap) (struct file *, struct vm_area_struct *);
 	int (*open) (struct inode *, struct file *);
+	struct file *(*open_other) (struct file *);
 	int (*flush) (struct file *, fl_owner_t id);
 	int (*release) (struct inode *, struct file *);
 	int (*fsync) (struct file *, int datasync);

-- 

  reply	other threads:[~2010-08-26 18:35 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-26 18:33 [PATCH 0/5] hybrid union filesystem prototype Miklos Szeredi
2010-08-26 18:33 ` Miklos Szeredi [this message]
2010-08-26 18:33 ` [PATCH 2/5] vfs: make i_op->permission take a dentry instead of an inode Miklos Szeredi
2010-08-26 20:24   ` David P. Quigley
2010-08-27  4:11     ` Neil Brown
2010-08-27 18:13       ` David P. Quigley
2010-08-27 19:21         ` Valerie Aurora
2010-08-27 18:31       ` David P. Quigley
2010-08-26 18:33 ` [PATCH 3/5] vfs: add flag to allow rename to same inode Miklos Szeredi
2010-08-26 18:33 ` [PATCH 4/5] vfs: export do_splice_direct() to modules Miklos Szeredi
2010-08-26 18:33 ` [PATCH 5/5] union: hybrid union filesystem prototype Miklos Szeredi
2010-09-01 21:42   ` Valerie Aurora
2010-09-02  9:19     ` Miklos Szeredi
2010-09-02 21:33       ` Valerie Aurora
2010-09-03  5:10         ` Neil Brown
2010-09-03  9:16           ` Miklos Szeredi
2010-09-09 16:02             ` David P. Quigley
2010-09-03  8:52         ` Miklos Szeredi
2010-09-02 21:42   ` Valerie Aurora
2010-09-03 12:31     ` Miklos Szeredi
2010-08-27  7:05 ` [PATCH 0/5] " Neil Brown
2010-08-27  8:47   ` Miklos Szeredi
2010-08-27 11:35     ` Neil Brown
2010-08-27 16:53       ` Miklos Szeredi
2010-08-29  4:42         ` Neil Brown
2010-08-30 10:18           ` Miklos Szeredi
2010-08-30 11:40             ` Neil Brown
2010-08-30 12:20               ` Miklos Szeredi
2010-08-31 19:18                 ` Valerie Aurora
2010-08-31 20:19                   ` Trond Myklebust
2010-09-01  1:56                     ` Valerie Aurora
2010-09-01  4:04                       ` Trond Myklebust
2010-09-01  4:33               ` Neil Brown
2010-09-01 20:11                 ` Miklos Szeredi
2010-08-31 19:29             ` Valerie Aurora
2010-09-02 13:15             ` Jan Engelhardt
2010-09-02 13:32               ` Neil Brown
2010-09-02 14:25                 ` Jan Engelhardt
2010-09-02 14:28                   ` Miklos Szeredi
2010-09-08 19:47                     ` David P. Quigley
2010-09-23 13:18                   ` Jan Engelhardt
2010-09-23 19:22                     ` Valerie Aurora
2010-08-30 18:38       ` Valerie Aurora
2010-08-30 23:12         ` Neil Brown
2010-08-31 11:00           ` Miklos Szeredi
2010-08-31 11:24             ` Neil Brown
2010-08-31 15:05               ` Kyle Moffett
2010-08-31 20:36                 ` Valerie Aurora

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=20100826183459.657502358@szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=hch@infradead.org \
    --cc=jblunck@suse.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=vaurora@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /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®