Skip to content

Commit

Permalink
erofs: fix out-of-bound read for shifted uncompressed block
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Gao Xiang committed Jan 11, 2020
1 parent e3915ad commit 4d20243
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions fs/erofs/decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,24 +306,22 @@ static int z_erofs_shifted_transform(const struct z_erofs_decompress_req *rq,
}

src = kmap_atomic(*rq->in);
if (!rq->out[0]) {
dst = NULL;
} else {
if (rq->out[0]) {
dst = kmap_atomic(rq->out[0]);
memcpy(dst + rq->pageofs_out, src, righthalf);
kunmap_atomic(dst);
}

if (rq->out[1] == *rq->in) {
memmove(src, src + righthalf, rq->pageofs_out);
} else if (nrpages_out == 2) {
if (dst)
kunmap_atomic(dst);
if (nrpages_out == 2) {
DBG_BUGON(!rq->out[1]);
dst = kmap_atomic(rq->out[1]);
memcpy(dst, src + righthalf, rq->pageofs_out);
if (rq->out[1] == *rq->in) {
memmove(src, src + righthalf, rq->pageofs_out);
} else {
dst = kmap_atomic(rq->out[1]);
memcpy(dst, src + righthalf, rq->pageofs_out);
kunmap_atomic(dst);
}
}
if (dst)
kunmap_atomic(dst);
kunmap_atomic(src);
return 0;
}
Expand Down

0 comments on commit 4d20243

Please sign in to comment.