Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Subject: [PATCH 12/23] ext4: reject EXT4_IOC_GROUP_ADD inputs larger than a block group
Date: Wed, 11 Nov 2026 23:47:01 -0500	[thread overview]
Message-ID: <20261112044712.1577296-13-tytso@mit.edu> (raw)
In-Reply-To: <20261112044712.1577296-1-tytso@mit.edu>

verify_group_input() checks that the group described by
EXT4_IOC_GROUP_ADD lies on the device and that its bitmaps and inode
table are inside [start, start + blocks_count), but never checks that
blocks_count does not exceed EXT4_BLOCKS_PER_GROUP().  A blocks_count
covering several groups is therefore accepted, and the metadata may be
placed in the second (or later) group of that range.

ext4_group_add() then hands ext4_flex_group_add() a flex group made of
the single on-stack input and bg_flags entries.  When
setup_new_flex_group_blocks() marks the group tables in the block
bitmap, set_flexbg_block_bitmap() derives the group index from the
metadata block number and uses it to index flex_gd->bg_flags[] and
flex_gd->groups[], reading past those single-entry stack objects and
modifying whatever block number it finds there.  Even without that,
adding a "group" larger than a block group leaves s_blocks_count
inconsistent with s_groups_count.

Treat blocks_count > EXT4_BLOCKS_PER_GROUP() as a bad blocks count,
before the device read.  A zero blocks_count is already rejected by the
free_blocks_count < 0 check, and the start + blocks_count addition
cannot overflow because ext4_group_add() checks it beforehand.

Fixes: 61f296cc4975 ("ext4: let ext4_group_add() use common code")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 fs/ext4/resize-test.c | 12 ++++++++++++
 fs/ext4/resize.c      |  3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/resize-test.c b/fs/ext4/resize-test.c
index 32de2876416b..4a08a47b3481 100644
--- a/fs/ext4/resize-test.c
+++ b/fs/ext4/resize-test.c
@@ -950,6 +950,18 @@ static void test_verify_group_input_rejections_and_acceptance(struct kunit *test
 			-EINVAL);
 	input.blocks_count = RESIZE_TEST_BLOCKS_PER_GRP;
 
+	/*
+	 * 4b. blocks_count spanning two groups, with the block bitmap in the
+	 * second one, would make ext4_flex_group_add() index past the
+	 * single-entry flex group arrays.
+	 */
+	input.blocks_count = 2 * RESIZE_TEST_BLOCKS_PER_GRP;
+	input.block_bitmap = start + RESIZE_TEST_BLOCKS_PER_GRP;
+	KUNIT_EXPECT_EQ(test, ext4_verify_group_input_test(sb, &input),
+			-EINVAL);
+	input.block_bitmap = start + overhead;
+	input.blocks_count = RESIZE_TEST_BLOCKS_PER_GRP;
+
 	/* 5. Last block beyond underlying device -> -EIO */
 	ctx->device_blocks = start + 100;
 	KUNIT_EXPECT_EQ(test, ext4_verify_group_input_test(sb, &input), -EIO);
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 2ecd758be38e..5e3b4e9f99f8 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -181,7 +181,8 @@ static int verify_group_input(struct super_block *sb,
 	else if (input->reserved_blocks > input->blocks_count / 5)
 		ext4_warning(sb, "Reserved blocks too high (%u)",
 			     input->reserved_blocks);
-	else if (free_blocks_count < 0)
+	else if (input->blocks_count > EXT4_BLOCKS_PER_GROUP(sb) ||
+		 free_blocks_count < 0)
 		ext4_warning(sb, "Bad blocks count %u",
 			     input->blocks_count);
 	else if (IS_ERR(bh = ext4_sb_bread(sb, end - 1, 0))) {
-- 
2.56.0.542.g3ef89b7020-goog


  parent reply	other threads:[~2026-11-12  4:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  4:46 [PATCH 00/23] ext4: lots of misc bug fixes Theodore Ts'o
2026-11-12  4:46 ` [PATCH 01/23] ext4: only update s_mount_opts when EXT4_TUNE_FL_MOUNT_OPTS is set Theodore Ts'o
2026-11-12  4:46 ` [PATCH 02/23] ext4: return -EFSBADCRC when skipping a corrupt backup superblock Theodore Ts'o
2026-11-12  4:46 ` [PATCH 03/23] ext4: don't allow enabling casefold via EXT4_IOC_SET_TUNE_SB_PARAM Theodore Ts'o
2026-11-12  4:46 ` [PATCH 04/23] ext4: persist the htree hash seed when enabling dir_index online Theodore Ts'o
2026-11-12  4:46 ` [PATCH 05/23] ext4: enforce feature prerequisites when tuning a mounted fs Theodore Ts'o
2026-11-12  4:46 ` [PATCH 06/23] ext4: handle s_lastcheck_hi in the get/set tune superblock ioctls Theodore Ts'o
2026-11-12  4:46 ` [PATCH 07/23] ext4: pass missing ioctls through ext4_compat_ioctl Theodore Ts'o
2026-11-12  4:46 ` [PATCH 08/23] ext4: fix inverted err_report_sec check in ext4_update_super() Theodore Ts'o
2026-11-12  4:46 ` [PATCH 09/23] ext4: fix err_report_sec_store() timer and value handling Theodore Ts'o
2026-11-12  4:46 ` [PATCH 10/23] ext4: fix inode table accounting in count_overhead() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 11/23] ext4: handle flex groups straddling s_first_meta_bg in online resize Theodore Ts'o
2026-11-12  4:47 ` Theodore Ts'o [this message]
2026-11-12  4:47 ` [PATCH 13/23] ext4: propagate ext4_alloc_group_tables() errors from ext4_resize_fs() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 14/23] ext4: reject online shrink before probing the device size Theodore Ts'o
2026-11-12  4:47 ` [PATCH 15/23] ext4: cap migrated extents at EXT_INIT_MAX_LEN Theodore Ts'o
2026-11-12  4:47 ` [PATCH 16/23] ext4: don't treat a handle restart as an error in finish_range() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 17/23] ext4: don't clobber the migration result in ext4_ext_migrate() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 18/23] ext4: fix EOF clamping of the range in mext_check_adjust_range() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 19/23] ext4: bound the MMP update and check intervals Theodore Ts'o
2026-11-12  4:47 ` [PATCH 20/23] ext4: fix MMP claim of a cleanly unmounted filesystem Theodore Ts'o
2026-11-12  4:47 ` [PATCH 21/23] ext4: fix device comparison overflow in ext4_getfsmap_dev_compare() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 22/23] ext4: don't allocate over indirect branches that failed to load Theodore Ts'o
2026-11-12  4:47 ` [PATCH 23/23] ext4: don't stop EXT4_IOC_GET_ES_CACHE at uncached ranges Theodore Ts'o

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=20261112044712.1577296-13-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox