Skip to content

Commit fcd5df3

Browse files
Mingming CaoLinus Torvalds
authored andcommitted
[PATCH] Avoid disk sector_t overflow for >2TB ext3 filesystem
If ext3 filesystem is larger than 2TB, and sector_t is a u32 (i.e. CONFIG_LBD not defined in the kernel), the calculation of the disk sector will overflow. Add check at ext3_fill_super() and ext3_group_extend() to prevent mount/remount/resize >2TB ext3 filesystem if sector_t size is 4 bytes. Verified this patch on a 32 bit platform without CONFIG_LBD defined (sector_t is 32 bits long), mount refuse to mount a 10TB ext3. Signed-off-by: Mingming Cao<cmm@us.ibm.com> Acked-by: Andreas Dilger <adilger@clusterfs.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent b613677 commit fcd5df3

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎fs/ext3/resize.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,16 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
925925
if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
926926
return 0;
927927

928+
if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
929+
printk(KERN_ERR "EXT3-fs: filesystem on %s:"
930+
" too large to resize to %lu blocks safely\n",
931+
sb->s_id, n_blocks_count);
932+
if (sizeof(sector_t) < 8)
933+
ext3_warning(sb, __FUNCTION__,
934+
"CONFIG_LBD not enabled\n");
935+
return -EINVAL;
936+
}
937+
928938
if (n_blocks_count < o_blocks_count) {
929939
ext3_warning(sb, __FUNCTION__,
930940
"can't shrink FS - resize aborted");

‎fs/ext3/super.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,16 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
15651565
goto failed_mount;
15661566
}
15671567

1568+
if (le32_to_cpu(es->s_blocks_count) >
1569+
(sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
1570+
printk(KERN_ERR "EXT3-fs: filesystem on %s:"
1571+
" too large to mount safely\n", sb->s_id);
1572+
if (sizeof(sector_t) < 8)
1573+
printk(KERN_WARNING "EXT3-fs: CONFIG_LBD not "
1574+
"enabled\n");
1575+
goto failed_mount;
1576+
}
1577+
15681578
if (EXT3_BLOCKS_PER_GROUP(sb) == 0)
15691579
goto cantfind_ext3;
15701580
sbi->s_groups_count = (le32_to_cpu(es->s_blocks_count) -

0 commit comments

Comments
 (0)