From: Aykut Cıncık If ext4_handle_dirty_metadata() or ext4_mark_inode_dirty() fails, ext4_splice_branch() frees the new blocks but leaves the pointers to them in place. A later write then reuses the freed blocks, which can silently overwrite another file's data. Clear the pointers before freeing the blocks. Found and fixed with the help of Claude Code (Claude Opus). Fixes: ac27a0ec112a ("[PATCH] ext4: initial copy of files from ext3") Cc: stable@vger.kernel.org Signed-off-by: Aykut Cıncık --- Tested in QEMU by making each of the two calls fail with the dm "error" target. Without the fix all 12 runs showed corruption (another file overwritten, or a double free); with it all 12 were clean, with KASAN and lockdep enabled. Tested on top of [1]; the two patches apply in either order. [1] https://patch.msgid.link/20261121-ext4-ind-discard-pa-v1-1-ee92928f7797@ogr.eskisehir.edu.tr --- fs/ext4/indirect.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index a495080df710..764f01057aca 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -471,18 +471,21 @@ static int ext4_splice_branch(handle_t *handle, BUFFER_TRACE(where->bh, "call ext4_handle_dirty_metadata"); err = ext4_handle_dirty_metadata(handle, ar->inode, where->bh); if (err) - goto err_out; + goto err_unsplice; } else { /* * OK, we spliced it into the inode itself on a direct block. */ err = ext4_mark_inode_dirty(handle, ar->inode); if (unlikely(err)) - goto err_out; + goto err_unsplice; ext4_debug("splicing direct\n"); } return err; +err_unsplice: + /* Do not leave the tree pointing at the blocks freed below. */ + memset(where->p, 0, sizeof(*where->p) * (num == 0 ? ar->len : 1)); err_out: for (i = 1; i <= num; i++) { /* --- base-commit: c44104f3642da720164042623e4832836aefdd8e change-id: 20261123-ext4-splice-unsplice-78a3adcb82cb Best regards, -- Aykut Cıncık