public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Mikhail Arkhipov <m.arhipov@rosa.ru>
Cc: Richard Weinberger <richard@nod.at>,
	 Vignesh Raghavendra <vigneshr@ti.com>,
	 linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
	 lvc-project@linuxtesting.org
Subject: Re: [PATCH] mtd: nand: ecc-mxic: Fix use of uninitialized variable ret
Date: Wed, 09 Apr 2025 09:38:17 +0200	[thread overview]
Message-ID: <87v7rdhjiu.fsf@bootlin.com> (raw)
In-Reply-To: <20250408213906.23129-1-m.arhipov@rosa.ru> (Mikhail Arkhipov's message of "Wed, 9 Apr 2025 00:39:06 +0300")

On 09/04/2025 at 00:39:06 +03, Mikhail Arkhipov <m.arhipov@rosa.ru> wrote:

> If ctx->steps is zero, the loop processing ECC steps is skipped,
> and the variable ret remains uninitialized. It is later checked
> and returned, which leads to undefined behavior and may cause
> unpredictable results in user space or kernel crashes.
>
> This scenario can be triggered in edge cases such as misconfigured
> geometry,

Would clearly be a huge bug, nothing else would work in this case, not a
single read, ie. we would stop way before reaching this point.

> ECC engine misuse,

Ditto.

> or if ctx->steps is not validated after initialization.

steps = mtd->writesize / 1K
and
we only run on large-page NANDs, ie. chips with mtd->writesize >= 1K.
so this case is not plausible.

> Initialize ret to zero before the loop to ensure correct and safe
> behavior regardless of the ctx->steps value.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 48e6633a9fa2 ("mtd: nand: mxic-ecc: Add Macronix external ECC
> engine support")

I will apply, but honestly I do not think this fixes anything.

> Signed-off-by: Mikhail Arkhipov <m.arhipov@rosa.ru>

Thanks,
Miquèl

  reply	other threads:[~2025-04-09  7:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 21:39 [PATCH] mtd: nand: ecc-mxic: Fix use of uninitialized variable ret Mikhail Arkhipov
2025-04-09  7:38 ` Miquel Raynal [this message]
2025-04-29  9:26 ` 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=87v7rdhjiu.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=m.arhipov@rosa.ru \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.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