Whamcloud - gitweb
b=12348
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext3-sector_t-overflow-2.6.12.patch
1 Subject: Avoid disk sector_t overflow for >2TB ext3 filesystem
2 From: Mingming Cao <cmm@us.ibm.com>
3
4
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
9 bytes.
10
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.
13
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>
17 ---
18
19  fs/ext3/resize.c |   10 ++++++++++
20  fs/ext3/super.c  |   10 ++++++++++
21  2 files changed, 20 insertions(+)
22
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)
28                 return 0;
29  
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");
37 +               return -EINVAL;
38 +       }
39 +
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
47                 goto failed_mount;
48         }
49  
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)
56 +                       printk(KERN_WARNING
57 +                              "EXT3-fs: CONFIG_LBD not enabled\n");
58 +               goto failed_mount;
59 +       }
60 +
61         if (EXT3_BLOCKS_PER_GROUP(sb) == 0)
62                 goto cantfind_ext3;
63         sbi->s_groups_count = (le32_to_cpu(es->s_blocks_count) -
64 _