Skip to content

Commit 97ef77c

Browse files
zx2c4Al Viro
authored andcommitted
fs: check FMODE_LSEEK to control internal pipe splicing
The original direct splicing mechanism from Jens required the input to be a regular file because it was avoiding the special socket case. It also recognized blkdevs as being close enough to a regular file. But it forgot about chardevs, which behave the same way and work fine here. This is an okayish heuristic, but it doesn't totally work. For example, a few chardevs should be spliceable here. And a few regular files shouldn't. This patch fixes this by instead checking whether FMODE_LSEEK is set, which represents decently enough what we need rewinding for when splicing to internal pipes. Fixes: b92ce55 ("[PATCH] splice: add direct fd <-> fd splicing support") Cc: Jens Axboe <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 54ef7a4 commit 97ef77c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

fs/splice.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -814,17 +814,15 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
814814
{
815815
struct pipe_inode_info *pipe;
816816
long ret, bytes;
817-
umode_t i_mode;
818817
size_t len;
819818
int i, flags, more;
820819

821820
/*
822-
* We require the input being a regular file, as we don't want to
823-
* randomly drop data for eg socket -> socket splicing. Use the
824-
* piped splicing for that!
821+
* We require the input to be seekable, as we don't want to randomly
822+
* drop data for eg socket -> socket splicing. Use the piped splicing
823+
* for that!
825824
*/
826-
i_mode = file_inode(in)->i_mode;
827-
if (unlikely(!S_ISREG(i_mode) && !S_ISBLK(i_mode)))
825+
if (unlikely(!(in->f_mode & FMODE_LSEEK)))
828826
return -EINVAL;
829827

830828
/*

0 commit comments

Comments
 (0)