[PATCH] afs: Replace simple_strtoul with kstrtoul in afs_parse_address
Su Hui
suhui at nfschina.com
Fri May 30 03:29:27 PDT 2025
On 5/30/25 7:35 AM, Jeffrey E Altman wrote:
> On 5/27/2025 4:49 AM, Su Hui wrote:
>> kstrtoul() is better because simple_strtoul() ignores overflow which
>> may lead to unexpected results.
>>
>> Signed-off-by: Su Hui<suhui at nfschina.com>
>> ---
>>
> Su Hui,
>
> Thank you for the contribution but I do not believe this patch is
> correct.
>
Oh, really sorry for my stupid mistake. Thanks for your review too :) .
> The second block is required even if the simple_stroul() is replaced
> by kstrtoul() as it protects against an input string which does not
> contain the optional subnet mask but has some other characters after
> the address.
>
> afs_parse_address() already has its own overflow checks following the
> simple_strtoul() call which is specific to the interpretation of the
> allowed subnet mask values.
Agreed, it's my fault that I only see the pattern about
'simple_strtoxx(....)' and 'if (*p)'.....
>
> Do you see an overflow condition which would not be caught by those
> checks which would be caught by use of kstrtoul()?
Actually, no example in reality.
If p can equal to '0xffffffffffffffff0000000000000001', simple_strtoul()
and kstroul() all transform 'p' to unsigned long value '0x1'.
But kstrtoul() return an error and we can know overflow happens. If 'p'
can be a very long string, kstroul() make sense.
Su Hui
More information about the linux-afs
mailing list