aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-01-07 19:14:29 +0100
committerMister Oyster <oysterized@gmail.com>2017-04-11 10:59:57 +0200
commit1548d6d880fbcc83d57825b6357f7fa0be8148f8 (patch)
tree48ab9e2d64b33e52ec28bdf1016496aa85b6be9c
parent420f298f0f39260964c11bee74aa980d1b4d2175 (diff)
splice: introduce FMODE_SPLICE_READ and FMODE_SPLICE_WRITE
Introduce FMODE_SPLICE_READ and FMODE_SPLICE_WRITE. These modes check whether it is legal to read or write a file using splice. Both get automatically set on regular files and are not checked when a 'struct fileoperations' includes the splice_{read,write} methods. Change-Id: Ice6a3fab20bf0ac131f8d908f4bb0f7dc34bf4e3 Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
-rw-r--r--fs/open.c4
-rw-r--r--fs/splice.c6
-rw-r--r--include/linux/fs.h5
3 files changed, 15 insertions, 0 deletions
diff --git a/fs/open.c b/fs/open.c
index 5f129683b..1930f2362 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -680,6 +680,10 @@ static int do_dentry_open(struct file *f,
return 0;
}
+ if (S_ISREG(inode->i_mode))
+ f->f_mode |= FMODE_SPLICE_WRITE | FMODE_SPLICE_READ;
+
+
f->f_op = fops_get(inode->i_fop);
error = security_file_open(f, cred);
diff --git a/fs/splice.c b/fs/splice.c
index 2ffa7b0c6..8e3f3b1dd 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -384,6 +384,9 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
index++;
}
+ if (unlikely(!(in->f_mode & FMODE_SPLICE_READ)))
+ return -EINVAL;
+
/*
* Now loop over the map and see if we need to start IO on any
* pages, fill in the partial map, etc.
@@ -1088,6 +1091,9 @@ static ssize_t default_file_splice_write(struct pipe_inode_info *pipe,
{
ssize_t ret;
+ if (unlikely(!(out->f_mode & FMODE_SPLICE_WRITE)))
+ return -EINVAL;
+
ret = splice_from_pipe(pipe, out, ppos, len, flags, write_pipe_buf);
if (ret > 0)
*ppos += ret;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 264a4f9cf..7b0583da9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -136,6 +136,11 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
*/
#define CHECK_IOVEC_ONLY -1
+/* File can be read using splice */
+#define FMODE_SPLICE_READ ((__force fmode_t)0x8000000)
+/* File can be written using splice */
+#define FMODE_SPLICE_WRITE ((__force fmode_t)0x10000000)
+
/*
* The below are the various read and write types that we support. Some of
* them include behavioral modifiers that send information down to the