Re: [PATCH] mm: Replace-simple_strtoul-with-kstrtoul

From: Matthew Wilcox
Date: Thu Nov 09 2017 - 08:04:17 EST


On Thu, Nov 09, 2017 at 04:58:18PM +0530, Manjeet Pawar wrote:
> simple_strtoul() is obselete now, so using newer function kstrtoul()
>
> Signed-off-by: Manjeet Pawar <manjeet.p@xxxxxxxxxxx>
> Signed-off-by: Vinay Kumar Rijhwani <v.rijhwani@xxxxxxxxxxx>
> Signed-off-by: Rohit Thapliyal <r.thapliyal@xxxxxxxxxxx>

NAK NAK NAK.

You haven't tested this on a 64-bit big-endian machine.

> static int __init set_hashdist(char *str)
> {
> - if (!str)
> + if (!str || kstrtoul(str, 0, (unsigned long *)&hashdist))
> return 0;
> - hashdist = simple_strtoul(str, &str, 0);
> return 1;

The context missing from this patch is:

int hashdist = HASHDIST_DEFAULT;

So you're taking the address of an int and passing it to a function
which is expecting a pointer to an unsigned long. That works on a
32-bit machine because ints and longs are the same size. On a 64-bit
little-endian machine, the bits are in the right place, but kstrtoul()
will overwrite the 32 bits after the int with zeroes. On a 64-bit
big-endian machine, you'll overwrite the int that you're pointing to
with zeroes and the 32 bits after the int will have the data you're
looking for.

There's a kstrtoint(). Why would you not just use that?

Also, I'm shocked that this went through a chain of three different
sign-offs with nobody noticing the problem. Do none of you understand C?

(similar problems snipped).