crypto: caam - guard HMAC key hex dumps in hash_digest_key
Subsystems (3)
PATCH v2 1/1 crypto: caam - guard HMAC key hex dumps in hash_digest_key
Guard sensitive HMAC key hex dumps with DEBUG in hash_digest_key() to avoid leaking secrets at runtime when CONFIG_DYNAMIC_DEBUG is enabled.
---
Changes in v2:
- Debug-guard key hex dumps instead of removing them entirely (Herbert)
- Use print_hex_dump() instead of print_hex_dump_debug() since the dumps
are already guarded by DEBUG
- Link to v1: https://lore.kernel.org/lkml/[email protected]/
--- drivers/crypto/caam/caamalg_qi2.c | 13 ++++++++----- drivers/crypto/caam/caamhash.c | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-)
drivers/crypto/caam/caamalg_qi2.c +8 -5
@@ -3269,8 +3269,10 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, u32 *keylen, u8 *key,dpaa2_fl_set_addr (out_fle, key_dma);dpaa2_fl_set_len (out_fle, digestsize); - print_hex_dump_debug("key_in@" __stringify(__LINE__)": ", -DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); +#ifdef DEBUG + print_hex_dump(KERN_DEBUG, "key_in@" __stringify(__LINE__)": ", +DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); +#endif print_hex_dump_debug("shdesc@" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , desc,desc_bytes (desc),1 );
@@ -3289,9 +3291,10 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, u32 *keylen, u8 *key,/* in progress */ wait_for_completion (&result.completion); ret = result.err; - print_hex_dump_debug("digested key@" __stringify(__LINE__)": ", -DUMP_PREFIX_ADDRESS ,16 ,4 , key, - digestsize,1 ); +#ifdef DEBUG + print_hex_dump(KERN_DEBUG, "digested key@" __stringify(__LINE__)": ", +DUMP_PREFIX_ADDRESS ,16 ,4 , key, digestsize,1 ); +#endif } dma_unmap_single(ctx->dev, flc_dma, sizeof(flc->flc) + desc_bytes(desc),
drivers/crypto/caam/caamhash.c +8 -5
@@ -393,8 +393,10 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, u32 *keylen, u8 *key,append_seq_store (desc, digestsize,LDST_CLASS_2_CCB |LDST_SRCDST_BYTE_CONTEXT ); - print_hex_dump_debug("key_in@"__stringify(__LINE__)": ", -DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); +#ifdef DEBUG + print_hex_dump(KERN_DEBUG, "key_in@"__stringify(__LINE__)": ", +DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); +#endif print_hex_dump_debug("jobdesc@"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , desc,desc_bytes (desc),1 );
@@ -408,9 +410,10 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, u32 *keylen, u8 *key,wait_for_completion (&result.completion); ret = result.err; - print_hex_dump_debug("digested key@"__stringify(__LINE__)": ", -DUMP_PREFIX_ADDRESS ,16 ,4 , key, - digestsize,1 ); +#ifdef DEBUG + print_hex_dump(KERN_DEBUG, "digested key@"__stringify(__LINE__)": ", +DUMP_PREFIX_ADDRESS ,16 ,4 , key, digestsize,1 ); +#endif }dma_unmap_single (jrdev, key_dma, *keylen,DMA_BIDIRECTIONAL );
Herbert Xu
maintainerQuoted 6 lines · Thorsten Blum
drivers/crypto/caam/caamalg_qi2.c +0
-0
drivers/crypto/caam/caamalg_qi2.c static int hash_digest_key(struct caam_hash_ctx *ctx, u32 *keylen, u8 *key, · line 3275
Quoted 9 lines
drivers/crypto/caam/caamalg_qi2.c +4
-2@@ -3269,8 +3269,10 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, u32 *keylen, u8 *key,dpaa2_fl_set_addr (out_fle, key_dma);dpaa2_fl_set_len (out_fle, digestsize); - print_hex_dump_debug("key_in@" __stringify(__LINE__)": ", -DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); +#ifdef DEBUG + print_hex_dump(KERN_DEBUG, "key_in@" __stringify(__LINE__)": ", +DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); +#endif
I'd prefer to keep the compiler coverage when DEBUG is off.
Please add a new helper, either print_hex_dump_devel or print_hex_dump_sensitive that only gets enabled when DEBUG is defined.
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