From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE2A3C7EE21 for ; Thu, 4 May 2023 20:01:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232217AbjEDUBa (ORCPT ); Thu, 4 May 2023 16:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232192AbjEDUBG (ORCPT ); Thu, 4 May 2023 16:01:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24E30150C4; Thu, 4 May 2023 12:51:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B6D89637DA; Thu, 4 May 2023 19:49:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 632C7C43323; Thu, 4 May 2023 19:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683229788; bh=f0J1s3O97S5PWIY9pto77hRoNRoyEl5+G6HMZ08MPJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=beSDdCOJSpQW25kR3OxKD9ngLvjUowsL6vZRu1CnPN5jhRKvkSOVfrqyJtulyBUxG 2Lk9+gXR1SuX27feEXyFT8+83papH476QhM9BxWItVI8B+mmcmZWR3ODyz2WBA29ps YpHTwriDPRId6ts0P68rZhweJND/pYiiXhut5RkmzZvOdnhp6EWRweE3Fr2zg7ujOs 5LCx9h2c+5JpVJp/WeGpcKty/pvJIIWrPQNSbQbAhBV5IvjW5LsCkU+ovX2AxZv07K cMfUh6odUAP7HPqAqsz6tINsyWyVPnlZJHMHs1pQB5CivF4Bhm2NLdomhuKEpzb4+k 0vXj21sps2Kkw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jan Kara , syzbot+4fec412f59eba8c01b77@syzkaller.appspotmail.com, Sasha Levin , jack@suse.com, linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 04/24] ext2: Check block size validity during mount Date: Thu, 4 May 2023 15:49:17 -0400 Message-Id: <20230504194937.3808414-4-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230504194937.3808414-1-sashal@kernel.org> References: <20230504194937.3808414-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara [ 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 Signed-off-by: Sasha Levin --- fs/ext2/ext2.h | 1 + fs/ext2/super.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index 5136b7289e8da..f06367cfd7641 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -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) diff --git a/fs/ext2/super.c b/fs/ext2/super.c index 9a6475b2ab28b..ab01ec7ac48c5 100644 --- a/fs/ext2/super.c +++ b/fs/ext2/super.c @@ -950,6 +950,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)) { -- 2.39.2