From: Mehtab Zafar <hello@mzfr.me>
To: Al Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
linux-fsdevel@vger.kernel.org
Cc: Jan Kara <jack@suse.cz>, Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] splice: return immediately for zero-length file-to-pipe splices
Date: Sat, 28 Nov 2026 13:42:40 +0000 [thread overview]
Message-ID: <20261128134221.64884-2-hello@mzfr.me> (raw)
In-Reply-To: <20261128134221.64884-1-hello@mzfr.me>
[-- Attachment #1: Type: text/plain, Size: 1429 bytes --]
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@vger.kernel.org
Signed-off-by: Mehtab Zafar <hello@mzfr.me>
---
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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 563 bytes --]
next prev parent reply other threads:[~2026-11-28 13:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 13:42 [PATCH 0/2] splice: handle zero-count sendfile to full pipes Mehtab Zafar
2026-11-28 13:42 ` Mehtab Zafar [this message]
2026-11-28 13:42 ` [PATCH 2/2] selftests/splice: cover zero-count sendfile to a full pipe Mehtab Zafar
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=20261128134221.64884-2-hello@mzfr.me \
--to=hello@mzfr.me \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®