splice_to_socket() hands sock_sendmsg() a bvec iterator of len - remain
bytes from the pipe and then releases pipe buffers for as many bytes as
sock_sendmsg() reports. A packet socket with a TX ring sends the frames
of its ring instead of the iterator and returns their size, which can
be more than it was given. The loop then walks past the buffers it
handed over and releases an empty pipe buffer:
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
RIP: 0010:splice_to_socket (fs/splice.c:827)
Call Trace:
do_splice (fs/splice.c:863 fs/splice.c:1304)
__do_splice (fs/splice.c:1386)
__x64_sys_splice (fs/splice.c:1583 fs/splice.c:1565)
Commit 2d956723e82c ("fs/splice: clamp an over-reported write_iter
result") does the same for iter_file_splice_write(). Clamp the result
to the bytes that were passed to sock_sendmsg().
Fixes: 2dc334f1a63a ("splice, net: Use sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()")
Signed-off-by: Kyuwon Cho <kyuw…@skku.edu>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype. It reproduces as any user, in
its own user and network namespace: a packet socket with a TX ring
(PACKET_TX_RING, frames queued in the ring) gets a one-byte splice()
from a pipe. packet_sendmsg() sends the ring's frames and returns their
size (write() of one byte to such a socket returns 128 as well), and
splice_to_socket() releases pipe buffers past the one it handed over.
With the patch the splice returns 1 and nothing crashes. The reproducer
is available on request.
Found and tested on mainline fe6ff8d5d675 (v7.4-rc5, with KASAN);
the patch is against mainline.
fs/splice.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/splice.c b/fs/splice.c
index 5397ded643a7..968a98fca238 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -811,6 +811,7 @@ ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out,
ret = sock_sendmsg(sock, &msg);
if (ret <= 0)
break;
+ ret = min_t(ssize_t, ret, len - remain);
spliced += ret;
len -= ret;
--
2.43.0