From: Liu Chao <liuc63@xiaopeng.com>
To: Chao Yu <chao@kernel.org>, Chunhai Guo <guochunhai@vivo.com>,
Gao Xiang <xiang@kernel.org>, Hongbo Li <lihongbo22@huawei.com>,
Jeffle Xu <jefflexu@linux.alibaba.com>,
Sandeep Dhavale <dhavale@google.com>, Yue Hu <zbestahu@gmail.com>
Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH] erofs: fix unsigned underflow in LZ4 in-place decompression
Date: Fri, 16 Oct 2026 12:11:43 +0800 [thread overview]
Message-ID: <20261016041143.2293155-1-liuc63@xiaopeng.com> (raw)
z_erofs_lz4_handle_overlap() computes the overlap offset between the
input and output page arrays as rq->outpages - rq->inpages. Both
values are derived from on-disk pcluster metadata (pcl->length and
pcl->pclustersize) which an attacker can set independently, so
outpages may legitimately be smaller than inpages. The unsigned
subtraction then underflows, causing rq->out[] to be indexed far out
of bounds and the returned LZ4 source pointer to point past the
output buffer, resulting in out-of-bounds reads and writes.
The in-place path is only valid when the output buffer is at least as
large as the input buffer, so guard the branch with
rq->outpages >= rq->inpages. When the condition does not hold, fall
through to docopy, which copies the compressed data to the per-CPU
buffer and decompresses safely.
Reviewed-by: Fang Xieyan <fangxy@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
fs/erofs/decompressor.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index 354762c97..50a5f9ddf 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -117,6 +117,7 @@ static void *z_erofs_lz4_handle_overlap(struct z_erofs_decompress_req *rq,
oend = rq->pageofs_out + rq->outputsize;
omargin = PAGE_ALIGN(oend) - oend;
if (rq->partial_decoding || !may_inplace ||
+ rq->outpages < rq->inpages ||
omargin < LZ4_DECOMPRESS_INPLACE_MARGIN(rq->inputsize))
goto docopy;
--
2.50.1
next reply other threads:[~2026-10-16 4:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 4:11 Liu Chao [this message]
2026-10-16 7:09 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261016041143.2293155-1-liuc63@xiaopeng.com \
--to=liuc63@xiaopeng.com \
--cc=chao@kernel.org \
--cc=dhavale@google.com \
--cc=guochunhai@vivo.com \
--cc=jefflexu@linux.alibaba.com \
--cc=lihongbo22@huawei.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
--cc=zbestahu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®