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 06/23] ext4: handle s_lastcheck_hi in the get/set tune superblock ioctls
Date: Wed, 11 Nov 2026 23:46:55 -0500 [thread overview]
Message-ID: <20261112044712.1577296-7-tytso@mit.edu> (raw)
In-Reply-To: <20261112044712.1577296-1-tytso@mit.edu>
struct ext4_tune_sb_params exposes last_check_time as a __u64, and the
superblock stores the time of the last check as a 40-bit value split
between s_lastcheck and s_lastcheck_hi. However,
EXT4_IOC_GET_TUNE_SB_PARAM only reports s_lastcheck, and
EXT4_IOC_SET_TUNE_SB_PARAM only writes s_lastcheck, leaving any
existing s_lastcheck_hi in place.
So timestamps past 2106 are truncated when read, and setting the last
check time on a file system whose s_lastcheck_hi is non-zero results
in a timestamp that is off by a multiple of 2^32 seconds, which
confuses the time-based fsck check in ext4_setup_super() and e2fsck.
Read and write s_lastcheck_hi along with s_lastcheck, and reject
values which don't fit in the 40-bit on-disk representation.
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 | 62 ++++++++++++++++++++++++++++++++++++++++++++
fs/ext4/ioctl.c | 12 +++++++--
2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ioctl-test.c b/fs/ext4/ioctl-test.c
index fd7b4ff2cd81..831b7e032fad 100644
--- a/fs/ext4/ioctl-test.c
+++ b/fs/ext4/ioctl-test.c
@@ -17,6 +17,7 @@
#include <linux/iversion.h>
#include <linux/kernel.h>
#include <linux/mm.h>
+#include <linux/mman.h>
#include <linux/module.h>
#include <linux/mount.h>
#include <linux/part_stat.h>
@@ -27,6 +28,7 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/timer.h>
+#include <linux/uaccess.h>
#include <linux/uuid.h>
#include <linux/workqueue.h>
@@ -889,6 +891,65 @@ static void test_tune_sb_feature_prereqs(struct kunit *test)
KUNIT_EXPECT_EQ(test, sbi->s_csum_seed, seed);
}
+/*
+ * Verify that last_check_time is validated against, stored to, and
+ * reported from the 40-bit s_lastcheck / s_lastcheck_hi timestamp.
+ */
+static void test_tune_sb_last_check_time(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;
+ struct vfsmount mnt = {
+ .mnt_root = sb->s_root,
+ .mnt_sb = sb,
+ .mnt_idmap = &nop_mnt_idmap,
+ };
+ struct file filp = {
+ .f_inode = d_inode(sb->s_root),
+ .f_path = {
+ .mnt = &mnt,
+ .dentry = sb->s_root,
+ },
+ .f_mode = FMODE_READ,
+ };
+ unsigned long uaddr;
+
+ memset(¶ms, 0, sizeof(params));
+ params.set_flags = EXT4_TUNE_FL_LAST_CHECK_TIME;
+ params.last_check_time = 1ULL << 40;
+ KUNIT_EXPECT_EQ(test, ext4_validate_tune_sb_params_test(sb, ¶ms),
+ -EINVAL);
+
+ params.last_check_time = 0x123456789aULL;
+ KUNIT_EXPECT_EQ(test, ext4_validate_tune_sb_params_test(sb, ¶ms),
+ 0);
+ es->s_lastcheck_hi = 0xff;
+ ext4_sb_setparams_test(sbi, es, ¶ms);
+ KUNIT_EXPECT_EQ(test, le32_to_cpu(es->s_lastcheck), 0x3456789aU);
+ KUNIT_EXPECT_EQ(test, es->s_lastcheck_hi, 0x12);
+
+ /* EXT4_IOC_GET_TUNE_SB_PARAM reports all 40 bits */
+ uaddr = kunit_vm_mmap(test, NULL, 0, PAGE_SIZE,
+ PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, 0);
+ KUNIT_ASSERT_NE_MSG(test, uaddr, 0UL, "Could not create user mm");
+ KUNIT_ASSERT_LT_MSG(test, uaddr, (unsigned long)TASK_SIZE,
+ "Failed to allocate user memory");
+
+ KUNIT_ASSERT_EQ(test,
+ ext4_ioctl(&filp, EXT4_IOC_GET_TUNE_SB_PARAM, uaddr),
+ 0);
+ memset(¶ms, 0, sizeof(params));
+ KUNIT_ASSERT_EQ(test,
+ copy_from_user(¶ms, (void __user *)uaddr,
+ sizeof(params)),
+ 0UL);
+ KUNIT_EXPECT_EQ(test, params.last_check_time, 0x123456789aULL);
+}
+
/*
* Verify ext4_update_backup_sb, ext4_update_superblocks_fn, and
* ext4_update_overhead across primary + 4 sparse_super backup groups (1, 3,
@@ -1398,6 +1459,7 @@ static struct kunit_case ioctl_test_cases[] = {
KUNIT_CASE(test_tune_sb_mount_opts_guard),
KUNIT_CASE(test_tune_sb_dir_index_hash_state),
KUNIT_CASE(test_tune_sb_feature_prereqs),
+ KUNIT_CASE(test_tune_sb_last_check_time),
KUNIT_CASE(test_update_superblocks_and_overhead),
KUNIT_CASE(test_update_backup_sb_bad_csum),
KUNIT_CASE(test_swap_inode_data_and_seed),
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 8bd4958217e0..9e2bde83a033 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1308,7 +1308,8 @@ static int ext4_ioctl_get_tune_sb(struct ext4_sb_info *sbi,
ret.mnt_count = le16_to_cpu(es->s_mnt_count);
ret.max_mnt_count = le16_to_cpu(es->s_max_mnt_count);
ret.checkinterval = le32_to_cpu(es->s_checkinterval);
- ret.last_check_time = le32_to_cpu(es->s_lastcheck);
+ ret.last_check_time = ((u64)es->s_lastcheck_hi << 32) |
+ le32_to_cpu(es->s_lastcheck);
ret.reserved_blocks = ext4_r_blocks_count(es);
ret.blocks_count = ext4_blocks_count(es);
ret.reserved_uid = ext4_get_resuid(es);
@@ -1347,8 +1348,10 @@ static void ext4_sb_setparams(struct ext4_sb_info *sbi,
es->s_max_mnt_count = cpu_to_le16(params->max_mnt_count);
if (params->set_flags & EXT4_TUNE_FL_CHECKINTRVAL)
es->s_checkinterval = cpu_to_le32(params->checkinterval);
- if (params->set_flags & EXT4_TUNE_FL_LAST_CHECK_TIME)
+ if (params->set_flags & EXT4_TUNE_FL_LAST_CHECK_TIME) {
es->s_lastcheck = cpu_to_le32(params->last_check_time);
+ es->s_lastcheck_hi = upper_32_bits(params->last_check_time);
+ }
if (params->set_flags & EXT4_TUNE_FL_RESERVED_BLOCKS) {
ext4_fsblk_t blk = params->reserved_blocks;
@@ -1432,6 +1435,11 @@ static int ext4_validate_tune_sb_params(struct super_block *sb,
(params->errors_behavior > EXT4_ERRORS_PANIC))
return -EINVAL;
+ /* s_lastcheck{,_hi} hold a 40-bit timestamp */
+ if ((params->set_flags & EXT4_TUNE_FL_LAST_CHECK_TIME) &&
+ (params->last_check_time >> 40))
+ return -EINVAL;
+
if ((params->set_flags & EXT4_TUNE_FL_RESERVED_BLOCKS) &&
(params->reserved_blocks > ext4_blocks_count(sbi->s_es) / 2))
return -EINVAL;
--
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 ` [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 ` Theodore Ts'o [this message]
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-7-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