Skip to content

Commit 7827a7f

Browse files
committed
ext4: clean up error handling when orphan list is corrupted
Instead of just printing warning messages, if the orphan list is corrupted, declare the file system is corrupted. If there are any reserved inodes in the orphaned inode list, declare the file system corrupted and stop right away to avoid doing more potential damage to the file system. Cc: stable@vger.kernel.org Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent c9eb13a commit 7827a7f

1 file changed

Lines changed: 22 additions & 27 deletions

File tree

‎fs/ext4/ialloc.c‎

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,25 +1150,20 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
11501150
unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
11511151
ext4_group_t block_group;
11521152
int bit;
1153-
struct buffer_head *bitmap_bh;
1153+
struct buffer_head *bitmap_bh = NULL;
11541154
struct inode *inode = NULL;
1155-
long err = -EIO;
1155+
int err = -EFSCORRUPTED;
11561156

1157-
/* Error cases - e2fsck has already cleaned up for us */
1158-
if (ino > max_ino) {
1159-
ext4_warning(sb, "bad orphan ino %lu! e2fsck was run?", ino);
1160-
err = -EFSCORRUPTED;
1161-
goto error;
1162-
}
1157+
if (ino < EXT4_FIRST_INO(sb) || ino > max_ino)
1158+
goto bad_orphan;
11631159

11641160
block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
11651161
bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
11661162
bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
11671163
if (IS_ERR(bitmap_bh)) {
1168-
err = PTR_ERR(bitmap_bh);
1169-
ext4_warning(sb, "inode bitmap error %ld for orphan %lu",
1170-
ino, err);
1171-
goto error;
1164+
ext4_error(sb, "inode bitmap error %ld for orphan %lu",
1165+
ino, PTR_ERR(bitmap_bh));
1166+
return (struct inode *) bitmap_bh;
11721167
}
11731168

11741169
/* Having the inode bit set should be a 100% indicator that this
@@ -1179,8 +1174,12 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
11791174
goto bad_orphan;
11801175

11811176
inode = ext4_iget(sb, ino);
1182-
if (IS_ERR(inode))
1183-
goto iget_failed;
1177+
if (IS_ERR(inode)) {
1178+
err = PTR_ERR(inode);
1179+
ext4_error(sb, "couldn't read orphan inode %lu (err %d)",
1180+
ino, err);
1181+
return inode;
1182+
}
11841183

11851184
/*
11861185
* If the orphans has i_nlinks > 0 then it should be able to
@@ -1197,29 +1196,25 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
11971196
brelse(bitmap_bh);
11981197
return inode;
11991198

1200-
iget_failed:
1201-
err = PTR_ERR(inode);
1202-
inode = NULL;
12031199
bad_orphan:
1204-
ext4_warning(sb, "bad orphan inode %lu! e2fsck was run?", ino);
1205-
printk(KERN_WARNING "ext4_test_bit(bit=%d, block=%llu) = %d\n",
1206-
bit, (unsigned long long)bitmap_bh->b_blocknr,
1207-
ext4_test_bit(bit, bitmap_bh->b_data));
1208-
printk(KERN_WARNING "inode=%p\n", inode);
1200+
ext4_error(sb, "bad orphan inode %lu", ino);
1201+
if (bitmap_bh)
1202+
printk(KERN_ERR "ext4_test_bit(bit=%d, block=%llu) = %d\n",
1203+
bit, (unsigned long long)bitmap_bh->b_blocknr,
1204+
ext4_test_bit(bit, bitmap_bh->b_data));
12091205
if (inode) {
1210-
printk(KERN_WARNING "is_bad_inode(inode)=%d\n",
1206+
printk(KERN_ERR "is_bad_inode(inode)=%d\n",
12111207
is_bad_inode(inode));
1212-
printk(KERN_WARNING "NEXT_ORPHAN(inode)=%u\n",
1208+
printk(KERN_ERR "NEXT_ORPHAN(inode)=%u\n",
12131209
NEXT_ORPHAN(inode));
1214-
printk(KERN_WARNING "max_ino=%lu\n", max_ino);
1215-
printk(KERN_WARNING "i_nlink=%u\n", inode->i_nlink);
1210+
printk(KERN_ERR "max_ino=%lu\n", max_ino);
1211+
printk(KERN_ERR "i_nlink=%u\n", inode->i_nlink);
12161212
/* Avoid freeing blocks if we got a bad deleted inode */
12171213
if (inode->i_nlink == 0)
12181214
inode->i_blocks = 0;
12191215
iput(inode);
12201216
}
12211217
brelse(bitmap_bh);
1222-
error:
12231218
return ERR_PTR(err);
12241219
}
12251220

0 commit comments

Comments
 (0)