OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: "Denis V. Lunev" <den@openvz.org>,
	ptikhomirov@virtuozzo.com, vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.2 5/8] ms/ext4: implemet new ioctls to set and get superblock parameters
Date: Thu, 19 Nov 2026 12:13:03 +0000	[thread overview]
Message-ID: <010701a1f3b981e9-116787cf-f549-4d3f-b955-58b3acc704c8-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261119120325.792064-6-den@openvz.org>

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@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

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-11-19 12:14 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:03 [Devel] [PATCH hci-8.2 0/8] ext4: port the " Denis V. Lunev
2026-11-19 12:03 ` [Devel] [PATCH hci-8.2 1/8] ms/ext4: avoid potential buffer over-read in parse_apply_sb_mount_options() Denis V. Lunev
2026-11-19 12:07   ` no-reply
2026-11-19 16:49   ` Konstantin Khorenko
2026-11-19 12:03 ` [Devel] [PATCH hci-8.2 2/8] ms/ext4: fix string copying " Denis V. Lunev
2026-11-19 12:08   ` no-reply
2026-11-19 16:49   ` Konstantin Khorenko
2026-11-19 12:03 ` [Devel] [PATCH hci-8.2 3/8] ms/ext4: add support for 32-bit default reserved uid and gid values Denis V. Lunev
2026-11-19 12:09   ` no-reply
2026-11-19 16:49   ` Konstantin Khorenko
2026-11-19 12:03 ` [Devel] [PATCH hci-8.2 4/8] ms/ext4: fix incorrect function call when initializing s_resgid Denis V. Lunev
2026-11-19 12:08   ` no-reply
2026-11-19 16:49   ` Konstantin Khorenko
2026-11-19 12:03 ` [Devel] [PATCH hci-8.2 5/8] ms/ext4: implemet new ioctls to set and get superblock parameters Denis V. Lunev
2026-11-19 12:13   ` no-reply [this message]
2026-11-19 16:49   ` Konstantin Khorenko
2026-11-19 12:03 ` [Devel] [PATCH hci-8.2 6/8] ms/ext4: check if mount_opts is NUL-terminated in ext4_ioctl_set_tune_sb() Denis V. Lunev
2026-11-19 12:10   ` no-reply
2026-11-19 16:49   ` Konstantin Khorenko
2026-11-19 12:03 ` [Devel] [PATCH hci-8.2 7/8] ms/ext4: fix ext4_tune_sb_params padding Denis V. Lunev
2026-11-19 12:11   ` no-reply
2026-11-19 16:49   ` Konstantin Khorenko
2026-11-19 12:03 ` [Devel] [PATCH hci-8.2 8/8] ms/ext4: only update tune mount options when requested Denis V. Lunev
2026-11-19 12:12   ` no-reply
2026-11-19 16:49   ` Konstantin Khorenko
2026-11-19 16:49 ` [Devel] [PATCH hci-8.2 0/8] ext4: port the ioctls to set and get superblock parameters Konstantin Khorenko
2026-11-19 16:49 ` Konstantin Khorenko

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=010701a1f3b981e9-116787cf-f549-4d3f-b955-58b3acc704c8-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=den@openvz.org \
    --cc=devel@openvz.org \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=vasileios.almpanis@virtuozzo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox