1 ext4: clean up error handling when orphan list is corrupted
3 Instead of just printing warning messages, if the orphan list is
4 corrupted, declare the file system is corrupted. If there are any
5 reserved inodes in the orphaned inode list, declare the file system
6 corrupted and stop right away to avoid doing more potential damage to
9 Cc: stable@vger.kernel.org
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 fs/ext4/ialloc.c | 49 ++++++++++++++++++++++---------------------------
13 1 file changed, 22 insertions(+), 27 deletions(-)
15 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
16 index c2caf2d..3da4cf8 100644
17 --- a/fs/ext4/ialloc.c
18 +++ b/fs/ext4/ialloc.c
19 @@ -1150,25 +1150,20 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
20 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
21 ext4_group_t block_group;
23 - struct buffer_head *bitmap_bh;
24 + struct buffer_head *bitmap_bh = NULL;
25 struct inode *inode = NULL;
27 + int err = -EFSCORRUPTED;
29 - /* Error cases - e2fsck has already cleaned up for us */
30 - if (ino > max_ino) {
31 - ext4_warning(sb, "bad orphan ino %lu! e2fsck was run?", ino);
32 - err = -EFSCORRUPTED;
35 + if (ino < EXT4_FIRST_INO(sb) || ino > max_ino)
38 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
39 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
40 bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
41 if (IS_ERR(bitmap_bh)) {
42 - err = PTR_ERR(bitmap_bh);
43 - ext4_warning(sb, "inode bitmap error %ld for orphan %lu",
46 + ext4_error(sb, "inode bitmap error %ld for orphan %lu",
47 + ino, PTR_ERR(bitmap_bh));
48 + return (struct inode *) bitmap_bh;
51 /* Having the inode bit set should be a 100% indicator that this
52 @@ -1179,8 +1174,12 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
55 inode = ext4_iget(sb, ino);
58 + if (IS_ERR(inode)) {
59 + err = PTR_ERR(inode);
60 + ext4_error(sb, "couldn't read orphan inode %lu (err %d)",
66 * If the orphans has i_nlinks > 0 then it should be able to
67 @@ -1197,29 +1196,25 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
72 - err = PTR_ERR(inode);
75 - ext4_warning(sb, "bad orphan inode %lu! e2fsck was run?", ino);
76 - printk(KERN_WARNING "ext4_test_bit(bit=%d, block=%llu) = %d\n",
77 - bit, (unsigned long long)bitmap_bh->b_blocknr,
78 - ext4_test_bit(bit, bitmap_bh->b_data));
79 - printk(KERN_WARNING "inode=%p\n", inode);
80 + ext4_error(sb, "bad orphan inode %lu", ino);
82 + printk(KERN_ERR "ext4_test_bit(bit=%d, block=%llu) = %d\n",
83 + bit, (unsigned long long)bitmap_bh->b_blocknr,
84 + ext4_test_bit(bit, bitmap_bh->b_data));
86 - printk(KERN_WARNING "is_bad_inode(inode)=%d\n",
87 + printk(KERN_ERR "is_bad_inode(inode)=%d\n",
89 - printk(KERN_WARNING "NEXT_ORPHAN(inode)=%u\n",
90 + printk(KERN_ERR "NEXT_ORPHAN(inode)=%u\n",
92 - printk(KERN_WARNING "max_ino=%lu\n", max_ino);
93 - printk(KERN_WARNING "i_nlink=%u\n", inode->i_nlink);
94 + printk(KERN_ERR "max_ino=%lu\n", max_ino);
95 + printk(KERN_ERR "i_nlink=%u\n", inode->i_nlink);
96 /* Avoid freeing blocks if we got a bad deleted inode */
97 if (inode->i_nlink == 0)