[Devel] [PATCH hci-8.2 5/8] ms/ext4: implemet new ioctls to set and get superblock parameters

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Thu Nov 19 15:13:03 MSK 2026


Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] ext4: set_tune_sb generates dir_index hash seed in memory
  only, never persisted
- [Medium] ext4: tune ioctl enables casefold online without loading
  sb->s_encoding
- [Low] ext4: tune_sb ioctls missing from ext4_compat_ioctl() whitelist
- [Low] ext4: set_tune_sb does not refresh cached sbi resuid/resgid
- [Low] ext4: tune_sb ioctls read superblock fields without
  lock_buffer()
--

commit f990ab6fe39977af5cf64ce3b68662bdc273a9bd
Author: Theodore Ts'o <tytso at mit.edu>

ms/ext4: implemet new ioctls to set and get superblock parameters

This adds the EXT4_IOC_GET_TUNE_SB_PARAM and EXT4_IOC_SET_TUNE_SB_PARAM
ioctls. They let selected superblock parameters be read and changed on a
mounted file system without write access to the block device.

> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index 9547991447515..578a97f4c63d8 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c

[ ... ]

> +static int ext4_ioctl_get_tune_sb(struct ext4_sb_info *sbi,
> +				  struct ext4_tune_sb_params __user *params)
> +{
> +	struct ext4_tune_sb_params ret;
> +	struct ext4_super_block *es = sbi->s_es;
> +
> +	memset(&ret, 0, sizeof(ret));
> +	ret.set_flags = TUNE_OPS_SUPPORTED;
> +	ret.errors_behavior = le16_to_cpu(es->s_errors);

[Severity: Low]
Should this read es under lock_buffer(sbi->s_sbh), the way
ext4_ioctl_getuuid() does?  A concurrent SET modifies es under that lock,
so GET can return a torn snapshot.  ext4_ioctl_set_tune_sb() has the same
issue when it derives the feature set/clear masks from es->s_feature_*
without the lock.

[ ... ]

> +	if (params->set_flags & EXT4_TUNE_FL_RESERVED_UID) {
> +		int uid = params->reserved_uid;
> +
> +		es->s_def_resuid = cpu_to_le16(uid & 0xFFFF);
> +		es->s_def_resuid_hi = cpu_to_le16(uid >> 16);
> +	}

[Severity: Low]
Does this take effect on the running file system?  Only the on-disk
superblock is updated.  The allocator uses sbi->s_resuid and
sbi->s_resgid, which are loaded at mount time and not refreshed here.  The
ioctl returns success, but the reserved-block uid/gid (and the gid
equivalent below) stay unchanged until remount.

[ ... ]

> +		if ((params.set_feature_incompat_mask &
> +		     EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
> +			enabling_casefold = 1;
> +			if (!(params.set_flags & EXT4_TUNE_FL_ENCODING)) {
> +				params.encoding = EXT4_ENC_UTF8_12_1;

[Severity: Medium]
Does enabling casefold online leave sb->s_encoding NULL?  Only the on-disk
s_encoding and s_encoding_flags are written.  sb->s_encoding is set only
at mount time in ext4_encoding_init(), and that does not run again.

After this ioctl, an unprivileged owner of an empty directory can run
chattr +F, because ext4_ioctl_setflags() checks the live
ext4_has_feature_casefold(sb).  The next lookup or create in that
directory reaches ext4_fname_setup_ci_filename() and calls
utf8_casefold(dir->i_sb->s_encoding, ...) with a NULL map.  That is a NULL
pointer dereference in utf8byte()/utf8lookup().  Should the ioctl load the
encoding (utf8_load()) or reject enabling casefold on a mounted file
system?

> +		if ((params.set_feature_compat_mask &
> +		     EXT4_FEATURE_COMPAT_DIR_INDEX)) {
> +			uuid_t	uu;
> +
> +			memcpy(&uu, sbi->s_hash_seed, UUID_SIZE);
> +			if (uuid_is_null(&uu))
> +				generate_random_uuid((char *)
> +						     &sbi->s_hash_seed);

[Severity: Medium]
Is the generated hash seed ever persisted?  It goes only into
sbi->s_hash_seed.  ext4_sb_setparams() copies s_def_hash_version (and the
checksum seed) but never writes es->s_hash_seed, and it does not set
EXT2_FLAGS_SIGNED_HASH or EXT2_FLAGS_UNSIGNED_HASH in es->s_flags either.

Htree directories created in this mount are hashed with the in-memory
seed.  After remount the all-zero seed is reloaded from disk, so lookups
in those directories can fail.

These sbi fields are also changed before mnt_want_write_file() and before
the superblock update, with no lock and no rollback if the update fails.

[ ... ]

> +	ret = ext4_update_superblocks_fn(sb, ext4_sb_setparams, &params);
> +	mnt_drop_write_file(filp);
> +
> +	if (params.set_flags & EXT4_TUNE_FL_DEF_HASH_ALG)
> +		sbi->s_def_hash_version = params.def_hash_alg;

[Severity: Medium]
Should this assignment be conditional on ret being 0?  As written, the
in-core hash version is changed even when ext4_update_superblocks_fn()
failed, so memory and disk disagree.

[ ... ]

> @@ -1795,6 +2087,11 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  		return ext4_ioctl_getuuid(EXT4_SB(sb), (void __user *)arg);
>  	case EXT4_IOC_SETFSUUID:
>  		return ext4_ioctl_setuuid(filp, (const void __user *)arg);
> +	case EXT4_IOC_GET_TUNE_SB_PARAM:
> +		return ext4_ioctl_get_tune_sb(EXT4_SB(sb),
> +					      (void __user *)arg);
> +	case EXT4_IOC_SET_TUNE_SB_PARAM:
> +		return ext4_ioctl_set_tune_sb(filp, (void __user *)arg);

[Severity: Low]
Should the two new commands also be added to the whitelist in
ext4_compat_ioctl(), next to EXT4_IOC_GETFSUUID and EXT4_IOC_SETFSUUID?
Without that, a 32-bit caller (for example a 32-bit tune2fs) on a 64-bit
kernel gets -ENOTTY from both ioctls, so the new interface is unusable for
it.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261119120325.792064-1-den@openvz.org?part=5



More information about the Devel mailing list