mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] jffs2: return -EIO from failing decompressors
@ 2026-12-03  3:03 Karthikeyan KS
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Karthikeyan KS @ 2026-12-03  3:03 UTC (permalink / raw)
  To: Richard Weinberger, David Woodhouse
  Cc: linux-mtd, linux-kernel, Haris Iqbal, Karthikeyan KS

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-03  3:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03  3:03 [PATCH v2 0/2] jffs2: return -EIO from failing decompressors Karthikeyan KS
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

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®