Skip to content

Commit b0356b7

Browse files
committed
crypto: ahash - Fix crypto_ahash_import with partial block data
Restore the partial block buffer in crypto_ahash_import by copying it. Check whether the partial block buffer exceeds the maximum size and return -EOVERFLOW if it does. Zero the partial block buffer in crypto_ahash_import_core. Reported-by: T Pratham <t-pratham@ti.com> Tested-by: T Pratham <t-pratham@ti.com> Fixes: 9d7a0ab ("crypto: ahash - Handle partial blocks in API") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 80b6104 commit b0356b7

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

crypto/ahash.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,12 @@ int crypto_ahash_import_core(struct ahash_request *req, const void *in)
661661
in);
662662
if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
663663
return -ENOKEY;
664+
if (crypto_ahash_block_only(tfm)) {
665+
unsigned int reqsize = crypto_ahash_reqsize(tfm);
666+
u8 *buf = ahash_request_ctx(req);
667+
668+
buf[reqsize - 1] = 0;
669+
}
664670
return crypto_ahash_alg(tfm)->import_core(req, in);
665671
}
666672
EXPORT_SYMBOL_GPL(crypto_ahash_import_core);
@@ -674,10 +680,14 @@ int crypto_ahash_import(struct ahash_request *req, const void *in)
674680
if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
675681
return -ENOKEY;
676682
if (crypto_ahash_block_only(tfm)) {
683+
unsigned int plen = crypto_ahash_blocksize(tfm) + 1;
677684
unsigned int reqsize = crypto_ahash_reqsize(tfm);
685+
unsigned int ss = crypto_ahash_statesize(tfm);
678686
u8 *buf = ahash_request_ctx(req);
679687

680-
buf[reqsize - 1] = 0;
688+
memcpy(buf + reqsize - plen, in + ss - plen, plen);
689+
if (buf[reqsize - 1] >= plen)
690+
return -EOVERFLOW;
681691
}
682692
return crypto_ahash_alg(tfm)->import(req, in);
683693
}

0 commit comments

Comments
 (0)