aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>2007-10-17 02:27:02 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:42:52 -0400
commit7c9e69faa28027913ee059c285a5ea8382e24b5d (patch)
tree951e6e780da734c61337eb8fef23ac3ad68b1e18 /fs/ext4
parent82df39738ba9e02c057fa99b7461a56117d36119 (diff)
ext2/ext3/ext4: add block bitmap validation
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 ext4_blk_bitmap, ext4_inode_bitmap and ext4_inode_table. Validate the block bitmap against these blocks. [akpm@linux-foundation.org: cleanups] Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Andreas Dilger <adilger@clusterfs.com> Acked-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/balloc.c62
1 files changed, 47 insertions, 15 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 8d59eec2e82b..b74bf4368441 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -100,6 +100,15 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
100 return desc; 100 return desc;
101} 101}
102 102
103static inline int
104block_in_use(ext4_fsblk_t block, struct super_block *sb, unsigned char *map)
105{
106 ext4_grpblk_t offset;
107
108 ext4_get_group_no_and_offset(sb, block, NULL, &offset);
109 return ext4_test_bit (offset, map);
110}
111
103/** 112/**
104 * read_block_bitmap() 113 * read_block_bitmap()
105 * @sb: super block 114 * @sb: super block
@@ -113,21 +122,53 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
113static struct buffer_head * 122static struct buffer_head *
114read_block_bitmap(struct super_block *sb, unsigned int block_group) 123read_block_bitmap(struct super_block *sb, unsigned int block_group)
115{ 124{
125 int i;
116 struct ext4_group_desc * desc; 126 struct ext4_group_desc * desc;
117 struct buffer_head * bh = NULL; 127 struct buffer_head * bh = NULL;
128 ext4_fsblk_t bitmap_blk;
118 129
119 desc = ext4_get_group_desc (sb, block_group, NULL); 130 desc = ext4_get_group_desc (sb, block_group, NULL);
120 if (!desc) 131 if (!desc)
121 goto error_out; 132 return NULL;
122 bh = sb_bread(sb, ext4_block_bitmap(sb, desc)); 133 bitmap_blk = ext4_block_bitmap(sb, desc);
134 bh = sb_bread(sb, bitmap_blk);
123 if (!bh) 135 if (!bh)
124 ext4_error (sb, "read_block_bitmap", 136 ext4_error (sb, __FUNCTION__,
125 "Cannot read block bitmap - " 137 "Cannot read block bitmap - "
126 "block_group = %d, block_bitmap = %llu", 138 "block_group = %d, block_bitmap = %llu",
127 block_group, 139 block_group, bitmap_blk);
128 ext4_block_bitmap(sb, desc)); 140
129error_out: 141 /* check whether block bitmap block number is set */
142 if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
143 /* bad block bitmap */
144 goto error_out;
145 }
146
147 /* check whether the inode bitmap block number is set */
148 bitmap_blk = ext4_inode_bitmap(sb, desc);
149 if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
150 /* bad block bitmap */
151 goto error_out;
152 }
153 /* check whether the inode table block number is set */
154 bitmap_blk = ext4_inode_table(sb, desc);
155 for (i = 0; i < EXT4_SB(sb)->s_itb_per_group; i++, bitmap_blk++) {
156 if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
157 /* bad block bitmap */
158 goto error_out;
159 }
160 }
161
130 return bh; 162 return bh;
163
164error_out:
165 brelse(bh);
166 ext4_error(sb, __FUNCTION__,
167 "Invalid block bitmap - "
168 "block_group = %d, block = %llu",
169 block_group, bitmap_blk);
170 return NULL;
171
131} 172}
132/* 173/*
133 * The reservation window structure operations 174 * The reservation window structure operations
@@ -1747,15 +1788,6 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
1747#endif 1788#endif
1748} 1789}
1749 1790
1750static inline int
1751block_in_use(ext4_fsblk_t block, struct super_block *sb, unsigned char *map)
1752{
1753 ext4_grpblk_t offset;
1754
1755 ext4_get_group_no_and_offset(sb, block, NULL, &offset);
1756 return ext4_test_bit (offset, map);
1757}
1758
1759static inline int test_root(int a, int b) 1791static inline int test_root(int a, int b)
1760{ 1792{
1761 int num = b; 1793 int num = b;