[Devel] [PATCH hci-8.2 3/8] ms/ext4: add support for 32-bit default reserved uid and gid values
no-reply at sashiko.virtuozzo.com
no-reply at sashiko.virtuozzo.com
Thu Nov 19 15:09:05 MSK 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ext4: ext4_get_resuid()/ext4_get_resgid() shift u16 into int
sign bit
--
commit da23b39c3b9f8774c5ca33e7852c644658a23aee
Author: Theodore Ts'o <tytso at mit.edu>
ms/ext4: add support for 32-bit default reserved uid and gid values
The patch adds s_def_resuid_hi and s_def_resgid_hi to the ext4 superblock,
carved out of s_reserved[]. It adds ext4_get_resuid() and ext4_get_resgid()
helpers that combine the low and high halves. It then uses the helpers in
_ext4_show_options() and __ext4_fill_super().
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 3de0fc6e77f2..e9d1b471a8cc 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
[ ... ]
> +static inline int ext4_get_resuid(struct ext4_super_block *es)
> +{
> + return le16_to_cpu(es->s_def_resuid) |
> + le16_to_cpu(es->s_def_resuid_hi) << 16;
> +}
> +
> +static inline int ext4_get_resgid(struct ext4_super_block *es)
> +{
> + return le16_to_cpu(es->s_def_resgid) |
> + le16_to_cpu(es->s_def_resgid_hi) << 16;
> +}
[Severity: Low]
Can the shift overflow a signed int here? The u16 high half is promoted
to int, so a value of 0x8000 or more shifts into the sign bit. That is
undefined behaviour, and UBSAN could report it. The helpers also return
int.
In practice the bit pattern survives the conversion to uid_t/gid_t.
Would it be cleaner to return u32 and cast the high half to u32 before
shifting?
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index bf42593efcea..a6581dee49ed 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
[ ... ]
> - sbi->s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));
> - sbi->s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));
> + sbi->s_resuid = make_kuid(&init_user_ns, ext4_get_resuid(es));
> + sbi->s_resgid = make_kgid(&init_user_ns, ext4_get_resuid(es));
[Severity: Medium]
Should the second line call ext4_get_resgid()? As written, s_resgid is
filled from the default resuid, so the default reserved gid is wrong
whenever s_def_resuid and s_def_resgid differ. The resgid= value shown
in /proc/mounts is wrong in the same case.
Carry the trailer below into the next revision and Sashiko will not review this patch again.
Reviewed-by: Sashiko <no-reply at sashiko.virtuozzo.com>
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261119120325.792064-1-den@openvz.org?part=3
More information about the Devel
mailing list