All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: Andreas Dilger <adilger@clusterfs.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: simple block bitmap sanity checking
Date: Mon, 09 Jul 2007 22:52:10 +0530	[thread overview]
Message-ID: <46926EC2.7030706@linux.vnet.ibm.com> (raw)
In-Reply-To: <20070706184856.GA13812@schatzie.adilger.int>



Andreas Dilger wrote:
> During a discussion at OLS, I came up with a very simple way of validating
> the ext2/3/4 block bitmaps at read time.  Until such a time when we have
> checksums for the bitmaps we can have a simple but quite robust mechanism
> that is useful for ext2/3/4.
> 
> When a new block bitmap is read from disk in read_block_bitmap() there are a
> few bits that should ALWAYS be set.  In particular, the blocks given by
> desc->bg_block_bitmap, desc->bg_inode_bitmap, and the inode table in
> [desc->bg_inode_table, +sbi->s_itb_per_group].  If those bits (shifted to be
> relative to the current group, of course) are not set then the on-disk group
> descriptor is corrupt, or there is some problem reading it from disk, and
> this needs to generate an extN_error() call[*] to make the fs read-only.
> 
> A similar check can be done with the inode bitmap - it should have the
> bits at the end of each bitmap set, for bits higher than s_inodes_per_group.


Something like this ?. If yes i can send a patch with full changelog


diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 44c6254..b9a334c 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -115,17 +115,50 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)
 {
 	struct ext4_group_desc * desc;
 	struct buffer_head * bh = NULL;
+	ext4_fsblk_t bitmap_blk, grp_rel_blk, grp_first_blk;
 
 	desc = ext4_get_group_desc (sb, block_group, NULL);
 	if (!desc)
 		goto error_out;
-	bh = sb_bread(sb, ext4_block_bitmap(sb, desc));
+	bitmap_blk = ext4_block_bitmap(sb, desc);
+	bh = sb_bread(sb, bitmap_blk);
 	if (!bh)
 		ext4_error (sb, "read_block_bitmap",
 			    "Cannot read block bitmap - "
 			    "block_group = %d, block_bitmap = %llu",
-			    block_group,
-			    ext4_block_bitmap(sb, desc));
+			    block_group, bitmap_blk);
+
+	/* check whether block bitmap block number is set */
+	printk("blk bitmap = %llu first block = %llu block group = %u \n",
+			bitmap_blk, ext4_group_first_block_no(sb, block_group),
+			block_group);
+
+	grp_first_blk = ext4_group_first_block_no(sb, block_group);
+
+	grp_rel_blk = bitmap_blk - grp_first_blk;
+	if (!ext4_test_bit(grp_rel_blk, bh->b_data)) {
+		/* bad block bitmap */
+		brelse(bh);
+		return NULL;
+	}
+
+	/* check whether the inode bitmap block number is set */
+	bitmap_blk = ext4_inode_bitmap(sb, desc);
+	grp_rel_blk = bitmap_blk - grp_first_blk;
+	if (!ext4_test_bit(grp_rel_blk, bh->b_data)) {
+		/* bad block bitmap */
+		brelse(bh);
+		return NULL;
+	}
+	/* check whether the inode table block number is set */
+	bitmap_blk = ext4_inode_table(sb, desc);
+	grp_rel_blk = bitmap_blk - grp_first_blk;
+	if (!ext4_test_bit(grp_rel_blk, bh->b_data)) {
+		/* bad block bitmap */
+		brelse(bh);
+		return NULL;
+	}
+
 error_out:
 	return bh;
 }

  reply	other threads:[~2007-07-09 17:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-06 18:48 simple block bitmap sanity checking Andreas Dilger
2007-07-09 17:22 ` Aneesh Kumar K.V [this message]
2007-07-09 18:58   ` Andreas Dilger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46926EC2.7030706@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=adilger@clusterfs.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.