]> err.no Git - linux-2.6/commitdiff
[PATCH] Avoid disk sector_t overflow for >2TB ext3 filesystem
authorMingming Cao <cmm@us.ibm.com>
Sun, 25 Jun 2006 12:47:50 +0000 (05:47 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sun, 25 Jun 2006 17:01:07 +0000 (10:01 -0700)
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>
fs/ext3/resize.c
fs/ext3/super.c

index 34b39e9a1e5a01588db869c02c85f2407d12221a..a31dff81ed779feff2e4ae69f80694cc17bf235c 100644 (file)
@@ -925,6 +925,16 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
        if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
                return 0;
 
+       if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
+               printk(KERN_ERR "EXT3-fs: filesystem on %s:"
+                       " too large to resize to %lu blocks safely\n",
+                       sb->s_id, n_blocks_count);
+               if (sizeof(sector_t) < 8)
+                       ext3_warning(sb, __FUNCTION__,
+                       "CONFIG_LBD not enabled\n");
+               return -EINVAL;
+       }
+
        if (n_blocks_count < o_blocks_count) {
                ext3_warning(sb, __FUNCTION__,
                             "can't shrink FS - resize aborted");
index a60cc6ec130f4a1ebe5fcbe296fff141535108b8..df98a770925294acaefdb357b5adc75b113090ef 100644 (file)
@@ -1565,6 +1565,16 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
                goto failed_mount;
        }
 
+       if (le32_to_cpu(es->s_blocks_count) >
+                   (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
+               printk(KERN_ERR "EXT3-fs: filesystem on %s:"
+                       " too large to mount safely\n", sb->s_id);
+               if (sizeof(sector_t) < 8)
+                       printk(KERN_WARNING "EXT3-fs: CONFIG_LBD not "
+                                       "enabled\n");
+               goto failed_mount;
+       }
+
        if (EXT3_BLOCKS_PER_GROUP(sb) == 0)
                goto cantfind_ext3;
        sbi->s_groups_count = (le32_to_cpu(es->s_blocks_count) -