]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ext2: Check block size validity during mount
authorJan Kara <jack@suse.cz>
Wed, 1 Mar 2023 10:59:39 +0000 (11:59 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 May 2023 11:44:02 +0000 (12:44 +0100)
[ Upstream commit 62aeb94433fcec80241754b70d0d1836d5926b0a ]

Check that log of block size stored in the superblock has sensible
value. Otherwise the shift computing the block size can overflow leading
to undefined behavior.

Reported-by: syzbot+4fec412f59eba8c01b77@syzkaller.appspotmail.com
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext2/ext2.h
fs/ext2/super.c

index 10ab238de9a65e4df112e0f2869bd12e84f8287a..a89b43d75905242885e7fe0de14746879200e547 100644 (file)
@@ -177,6 +177,7 @@ static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
 #define EXT2_MIN_BLOCK_SIZE            1024
 #define        EXT2_MAX_BLOCK_SIZE             4096
 #define EXT2_MIN_BLOCK_LOG_SIZE                  10
+#define EXT2_MAX_BLOCK_LOG_SIZE                  16
 #define EXT2_BLOCK_SIZE(s)             ((s)->s_blocksize)
 #define        EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
 #define EXT2_BLOCK_SIZE_BITS(s)                ((s)->s_blocksize_bits)
index 644c83c115bc219080c6bdc992ee2321becf6707..6e8e47871fa261e3808a7d04ae8b22aee1e2d436 100644 (file)
@@ -967,6 +967,13 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
                goto failed_mount;
        }
 
+       if (le32_to_cpu(es->s_log_block_size) >
+           (EXT2_MAX_BLOCK_LOG_SIZE - BLOCK_SIZE_BITS)) {
+               ext2_msg(sb, KERN_ERR,
+                        "Invalid log block size: %u",
+                        le32_to_cpu(es->s_log_block_size));
+               goto failed_mount;
+       }
        blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
 
        if (test_opt(sb, DAX)) {