mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Karthikeyan KS <karthiproffesional@gmail.com>
To: Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
	Haris Iqbal <haris.iqbal@linux.dev>,
	Karthikeyan KS <karthiproffesional@gmail.com>
Subject: [PATCH v2 0/2] jffs2: return -EIO from failing decompressors
Date: Thu,  3 Dec 2026 03:03:08 +0000	[thread overview]
Message-ID: <20261203030310.261227-1-karthiproffesional@gmail.com> (raw)

Hi Richard,

JFFS2's decompressors report failure in three different ways, and none
of them is the negative errno that generic code expects. rtime and zlib
(inflateInit failure) return 1: that crashes the kernel on read, write
and garbage collection, or makes read() return 1 forever. lzo returns
-1, which userspace sees as EPERM. zlib returns 0 when a stream breaks
or ends early, so the read succeeds with stale data from the page.

Patch 1 is v2 of "jffs2: return -EIO when a decompressor reports
failure" (v1 [1], resend [2]). v1 converted a positive return value in
jffs2_decompress(). This version returns -EIO from the decompressors
themselves. It also fixes the lzo -1 (EPERM) pointed out in the Sashiko
review.

Patch 2 is new. It fixes the zlib cases that the same review pointed out
as a separate, pre-existing issue, and one more that came up while
working on it: a stream that is valid but ends early. The two patches
change different lines and can be applied in either order.

How this was found: we backported fe051552f507 ("jffs2: Prevent rtime
decompress memory corruption") to our kernel without b29bf7119d6b
("jffs2: Fix rtime decompressor"). On an AST2500 SoC, the off-by-one in
the rtime bounds check then rejected a valid node. We reproduced the
resulting failure paths on qemu, using crafted flash images that make a
node fail to decompress.

Tested on qemu ast2500-evb (ARM, TCG) with mainline 693c2e04e3f1 and
both patches. The kernel is an aspeed_g5 configuration with
CONFIG_JFFS2_ZLIB, CONFIG_JFFS2_LZO, CONFIG_JFFS2_RTIME and
CONFIG_JFFS2_RUBIN enabled:

 - rtime, zlib (inflateInit failure) and lzo nodes that fail: read() and
   pwrite() fail with EIO, a mmap fault raises SIGBUS, nothing oopses.
   The four failures listed under patch 1 (read panic, read() returning 1
   forever, BUG in jffs2_write_end(), GC fault) no longer happen.
 - A zlib node whose stream breaks partway, and one whose stream is
   valid but ends after 2240 of 2560 bytes: read() and pwrite() fail
   with EIO. Without patch 2 the broken stream was read successfully and
   returned incomplete data.
 - Valid rtime, zlib, lzo and uncompressed files read and write as
   before. Nine valid zlib files (270 kB, 58 zlib nodes written by
   mkfs.jffs2) read back with the expected checksums.

Not tested: garbage collection with zlib or lzo nodes, and real hardware.

[1] https://lore.kernel.org/20261025173152.147123-1-karthiproffesional@gmail.com
[2] https://lore.kernel.org/20261202142144.6358-1-karthiproffesional@gmail.com

Karthikeyan KS (2):
  jffs2: return -EIO when a decompressor reports failure
  jffs2: return -EIO when a zlib node does not decode completely

 fs/jffs2/compr_lzo.c   |  2 +-
 fs/jffs2/compr_rtime.c |  2 +-
 fs/jffs2/compr_zlib.c  | 12 ++++++++----
 3 files changed, 10 insertions(+), 6 deletions(-)


base-commit: 693c2e04e3f1d4c59af236e1211b7b8cb165a790
-- 
2.43.0


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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  3:03 Karthikeyan KS [this message]
2026-12-03  3:03 ` [PATCH v2 1/2] jffs2: return -EIO when a decompressor reports failure Karthikeyan KS
2026-12-03  3:03 ` [PATCH v2 2/2] jffs2: return -EIO when a zlib node does not decode completely Karthikeyan KS

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=20261203030310.261227-1-karthiproffesional@gmail.com \
    --to=karthiproffesional@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=haris.iqbal@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®