From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: chenwy <chenwy-fnst@cn.fujitsu.com>
Cc: <linux-mtd@lists.infradead.org>,
fnstml-fjl@cn.fujitsu.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mtdram: check offs and len where appropriate
Date: Wed, 29 Mar 2017 17:19:12 +0200 [thread overview]
Message-ID: <20170329171912.52327b15@bbrezillon> (raw)
In-Reply-To: <20170317022939.5511-1-chenwy-fnst@cn.fujitsu.com>
On Fri, 17 Mar 2017 10:29:39 +0800
chenwy <chenwy-fnst@cn.fujitsu.com> wrote:
> We should prevent user to operating mtd device with
> an illegal offset or length.
I realize that all the tests you do here are already done in mtdcore.c.
If one is missing, please patch mtdcore.c instead.
Thanks,
Boris
>
> Signed-off-by: Chen Wenyong <chenwy-fnst@cn.fujitsu.com>
> ---
> drivers/mtd/devices/mtdram.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
> index cbd8547..83e1603 100644
> --- a/drivers/mtd/devices/mtdram.c
> +++ b/drivers/mtd/devices/mtdram.c
> @@ -58,6 +58,10 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
> {
> if (check_offs_len(mtd, instr->addr, instr->len))
> return -EINVAL;
> + if (mtd->size < (instr->len + instr->addr) || instr->addr < 0
> + || instr->len < 0)
> + return -EINVAL;
> +
> memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
> instr->state = MTD_ERASE_DONE;
> mtd_erase_callback(instr);
> @@ -67,6 +71,9 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
> static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
> size_t *retlen, void **virt, resource_size_t *phys)
> {
> + if (mtd->size < (len + from) || from < 0 || len < 0)
> + return -EINVAL;
> +
> *virt = mtd->priv + from;
> *retlen = len;
> return 0;
> @@ -74,6 +81,9 @@ static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
>
> static int ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
> {
> + if (mtd->size < (len + from) || from < 0 || len < 0)
> + return -EINVAL;
> +
> return 0;
> }
>
> @@ -93,6 +103,9 @@ static unsigned long ram_get_unmapped_area(struct mtd_info *mtd,
> static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
> size_t *retlen, u_char *buf)
> {
> + if (mtd->size < (len + from) || from < 0 || len < 0)
> + return -EINVAL;
> +
> memcpy(buf, mtd->priv + from, len);
> *retlen = len;
> return 0;
> @@ -101,6 +114,9 @@ static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
> static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
> size_t *retlen, const u_char *buf)
> {
> + if (mtd->size < (len + to) || to < 0 || len < 0)
> + return -EINVAL;
> +
> memcpy((char *)mtd->priv + to, buf, len);
> *retlen = len;
> return 0;
prev parent reply other threads:[~2017-03-29 15:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-17 2:29 [PATCH v2] mtdram: check offs and len where appropriate chenwy
2017-03-29 15:19 ` Boris Brezillon [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=20170329171912.52327b15@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=chenwy-fnst@cn.fujitsu.com \
--cc=fnstml-fjl@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.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