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 01/23] ext4: only update s_mount_opts when EXT4_TUNE_FL_MOUNT_OPTS is set
Date: Wed, 11 Nov 2026 23:46:50 -0500 [thread overview]
Message-ID: <20261112044712.1577296-2-tytso@mit.edu> (raw)
In-Reply-To: <20261112044712.1577296-1-tytso@mit.edu>
Every field written by ext4_sb_setparams() is guarded by its
EXT4_TUNE_FL_* bit in params->set_flags, except for s_mount_opts,
which is unconditionally overwritten with params->mount_opts.
Likewise, ext4_validate_tune_sb_params() rejects an unterminated
mount_opts string even when the caller is not asking to change it.
As a result, any EXT4_IOC_SET_TUNE_SB_PARAM call that tunes an
unrelated field (e.g. errors behavior or the reserved block count)
with a zeroed mount_opts silently wipes the default mount options
stored in the primary and all backup superblocks, and a caller that
leaves mount_opts uninitialized can get a spurious -E2BIG or have
stack garbage written into the superblock.
Only validate and copy mount_opts when EXT4_TUNE_FL_MOUNT_OPTS is
set.
Fixes: 04a91570ac67 ("ext4: implemet new ioctls to set and get superblock parameters")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
fs/ext4/ioctl-test.c | 40 ++++++++++++++++++++++++++++++++++++++++
fs/ext4/ioctl.c | 6 ++++--
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ioctl-test.c b/fs/ext4/ioctl-test.c
index fa31a9cc5d92..ebe4a87f17e1 100644
--- a/fs/ext4/ioctl-test.c
+++ b/fs/ext4/ioctl-test.c
@@ -597,6 +597,7 @@ static void test_validate_tune_sb_params(struct kunit *test)
/* Unterminated mount_opts -> -E2BIG */
memset(¶ms, 0, sizeof(params));
+ params.set_flags = EXT4_TUNE_FL_MOUNT_OPTS;
memset(params.mount_opts, 'a', sizeof(params.mount_opts));
KUNIT_EXPECT_EQ(test, ext4_validate_tune_sb_params_test(sb, ¶ms),
-E2BIG);
@@ -690,6 +691,44 @@ static void test_validate_tune_sb_params(struct kunit *test)
KUNIT_EXPECT_EQ(test, params.encoding_flags, 0);
}
+/*
+ * Verify that s_mount_opts is only validated and rewritten when
+ * EXT4_TUNE_FL_MOUNT_OPTS is set, so that tuning an unrelated field does
+ * not wipe the mount options stored in the superblock.
+ */
+static void test_tune_sb_mount_opts_guard(struct kunit *test)
+{
+ struct ioctl_test_ctx *ctx = test->priv;
+ struct super_block *sb = ctx->sb;
+ struct ext4_sb_info *sbi = &ctx->sbi;
+ struct ext4_super_block *es = ctx->es;
+ struct ext4_tune_sb_params params;
+
+ strscpy_pad(es->s_mount_opts, "journal_checksum");
+
+ /* Garbage in mount_opts is ignored without EXT4_TUNE_FL_MOUNT_OPTS */
+ memset(¶ms, 0, sizeof(params));
+ params.set_flags = EXT4_TUNE_FL_ERRORS_BEHAVIOR;
+ params.errors_behavior = EXT4_ERRORS_RO;
+ memset(params.mount_opts, 'a', sizeof(params.mount_opts));
+ KUNIT_EXPECT_EQ(test, ext4_validate_tune_sb_params_test(sb, ¶ms),
+ 0);
+
+ /* Tuning another field leaves s_mount_opts untouched */
+ memset(params.mount_opts, 0, sizeof(params.mount_opts));
+ ext4_sb_setparams_test(sbi, es, ¶ms);
+ KUNIT_EXPECT_EQ(test, le16_to_cpu(es->s_errors), EXT4_ERRORS_RO);
+ KUNIT_EXPECT_STREQ(test, (char *)es->s_mount_opts, "journal_checksum");
+
+ /* With EXT4_TUNE_FL_MOUNT_OPTS the new value is written */
+ params.set_flags = EXT4_TUNE_FL_MOUNT_OPTS;
+ strscpy(params.mount_opts, "nodelalloc", sizeof(params.mount_opts));
+ KUNIT_EXPECT_EQ(test, ext4_validate_tune_sb_params_test(sb, ¶ms),
+ 0);
+ ext4_sb_setparams_test(sbi, es, ¶ms);
+ KUNIT_EXPECT_STREQ(test, (char *)es->s_mount_opts, "nodelalloc");
+}
+
/*
* Verify ext4_update_backup_sb, ext4_update_superblocks_fn, and
* ext4_update_overhead across primary + 4 sparse_super backup groups (1, 3,
@@ -1150,6 +1189,7 @@ static void test_force_shutdown_and_ioctl_dispatch(struct kunit *test)
static struct kunit_case ioctl_test_cases[] = {
KUNIT_CASE(test_sb_callbacks_and_setparams),
KUNIT_CASE(test_validate_tune_sb_params),
+ KUNIT_CASE(test_tune_sb_mount_opts_guard),
KUNIT_CASE(test_update_superblocks_and_overhead),
KUNIT_CASE(test_swap_inode_data_and_seed),
KUNIT_CASE(test_immutable_dax_and_fileattr),
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 61e59c30e761..286f4a3e459a 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1374,7 +1374,8 @@ static void ext4_sb_setparams(struct ext4_sb_info *sbi,
es->s_encoding = cpu_to_le16(params->encoding);
if (params->set_flags & EXT4_TUNE_FL_ENCODING_FLAGS)
es->s_encoding_flags = cpu_to_le16(params->encoding_flags);
- strscpy_pad(es->s_mount_opts, params->mount_opts);
+ if (params->set_flags & EXT4_TUNE_FL_MOUNT_OPTS)
+ strscpy_pad(es->s_mount_opts, params->mount_opts);
if (params->set_flags & EXT4_TUNE_FL_EDIT_FEATURES) {
es->s_feature_compat |=
cpu_to_le32(params->set_feature_compat_mask);
@@ -1406,7 +1407,8 @@ static int ext4_validate_tune_sb_params(struct super_block *sb,
struct ext4_super_block *es = sbi->s_es;
int enabling_casefold = 0;
- if (strnlen(params->mount_opts, sizeof(params->mount_opts)) ==
+ if ((params->set_flags & EXT4_TUNE_FL_MOUNT_OPTS) &&
+ strnlen(params->mount_opts, sizeof(params->mount_opts)) ==
sizeof(params->mount_opts))
return -E2BIG;
--
2.56.0.542.g3ef89b7020-goog
next prev 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 ` Theodore Ts'o [this message]
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 ` [PATCH 12/23] ext4: reject EXT4_IOC_GROUP_ADD inputs larger than a block group Theodore Ts'o
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-2-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