linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Zhen <zhenzhang.zhang@huawei.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: MTD Maling List <linux-mtd@lists.infradead.org>,
	adrian.hunter@intel.com, Artem Bityutskiy <dedekind1@gmail.com>
Subject: Re: [PATCH] ubifs: replace simple_strtoul() with kstrtoul()
Date: Mon, 19 May 2014 17:49:21 +0800	[thread overview]
Message-ID: <5379D3A1.8050703@huawei.com> (raw)
In-Reply-To: <CAMuHMdXoJKgzfyo6OcLz1SaTO_zCuvwM8iu-cNt6msvVSRCFKA@mail.gmail.com>

On 2014/5/19 17:13, Geert Uytterhoeven wrote:
> Please don't add mindless casts!
> 
> On Mon, May 19, 2014 at 5:26 AM, Zhang Zhen <zhenzhang.zhang@huawei.com> wrote:
>> --- a/fs/ubifs/super.c
>> +++ b/fs/ubifs/super.c
>> @@ -1905,6 +1905,7 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>>         struct ubi_volume_desc *ubi;
>>         int dev, vol;
> 
> dev is int
> 
>>         char *endptr;
>> +       int ret;
>>
>>         /* First, try to open using the device node path method */
>>         ubi = ubi_open_volume_path(name, mode);
>> @@ -1922,7 +1923,10 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>>         if (!isdigit(name[3]))
>>                 return ERR_PTR(-EINVAL);
>>
>> -       dev = simple_strtoul(name + 3, &endptr, 0);
>> +       endptr = (char *)name + 3;
>> +       ret = kstrtoul(endptr, 0, (unsigned long *)&dev);
> 
> On 64-bit, long is 64-bit, hence this will write beyond dev and will corrupt
> the stack.
> 
Yeah, you are right. This really may write beyond dev.

The kstrtoul(const char *s, unsigned int base, unsigned long *res) only accept unsigned long
pointer as the third parameter.
And the original function simple_strtoul() returns unsigned long type value.
It is also cast. So this may not corrupt the stack.

Or do you have any better suggestion about this?
Thanks.

>> +       if (ret)
>> +               return ERR_PTR(-EINVAL);
>>
>>         /* ubiY method */
>>         if (*endptr == '\0')
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
> 
> 

  reply	other threads:[~2014-05-19  9:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1400469756-18212-1-git-send-email-zhenzhang.zhang@huawei.com>
2014-05-19  3:26 ` [PATCH] ubifs: replace simple_strtoul() with kstrtoul() Zhang Zhen
2014-05-19  9:13   ` Geert Uytterhoeven
2014-05-19  9:49     ` Zhang Zhen [this message]
2014-05-20  6:53       ` Geert Uytterhoeven
2014-05-20  6:57         ` Geert Uytterhoeven
2014-05-20  8:14           ` Zhang Zhen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5379D3A1.8050703@huawei.com \
    --to=zhenzhang.zhang@huawei.com \
    --cc=adrian.hunter@intel.com \
    --cc=dedekind1@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).