From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221315; b=hOo9jEDT8pqsJW4s0mrK2SgwLESarnO4BR6IFhXqPmXE56ukZzXINLKr2wkkPl9r6XG1 ZHOMRlASOzfOymryfzN17akV8L3f6g0jRIrUiBHtqk8UyoZvvfW7cjqWk27jUpxixxWvd Y01O/PNiZy76v2H3vY1vmiVN9Xh3E7zzpCsjZR8CC3EoOR3D/mGlsPaemax6FhxKD8Jip UpDXW8HJc+ZusnPB/K2HzmEnS0dVogdHwF/WdTqNCMfLfRAuhT+hfb2mES74N0qdQ2P4r iuBvylRxKR7kDJF0gsXD2qBfnQ/YDtIn7ufMK7gzKobdmzowQfqKOX45U9N05gyuJwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221315; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=Yv3Yr0rQM0l8ZplRUdspU9Bm4d2hNfGKgDqqaScli9I=; b=h3SvQOtD0i4OAHB5i9/MzjGB/ykrWcj7vBX0fAkBUQdHH6JagwHSv0eXU11eh793AnFE swibo5q9m+BWDoPl3cGyK7RYwCzDnLnJt3liI2wLYtXERbu3jpCsopl2ftk86xiWkCKDA nxkgPgitKV8jmlUFEkBVYJ+OkhmHbhHdeIa3Z7zPpytdFm0J6oYsPAcHRom5MNJrLZBs3 EewX+jjFtaXnLr4nGiWVrGh0XHDgked/zkHXifp9ZoRW7FVNzr/psv/p9NRGfJLwCtgPf FwDqOQkC/u8urwydRNKsuXNx5Yn+0D5UXbhR9nCa1BNanMwk8sc11DS0AngoMVCirHg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=VWnXhN9O; arc=none smtp.remote-ip=74.125.82.47 Received: from mail-dl1-f47.google.com (mail-dl1-f47.google.com [74.125.82.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4E4D606A32A for ; Wed, 2 Dec 2026 14:21:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D4E4D606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=VWnXhN9O Received: by mail-dl1-f47.google.com with SMTP id a92af1059eb24-1b546061d58so5820971c88.1 for ; Wed, 02 Dec 2026 06:21:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796221314; x=1796826114; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Yv3Yr0rQM0l8ZplRUdspU9Bm4d2hNfGKgDqqaScli9I=; b=VWnXhN9ODmElCAHz78TSpwX7mZtsWNSu3ozqexTEXlXt7qaz0IIGqX5HL1nsTXIZZr ov9RFo/wLAzIxoZFK9W7VBPZdt8Ix21aCSoX07cz06WgCBzuYGr754oGr/4nXunB+phc FCMNeXaMvhY5F5aeN4+xypUyzuoFRgCIust7N+TdK9cAC2AhWdeyNrnmpl8LQIunRZPf OCpsE6BwosY3N5XyHd5ZqGe08551It8euaxilTEVN897yAc8X7O/z3pNNJ7a7jkB73sa Ut845KxVMWxaFBIFhPesfAh8GZxcZ2/qBxi4MbOjKV+wkAkXPHECeXJtBIbkh3LTLoVs TL1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796221314; x=1796826114; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Yv3Yr0rQM0l8ZplRUdspU9Bm4d2hNfGKgDqqaScli9I=; b=YNthMtARq0oF373d0O51v2MJl4guR7NCYmJsqZHFF8ZWRcGtqKtclHQG47YHYRcgql G0NRXSNOz41MWE0LQvCJ1UMYMsQHpu2IVTLLwWy9akXipcXOueMi2A0ezk+Q59ta+6DW KjpKjXM6CFIxPMGFs2XRIzOQvYJjGxFthpQlGViMvWDIC1XgXiBT+jVw7zAIPVPkPLMs HAjPaASvGVSZ5TAMECNHD9Uikz9EsqiPtBhpHUGRuQhfk7Ed+pA77wIrvl+5aunfVl14 ct6wCDP7dRf9tCDJS6heuDY0EPQjbCuc/MH3GbpHpaBqA6+jryuBuIWL/pra/3vfT+Bn jq1Q== X-Forwarded-Encrypted: i=1; AL+hErFwGuDNaFrVzuzVmoz6MO3p+55fgXYyTcAcUX2Zma3yuf9x4Eq6P0r2XhOvg2X4WhuY6qIi7K6QQL0qhqE=@vger.kernel.org X-Gm-Message-State: APuU4Z8AlGGD9rsJh8hv1VcmgtznCX/bQABbAXCH4YoBZSP7PjuxCA8S xNn+NBlQF8XH9EdNxv63INJYSStwAFIjIgBN13Rhb4g89RczSQGd2fPp X-Gm-Gg: AZFdTZc/FMX5oKumwul9tqE0Sv+SV978Fyd0GQ5pMgOqthfaaKaEunLvDnCjBnKCwgX DaIAUi9B2BGVwWHyGvQb35bLZ3wNol2ChuOb1H9dCvsnq478eOlPingbZU8DOX4lTaFn7hYZWF9 pJyhVs2i27EINsdh9V+3inu7Wb8XzJ2NXTd+hV9WcgY2jqccwHXxaCG+jXqc5Lucmz14lYZkYHp r0O6+bSoe1kFTs07nq1AGGMaxiB2s+OrrpM2jr3brOC0g3v+FNtMJxpRMV7HGofJlIgrpwGBqES mG4Ss72JQiJjC/GQzan17ud8DQmnQkLXH94KoOoCdtiNC92RGQYiHsMd/waMkZ2uI1SbSrn5fjE /RSl5Moy4UYRnBCU2kE99Mv9loCopmaTvHLWVQ8bvnrVemarfa+PSishUlKGP+0buEkT6idWCrl wVcdTH8qlcHc9D3nafCWqdDzt1VmLd+WBngp4tD16jmK31Dcr6WZ6hkhQx6oKzI9Svpr8S1GDpx NqsEMETQ4GzOVSi0zwfd5lkWNp411w2wOBbsFWwBmlXW3I2WNVsWV2GDYf8b5EKXfxYoFHZiMrB TxI89EqPqopltKtR3anvffNc7MKD9l/tNLKvv3VHlLfrVhpijfQV0D+0z12HNDv58sCMfhAm/+Q AAyiOQhnk8S++lHT0OzXmjqX9hFkLOlb8Ki1d3NkO/OF9nXMPHwyO007ZJveJwMGKdBjyL0lniw s= X-Received: by 2002:a05:7300:f483:b0:384:e31e:3c58 with SMTP id 5a478bee46e88-385714160f6mr38842878eec.33.1796221313730; Wed, 02 Dec 2026 06:21:53 -0800 (PST) Received: from LAPTOP-97G9G880.domain.name ([106.222.201.137]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386f676c3ccsm42506756eec.12.2026.12.02.06.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 06:21:53 -0800 (PST) From: Karthikeyan KS To: Richard Weinberger , David Woodhouse Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Karthikeyan KS , stable@vger.kernel.org Subject: [PATCH RESEND] jffs2: return -EIO when a decompressor reports failure Date: Wed, 2 Dec 2026 14:21:44 +0000 Message-ID: <20261202142144.6358-1-karthiproffesional@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit jffs2_decompress() passes the decompressor's return value straight up. The rtime and zlib decompressors report failure by returning a positive 1. That breaks the kernel's error convention: a function that can fail returns 0 or a negative errno, and generic code (the page cache, the write path, IS_ERR()) relies on that, so a positive value is read as success. JFFS2's own callers only check for non-zero, which hides the violation: the value travels unchanged through jffs2_read_dnode(), jffs2_read_inode_range() and jffs2_do_readpage_nolock() to that generic code. On a read, filemap_get_pages() returns 1 without filling its folio batch, filemap_read() carries on and dereferences the empty batch: jffs2: Decompressor "rtime" returned 1 jffs2: Error: jffs2_decompress returned 1 Unhandled fault: page domain fault (0x01b) at 0x00000000 PC is at filemap_read+0x1d8/0x5b4 Call trace: filemap_read from vfs_read+0x23c/0x318 vfs_read from ksys_read+0x74/0xf0 ksys_read from ret_fast_syscall+0x0/0x54 Kernel panic - not syncing: Fatal exception On a partial write, jffs2_write_begin() has to read the old page in. When that fails it returns 1, generic_perform_write() carries on, and jffs2_write_end() is called for a folio that is not uptodate: jffs2: Error: jffs2_decompress returned 1 kernel BUG at fs/jffs2/file.c:270! PC is at jffs2_write_end+0x50/0x3b4 Call trace: jffs2_write_end from generic_perform_write+0x144/0x280 generic_perform_write from generic_file_write_iter+0x64/0x10c generic_file_write_iter from vfs_write+0x230/0x3e8 vfs_write from sys_pwrite64+0xa0/0xc8 Garbage collection has the same problem. read_cache_folio() returns ERR_PTR(1), which IS_ERR() does not treat as an error, and the "folio" at address 0x1 gets mapped: jffs2: Error: jffs2_decompress returned 1 Unhandled fault: page domain fault (0x01b) at 0x00000001 PC is at __kmap_local_page_prot+0x8/0x5c LR is at jffs2_garbage_collect_dnode+0x1dc/0x518 Call trace: __kmap_local_page_prot from jffs2_garbage_collect_dnode+0x1dc/0x518 jffs2_garbage_collect_dnode from jffs2_garbage_collect_pass+0xa54/0xec4 jffs2_garbage_collect_pass from jffs2_reserve_space+0x12c/0x344 Restore the convention at the one place every decompressor result passes through: convert any positive return value into -EIO in jffs2_decompress(), the only caller of the decompressors, so that its callers get a negative errno. The warning still shows the value the decompressor returned. Negative return values (lzo returns -1) are not changed. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: fe051552f507 ("jffs2: Prevent rtime decompress memory corruption") Cc: stable@vger.kernel.org Signed-off-by: Karthikeyan KS --- Hi Richard, Resending the patch I sent on 25 Oct, unchanged, as I have not seen a reply. It still applies to mainline and to mtd/next and mtd/fixes. 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 an rtime or zlib node fail to decompress. Tested on: qemu ast2500-evb (aspeed_g5_defconfig, v7.3-rc7, 32-bit ARM) with images holding an rtime or zlib node that fails to decompress. With the patch, read() fails with EIO, a mmap fault raises SIGBUS, pwrite() fails with EIO, GC logs "read_cache_folio() returned error: -5", and nothing oopses. Valid rtime, zlib, lzo and uncompressed files read and write the same as before. We did not test GC with zlib or lzo nodes, or on real hardware. fs/jffs2/compr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/jffs2/compr.c b/fs/jffs2/compr.c index 764f19dec3f0..da317ed3ccdb 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; } } -- 2.43.0