Skip to content

Commit 8cdf337

Browse files
committed
ext4: sanity check the block and cluster size at mount time
If the block size or cluster size is insane, reject the mount. This is important for security reasons (although we shouldn't be just depending on this check). Ref: http://www.securityfocus.com/archive/1/539661 Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1332506 Reported-by: Borislav Petkov <bp@alien8.de> Reported-by: Nikolay Borisov <kernel@kyup.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
1 parent 0f0909e commit 8cdf337

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

fs/ext4/ext4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ struct ext4_io_submit {
235235
#define EXT4_MAX_BLOCK_SIZE 65536
236236
#define EXT4_MIN_BLOCK_LOG_SIZE 10
237237
#define EXT4_MAX_BLOCK_LOG_SIZE 16
238+
#define EXT4_MAX_CLUSTER_LOG_SIZE 30
238239
#ifdef __KERNEL__
239240
# define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize)
240241
#else

fs/ext4/super.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3565,7 +3565,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
35653565
if (blocksize < EXT4_MIN_BLOCK_SIZE ||
35663566
blocksize > EXT4_MAX_BLOCK_SIZE) {
35673567
ext4_msg(sb, KERN_ERR,
3568-
"Unsupported filesystem blocksize %d", blocksize);
3568+
"Unsupported filesystem blocksize %d (%d log_block_size)",
3569+
blocksize, le32_to_cpu(es->s_log_block_size));
3570+
goto failed_mount;
3571+
}
3572+
if (le32_to_cpu(es->s_log_block_size) >
3573+
(EXT4_MAX_BLOCK_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
3574+
ext4_msg(sb, KERN_ERR,
3575+
"Invalid log block size: %u",
3576+
le32_to_cpu(es->s_log_block_size));
35693577
goto failed_mount;
35703578
}
35713579

@@ -3697,6 +3705,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
36973705
"block size (%d)", clustersize, blocksize);
36983706
goto failed_mount;
36993707
}
3708+
if (le32_to_cpu(es->s_log_cluster_size) >
3709+
(EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) {
3710+
ext4_msg(sb, KERN_ERR,
3711+
"Invalid log cluster size: %u",
3712+
le32_to_cpu(es->s_log_cluster_size));
3713+
goto failed_mount;
3714+
}
37003715
sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -
37013716
le32_to_cpu(es->s_log_block_size);
37023717
sbi->s_clusters_per_group =

0 commit comments

Comments
 (0)