From: sashiko-bot@kernel.org
To: "Guanglei Zhu" <zhugl3@xiaopeng.com>,
"Paul Cercueil" <paul@crapouillou.net>,
"Harvey Hunt" <harveyhuntnexus@gmail.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>
Cc: "Richard Weinberger" <richard@nod.at>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
linux-mtd@lists.infradead.org, "Weibin Liu" <liuwb@xiaopeng.com>
Subject: Re: [PATCH 1/2] mtd: rawnand: ingenic: validate BCH error index in jz4725b_correct()
Date: Thu, 05 Nov 2026 04:10:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-198542@kernel.org> (raw)
In-Reply-To: <20261105040153.66597-1-zhugl3@xiaopeng.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: rawnand: ingenic: jz4725b_correct() rejects parity bitflips with -EBADMSG
--
commit 2ec6f1cdbda7137d56bda90c1d422ad8f955d1df
Author: Weibin Liu <liuwb@xiaopeng.com>
mtd: rawnand: ingenic: validate BCH error index in jz4725b_correct()
This commit adds a bounds check on the decoded bit error index in
jz4725b_correct() to prevent writing past the end of the data buffer when the
BCH controller reports an index >= params->size * 8, returning -EBADMSG
instead.
> diff --git a/drivers/mtd/nand/raw/ingenic/jz4725b_bch.c b/drivers/mtd/nand/raw/ingenic/jz4725b_bch.c
> index 2d0e0a2192ae4..727f135f381e4 100644
> --- a/drivers/mtd/nand/raw/ingenic/jz4725b_bch.c
> +++ b/drivers/mtd/nand/raw/ingenic/jz4725b_bch.c
> @@ -259,6 +259,11 @@ static int jz4725b_correct(struct ingenic_ecc *bch,
> bit = (reg & BCH_BHERR_INDEX0_MASK) >> BCH_BHERR_INDEX0_SHIFT;
> }
>
> + if (bit >= params->size * 8) {
> + ret = -EBADMSG;
> + goto out;
> + }
[Severity: High]
Does returning -EBADMSG when bit >= params->size * 8 cause valid pages with a
correctable bitflip in the OOB ECC parity bytes to fail with an uncorrectable
ECC error?
In jz4725b_bch_reset(), the hardware decode count is programmed to cover both
the data area and the ECC parity area:
drivers/mtd/nand/raw/ingenic/jz4725b_bch.c:jz4725b_bch_reset() {
...
reg = params->size << BCH_BHCNT_ENC_COUNT_SHIFT;
reg |= (params->size + params->bytes) << BCH_BHCNT_DEC_COUNT_SHIFT;
writel(reg, bch->base + BCH_BHCNT);
...
}
And jz4725b_correct() feeds both buf and ecc_code into the BCH engine as a
single codeword of (params->size + params->bytes) * 8 bits:
drivers/mtd/nand/raw/ingenic/jz4725b_bch.c:jz4725b_correct() {
...
jz4725b_bch_write_data(bch, buf, params->size);
jz4725b_bch_write_data(bch, ecc_code, params->bytes);
...
}
When a normal, correctable bitflip occurs on flash within the ECC parity bytes
themselves, the hardware reports a bit index in the range
[params->size * 8, (params->size + params->bytes) * 8) without setting
BCH_BHINT_UNCOR.
With this check, a bitflip in the parity region causes jz4725b_correct() to
abort the correction loop early (potentially leaving remaining data bitflips
in later BCH_BHERRn entries uncorrected) and return -EBADMSG to
ingenic_nand_ecc_correct(), incrementing mtd->ecc_stats.failed.
Should bit indices in the parity region simply skip modifying buf (while still
counting the bitflip or continuing the loop, similar to jz4740_ecc_correct()),
or only return -EBADMSG if bit >= (params->size + params->bytes) * 8?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261105040153.66597-1-zhugl3@xiaopeng.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-11-05 4:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 4:01 [PATCH 1/2] mtd: rawnand: ingenic: validate BCH error index in jz4725b_correct() Guanglei Zhu
2026-11-05 4:01 ` [PATCH 2/2] mtd: rawnand: ingenic: validate BCH error index in jz4780_correct() Guanglei Zhu
2026-11-05 4:15 ` sashiko-bot
2026-11-05 4:10 ` sashiko-bot [this message]
2026-11-05 4:24 ` [PATCH v2 1/2] mtd: rawnand: ingenic: validate BCH error index in jz4725b_correct() Guanglei Zhu
2026-11-05 4:24 ` [PATCH v2 2/2] mtd: rawnand: ingenic: validate BCH error index in jz4780_correct() Guanglei Zhu
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=sashiko-outbox-198542@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=harveyhuntnexus@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=liuwb@xiaopeng.com \
--cc=miquel.raynal@bootlin.com \
--cc=paul@crapouillou.net \
--cc=richard@nod.at \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vigneshr@ti.com \
--cc=zhugl3@xiaopeng.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