From: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
To: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
David Woodhouse <dwmw2@infradead.org>,
Brian Norris <computersforpeace@gmail.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-mtd@lists.infradead.org>
Subject: Re: [PATCH] mtd: mtdram: check offs and len in mtdram->erase
Date: Fri, 2 Oct 2015 17:39:02 +0800 [thread overview]
Message-ID: <560E50B6.5060103@cn.fujitsu.com> (raw)
In-Reply-To: <1443631303-22057-1-git-send-email-sudipm.mukherjee@gmail.com>
On 10/01/2015 12:41 AM, Sudip Mukherjee wrote:
> We should prevent user to erasing mtd device with an unaligned offset
> or length.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
>
> I am not sure if I should add the Signed-off-by of
> Dongsheng Yang <yangds.fnst@cn.fujitsu.com> . He is the original author
> and he should get the credit for that.
But I had sent a a patch out to fix this problem before your v1.
http://lists.infradead.org/pipermail/linux-mtd/2015-September/062234.html
Yang
>
> drivers/mtd/devices/mtdram.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
> index 8e28508..21b6a05 100644
> --- a/drivers/mtd/devices/mtdram.c
> +++ b/drivers/mtd/devices/mtdram.c
> @@ -32,8 +32,35 @@ MODULE_PARM_DESC(erase_size, "Device erase block size in KiB");
> // We could store these in the mtd structure, but we only support 1 device..
> static struct mtd_info *mtd_info;
>
> +static int check_offs_len(struct mtd_info *mtd, loff_t ofs, uint64_t len)
> +{
> + int ret = 0;
> + uint64_t temp_len, rem;
> +
> + /* Start address must align on block boundary */
> + temp_len = ofs;
> + rem = do_div(temp_len, mtd->erasesize);
> + if (rem) {
> + pr_debug("%s: unaligned address\n", __func__);
> + ret = -EINVAL;
> + }
> +
> + /* Length must align on block boundary */
> + temp_len = len;
> + rem = do_div(temp_len, mtd->erasesize);
> +
> + if (rem) {
> + pr_debug("%s: length not block aligned\n", __func__);
> + ret = -EINVAL;
> + }
> +
> + return ret;
> +}
> +
> static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
> {
> + if (check_offs_len(mtd, instr->addr, instr->len))
> + return -EINVAL;
> memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
> instr->state = MTD_ERASE_DONE;
> mtd_erase_callback(instr);
>
next prev parent reply other threads:[~2015-10-02 9:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-30 16:41 [PATCH] mtd: mtdram: check offs and len in mtdram->erase Sudip Mukherjee
2015-10-02 9:39 ` Dongsheng Yang [this message]
2015-10-02 10:01 ` Sudip Mukherjee
2015-10-02 17:38 ` Brian Norris
2015-10-03 3:31 ` Dongsheng Yang
2015-10-03 5:42 ` Sudip Mukherjee
-- strict thread matches above, loose matches on Subject: below --
2015-07-21 8:30 Dongsheng Yang
2015-09-29 22:44 ` Brian Norris
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=560E50B6.5060103@cn.fujitsu.com \
--to=yangds.fnst@cn.fujitsu.com \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=sudipm.mukherjee@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.