Skip to content

Commit 5ddfdcb

Browse files
horiagherbertx
authored andcommitted
crypto: caam - fix DMA corruption 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 rounding was performed, but never actually used for the allocation. Fix this by replacing kmemdup with kmalloc for a larger buffer, followed by memcpy. Fixes: 199354d ("crypto: caam - Remove GFP_DMA and add DMA alignment padding") Reported-by: Paul Bunyan <[email protected]> Signed-off-by: Horia Geantă <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 4b56770 commit 5ddfdcb

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/crypto/caam/caamhash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,10 @@ static int ahash_setkey(struct crypto_ahash *ahash,
441441
if (aligned_len < keylen)
442442
return -EOVERFLOW;
443443

444-
hashed_key = kmemdup(key, keylen, GFP_KERNEL);
444+
hashed_key = kmalloc(aligned_len, GFP_KERNEL);
445445
if (!hashed_key)
446446
return -ENOMEM;
447+
memcpy(hashed_key, key, keylen);
447448
ret = hash_digest_key(ctx, &keylen, hashed_key, digestsize);
448449
if (ret)
449450
goto bad_free_key;

0 commit comments

Comments
 (0)