From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A0A1279DC3 for ; Sat, 9 May 2026 03:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778298864; cv=none; b=UYLMsOc3m2wgRDadko5cMVwek1kgbA6t2bCqPg1MFwBszmwUw5GLxqVeSONH8liwSY5YpQg1+aG3X3FAom6zUc7QfKB+c24/Sk/kouCuck2oT137R/m/rq9XW2ocrgopfStsQeGrJDVtEejFd+OVxy3z0XGk3NGrV144ZBFhA9E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778298864; c=relaxed/simple; bh=jSZxxzhP+uoENkzrtWpFk6i7UUabOIp1OYvcR9Z9ygM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NyFVj6qJaiXPJ1tCU3L1gxfbf8Q8n8gLtDXas9yB/dHTcS4R0wUSk+Too/yqQiMBWJd8W+romCmUbQs5u84nyU9A3rMfArZI1nihboMWrkyAHHnltFEW0IaX64xmF0xp42ooAWg9nZOJQXNSSrlPnxxppmxw8CnsCcWESg+Ea6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a0cggDrm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="a0cggDrm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80702C2BCB2; Sat, 9 May 2026 03:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778298864; bh=jSZxxzhP+uoENkzrtWpFk6i7UUabOIp1OYvcR9Z9ygM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a0cggDrmP0MvTuRl9SvXOxa80d3ivP07lMKO8/FnvyCP6mH/3xAwXSV+ODOpuu14L lBG1bYn+rwuOjCVYaJI7IY84lh4IH0LgbDr3byie6ibxyv4sEJcucf015K5R/iGrlb seqCHr1cppwPiF0XXS3s5FXSfD5XHZav3rhgUtMktveNFo7D79YW+WWcB+VQB/Bo+R RiWCZZmMAq6w99Td/SPWAPnuZJ/c8wpZr6x5XJuiyi0ma4s+wXUBdlizBLNV8zD8s2 O+IB/JP84zUAPTFJq6JuazBIoIUYKLm3YaIYgYM9LHdjVrsLryYlDxLxYcJ8vHkjDt A3h3H5Js/PU5g== From: Sasha Levin To: stable@vger.kernel.org Cc: Junrui Luo , Yuhao Jiang , Gao Xiang , Sasha Levin Subject: [PATCH 6.6.y] erofs: fix unsigned underflow in z_erofs_lz4_handle_overlap() Date: Fri, 8 May 2026 23:54:21 -0400 Message-ID: <20260509035421.3122562-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050415-landmark-dedicator-394a@gregkh> References: <2026050415-landmark-dedicator-394a@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Junrui Luo [ Upstream commit 21e161de2dc660b1bb70ef5b156ab8e6e1cca3ab ] Some crafted images can have illegal (!partial_decoding && m_llen < m_plen) extents, and the LZ4 inplace decompression path can be wrongly hit, but it cannot handle (outpages < inpages) properly: "outpages - inpages" wraps to a large value and the subsequent rq->out[] access reads past the decompressed_pages array. However, such crafted cases can correctly result in a corruption report in the normal LZ4 non-inplace path. Let's add an additional check to fix this for backporting. Reproducible image (base64-encoded gzipped blob): H4sIAJGR12kCA+3SPUoDQRgG4MkmkkZk8QRbRFIIi9hbpEjrHQI5ghfwCN5BLCzTGtLbBI+g dilSJo1CnIm7GEXFxhT6PDDwfrs73/ywIQD/1ePD4r7Ou6ETsrq4mu7XcWfj++Pb58nJU/9i PNtbjhan04/9GtX4qVYc814WDqt6FaX5s+ZwXXeq52lndT6IuVvlblytLMvh4Gzwaf90nsvz 2DF/21+20T/ldgp5s1jXRaN4t/8izsy/OUB6e/Qa79r+JwAAAAAAAL52vQVuGQAAAP6+my1w ywAAAAAAAADwu14ATsEYtgBQAAA= $ mount -t erofs -o cache_strategy=disabled foo.erofs /mnt $ dd if=/mnt/data of=/dev/null bs=4096 count=1 Fixes: 598162d05080 ("erofs: support decompress big pcluster for lz4 backend") Reported-by: Yuhao Jiang Cc: stable@vger.kernel.org Signed-off-by: Junrui Luo Reviewed-by: Gao Xiang Signed-off-by: Gao Xiang [ inverted condition to early-out `goto docopy` form and used `ctx->inpages`/`ctx->outpages` instead of `rq->` ] Signed-off-by: Sasha Levin --- fs/erofs/decompressor.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 86e088fd386ee..18e4da98309d5 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -133,6 +133,7 @@ static void *z_erofs_lz4_handle_overlap(struct z_erofs_lz4_decompress_ctx *ctx, if (rq->inplace_io) { omargin = PAGE_ALIGN(ctx->oend) - ctx->oend; if (rq->partial_decoding || !may_inplace || + ctx->outpages < ctx->inpages || omargin < LZ4_DECOMPRESS_INPLACE_MARGIN(rq->inputsize)) goto docopy; -- 2.53.0