1 From b9a037b7f3c401d3c63e0423e56aef606b1ffaaf Mon Sep 17 00:00:00 2001
2 From: Zhang Yi <yi.zhang@huawei.com>
3 Date: Fri, 7 May 2021 15:19:04 +0800
4 Subject: ext4: cleanup in-core orphan list if ext4_truncate() failed to get a transaction handle
6 From: Zhang Yi <yi.zhang@huawei.com>
8 commit b9a037b7f3c401d3c63e0423e56aef606b1ffaaf upstream.
10 In ext4_orphan_cleanup(), if ext4_truncate() failed to get a transaction
11 handle, it didn't remove the inode from the in-core orphan list, which
12 may probably trigger below error dump in ext4_destroy_inode() during the
13 final iput() and could lead to memory corruption on the later orphan
16 EXT4-fs (sda): Inode 6291467 (00000000b8247c67): orphan list check failed!
17 00000000b8247c67: 0001f30a 00000004 00000000 00000023 ............#...
18 00000000e24cde71: 00000006 014082a3 00000000 00000000 ......@.........
19 0000000072c6a5ee: 00000000 00000000 00000000 00000000 ................
22 This patch fix this by cleanup in-core orphan list manually if
23 ext4_truncate() return error.
26 Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
27 Reviewed-by: Jan Kara <jack@suse.cz>
28 Link: https://lore.kernel.org/r/20210507071904.160808-1-yi.zhang@huawei.com
29 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33 fs/ext4/super.c | 9 ++++++++-
34 1 file changed, 8 insertions(+), 1 deletion(-)
38 @@ -2689,8 +2689,15 @@ static void ext4_orphan_cleanup(struct s
40 truncate_inode_pages(inode->i_mapping, inode->i_size);
41 ret = ext4_truncate(inode);
45 + * We need to clean up the in-core orphan list
46 + * manually if ext4_truncate() failed to get a
47 + * transaction handle.
49 + ext4_orphan_del(NULL, inode);
50 ext4_std_error(inode->i_sb, ret);