backing-file: covert to using fops->splice_write
Subsystems (3)
PATCH 1/1 backing-file: covert to using fops->splice_write
From: Ed Tsai <[email protected]>
Filesystems may define their own splice write. Therefore, use file fops instead of invoking iter_file_splice_write() directly.
--- fs/backing-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/backing-file.c +4 -1
@@ -280,13 +280,16 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,if (WARN_ON_ONCE (!(out->f_mode &FMODE_BACKING )))return -EIO ; +if (out->f_op->splice_write) +return -EINVAL ; + ret =file_remove_privs (ctx->user_file);if (ret)return ret; old_cred =override_creds (ctx->cred);file_start_write (out); - ret =iter_file_splice_write (pipe, out, ppos, len, flags); + ret = out->f_op->splice_write (pipe, out, ppos, len, flags);file_end_write (out);revert_creds (old_cred);
Signature · 1 line
2.18.0
Quoted 23 lines · On Fri, 2024-07-05 at 16:16 +0800, [email protected] wrote:
From: Ed Tsai <[email protected]>
Filesystems may define their own splice write. Therefore, use file fops instead of invoking
iter_file_splice_write()directly.Signed-off-by Ed Tsai <[email protected]>--- fs/backing-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/backing-file.c +3
-0@@ -280,13 +280,16 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, if (WARN_ON_ONCE(!(out->f_mode & FMODE_BACKING))) return -EIO; +if (out->f_op->splice_write) +return -EINVAL ; +
fs/backing-file.c ssize_t backing_file_splice_write(struct · line 295
Quoted 10 lines
fs/backing-file.c +1
-1ret =file_remove_privs (ctx->user_file);if (ret)return ret; old_cred =override_creds (ctx->cred);file_start_write (out); - ret =iter_file_splice_write (pipe, out, ppos, len, flags); + ret = out->f_op->splice_write (pipe, out, ppos, len, flags);file_end_write (out);revert_creds (old_cred);
s/covert/convert/ for subject
Amir Goldstein
maintainerQuoted 5 lines · On Fri, Jul 5, 2024 at 11:17 AM <[email protected]> wrote:
From: Ed Tsai <[email protected]>
Filesystems may define their own splice write. Therefore, use file fops instead of invoking
iter_file_splice_write()directly.
This looks sane, but can you share the scenario where you ran into this? or did you find this via code audit?
I can think of these cases:
1. overlayfs with fuse (virtiofs) upper
2. fuse passthrough over fuse
3. fuse passthrough over overlayfs
4. fuse passthrough over gfs2 or some out of tree fs
The first two will not cause any harm,
In case #3, according to the comment above ovl_splice_write() the current code could even deadlock.
So do you have a reproduction?
Thanks,
Amir.
Quoted 31 lines
Signed-off-by Ed Tsai <[email protected]>--- fs/backing-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/backing-file.c +4
-2@@ -280,13 +280,16 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,if (WARN_ON_ONCE (!(out->f_mode &FMODE_BACKING )))return -EIO ; +if (out->f_op->splice_write) +return -EINVAL ; + ret =file_remove_privs (ctx->user_file);if (ret)return ret; old_cred =override_creds (ctx->cred);file_start_write (out); - ret =iter_file_splice_write (pipe, out, ppos, len, flags); + ret = out->f_op->splice_write (pipe, out, ppos, len, flags);file_end_write (out);revert_creds (old_cred); --2.18.0
fs/backing-file.c ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, · line 284
Quoted 7 lines · On Fri, Jul 05, 2024 at 04:16:39PM +0800, [email protected] wrote:
+++
b/fs/backing-file.cfs/backing-file.c +2
-0@@ -280,13 +280,16 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,if (WARN_ON_ONCE (!(out->f_mode &FMODE_BACKING )))return -EIO ; +if (out->f_op->splice_write) +return -EINVAL ;
Umm ... shouldn't this have been !out->f_op->splice_write?
Quoted 15 lines
fs/backing-file.c +1
-1ret =file_remove_privs (ctx->user_file);if (ret)return ret; old_cred =override_creds (ctx->cred);file_start_write (out); - ret =iter_file_splice_write (pipe, out, ppos, len, flags); + ret = out->f_op->splice_write (pipe, out, ppos, len, flags);file_end_write (out);revert_creds (old_cred);Signature · 1 line
2.18.0
Quoted 20 lines · Amir Goldstein
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 5 lines · On Fri, Jul 5, 2024 at 11:17 AM <[email protected]> wrote:
From: Ed Tsai <[email protected]>
Filesystems may define their own splice write. Therefore, use file fops instead of invoking
iter_file_splice_write()directly.This looks sane, but can you share the scenario where you ran into this?
or did you find this via code audit?I can think of these cases:
1. overlayfs with fuse (virtiofs) upper
2. fuse passthrough over fuse
3. fuse passthrough over overlayfs
4. fuse passthrough over gfs2 or some out of tree fs
Quoted 8 lines
The first two will not cause any harm,
In case #3, according to the comment aboveovl_splice_write()the current code could even deadlock.So do you have a reproduction?
Thanks,
Amir.
I came across this while checking what's new in the next LTS kernel.
This appears to be taken from overlayfs, and currently, no one has encountered any issus about this.
Quoted 4 lines · Matthew Wilcox
Review ssize_t backing_file_splice_write(struct
Quoted 2 lines · On Fri, Jul 05, 2024 at 04:16:39PM +0800, [email protected] wrote:
+++
b/fs/backing-file.c(quoted diff) +0
-0@@ -280,13 +280,16 @@ ssize_t backing_file_splice_write(struct
pipe_inode_info*pipe,
Quoted 8 lines
fs/backing-file.c ssize_t backing_file_splice_write(struct pipe_inode_info *pipe, · line 284
Quoted 5 lines
fs/backing-file.c +2
-0if (WARN_ON_ONCE (!(out->f_mode &FMODE_BACKING )))return -EIO ; +if (out->f_op->splice_write) +return -EINVAL ;Umm ... shouldn't this have been !out->f_op->splice_write?
OMG... This is the wrong version. I will send the correct on later.
Quoted 16 lines
Quoted 15 lines
fs/backing-file.c +1
-1ret =file_remove_privs (ctx->user_file);if (ret)return ret; old_cred =override_creds (ctx->cred);file_start_write (out); -ret =iter_file_splice_write (pipe, out, ppos, len, flags); +ret = out->f_op->splice_write (pipe, out, ppos, len, flags);file_end_write (out);revert_creds (old_cred);Signature · 1 line
2.18.0