[PATCH 1/2] splice: return immediately for zero-length file-to-pipe splices
From: Mehtab Zafar
Date: Sat Nov 28 2026 - 08:42:52 EST
sendfile() to a pipe calls splice_file_to_pipe() directly. Unlike
splice(), this path reaches wait_for_space() before the lower-level read
handles a zero length. A zero-count sendfile() therefore blocks on a
full blocking pipe and returns -EAGAIN on a full nonblocking pipe.
There is no data to enqueue for a zero-length transfer. Return 0 before
locking or waiting for pipe space, matching splice() behavior.
This bug was found with AI assistance, which also helped
prepare the fix, tests, and description.
Fixes: b964bf53e540 ("teach sendfile(2) to handle send-to-pipe directly")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Mehtab Zafar <hello@xxxxxxx>
---
Tested on x86_64 against vfs/vfs.all at 3857587d9d6f in three fresh KVM
boots per kernel. Baseline: zero count returned -EAGAIN on a full
nonblocking pipe and waited until interrupted on a full blocking pipe.
Patched: both returned 0 immediately. Positive-count and invalid-fd
controls were unchanged. W=1 fs/splice.o and
full bzImage builds passed;
strict checkpatch and git diff --check were clean.
fs/splice.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/splice.c b/fs/splice.c
index 5397ded643a7..afad10adf138 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1239,6 +1239,9 @@ ssize_t splice_file_to_pipe(struct file *in,
{
ssize_t ret;
+ if (!len)
+ return 0;
+
pipe_lock(opipe);
ret = wait_for_space(opipe, flags);
if (!ret)
--
2.34.1
Attachment:
signature.asc
Description: OpenPGP digital signature