[PATCH] Avoid disk sector_t overflow for >2TB ext3 filesystem
Mingming Cao <[email protected]>
| Newsgroups | gmane.comp.file-systems.ext2.devel |
|---|---|
| Organization | IBM LTC |
| Message-ID | <[email protected]> |
On Fri, 2006-05-19 at 00:56 -0600, Andreas Dilger wrote:
> On May 18, 2006 17:31 -0700, Mingming Cao wrote:
> > Hmm, do we have the sector overflow issue with upstream right now?? As
> > ext3 filesystem blocks account in upstream right now is unsigned long
> > type, I could be wrong but I don't think we have the sector overflow
> > issue until we have >32 bit block number support on disk?
>
> Yes, I believe we currently have an overflow issue in the vanilla kernel
> right now. I had been worried about this for some time already (enough
> that CFS has not supported > 2TB ext3 filesystems as a result, because
> I didn't know where the corruption was coming from) but I didn't have
> enough information to work on, only some rare but serious reports of
> ext3 corruption on large filesystems, sometimes correlated to 32-bit
> systems.
>
> What confused me is that RHEL4 had no problem with filesystems > 2TB,
> but this is because their kernels always include CONFIG_LBD.
>
>
> The problem is that if sector_t is a u32 (i.e. CONFIG_LBD not defined in
> the kernel) and we are using a filesystem larger than 2TB the calculation
> of the disk sector will overflow. This is because the a device offset
> of >= 2TB is >= 2^40 bytes is >= 2^29 4kB blocks is >= 2^32 512-byte sectors
> and we overflow the sector offset and overwrite the beginning of the disk.
>
> So, the above check could be initially added for only the 32-bit size:
>
> 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 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. Patch
against 2.6.17-rc4.
Signed-Off-By: Mingming Cao<[email protected]>
---
linux-2.6.16-ming/fs/ext3/resize.c | 9 +++++++++
linux-2.6.16-ming/fs/ext3/super.c | 10 ++++++++++
2 files changed, 19 insertions(+)
diff -puN fs/ext3/super.c~ext3_check_sector_t_overflow fs/ext3/super.c
--- linux-2.6.16/fs/ext3/super.c~ext3_check_sector_t_overflow 2006-05-19 17:19:43.000000000 -0700
+++ linux-2.6.16-ming/fs/ext3/super.c 2006-05-22 10:54:27.000000000 -0700
@@ -1579,6 +1579,16 @@ static int ext3_fill_super (struct super
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;
+ }
+
percpu_counter_init(&sbi->s_freeblocks_counter);
percpu_counter_init(&sbi->s_freeinodes_counter);
percpu_counter_init(&sbi->s_dirs_counter);
diff -puN fs/ext3/resize.c~ext3_check_sector_t_overflow fs/ext3/resize.c
--- linux-2.6.16/fs/ext3/resize.c~ext3_check_sector_t_overflow 2006-05-19 17:19:43.000000000 -0700
+++ linux-2.6.16-ming/fs/ext3/resize.c 2006-05-22 10:54:27.000000000 -0700
@@ -926,6 +926,15 @@ int ext3_group_extend(struct super_block
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 mount safely\n", sb->s_id);
+ 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");
_
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642