From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796267011; b=TwODysDOw7qQCKpNu4bYfwbebvw46k1GgXCT3qdXD8eBwL+sYjnC3b0Lo0jgAWGt4XDx A3goLujoEWsUO3JlpLGLzVNTZXLpbvW3FZq40WwKh2XqMDK5s5HVnayrWl1Djx+pwwXVF pluo68imySM3/Y1bHI6AacwwWZ25XACQrbzKfEcRZRUv7BCSSis20G0K3FBiZY89Srx5J AS+tVmyPuUwqUACvVCQqKiNDPG4qSBu8rmWmjW0B7m59h9S3wRheGoHSGZ6tl42As9Ptk LeWD2SIHRUzp4vJYf32dpbQZXYodJvj6nfwDhcinHR1RJDjpI0ClDAhbTXRxgG7AA7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796267011; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=Ja74287Cqdko3N7gipo0TvCyklCsJxvOxWyK3rFrAJw=; b=ahqOTb/osw7mjsdhzcmXgn1qAgembRpKRwIV0ZZDV1iGfCdbOSpV/M1/KvU1WOhJYS9S zqMyV/v8Z+CY01w86r8xiowc+BlQUHHdBrrh71FLFdvINLzv9lsY2PL0iKXnl3HElinh5 rW9O+bzUqsbdS3xmaipC2jMD/x9FOk+etCBRjqCwXz67t43HMt8IFpXM5otSxFCnYupnG resTMpk0TzRst2LwrxvI7rInChe9YBXr0w6z5cF/GmthZWWqmzzvACKbi/TSq1InEhrAt 45m/Kjzct5i61Po3WfHgji2PUx7A5nF3Pa8MXLmvbLk+SAEis7ZfJKVYU4wiqesjvkA== 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=hEsPlVk6; arc=none smtp.remote-ip=74.125.82.172 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (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 7C19C606A32D for ; Thu, 3 Dec 2026 03:03:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7C19C606A32D 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=hEsPlVk6 Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-3866a784546so19143124eec.0 for ; Wed, 02 Dec 2026 19:03:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796267010; x=1796871810; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Ja74287Cqdko3N7gipo0TvCyklCsJxvOxWyK3rFrAJw=; b=hEsPlVk6RTYGpe+beuUCiQhKNfUjozUOpz61gnjqrsaDmSxR+jI+EI7puo6NJcG52y AIi/3H8GrZfV2v1rVo3+/LabHpAVDI2ob4fkddXS+Dqe7uKhNNhlSI+Y3hKjl5tGZNP+ Bl+NXApL7MS4K9GpExB+g5Sr8TjldGM7wTVQnztAWCMrX1OFqkt+cJ0Wu0UzfGncw5kp ymixGf2qnc2xUd1GCDeRwxM6YkohpjTydpTEVQqnVxX7CfTzYdLa8sdGUvJKGGfe0+nR bsJZirbh8KgHnTgt3sE0LMVAf9Hp+WlgE32Va7QNw+FEwoBtDzSSFl0my3D79nkhKQ5J aWxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796267010; x=1796871810; h=content-transfer-encoding:mime-version:references:in-reply-to :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=Ja74287Cqdko3N7gipo0TvCyklCsJxvOxWyK3rFrAJw=; b=1mH+9X/Vj8pFNrt7ufwz2AAu+71SKSWXN1pSnh2ZypA+DVo2T3r3F0YHMoBOU7faiJ U2sbtlvFEfm1tiXdbsRJvfW9U/VP3aqXXnhgI0KAcbeu1SYV1Ktar3VPmXglij1phqny 6+Nc5rvIwqKBu3zOJMdK5lrVDZEzkFa/Dglzg3pbYfAW3U50XahAiBYKviOLLFHt0hzB 6BP0cfXTq9olFgqeJbeWot+t9srWzwKk/s3FrLl0oF0jrfJNHOL1uFqMB3xkUYoD8ueB hcXq+nIeYTB9WNT0kPybxk3VdGEvJTlJeKJQ+FUMmIvHRxkiS6B688rTeafl6dAlS5VP buLA== X-Forwarded-Encrypted: i=1; AL+hErHyWEnPY/b3NJPLcNSMtetTf02g6eK/GxZ1058HRfrKiJWAmWrJoLmG3UYhxTqq2YVO25kQiNqTPYzLBkg=@vger.kernel.org X-Gm-Message-State: APuU4Z8pNYSLwFMVRaP6HS1YhwYzJr+6CixbP9YGR4HX7uLeWotChuCy g4bTKWHjOSBzcJTuRBTssTXTCHe/5RrnOwaCSLzD2tMWjAqbHmQZbuZ6 X-Gm-Gg: AZFdTZf2KXYxEQ+8EYVLxL3qMoAcFEpdDYaH2ErSHHZS9kTimt571s/umZH2b1mLJ9l un8aFnv7WpUXxS18nl9WEEgfcNadxU/QzTc82sFmZB0LCuafA02i1+bl07k0HItemMLLGrulOK4 glTrIMNRlXn2tIiDnEhAED1viYqDF+4fIwLznTZksZcibaAXzTr3maQh8KG7GXzDk4YoHV0d7XB Win5tgjxF7GR6FeMGkxUunfe0TvN3Jt7Ij4ZJ0kt2yvhflNGLIp++WEFEVfjKqU4BmQiqHPO6ny rpc4SP7GnJwXXhMpZtr9ZPWF+fQdCAADdSeEniREpZopQAYwbDkCz9hL8TMketIx8Gm4getLdOQ saHk4Knj9DYrkCbqqZpGOMTlgneC8FPh6YwP7hteTxc+x4yHp3B0H7qeVWYTDlWGIeapmyv5F0H NvheRfx09SGTuwUiHAAqBjiws9ARkYFQueKcpbxt5rkuIdDdZk2aCbXWui68oFEneHJxXVHaLrm yeS508IUwv+vJ6T4sCA5/EFtuax5ibUDhrol0eHDKLPc/RR5aXE21fZPj7EWxHTw2VJ9gi6F55K vzaqRfR1JEz9sB2jVbLASNoht2k1tgq/54/W9zkJ1A6tiFE/+DAAe2JMJ4Vla3EmCIVupNwDQam ZbeNeUhFHrzoOCdjGiBBvs8mxf+PzRsamvBQap2LxZaEqRHKcNBx/ZIPMHHt6gJoLmGEZ/o4LQU 6x X-Received: by 2002:a05:7301:4b10:b0:386:ab5a:d3f6 with SMTP id 5a478bee46e88-386ab5ad528mr32160084eec.19.1796267010272; Wed, 02 Dec 2026 19:03:30 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 19:03:29 -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 , 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 Message-ID: <20261203030310.261227-3-karthiproffesional@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203030310.261227-1-karthiproffesional@gmail.com> References: <20261203030310.261227-1-karthiproffesional@gmail.com> 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_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 --- 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