From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10.y 1/5] do_splice_to(): move the logics for limiting the read length in
Date: Wed, 11 Nov 2026 11:19:52 -0500 [thread overview]
Message-ID: <20261111161949.3187571-1-sashal@kernel.org> (raw)
In-Reply-To: <20261107063106-failed-5.10-79b496ebe382@kernel.org>
From: Al Viro <viro@zeniv.linux.org.uk>
[ Upstream commit 313d64a35d36b4bb00edde418179ff1a5f342070 ]
Both callers have the identical logics limiting the amount of
data we try to read into pipe - no more than would fit into
that pipe. Move that into do_splice_to() itself.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Stable-dep-of: 79b496ebe382 ("splice: avoid stale f_pos writeback on error")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/splice.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/fs/splice.c b/fs/splice.c
index 5b15c25f30527..070b192b56386 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -774,11 +774,16 @@ static long do_splice_to(struct file *in, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len,
unsigned int flags)
{
+ unsigned int p_space;
int ret;
if (unlikely(!(in->f_mode & FMODE_READ)))
return -EBADF;
+ /* Don't try to read more the pipe has space for. */
+ p_space = pipe->max_usage - pipe_occupancy(pipe->head, pipe->tail);
+ len = min_t(size_t, len, p_space << PAGE_SHIFT);
+
ret = rw_verify_area(READ, in, ppos, len);
if (unlikely(ret < 0))
return ret;
@@ -859,15 +864,10 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
WARN_ON_ONCE(!pipe_empty(pipe->head, pipe->tail));
while (len) {
- unsigned int p_space;
size_t read_len;
loff_t pos = sd->pos, prev_pos = pos;
- /* Don't try to read more the pipe has space for. */
- p_space = pipe->max_usage -
- pipe_occupancy(pipe->head, pipe->tail);
- read_len = min_t(size_t, len, p_space << PAGE_SHIFT);
- ret = do_splice_to(in, &pos, pipe, read_len, flags);
+ ret = do_splice_to(in, &pos, pipe, len, flags);
if (unlikely(ret <= 0))
goto out_release;
@@ -1086,15 +1086,8 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
pipe_lock(opipe);
ret = wait_for_space(opipe, flags);
- if (!ret) {
- unsigned int p_space;
-
- /* Don't try to read more the pipe has space for. */
- p_space = opipe->max_usage - pipe_occupancy(opipe->head, opipe->tail);
- len = min_t(size_t, len, p_space << PAGE_SHIFT);
-
+ if (!ret)
ret = do_splice_to(in, &offset, opipe, len, flags);
- }
pipe_unlock(opipe);
if (ret > 0)
wakeup_pipe_readers(opipe);
--
2.53.0
next prev parent reply other threads:[~2026-11-11 16:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 11:31 FAILED: patch "[PATCH] splice: avoid stale f_pos writeback on error" failed to apply to 5.10-stable tree Sasha Levin
2026-11-11 16:19 ` Sasha Levin [this message]
2026-11-11 16:19 ` [PATCH 5.10.y 2/5] take the guts of file-to-pipe splice into a helper function Sasha Levin
2026-11-11 16:19 ` [PATCH 5.10.y 3/5] splice: report related fsnotify events Sasha Levin
2026-11-11 16:19 ` [PATCH 5.10.y 4/5] splice: always fsnotify_access(in), fsnotify_modify(out) on success Sasha Levin
2026-11-11 16:19 ` [PATCH 5.10.y 5/5] splice: avoid stale f_pos writeback on error Sasha Levin
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=20261111161949.3187571-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=stable@vger.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