Skip to content

Commit 0a84874

Browse files
committed
crypto: shash - Fix buffer overrun in import function
Only set the partial block length to zero if the algorithm is block-only. Otherwise the descriptor context could be empty, e.g., for digest_null. Reported-by: syzbot+4851c19615d35f0e4d68@syzkaller.appspotmail.com Fixes: 7650f82 ("crypto: shash - Handle partial blocks in API") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 2297554 commit 0a84874

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

crypto/shash.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,13 @@ static int __crypto_shash_import(struct shash_desc *desc, const void *in,
257257
if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
258258
return -ENOKEY;
259259

260-
plen = crypto_shash_blocksize(tfm) + 1;
261-
descsize = crypto_shash_descsize(tfm);
262260
ss = crypto_shash_statesize(tfm);
263-
buf[descsize - 1] = 0;
264-
if (crypto_shash_block_only(tfm))
261+
if (crypto_shash_block_only(tfm)) {
262+
plen = crypto_shash_blocksize(tfm) + 1;
265263
ss -= plen;
264+
descsize = crypto_shash_descsize(tfm);
265+
buf[descsize - 1] = 0;
266+
}
266267
if (!import) {
267268
memcpy(buf, in, ss);
268269
return 0;

0 commit comments

Comments
 (0)