All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jan Kara <jack@suse.cz>,
	syzbot+d273f7d7f58afd93be48@syzkaller.appspotmail.com,
	Sasha Levin <sashal@kernel.org>,
	jack@suse.com, linux-ext4@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 2/8] ext2: Add more validity checks for inode counts
Date: Sun,  7 Aug 2022 21:39:57 -0400	[thread overview]
Message-ID: <20220808014005.317064-2-sashal@kernel.org> (raw)
In-Reply-To: <20220808014005.317064-1-sashal@kernel.org>

From: Jan Kara <jack@suse.cz>

[ Upstream commit fa78f336937240d1bc598db817d638086060e7e9 ]

Add checks verifying number of inodes stored in the superblock matches
the number computed from number of inodes per group. Also verify we have
at least one block worth of inodes per group. This prevents crashes on
corrupted filesystems.

Reported-by: syzbot+d273f7d7f58afd93be48@syzkaller.appspotmail.com
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ext2/super.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 5ca1f73958b0..7cc83403ebe7 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -1042,9 +1042,10 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 			sbi->s_frags_per_group);
 		goto failed_mount;
 	}
-	if (sbi->s_inodes_per_group > sb->s_blocksize * 8) {
+	if (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||
+	    sbi->s_inodes_per_group > sb->s_blocksize * 8) {
 		ext2_msg(sb, KERN_ERR,
-			"error: #inodes per group too big: %lu",
+			"error: invalid #inodes per group: %lu",
 			sbi->s_inodes_per_group);
 		goto failed_mount;
 	}
@@ -1054,6 +1055,13 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 	sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
 				le32_to_cpu(es->s_first_data_block) - 1)
 					/ EXT2_BLOCKS_PER_GROUP(sb)) + 1;
+	if ((u64)sbi->s_groups_count * sbi->s_inodes_per_group !=
+	    le32_to_cpu(es->s_inodes_count)) {
+		ext2_msg(sb, KERN_ERR, "error: invalid #inodes: %u vs computed %llu",
+			 le32_to_cpu(es->s_inodes_count),
+			 (u64)sbi->s_groups_count * sbi->s_inodes_per_group);
+		goto failed_mount;
+	}
 	db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
 		   EXT2_DESC_PER_BLOCK(sb);
 	sbi->s_group_desc = kmalloc (db_count * sizeof (struct buffer_head *), GFP_KERNEL);
-- 
2.35.1


  reply	other threads:[~2022-08-08  2:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08  1:39 [PATCH AUTOSEL 4.9 1/8] arm64: fix oops in concurrently setting insn_emulation sysctls Sasha Levin
2022-08-08  1:39 ` Sasha Levin
2022-08-08  1:39 ` Sasha Levin [this message]
2022-08-08  1:39 ` [PATCH AUTOSEL 4.9 3/8] ARM: dts: imx6ul: add missing properties for sram Sasha Levin
2022-08-08  1:39   ` Sasha Levin
2022-08-08  1:39 ` [PATCH AUTOSEL 4.9 4/8] ARM: dts: imx6ul: fix qspi node compatible Sasha Levin
2022-08-08  1:39   ` Sasha Levin
2022-08-08  1:40 ` [PATCH AUTOSEL 4.9 5/8] ACPI: LPSS: Fix missing check in register_device_clock() Sasha Levin
2022-08-08  1:40 ` [PATCH AUTOSEL 4.9 6/8] hwmon: (sht15) Fix wrong assumptions in device remove callback Sasha Levin
2022-08-08  1:40 ` [PATCH AUTOSEL 4.9 7/8] PM: hibernate: defer device probing when resuming from hibernation Sasha Levin
2022-08-08  1:40 ` [PATCH AUTOSEL 4.9 8/8] selinux: Add boundary check in put_entry() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220808014005.317064-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=jack@suse.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+d273f7d7f58afd93be48@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.