crypto: caam - fix DMA corruption on long hmac keys
Subsystems (3)
Horia Geantă
maintainerPATCH v2 1/1 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.
--- drivers/crypto/caam/caamhash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/caam/caamhash.c +2 -1
@@ -441,9 +441,10 @@ static int ahash_setkey(struct crypto_ahash *ahash,if (aligned_len < keylen)return -EOVERFLOW ; - hashed_key =kmemdup (key, keylen,GFP_KERNEL ); + hashed_key =kmalloc (aligned_len,GFP_KERNEL );if (!hashed_key)return -ENOMEM ; +memcpy (hashed_key, key, keylen); ret =hash_digest_key (ctx, &keylen, hashed_key, digestsize);if (ret) goto bad_free_key;
Signature · 1 line
2.25.1
Horia Geantă
maintainerPATCH 1/1 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.
--- drivers/crypto/caam/caamalg_qi2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/caam/caamalg_qi2.c +2 -1
@@ -3326,9 +3326,10 @@ static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key,if (aligned_len < keylen)return -EOVERFLOW ; - hashed_key =kmemdup (key, aligned_len,GFP_KERNEL ); + hashed_key =kmalloc (aligned_len,GFP_KERNEL );if (!hashed_key)return -ENOMEM ; +memcpy (hashed_key, key, keylen); ret =hash_digest_key (ctx, &keylen, hashed_key, digestsize);if (ret) goto bad_free_key;
Signature · 1 line
2.25.1
Herbert Xu
maintainerRe: [PATCH] crypto: caam - fix overflow on long hmac keys
Quoted 9 lines · Horia Geantă
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.
Quoted 5 lines
Fixes 199354d7fb6e ("crypto: caam - Remove GFP_DMA and add DMA alignment padding")Signed-off-by Horia Geantă <[email protected]>--- drivers/crypto/caam/caamalg_qi2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerQuoted 9 lines · Horia Geantă
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.
Quoted 6 lines
Fixes 199354d7fb6e ("crypto: caam - Remove GFP_DMA and add DMA alignment padding")Reported-by Paul Bunyan <[email protected]>Signed-off-by Horia Geantă <[email protected]>--- drivers/crypto/caam/caamhash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt