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>,
stable@vger.kernel.org
Subject: [PATCH v2 2/2] jffs2: return -EIO when a zlib node does not decode completely
Date: Thu, 3 Dec 2026 03:03:10 +0000 [thread overview]
Message-ID: <20261203030310.261227-3-karthiproffesional@gmail.com> (raw)
In-Reply-To: <20261203030310.261227-1-karthiproffesional@gmail.com>
jffs2_zlib_decompress() returns 0 when decoding did not finish: when the
stream breaks, or when it ends properly but produces fewer than destlen
bytes. The caller then returns the unwritten part of the buffer as file
data. For a read of a whole node, that is old page contents.
Return -EIO in both cases, as lzo already does for a short result. A
valid node always decodes to exactly destlen bytes: jffs2_zlib_compress()
and mtd-utils' mkfs.jffs2 both store total_in as its data size.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Karthikeyan KS <karthiproffesional@gmail.com>
---
New in v2. Independent of patch 1: it changes different lines of
compr_zlib.c and does not need patch 1.
Examples, both with a valid data CRC:
- A stream that breaks after 2240 of its 2560 bytes. Without this patch
read() returns all 2560 bytes without an error and the log only says
"jffs2: inflate returned -3". In a test that read another file and
evicted its page from the page cache just before the read, the last
320 bytes were that file's bytes. With init_on_alloc=1 they are zeros,
but the read still succeeds.
- A valid stream that ends properly after 2240 of 2560 bytes. It is also
caught, by the total_out check.
Tested on qemu ast2500-evb with crafted flash images (details in the
cover letter): with this patch both cases make read() and pwrite() fail
with EIO and no data is returned. Nine valid zlib files (58 zlib nodes
written by mkfs.jffs2) read back with the expected checksums.
Behaviour change: a node that does not decode completely used to be read
without an error and now fails with -EIO. Nodes written by
jffs2_zlib_compress() or mkfs.jffs2 are not affected.
fs/jffs2/compr_zlib.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/jffs2/compr_zlib.c b/fs/jffs2/compr_zlib.c
index 856728ed3..282811da1 100644
--- a/fs/jffs2/compr_zlib.c
+++ b/fs/jffs2/compr_zlib.c
@@ -179,12 +179,16 @@ static int jffs2_zlib_decompress(unsigned char *data_in,
while((ret = zlib_inflate(&inf_strm, Z_FINISH)) == Z_OK)
;
- if (ret != Z_STREAM_END) {
- pr_notice("inflate returned %d\n", ret);
+ if (ret != Z_STREAM_END || inf_strm.total_out != destlen) {
+ pr_notice("inflate returned %d, %lu of %u bytes\n",
+ ret, inf_strm.total_out, destlen);
+ ret = -EIO;
+ } else {
+ ret = 0;
}
zlib_inflateEnd(&inf_strm);
mutex_unlock(&inflate_mutex);
- return 0;
+ return ret;
}
static struct jffs2_compressor jffs2_zlib_comp = {
--
2.43.0
prev parent 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 [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 ` Karthikeyan KS [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=20261203030310.261227-3-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 \
--cc=stable@vger.kernel.org \
/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®