Skip to content

Commit 4d20243

Browse files
author
Gao Xiang
committed
erofs: fix out-of-bound read for shifted uncompressed block
rq->out[1] should be valid before accessing. Otherwise, in very rare cases, out-of-bound dirty onstack rq->out[1] can equal to *in and lead to unintended memmove behavior. Link: https://lore.kernel.org/r/[email protected] Fixes: 7fc45db ("staging: erofs: introduce generic decompression backend") Cc: <[email protected]> # 5.3+ Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent e3915ad commit 4d20243

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

fs/erofs/decompressor.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,24 +306,22 @@ static int z_erofs_shifted_transform(const struct z_erofs_decompress_req *rq,
306306
}
307307

308308
src = kmap_atomic(*rq->in);
309-
if (!rq->out[0]) {
310-
dst = NULL;
311-
} else {
309+
if (rq->out[0]) {
312310
dst = kmap_atomic(rq->out[0]);
313311
memcpy(dst + rq->pageofs_out, src, righthalf);
312+
kunmap_atomic(dst);
314313
}
315314

316-
if (rq->out[1] == *rq->in) {
317-
memmove(src, src + righthalf, rq->pageofs_out);
318-
} else if (nrpages_out == 2) {
319-
if (dst)
320-
kunmap_atomic(dst);
315+
if (nrpages_out == 2) {
321316
DBG_BUGON(!rq->out[1]);
322-
dst = kmap_atomic(rq->out[1]);
323-
memcpy(dst, src + righthalf, rq->pageofs_out);
317+
if (rq->out[1] == *rq->in) {
318+
memmove(src, src + righthalf, rq->pageofs_out);
319+
} else {
320+
dst = kmap_atomic(rq->out[1]);
321+
memcpy(dst, src + righthalf, rq->pageofs_out);
322+
kunmap_atomic(dst);
323+
}
324324
}
325-
if (dst)
326-
kunmap_atomic(dst);
327325
kunmap_atomic(src);
328326
return 0;
329327
}

0 commit comments

Comments
 (0)