From: Paul Cercueil <paul@crapouillou.net>
To: Guanglei Zhu <zhugl3@xiaopeng.com>,
harveyhuntnexus@gmail.com, miquel.raynal@bootlin.com
Cc: richard@nod.at, vigneshr@ti.com, linux-mips@vger.kernel.org,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
liuwb@xiaopeng.com, stable@vger.kernel.org
Subject: Re: [PATCH v3 1/2] mtd: rawnand: ingenic: validate BCH error index in jz4725b_correct()
Date: Wed, 18 Nov 2026 09:53:03 +0100 [thread overview]
Message-ID: <b6aaeb0077bb0238c74aed16adfd212fb2fcb0a4.camel@crapouillou.net> (raw)
In-Reply-To: <20261118020751.1833498-1-zhugl3@xiaopeng.com>
Hi Zhu,
Le mercredi 18 novembre 2026 à 10:07 +0800, Guanglei Zhu a écrit :
> From: Weibin Liu <liuwb@xiaopeng.com>
>
> The JZ4725B BCH controller reports each corrected bit error as an
> index into the codeword it was asked to decode, in the INDEX0/INDEX1
> fields of the BCH_BHERR registers. These fields are 13 bits wide, but
> nothing in jz4725b_correct() checks the reported index against the
> size of the data buffer being corrected:
>
> buf[(bit >> 3)] ^= BIT(bit & 0x7);
>
> With data or ECC coming from an untrusted flash, the decoder can
> report an index that points past the end of the data buffer, and the
> above statement then flips a bit outside the buffer.
>
> Skip the correction when the reported index does not point into
> the data area. A bitflip in the parity bytes does not affect the
> data, so rejecting the page for it would fail reads that are
> perfectly correctable, and an index beyond the codeword has no
> buffer to update in the first place.
>
> Fixes: 3e6ac2ad90b3 ("mtd: rawnand: ingenic: Add support for the JZ4725B")
> Cc: stable@vger.kernel.org
> Signed-off-by: Weibin Liu <liuwb@xiaopeng.com>
> Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
Reviewed-by: Paul Cercueil <paul@crapouillou.net>
Cheers,
-Paul
> ---
> v3: add Cc: stable and my Signed-off-by as the sender, matching
> the review comments on 2/2.
>
> Changes in v2: skip the correction for an index that does not point
> into the data area instead of failing the page with -EBADMSG. A
> correctable bitflip in the ECC bytes leaves the data valid, and the
> early exit also dropped the error entries that followed it. This
> matches how jz4740_ecc_correct() treats its indexes.
>
> Verified with a userspace replica of the correction loop: with
> params->size = 512, an index of 4099 (parity area) followed by a
> data-area index of 100 in the same BHERR register is now corrected
> (v1 returned -EBADMSG and left the data error unfixed), the field
> maximum (0x1fff) produces no write outside the buffer, and in-range
> indexes keep correcting as before.
>
> drivers/mtd/nand/raw/ingenic/jz4725b_bch.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/ingenic/jz4725b_bch.c
> b/drivers/mtd/nand/raw/ingenic/jz4725b_bch.c
> index 2d0e0a2192ae..9b1c3d4e5f6a 100644
> --- a/drivers/mtd/nand/raw/ingenic/jz4725b_bch.c
> +++ b/drivers/mtd/nand/raw/ingenic/jz4725b_bch.c
> @@ -259,6 +259,10 @@ static int jz4725b_correct(struct ingenic_ecc *bch,
> bit = (reg & BCH_BHERR_INDEX0_MASK) >>
> BCH_BHERR_INDEX0_SHIFT;
> }
>
> + /* Skip indexes outside the data area. */
> + if (bit >= params->size * 8)
> + continue;
> +
> buf[(bit >> 3)] ^= BIT(bit & 0x7);
> }
>
next prev parent reply other threads:[~2026-11-18 8:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 4:01 [PATCH " 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: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
2026-11-17 14:22 ` Paul Cercueil
2026-11-18 2:07 ` [PATCH v3 1/2] mtd: rawnand: ingenic: validate BCH error index in jz4725b_correct() Guanglei Zhu
2026-11-18 2:07 ` [PATCH v3 2/2] mtd: rawnand: ingenic: validate BCH error index in jz4780_correct() Guanglei Zhu
2026-11-18 8:53 ` Paul Cercueil [this message]
2026-11-06 14:37 ` [PATCH v2 1/2] mtd: rawnand: ingenic: validate BCH error index in jz4725b_correct() Paul Cercueil
2026-11-16 17:06 ` Miquel Raynal
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=b6aaeb0077bb0238c74aed16adfd212fb2fcb0a4.camel@crapouillou.net \
--to=paul@crapouillou.net \
--cc=harveyhuntnexus@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=liuwb@xiaopeng.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=stable@vger.kernel.org \
--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
all inboxes | Powered by JetHome®