Skip to content

Commit 7d9e5be

Browse files
Chengming Zhougregkh
Chengming Zhou
authored andcommitted
crypto: scomp - fix req->dst buffer overflow
[ Upstream commit 744e188 ] The req->dst buffer size should be checked before copying from the scomp_scratch->dst to avoid req->dst buffer overflow problem. Fixes: 1ab53a7 ("crypto: acomp - add driver-side scomp interface") Reported-by: syzbot+3eff5e51bf1db122a16e@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/0000000000000b05cd060d6b5511@google.com/ Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com> Reviewed-by: Barry Song <v-songbaohua@oppo.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c660aa7 commit 7d9e5be

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crypto/scompress.c

+6
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
117117
struct crypto_scomp *scomp = *tfm_ctx;
118118
void **ctx = acomp_request_ctx(req);
119119
struct scomp_scratch *scratch;
120+
unsigned int dlen;
120121
int ret;
121122

122123
if (!req->src || !req->slen || req->slen > SCOMP_SCRATCH_SIZE)
@@ -128,6 +129,8 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
128129
if (!req->dlen || req->dlen > SCOMP_SCRATCH_SIZE)
129130
req->dlen = SCOMP_SCRATCH_SIZE;
130131

132+
dlen = req->dlen;
133+
131134
scratch = raw_cpu_ptr(&scomp_scratch);
132135
spin_lock(&scratch->lock);
133136

@@ -145,6 +148,9 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
145148
ret = -ENOMEM;
146149
goto out;
147150
}
151+
} else if (req->dlen > dlen) {
152+
ret = -ENOSPC;
153+
goto out;
148154
}
149155
scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen,
150156
1);

0 commit comments

Comments
 (0)