From 89db86d33c634374a3f6e15f943ab83cdc5bd93a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 20 Mar 2005 22:47:54 -0500 Subject: [PATCH] Make e2fsck check the superblock's inode_size to make sure it is sane before we start depending on it! --- e2fsck/ChangeLog | 3 +++ e2fsck/super.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 7a0d705..cbbe2fe 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,5 +1,8 @@ 2005-03-20 Theodore Ts'o + * super.c (check_super_block): Add sanity checks for the + superblock's inode_size field. + * pass3.c (check_root, e2fsck_get_lost_and_found): Call ext2fs_write_new_inode() instead of ext2fs_write_inode(). diff --git a/e2fsck/super.c b/e2fsck/super.c index 7e19e8e..294cd80 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -446,6 +446,7 @@ void check_super_block(e2fsck_t ctx) blk_t bpg_max; int inodes_per_block; int ipg_max; + int inode_size; dgrp_t i; blk_t should_be; struct problem_context pctx; @@ -494,7 +495,18 @@ void check_super_block(e2fsck_t ctx) check_super_value(ctx, "reserved_gdt_blocks", sb->s_reserved_gdt_blocks, MAX_CHECK, 0, fs->blocksize/4); - + inode_size = EXT2_INODE_SIZE(sb); + check_super_value(ctx, "inode_size", + inode_size, MIN_CHECK | MAX_CHECK, + EXT2_GOOD_OLD_INODE_SIZE, fs->blocksize); + if (inode_size & (inode_size - 1)) { + pctx.num = inode_size; + pctx.str = "inode_size"; + fix_problem(ctx, PR_0_MISC_CORRUPT_SUPER, &pctx); + ctx->flags |= E2F_FLAG_ABORT; /* never get here! */ + return; + } + if (!ctx->num_blocks) { pctx.errcode = e2fsck_get_device_size(ctx); if (pctx.errcode && pctx.errcode != EXT2_ET_UNIMPLEMENTED) { -- 1.8.3.1