linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 2/13] extents and 48bit ext3: sector_t overflow check
@ 2006-06-09  1:21 Mingming Cao
  0 siblings, 0 replies; only message in thread
From: Mingming Cao @ 2006-06-09  1:21 UTC (permalink / raw)
  To: linux-kernel, ext2-devel, linux-fsdevel

If ext3 fs system 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.

Signed-Off-By: Mingming Cao<cmm@us.ibm.com>
Acked-by: Andreas Dilger <adilger@clusterfs.com>


---

 linux-2.6.16-ming/fs/ext3/resize.c |   10 ++++++++++
 linux-2.6.16-ming/fs/ext3/super.c  |   10 ++++++++++
 2 files changed, 20 insertions(+)

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-06-07 15:42:26.000000000 -0700
+++ linux-2.6.16-ming/fs/ext3/resize.c	2006-06-08 16:50:07.390825336 -0700
@@ -925,6 +925,16 @@ 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 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");
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-06-07 15:42:26.000000000 -0700
+++ linux-2.6.16-ming/fs/ext3/super.c	2006-06-08 16:50:07.394824881 -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;
+	}
+
 	bgl_lock_init(&sbi->s_blockgroup_lock);
 
 	for (i = 0; i < db_count; i++) {

_

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-06-09  1:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-09  1:21 [RFC 2/13] extents and 48bit ext3: sector_t overflow check Mingming Cao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).