1 Subject: Avoid disk sector_t overflow for >2TB ext3 filesystem
2 From: Mingming Cao <cmm@us.ibm.com>
5 If ext3 filesystem is larger than 2TB, and sector_t is a u32 (i.e.
6 CONFIG_LBD not defined in the kernel), the calculation of the disk sector
7 will overflow. Add check at ext3_fill_super() and ext3_group_extend() to
8 prevent mount/remount/resize >2TB ext3 filesystem if sector_t size is 4
11 Verified this patch on a 32 bit platform without CONFIG_LBD defined
12 (sector_t is 32 bits long), mount refuse to mount a 10TB ext3.
14 Signed-off-by: Mingming Cao<cmm@us.ibm.com>
15 Acked-by: Andreas Dilger <adilger@clusterfs.com>
16 Signed-off-by: Andrew Morton <akpm@osdl.org>
19 fs/ext3/resize.c | 10 ++++++++++
20 fs/ext3/super.c | 10 ++++++++++
21 2 files changed, 20 insertions(+)
23 diff -puN fs/ext3/resize.c~avoid-disk-sector_t-overflow-for-2tb-ext3-filesystem fs/ext3/resize.c
24 --- devel/fs/ext3/resize.c~avoid-disk-sector_t-overflow-for-2tb-ext3-filesystem 2006-05-22 14:09:53.000000000 -0700
25 +++ devel-akpm/fs/ext3/resize.c 2006-05-22 14:10:56.000000000 -0700
26 @@ -926,6 +926,16 @@ int ext3_group_extend(struct super_block
27 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
30 + if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
31 + printk(KERN_ERR "EXT3-fs: filesystem on %s: "
32 + "too large to resize to %lu blocks safely\n",
33 + sb->s_id, n_blocks_count);
34 + if (sizeof(sector_t) < 8)
35 + ext3_warning(sb, __FUNCTION__,
36 + "CONFIG_LBD not enabled\n");
40 if (n_blocks_count < o_blocks_count) {
41 ext3_warning(sb, __FUNCTION__,
42 "can't shrink FS - resize aborted");
43 diff -puN fs/ext3/super.c~avoid-disk-sector_t-overflow-for-2tb-ext3-filesystem fs/ext3/super.c
44 --- devel/fs/ext3/super.c~avoid-disk-sector_t-overflow-for-2tb-ext3-filesystem 2006-05-22 14:09:53.000000000 -0700
45 +++ devel-akpm/fs/ext3/super.c 2006-05-22 14:11:10.000000000 -0700
46 @@ -1565,6 +1565,17 @@ static int ext3_fill_super (struct super
50 + if (le32_to_cpu(es->s_blocks_count) >
51 + (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
52 + printk(KERN_ERR "EXT3-fs: filesystem on %s: "
53 + "too large to mount safely - %u blocks\n", sb->s_id,
54 + le32_to_cpu(es->s_blocks_count));
55 + if (sizeof(sector_t) < 8)
57 + "EXT3-fs: CONFIG_LBD not enabled\n");
61 sbi->s_groups_count = (le32_to_cpu(es->s_blocks_count) -
62 le32_to_cpu(es->s_first_data_block) +
63 EXT3_BLOCKS_PER_GROUP(sb) - 1) /