Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] ext4: undo the splice when ext4_splice_branch() fails
@ 2026-11-23 18:15 Aykut Cıncık via B4 Relay
  2026-11-23 18:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Aykut Cıncık via B4 Relay @ 2026-11-23 18:15 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger
  Cc: Jan Kara, Baokun Li, Ojaswin Mujoo, Ritesh Harjani (IBM),
	Zhang Yi, linux-ext4, stable, Aykut Cıncık

From: Aykut Cıncık <aykutcincik@ogr.eskisehir.edu.tr>

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 <aykutcincik@ogr.eskisehir.edu.tr>
---
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 <aykutcincik@ogr.eskisehir.edu.tr>



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

* Re: [PATCH] ext4: undo the splice when ext4_splice_branch() fails
  2026-11-23 18:15 [PATCH] ext4: undo the splice when ext4_splice_branch() fails Aykut Cıncık via B4 Relay
@ 2026-11-23 18:26 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-23 18:26 UTC (permalink / raw)
  To: Aykut Cıncık; +Cc: linux-ext4, tytso

> From: Aykut Cıncık <aykutcincik@ogr.eskisehir.edu.tr>
> 
> 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 <aykutcincik@ogr.eskisehir.edu.tr>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-ext4-splice-unsplice-v1-1-d291b741d15a@ogr.eskisehir.edu.tr?part=1

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

end of thread, other threads:[~2026-11-23 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 18:15 [PATCH] ext4: undo the splice when ext4_splice_branch() fails Aykut Cıncık via B4 Relay
2026-11-23 18:26 ` sashiko-bot

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