summaryrefslogtreecommitdiffstats
path: root/fs/splice.c
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2023-11-30 16:16:23 +0200
committerChristian Brauner <brauner@kernel.org>2023-12-01 11:39:50 +0100
commitda40448ce4eb4de18eb7b0db61dddece32677939 (patch)
tree8e9b7d76b71343504a594db874ad0b7192718f0f /fs/splice.c
parent488e8f685207e0758398963d6834f81e5e61c162 (diff)
downloadlinux-da40448ce4eb4de18eb7b0db61dddece32677939.tar.gz
linux-da40448ce4eb4de18eb7b0db61dddece32677939.tar.bz2
linux-da40448ce4eb4de18eb7b0db61dddece32677939.zip
fs: move file_start_write() into direct_splice_actor()
The callers of do_splice_direct() hold file_start_write() on the output file. This may cause file permission hooks to be called indirectly on an overlayfs lower layer, which is on the same filesystem of the output file and could lead to deadlock with fanotify permission events. To fix this potential deadlock, move file_start_write() from the callers into the direct_splice_actor(), so file_start_write() will not be held while splicing from the input file. Suggested-by: Josef Bacik <josef@toxicpanda.com> Link: https://lore.kernel.org/r/20231128214258.GA2398475@perftesting/ Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Link: https://lore.kernel.org/r/20231130141624.3338942-3-amir73il@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/splice.c')
-rw-r--r--fs/splice.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/fs/splice.c b/fs/splice.c
index 9007b2c8baa8..7cda013e5a1e 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1157,9 +1157,20 @@ static int direct_splice_actor(struct pipe_inode_info *pipe,
struct splice_desc *sd)
{
struct file *file = sd->u.file;
+ long ret;
+
+ file_start_write(file);
+ ret = do_splice_from(pipe, file, sd->opos, sd->total_len, sd->flags);
+ file_end_write(file);
+ return ret;
+}
- return do_splice_from(pipe, file, sd->opos, sd->total_len,
- sd->flags);
+static int splice_file_range_actor(struct pipe_inode_info *pipe,
+ struct splice_desc *sd)
+{
+ struct file *file = sd->u.file;
+
+ return do_splice_from(pipe, file, sd->opos, sd->total_len, sd->flags);
}
static void direct_file_splice_eof(struct splice_desc *sd)
@@ -1233,6 +1244,8 @@ EXPORT_SYMBOL(do_splice_direct);
*
* Description:
* For use by generic_copy_file_range() and ->copy_file_range() methods.
+ * Like do_splice_direct(), but vfs_copy_file_range() already holds
+ * start_file_write() on @out file.
*
* Callers already called rw_verify_area() on the entire range.
*/
@@ -1242,7 +1255,7 @@ long splice_file_range(struct file *in, loff_t *ppos, struct file *out,
lockdep_assert(file_write_started(out));
return do_splice_direct_actor(in, ppos, out, opos, len, 0,
- direct_splice_actor);
+ splice_file_range_actor);
}
EXPORT_SYMBOL(splice_file_range);