From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796266999; b=Fl7Fp2EvK4HkwC93fatG44bUaFOW0TZg3xNYwwZitfVzd9GQNcqGkE8DW/jsLOHtLV4y qVYdKLxo7CCKsZYzWUZX/OB8E1g/JSr2E5q1kXi7q7QCDfsdpcMPGlHRzcwE47TYcjNWM oLKZvGTNG6O9dGrmd110YgEIydUetQ5XL5krWSHgyyRHx8iyzUko4xUPb4A3x8+lRsSb7 3IxBsg1kZdKrHV5iDLrIGidJo72MdiUW06k38jmAztIuZJM31lETKmtzJADFJfViO3gDF pVds60BmdqbrC5sUhscNFs9zDWFES7dM6iVQDvleaqCzDCO3sI2dwvqWwLxb0gWO23w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796266999; 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=6TxQdK7Ta5KyRSx70nxLS5ibKLLW8DZi3aa7qErFizE=; b=ou5fc2gbVUBneuUKxg+/HLuV+h1j7liwi/0rZkUW2bJcn2+/UJyzC8lg3CV5ApRAYetB H8IwiIld67WhjCo7OkDca6viv/M7G+4DN6VB8ZG+0eOsC+xGAdt2SgIukKoSS8HHKAjV+ crg5h5r3I8vKw6CYAD+XQVqqxlNLhg9u3Q/H4N5hMnE1daSXcJoQS61LMOTplGtHUABOd kJHkZs0yKqFd9ELNWL/J2UmuZWagNoRdUIOAP5+uJX5Lwc79OcbON0ADuRYYXjQXc2nuM VgrA+D5dSsEy+zbm0V+uN1x0AZIJ7IV7wtCghNRPKNJoJb9SMWRK/zzGyzeSbLd1DBA== 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=D7yx6hFi; arc=none smtp.remote-ip=74.125.82.54 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 64FBB606A322 for ; Thu, 3 Dec 2026 03:03:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 64FBB606A322 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=D7yx6hFi Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-1b589050416so7478852c88.0 for ; Wed, 02 Dec 2026 19:03:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796266998; x=1796871798; 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=6TxQdK7Ta5KyRSx70nxLS5ibKLLW8DZi3aa7qErFizE=; b=D7yx6hFi6telbbFuA8C/4WaWkJNsSo3whEfEJm6n/r3S4U8Wj1zks/V0AB1gzNeJ5r /hiGiBPHYKmfawqOubPLz8sJGeq54N+OzGxQjEHljAHTWxErPfT5pa478NowavopUQwm wTJexRdty+mbaDFx4FO5JxRRaY+MM8YPSN/iAqBhkFmZfmpPGOqr/sf8T8zLq7lZSC+4 DBGipVC2FSnjZCE3lUKANEbOY9NMgdRQe+syIHDRWnqRoNx2K1p/rI9sow3bObLvNqUP JjzMVRzRUU4hJdvS7vhN3h7H4vyuqyZboE7D9GIw5pKHWuJyXoT10f4p8j3BbXsFFpEI SGwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796266998; x=1796871798; 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=6TxQdK7Ta5KyRSx70nxLS5ibKLLW8DZi3aa7qErFizE=; b=oQWDUqi73x9X1FMugEtrmhcgRlXuGCUVjoSuXB0TaNhT1suEBBxglMNhba5wa+rpOS bFOddNFcF2GoK58tvBmKnTGrTj/vog3s2aYVh3csrZ+uitkYwqKvEjR6kYLjwsqRxwaV qa6l0DFxwrHHGh0OFhvgGIR7PbaK6sgz/MhyXd+bvhVi4xXq8r7GvOsHqDZRjckDNLmt pmmh0kbC+5iF/jUTTMISq1PD7XFpdl554Iw1NPskbVaeawf/YBlMODA+CovTNDay4jeX NFGyH9JsfhnJLAOhuPqZ5FkFZOp2eCF+CRBhE2JXf069fUZiFKBK9mGaIBbxxYn6V5Up +Hkw== X-Forwarded-Encrypted: i=1; AL+hErHSSuY0IRTGQsrw2IdXRmjTUhA5rpjirkC8wfP2dMOoz7QKpgMH5ZNHW3lusqrwV64QlAdU+XhME0xcjdU=@vger.kernel.org X-Gm-Message-State: APuU4Z+Mx4rYU8HSygfdpqSFi9rgmcmGsnAE5w6S8Px+BF/HDwpilOEV lxVs4xgjvX4aEBpH+onPgY+Eu/QdCVz187tev5E3mDGKOZ8tNaEgkGNj X-Gm-Gg: AZFdTZcloop8ceagp985vS8bPGZ57P4LL7nP8wbVyZ8WvvMBvKhRtJxHSJLzgd85Msd 99sVc+/4izQPiJwnvLbDmLOquFqA8QXZ9kCS1ZM6ljzvh8sGiGH0xdXJM9x+T02kkpObBLhQ3I5 JhQYj7YfgkblUfJV9V8+PZPkYnYuom9cUPv4L/uoVMkZG/iIKGUpRu/8mxUW9j9lTYhk8LvaCW6 GMePi2LGESFVfiwsOOFCKMMYPdtmpGJZoaX77sO1cvFk52QgAzPL7MTEh4kBtjvAOEgUq7O3rel vjnvjLn0bDUmxUXvgE+7jO3BoY+N9jR5FXz/h/kGyIcCrVJBvGKvc0vpwoWPedZtjyHdChxJKv7 RBfl7cQu0QTx/fW7aR5cNNKPiZykJnwsBiKWrwM/yHkH189ifZA8lJsLNSL6xFWnnTVgldbmT1+ 449am989arnSH+OYmnfJiI0qd2jA+yNz9nLykI7tYDM0RsceTI+DbkgECEj4qaQblVCbxTBhMAH J63Gi92fD2oL1qnK1WnyDZrT8mQr9R1jgxCT44vOEO7WCkwM0ZGM4sWi+84qG7w3ie9n8jacLhI d90H9sT6mFejOcSXncYH2u/aTKIWSsdsPtsmWBgyDgsaNbTkiK3kty1O7njQ7BDlsN8q76Rzr3W z35HGbCVKQuajKDlka692DEvplR0OLfTqhz92puSb1Y4Okdq5c2/1AYLBrgWgr67D+RdGsYHp6e A= X-Received: by 2002:a05:7301:5f14:b0:387:428e:611e with SMTP id 5a478bee46e88-387428e6718mr1119850eec.23.1796266998149; Wed, 02 Dec 2026 19:03:18 -0800 (PST) Received: from LAPTOP-97G9G880.domain.name ([106.222.201.137]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386f676c3ccsm46555084eec.12.2026.12.02.19.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 19:03:17 -0800 (PST) From: Karthikeyan KS To: Richard Weinberger , David Woodhouse Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Haris Iqbal , Karthikeyan KS Subject: [PATCH v2 0/2] jffs2: return -EIO from failing decompressors Date: Thu, 3 Dec 2026 03:03:08 +0000 Message-ID: <20261203030310.261227-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 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