From: Linus Torvalds <torvalds@linux-foundation.org>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: jens.axboe@oracle.com, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: splice vs O_APPEND
Date: Thu, 9 Oct 2008 08:37:50 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.00.0810090830170.3210@nehalem.linux-foundation.org> (raw)
In-Reply-To: <E1Knx26-0003ds-Ch@pomaz-ex.szeredi.hu>
On Thu, 9 Oct 2008, Miklos Szeredi wrote:
>
> While looking at the f_pos corruption thing, I found that splice() to
> a regular file totally ignores O_APPEND. Which allows users to bypass
> the append-only restriction. Bad...
>
> The only question is how this should be solved? Should splice()
> respect O_APPEND and ignore the offset? Or should it just return
> -EINVAL?
Good catch. sendfile() has the same issue, but I don't think we ever did
sendpage() for any filesystems, so it won't ever be relevant, and this is
probably just a splice issue.
EINVAL seems the simplest thing. Should check S_IMMUTABLE too for that
matter. Possible patch appended.
I do wonder if we shouldn't just do this in rw_verify_area(). The whole
reason for that function is that we used to have all those flock checks
etc spread out all over, and some path would inevitably just miss one
check or another. It's kind of stupid to expect low-level filesystems to
do the IS_APPEND/IS_IMMUTABLE checks.
Comments?
Linus
---
fs/splice.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/fs/splice.c b/fs/splice.c
index 1bbc6f4..769b2d3 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -891,6 +891,7 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
loff_t *ppos, size_t len, unsigned int flags)
{
int ret;
+ struct inode *inode;
if (unlikely(!out->f_op || !out->f_op->splice_write))
return -EINVAL;
@@ -898,6 +899,12 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
if (unlikely(!(out->f_mode & FMODE_WRITE)))
return -EBADF;
+ inode = out->f_dentry->d_inode;
+ if (IS_IMMUTABLE(inode))
+ return -EPERM;
+ if (IS_APPEND(inode))
+ return -EINVAL;
+
ret = rw_verify_area(WRITE, out, ppos, len);
if (unlikely(ret < 0))
return ret;
next prev parent reply other threads:[~2008-10-09 15:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-09 15:02 splice vs O_APPEND Miklos Szeredi
2008-10-09 15:37 ` Linus Torvalds [this message]
2008-10-09 16:04 ` Miklos Szeredi
2008-10-09 16:17 ` Linus Torvalds
2008-10-09 16:30 ` Miklos Szeredi
2008-10-09 19:22 ` Linus Torvalds
2008-10-09 19:51 ` Miklos Szeredi
2008-10-09 21:14 ` Linus Torvalds
2008-10-09 21:20 ` Jens Axboe
2008-10-09 21:27 ` Linus Torvalds
2008-10-10 9:46 ` Miklos Szeredi
2008-10-10 10:06 ` Jens Axboe
2008-10-10 15:49 ` [stable] " Greg KH
2008-10-10 16:05 ` Miklos Szeredi
2008-10-10 16:20 ` Greg KH
2008-10-10 10:23 ` Michael Kerrisk
2008-10-09 16:30 ` Andreas Schwab
2008-10-09 16:43 ` Miklos Szeredi
2008-10-09 17:03 ` Andreas Schwab
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=alpine.LFD.2.00.0810090830170.3210@nehalem.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=jens.axboe@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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