From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: linux-mtd@lists.infradead.org,
Marek Vasut <marek.vasut@gmail.com>,
Richard Weinberger <richard@nod.at>,
linux-kernel@vger.kernel.org,
Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>,
Brian Norris <computersforpeace@gmail.com>,
David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH] mtd: nand: check ecc->total sanity in nand_scan_tail
Date: Mon, 29 May 2017 20:40:49 +0200 [thread overview]
Message-ID: <20170529204049.25cb8c30@bbrezillon> (raw)
In-Reply-To: <1495687820-30692-1-git-send-email-yamada.masahiro@socionext.com>
On Thu, 25 May 2017 13:50:20 +0900
Masahiro Yamada <yamada.masahiro@socionext.com> wrote:
> Drivers are supposed to set correct ecc->{size,strength,bytes} before
> calling nand_scan_tail(), but it does not complain about ecc->total
> bigger than oobsize.
>
> In this case, chip->scan_bbt() crashes due to memory corruption, but
> it is hard to debug. It would be kind to fail it earlier with a clear
> message.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Applied to nand/next.
Thanks,
Boris
> ---
>
> I was actually hit by this case.
>
> I wasted half a day until I figured out my coding mistake in my
> Denali driver. It will be helpful to check this in NAND core.
>
>
> drivers/mtd/nand/nand_base.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index f4d686192717..14d6a5aa3ee8 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -4970,6 +4970,11 @@ int nand_scan_tail(struct mtd_info *mtd)
> goto err_free;
> }
> ecc->total = ecc->steps * ecc->bytes;
> + if (ecc->total > mtd->oobsize) {
> + WARN(1, "Total number of ECC bytes exceeded oobsize\n");
> + ret = -EINVAL;
> + goto err_free;
> + }
>
> /*
> * The number of bytes available for a client to place data into
prev parent reply other threads:[~2017-05-29 18:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-25 4:50 [PATCH] mtd: nand: check ecc->total sanity in nand_scan_tail Masahiro Yamada
2017-05-29 18:40 ` 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=20170529204049.25cb8c30@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=richard@nod.at \
--cc=yamada.masahiro@socionext.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;
as well as URLs for NNTP newsgroup(s).