Re: [syzbot] [fs?] general protection fault in iter_file_splice_write

From: Edward Adam Davis
Date: Wed May 22 2024 - 10:11:55 EST


please test null ptr in iter_file_splice_write

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33e02dc69afb

diff --git a/fs/splice.c b/fs/splice.c
index 60aed8de21f8..a6b44c10b08c 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -751,16 +751,25 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,

/* dismiss the fully eaten buffers, adjust the partial one */
tail = pipe->tail;
- while (ret) {
+ n = 0;
+ while (ret > 0 && n < nbufs) {
struct pipe_buffer *buf = &pipe->bufs[tail & mask];
- if (ret >= buf->len) {
+ printk("ret: %d, nbufs: %d, buf len: %lu, n: %d, %s\n", ret, nbufs, buf->len, n, __func__);
+ n++;
+ if (!buf->len) {
+ tail++;
+ continue;
+ }
+ if (ret >= (ssize_t)buf->len) {
ret -= buf->len;
+ printk("ret: %d, nbufs: %d, buf len: %lu, n: %d, %s\n", ret, nbufs, buf->len, n, __func__);
buf->len = 0;
pipe_buf_release(pipe, buf);
tail++;
pipe->tail = tail;
if (pipe->files)
sd.need_wakeup = true;
+ BUG_ON(1);
} else {
buf->offset += ret;
buf->len -= ret;