Re: [PATCH 1/7] ext4: avoid overflow when setting values via sysfs

Alexey Dobriyan
2024-01-27T09:44:13Z

Baokun Li wrote:

> @@ -463,6 +463,8 @@ static ssize_t ext4_attr_store(struct kobject *kobj,
> ret = kstrtoul(skip_spaces(buf), 0, &t);
> if (ret)
> return ret;
> + if (t != (unsigned int)t)
> + return -EINVAL;

kstrto*() interface has variants for all standard types.
It should be changed to kstrtou32() or kstrtouint();

If you check if kstrto*() result fits into another type,
you're probably doing it wrong.

> if (a->attr_ptr == ptr_ext4_super_block_offset)
> *((__le32 *) ptr) = cpu_to_le32(t);