From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga03-in.huawei.com ([119.145.14.66]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WmYiQ-0005Qg-MH for linux-mtd@lists.infradead.org; Tue, 20 May 2014 01:19:39 +0000 Message-ID: <537AAD6E.6020806@huawei.com> Date: Tue, 20 May 2014 09:18:38 +0800 From: Zhang Zhen MIME-Version: 1.0 To: Geert Uytterhoeven Subject: Re: [PATCH] ubi: replace simple_strtoul() with kstrtoul() References: <1400488570-20288-1-git-send-email-zhenzhang.zhang@huawei.com> <5379C2E8.5040000@huawei.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: Hu Jianyang , MTD Maling List , adrian.hunter@intel.com, Artem Bityutskiy List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 2014/5/19 17:14, Geert Uytterhoeven wrote: > Please don't add mindless casts! > > On Mon, May 19, 2014 at 10:38 AM, Zhang Zhen wrote: >> --- a/drivers/mtd/ubi/build.c >> +++ b/drivers/mtd/ubi/build.c >> @@ -1190,10 +1190,13 @@ static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev) >> static struct mtd_info * __init open_mtd_device(const char *mtd_dev) >> { >> struct mtd_info *mtd; >> - int mtd_num; >> + int mtd_num, ret; >> char *endp; >> >> - mtd_num = simple_strtoul(mtd_dev, &endp, 0); >> + endp = (char *)mtd_dev; >> + ret = kstrtoul(endp, 0, (unsigned long *)&mtd_num); > > On 64-bit, long is 64-bit, hence this will write beyond mtd_num 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. > > 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 > >