From: Miquel Raynal <miquel.raynal@bootlin.com>
To: yangerkun <yangerkun@huawei.com>
Cc: patrick@baymotion.com, zhongguohua1@huawei.com,
joern@lazybastard.org, linux-mtd@lists.infradead.org,
richard@nod.at
Subject: Re: [PATCH] mtd: phram: use div_u64_rem to stop overwrite len in phram_setup
Date: Mon, 25 Jan 2021 09:53:31 +0100 [thread overview]
Message-ID: <20210125095331.2abf626e@xps13> (raw)
In-Reply-To: <527f4357-16a6-2561-81c2-20127eabd68c@huawei.com>
Hello,
yangerkun <yangerkun@huawei.com> wrote on Mon, 25 Jan 2021 16:36:50
+0800:
> 在 2021/1/25 16:28, Miquel Raynal 写道:
> > Hi yangerkun,
> >
> > yangerkun <yangerkun@huawei.com> wrote on Mon, 25 Jan 2021 13:48:32
> > +0800:
> >
> >> Hi,
> >>
> >> Recheck the patch, and it seems we need check erasesize to prevent DIV/0...
> >
> > Can you elaborate a little bit?
> >
> > The do_div() != 0 has been replaced by the 'rem' condition and it seems
> > good to me. So please tell me what division by zero you are talking
> > about because the beginning of the if condition is "len == 0 ||
> > erasesize == 0 || erasesize > len", so it does already take care of
> > this situation.
>
> The patch I send show as follow:
>
> --- a/drivers/mtd/devices/phram.c
> +++ b/drivers/mtd/devices/phram.c
> @@ -222,6 +222,7 @@ static int phram_setup(const char *val)
> uint64_t start;
> uint64_t len;
> uint64_t erasesize = PAGE_SIZE;
> + uint32_t rem;
> int i, ret;
>
> if (strnlen(val, sizeof(buf)) >= sizeof(buf))
> @@ -263,8 +264,9 @@ static int phram_setup(const char *val)
> }
> }
>
> + div_u64_rem(len, (uint32_t)erasesize, &rem);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oh right this has been moved before the checks, please send a v2 then.
> Once user set erasesize == 0, the div_u64_rem will trigger the
> DIV/0...
>
> if (len == 0 || erasesize == 0 || erasesize > len
> - || erasesize > UINT_MAX || do_div(len, (uint32_t)erasesize) != 0) {
> + || erasesize > UINT_MAX || rem) {
> parse_err("illegal erasesize or len\n");
> goto error;
> }
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
prev parent reply other threads:[~2021-01-25 8:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-30 2:17 [PATCH] mtd: phram: use div_u64_rem to stop overwrite len in phram_setup yangerkun
2021-01-04 10:08 ` Miquel Raynal
2021-01-04 10:18 ` Miquel Raynal
2021-01-25 5:48 ` yangerkun
2021-01-25 8:28 ` Miquel Raynal
2021-01-25 8:36 ` yangerkun
2021-01-25 8:53 ` Miquel Raynal [this message]
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=20210125095331.2abf626e@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=joern@lazybastard.org \
--cc=linux-mtd@lists.infradead.org \
--cc=patrick@baymotion.com \
--cc=richard@nod.at \
--cc=yangerkun@huawei.com \
--cc=zhongguohua1@huawei.com \
/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