Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Haris Iqbal <haris.iqbal@linux.dev>
To: Karthikeyan KS <karthiproffesional@gmail.com>,
	Richard Weinberger <richard@nod.at>
Cc: linux-mtd@lists.infradead.org, David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH RESEND] jffs2: return -EIO when a decompressor reports failure
Date: Thu, 3 Dec 2026 02:42:30 +0100	[thread overview]
Message-ID: <86ccd302-3545-46c9-9b5f-f20c949605a6@linux.dev> (raw)
In-Reply-To: <sashiko-outbox-245962@kernel.org>



On 12/2/26 15:29, sashiko-bot@kernel.org wrote:
> 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.

This looks like a fair point.

Converting -1 to -EIO too would be a better approach IMHO, since it 
seems each compressor chose its own "non-zero means failed" value.

> 
> [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
> 


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

      reply	other threads:[~2026-12-03  1:42 UTC|newest]

Thread overview: 3+ 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
2026-12-03  1:42   ` Haris Iqbal [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=86ccd302-3545-46c9-9b5f-f20c949605a6@linux.dev \
    --to=haris.iqbal@linux.dev \
    --cc=dwmw2@infradead.org \
    --cc=karthiproffesional@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    /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