Skip to content

Commit 54f93b7

Browse files
committed
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext4: check block device size on mount ext4: Fix off-by-one-error in ext4_valid_extent_idx() ext4: Fix big-endian problem in __ext4_check_blockref()
2 parents 3b3809a + 0f2ddca commit 54f93b7

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

fs/ext4/extents.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static int ext4_valid_extent_idx(struct inode *inode,
342342
ext4_fsblk_t block = idx_pblock(ext_idx);
343343
struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
344344
if (unlikely(block < le32_to_cpu(es->s_first_data_block) ||
345-
(block > ext4_blocks_count(es))))
345+
(block >= ext4_blocks_count(es))))
346346
return 0;
347347
else
348348
return 1;

fs/ext4/inode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,16 @@ static int ext4_block_to_path(struct inode *inode,
372372
}
373373

374374
static int __ext4_check_blockref(const char *function, struct inode *inode,
375-
unsigned int *p, unsigned int max) {
375+
__le32 *p, unsigned int max) {
376376

377377
unsigned int maxblocks = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es);
378-
unsigned int *bref = p;
378+
__le32 *bref = p;
379379
while (bref < p+max) {
380-
if (unlikely(*bref >= maxblocks)) {
380+
if (unlikely(le32_to_cpu(*bref) >= maxblocks)) {
381381
ext4_error(inode->i_sb, function,
382382
"block reference %u >= max (%u) "
383383
"in inode #%lu, offset=%d",
384-
*bref, maxblocks,
384+
le32_to_cpu(*bref), maxblocks,
385385
inode->i_ino, (int)(bref-p));
386386
return -EIO;
387387
}

fs/ext4/super.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
25082508
if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
25092509
goto cantfind_ext4;
25102510

2511+
/* check blocks count against device size */
2512+
blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
2513+
if (blocks_count && ext4_blocks_count(es) > blocks_count) {
2514+
printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu "
2515+
"exceeds size of device (%llu blocks)\n",
2516+
ext4_blocks_count(es), blocks_count);
2517+
goto failed_mount;
2518+
}
2519+
25112520
/*
25122521
* It makes no sense for the first data block to be beyond the end
25132522
* of the filesystem.

0 commit comments

Comments
 (0)