]> git.proxmox.com Git - mirror_ubuntu-impish-kernel.git/commitdiff
ext4: cleanup in-core orphan list if ext4_truncate() failed to get a transaction...
authorZhang Yi <yi.zhang@huawei.com>
Fri, 7 May 2021 07:19:04 +0000 (15:19 +0800)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 2 Aug 2021 11:26:48 +0000 (13:26 +0200)
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!
 00000000b8247c670001f30a 00000004 00000000 00000023  ............#...
 00000000e24cde7100000006 014082a3 00000000 00000000  ......@.........
 0000000072c6a5ee00000000 00000000 00000000 00000000  ................
 ...

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

Cc: stable@kernel.org
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20210507071904.160808-1-yi.zhang@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
(cherry picked from commit b9a037b7f3c401d3c63e0423e56aef606b1ffaaf)
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
fs/ext4/super.c

index d29f6aa7d96eede2f7888e8ce29a59f253393ffb..73e90731cf90a22f1876cbdcea673709078095de 100644 (file)
@@ -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 {