Skip to content

Commit 80688af

Browse files
horiagherbertx
authored andcommitted
crypto: caam - fix overflow on long hmac keys
When a key longer than block size is supplied, it is copied and then hashed into the real key. The memory allocated for the copy needs to be rounded to DMA cache alignment, as otherwise the hashed key may corrupt neighbouring memory. The copying is performed using kmemdup, however this leads to an overflow: reading more bytes (aligned_len - keylen) from the keylen source buffer. Fix this by replacing kmemdup with kmalloc, followed by memcpy. Fixes: 199354d ("crypto: caam - Remove GFP_DMA and add DMA alignment padding") Signed-off-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5ddfdcb commit 80688af

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/crypto/caam/caamalg_qi2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3326,9 +3326,10 @@ static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key,
33263326
if (aligned_len < keylen)
33273327
return -EOVERFLOW;
33283328

3329-
hashed_key = kmemdup(key, aligned_len, GFP_KERNEL);
3329+
hashed_key = kmalloc(aligned_len, GFP_KERNEL);
33303330
if (!hashed_key)
33313331
return -ENOMEM;
3332+
memcpy(hashed_key, key, keylen);
33323333
ret = hash_digest_key(ctx, &keylen, hashed_key, digestsize);
33333334
if (ret)
33343335
goto bad_free_key;

0 commit comments

Comments
 (0)