Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Karthikeyan KS" <karthiproffesional@gmail.com>,
	"Richard Weinberger" <richard@nod.at>,
	"David Woodhouse" <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH RESEND] jffs2: return -EIO when a decompressor reports failure
Date: Wed, 02 Dec 2026 14:29:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-245962@kernel.org> (raw)
In-Reply-To: <20261202142144.6358-1-karthiproffesional@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] jffs2: jffs2_decompress() leaks -1 (-EPERM) from
  jffs2_lzo_decompress()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] jffs2: ignored zlib_inflate() failure in
  jffs2_zlib_decompress() [1]
--

commit ca29ca73ec2076d4b1f555f86e52826b3a10f925
Author: Karthikeyan KS <karthiproffesional@gmail.com>

jffs2: return -EIO when a decompressor reports failure

This commit converts positive return values from JFFS2 decompressors into
-EIO in jffs2_decompress() so callers receive a negative errno on
decompression failure.

> diff --git a/fs/jffs2/compr.c b/fs/jffs2/compr.c
> index 764f19dec3f0f..da317ed3ccdbc 100644
> --- a/fs/jffs2/compr.c
> +++ b/fs/jffs2/compr.c
> @@ -288,6 +288,8 @@ int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
>  				}
>  				this->usecount--;
>  				spin_unlock(&jffs2_compressor_list_lock);
> +				if (ret > 0)
> +					ret = -EIO;
>  				return ret;

[Severity: Medium]
Should this convert all non-zero ret values to -EIO instead of only
ret > 0?

jffs2_lzo_decompress() returns a literal -1 on decompression failure rather
than a negative errno:

fs/jffs2/compr_lzo.c:jffs2_lzo_decompress() {
	ret = lzo1x_decompress_safe(data_in, srclen, cpage_out, &dl);

	if (ret != LZO_E_OK || dl != destlen)
		return -1;

	return 0;
}

Leaving negative values unchanged causes a corrupted LZO node to propagate
-1 (-EPERM) through jffs2_read_dnode() to the page cache and userspace
instead of -EIO.  None of the registered JFFS2 decompressors return a
meaningful errno code.

[Severity: Critical]
This problem wasn't introduced by this patch, but jffs2_zlib_decompress()
ignores zlib_inflate() errors [1] and returns 0 to jffs2_decompress():

fs/jffs2/compr_zlib.c:jffs2_zlib_decompress() {
	...
	while((ret = zlib_inflate(&inf_strm, Z_FINISH)) == Z_OK)
		;
	if (ret != Z_STREAM_END) {
		pr_notice("inflate returned %d\n", ret);
	}
	zlib_inflateEnd(&inf_strm);
	mutex_unlock(&inflate_mutex);
	return 0;
}

When a zlib node passes zlib_inflateInit2() but fails during
zlib_inflate(), jffs2_decompress() reports success to jffs2_read_dnode(),
exposing uninitialized page cache or heap memory as valid file data and
writing it back to flash during garbage collection.

[1] https://sashiko.dev/#/bug/linux-40d97206-24d1-4353-814c-da3322334b46

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202142144.6358-1-karthiproffesional@gmail.com?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2026-12-02 14:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 14:21 [PATCH RESEND] jffs2: return -EIO when a decompressor reports failure Karthikeyan KS
2026-12-02 14:29 ` sashiko-bot [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=sashiko-outbox-245962@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=karthiproffesional@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    /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