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

From: Alexey Dobriyan
Date: Sat Jan 27 2024 - 04:44:25 EST


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);