public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] splice: prevent deadlock when splicing a file to itself
@ 2026-03-20 13:06 Deepanshu Kartikey
  2026-03-31  8:51 ` Deepanshu Kartikey
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Deepanshu Kartikey @ 2026-03-20 13:06 UTC (permalink / raw)
  To: viro, brauner, jack
  Cc: linux-fsdevel, linux-kernel, Deepanshu Kartikey,
	syzbot+d31a3b77e5cba96b9f69, Deepanshu Kartikey


When do_splice_direct_actor() is called with the same inode
for both input and output files (either via the same fd or a
dup'd fd), it causes a hung task in blkdev_write_iter().

The deadlock occurs because sendfile() calls do_splice_direct()
which tries to acquire inode_lock_shared() for reading, while
the write side already holds the same inode lock, causing the
task to block indefinitely in rwsem_down_read_slowpath().

Fix this by checking if the input and output files share the
same inode before proceeding, returning -EINVAL if they do.
This mirrors the existing check in do_splice() for the
pipe-to-pipe case where ipipe == opipe.

Reported-by: syzbot+d31a3b77e5cba96b9f69@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d31a3b77e5cba96b9f69
Tested-by: syzbot+d31a3b77e5cba96b9f69@syzkaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
 fs/splice.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/splice.c b/fs/splice.c
index 9d8f63e2fd1a..c0ad1859de34 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1199,6 +1199,9 @@ static ssize_t do_splice_direct_actor(struct file *in, loff_t *ppos,
 	if (unlikely(out->f_flags & O_APPEND))
 		return -EINVAL;
 
+	/* Prevent deadlock when splicing a file to itself */
+	if (file_inode(in) == file_inode(out))
+		return -EINVAL;
 	ret = splice_direct_to_actor(in, &sd, actor);
 	if (ret > 0)
 		*ppos = sd.pos;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-04-01 10:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 13:06 [PATCH] splice: prevent deadlock when splicing a file to itself Deepanshu Kartikey
2026-03-31  8:51 ` Deepanshu Kartikey
2026-03-31  9:33 ` Christian Brauner
2026-03-31 13:32   ` Jens Axboe
2026-03-31 15:10 ` Christoph Hellwig
2026-03-31 15:15   ` Jens Axboe
2026-03-31 15:21     ` Christoph Hellwig
2026-03-31 15:24       ` Jens Axboe
2026-04-01  8:08         ` Jan Kara
2026-04-01  8:32           ` Deepanshu Kartikey
2026-04-01 10:47             ` Jan Kara
2026-04-01 10:59               ` Deepanshu Kartikey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox