Skip to contentSkip to conversation

ext4: cleanup in-core orphan list if ext4_truncate() failed to get a transaction handle

PATCH Applied Zhang Yi 3 participants 3 messages May 7, 2021 – Jun 17, 2021 ext4 file system

lore
Share & tools
lore

Zhang Yi

author reviewer
#0 lore raw

PATCH 1/1 ext4: cleanup in-core orphan list if ext4_truncate() failed to get a transaction handle

In ext4_orphan_cleanup(), if ext4_truncate() failed to get a transaction handle, it didn't remove the inode from the in-core orphan list, which may probably trigger below error dump in ext4_destroy_inode() during the final iput() and could lead to memory corruption on the later orphan list changes.

EXT4-fs (sda): Inode 6291467 (00000000b8247c67): orphan list check failed!

 00000000b8247c67: 0001f30a 00000004 00000000 00000023  ............#...
 00000000e24cde71: 00000006 014082a3 00000000 00000000  ......@.........
 0000000072c6a5ee: 00000000 00000000 00000000 00000000  ................

...

This patch fix this by cleanup in-core orphan list manually if ext4_truncate() return error.

---
 fs/ext4/super.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/ext4/super.c +8 -1
index 7dc94f3e18e6..12850d72e9a4 100644
@@ -3101,8 +3101,15 @@ static void ext4_orphan_cleanup(struct super_block *sb,
 			inode_lock(inode);
 			truncate_inode_pages(inode->i_mapping, inode->i_size);
 			ret = ext4_truncate(inode);
-			if (ret)
+			if (ret) {
+				/*
+				 * We need to clean up the in-core orphan list
+				 * manually if ext4_truncate() failed to get a
+				 * transaction handle.
+				 */
+				ext4_orphan_del(NULL, inode);
 				ext4_std_error(inode->i_sb, ret);
+			}
 			inode_unlock(inode);
 			nr_truncates++;
 		} else {
Signature · 1 line
2.25.4
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Zhang Yi

In ext4_orphan_cleanup(), if ext4_truncate() failed to get a transaction handle, it didn't remove the inode from the in-core orphan list, which may probably trigger below error dump in ext4_destroy_inode() during the final iput() and could lead to memory corruption on the later orphan list changes.

EXT4-fs (sda): Inode 6291467 (00000000b8247c67): orphan list check failed!

 00000000b8247c67: 0001f30a 00000004 00000000 00000023  ............#...
 00000000e24cde71: 00000006 014082a3 00000000 00000000  ......@.........
 0000000072c6a5ee: 00000000 00000000 00000000 00000000  ................
Quoted 6 lines

...

This patch fix this by cleanup in-core orphan list manually if ext4_truncate() return error.

Thanks! The patch looks good to me. Feel free to add:

Honza

Quoted 28 lines
---
 fs/ext4/super.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/ext4/super.c +8 -1
index 7dc94f3e18e6..12850d72e9a4 100644
@@ -3101,8 +3101,15 @@ static void ext4_orphan_cleanup(struct super_block *sb,
 			inode_lock(inode);
 			truncate_inode_pages(inode->i_mapping, inode->i_size);
 			ret = ext4_truncate(inode);
-			if (ret)
+			if (ret) {
+				/*
+				 * We need to clean up the in-core orphan list
+				 * manually if ext4_truncate() failed to get a
+				 * transaction handle.
+				 */
+				ext4_orphan_del(NULL, inode);
 				ext4_std_error(inode->i_sb, ret);
+			}
 			inode_unlock(inode);
 			nr_truncates++;
 		} else {
Signature · 1 line
2.25.4
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#2 lore raw
In reply to Zhang Yi
Quoted 10 lines · Zhang Yi

In ext4_orphan_cleanup(), if ext4_truncate() failed to get a transaction handle, it didn't remove the inode from the in-core orphan list, which may probably trigger below error dump in ext4_destroy_inode() during the final iput() and could lead to memory corruption on the later orphan list changes.

EXT4-fs (sda): Inode 6291467 (00000000b8247c67): orphan list check failed!

 00000000b8247c67: 0001f30a 00000004 00000000 00000023  ............#...
 00000000e24cde71: 00000006 014082a3 00000000 00000000  ......@.........
 0000000072c6a5ee: 00000000 00000000 00000000 00000000  ................
Quoted 6 lines

...

This patch fix this by cleanup in-core orphan list manually if ext4_truncate() return error.

Applied, thanks.

- Ted