Skip to contentSkip to conversation

ext4: drop tmp inode ownership before migration cleanup

PATCH Superseded Yichong Chen 2 participants 2 messages Sep 30 – Oct 21 ext4 file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: drop tmp inode ownership before migration cleanup

After the extent tree is transferred to the original inode, ext4_journal_ensure_credits() can fail before tmp_inode is cleared. The subsequent iput(tmp_inode) may then free the transferred tree.

Clear tmp_inode's size and block count as soon as ownership is transferred.

Fixes a413036791d0 ("ext4: Provide function to handle transaction restarts")
---
 fs/ext4/migrate.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/ext4/migrate.c +6 -0
index e588b4157604..11b3da396966 100644
@@ -570,6 +570,12 @@ int ext4_ext_migrate(struct inode *inode)
 			free_ext_block(handle, tmp_inode);
 	}
 
+	if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
+		i_size_write(tmp_inode, 0);
+		tmp_inode->i_blocks = 0;
+		EXT4_I(tmp_inode)->i_csum_seed = tmp_csum_seed;
+	}
+
 	/* We mark the tmp_inode dirty via ext4_ext_tree_init. */
 	err = ext4_journal_ensure_credits(handle, 1, 0);
 	if (err < 0) {
Signature · 1 line
2.51.0
reviewer
#1 lore raw
Quoted 17 lines · Yichong Chen

After the extent tree is transferred to the original inode, ext4_journal_ensure_credits() can fail before tmp_inode is cleared. The subsequent iput(tmp_inode) may then free the transferred tree.

Clear tmp_inode's size and block count as soon as ownership is transferred.

Fixes a413036791d0 ("ext4: Provide function to handle transaction restarts")
---
 fs/ext4/migrate.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/ext4/migrate.c +0 -0
index e588b4157604..11b3da396966 100644

fs/ext4/migrate.c int ext4_ext_migrate(struct inode *inode) · line 577

Quoted 8 lines
fs/ext4/migrate.c +5 -0
@@ -570,6 +570,12 @@ int ext4_ext_migrate(struct inode *inode)
 			free_ext_block(handle, tmp_inode);
 	}
 
+	if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
+		i_size_write(tmp_inode, 0);
+		tmp_inode->i_blocks = 0;
+		EXT4_I(tmp_inode)->i_csum_seed = tmp_csum_seed;
+	}

I'd just move the setting of i_size, i_blocks and i_csum_seed above the ext4_journal_ensure_credits() instead of adding this extra branch...

Honza

Quoted 7 lines
fs/ext4/migrate.c +1 -0
+
 	/* We mark the tmp_inode dirty via ext4_ext_tree_init. */
 	err = ext4_journal_ensure_credits(handle, 1, 0);
 	if (err < 0) {
Signature · 1 line
2.51.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR