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 BA8BE1C5D59 for ; Sat, 9 May 2026 12:50:00 +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=1778331000; cv=none; b=sSo1P0Bc/BuAzpoEKbDdtKinHIFTgMseYFkoJqwVNzoeeLVnAEcFApyDQQxL/7o6usMPm5iMfMxmDOHpqb6HNv6RadG/V8Zg8oVwp9jxDipzNU3FKS3h8MRRLVP/lslG6N199c3pi3l4mj+KBji0711j3kmJuT5fI770z/MfDTY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778331000; c=relaxed/simple; bh=DgMWOcOeWA6BEMqe/AYFvLQd5rzID1zOTckIqAWRBho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=id2AlQp6c8rlnmY8HLYmmokYdsMxeus/g5JzVxujfsU/+M+k6SRm+IKRAtxD0Mi3sxKaHYi77H5Fb38rDnpRPBo/y4wWZY4TBwZfY/J8E21pFvYMLebO5MDnhuAyNRgkAUYDxhDev36cDE4lmdGNJpOW4akuoK8LG9MwqgVFM4s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IBlr9JPa; 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="IBlr9JPa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A848CC2BCB2; Sat, 9 May 2026 12:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778331000; bh=DgMWOcOeWA6BEMqe/AYFvLQd5rzID1zOTckIqAWRBho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IBlr9JPaoTYOnxXSu2xEah2F/KQ2rxLndQEu7eYvlQrIZd/MB60toahJR4VZ2OQou sVp1MP0yEvGjZof3sRsyCr0JaQHE1+WI3fdAnAXftpXyANl5oqXjykpp/cC2KB0uHh G3m7ATHaNZYSS2u5cN1vnpqtfzPOCbBGb0cfaAnvGow2LgeZLQcvZeFbeS1oHyHOiP S/pDfm4NrlI5uFq/5HMWTbUCifXtJAihAnX+B/970m4h4IhjUIrXywFyQEoH55ytqh Ew0Uzs0cT9GN1kxHU7UaRhg/gv0nzummDH1Z7MqqN/EGB3+8F2up8TPYLWne2tW/rf MaK6IwD/YHj1A== From: Sasha Levin To: stable@vger.kernel.org Cc: Junrui Luo , Yuhao Jiang , Gao Xiang , Sasha Levin Subject: [PATCH 5.15.y] erofs: fix unsigned underflow in z_erofs_lz4_handle_overlap() Date: Sat, 9 May 2026 08:49:57 -0400 Message-ID: <20260509124957.3382270-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050416-engraving-prefix-0214@gregkh> References: <2026050416-engraving-prefix-0214@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 [ renamed `rq->outpages`/`rq->inpages` to `nrpages_out`/`nrpages_in` and inverted the check to `nrpages_out < nrpages_in` on the existing `goto docopy` chain ] 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 b4be6c524815c..87773583b7da4 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -140,6 +140,7 @@ static void *z_erofs_handle_inplace_io(struct z_erofs_decompress_req *rq, if (rq->inplace_io) { if (rq->partial_decoding || !support_0padding || + nrpages_out < nrpages_in || ofull - oend < LZ4_DECOMPRESS_INPLACE_MARGIN(inputsize)) goto docopy; -- 2.53.0