Re: [PATCH] splice: prevent deadlock when splicing a file to itself

From: Christoph Hellwig

Date: Tue Mar 31 2026 - 11:26:58 EST


On Tue, Mar 31, 2026 at 09:15:07AM -0600, Jens Axboe wrote:
> On 3/31/26 9:10 AM, Christoph Hellwig wrote:
> > On Fri, Mar 20, 2026 at 06:36:15PM +0530, Deepanshu Kartikey wrote:
> >> 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.
> >
> > While restricting splice to be between difference inodes sounds like a
> > nice simplification, I'm not sure we can add it 20 years after the
> > syscall was added.
>
> Well if we could break splice all over with:
>
> 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops")

Well, that had an easy way out by converting instances people actually
used to the iter ops. Which we ended up doing for a few.

> then surely this one would be OK too?

While this has no way out. Not that I would complain if it worked,
but splicing into the same file doesn't seem like a too outlandish
idea. OTOH it probably already didn't work for file systems that
take i_rwsem in the read path like XFS or these days the block
device node.