printk: add print_hex_dump_devel()
Subsystems (4)
PATCH v3 1/2 printk: add print_hex_dump_devel()
Add print_hex_dump_devel() as the hex dump equivalent of pr_devel(), which emits output only when DEBUG is enabled, but keeps call sites compiled otherwise.
--- include/linux/printk.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/printk.h +13 -0
@@ -801,6 +801,19 @@ static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, }#endif +#if defined(DEBUG ) +#define print_hex_dump_devel (prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) +#else +static inline void print_hex_dump_devel (const char *prefix_str,int prefix_type, +int rowsize,int groupsize, +const void *buf,size_t len,bool ascii) +{ +} +#endif +/** * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params * @prefix_str: string to prefix each line with;
PATCH v3 2/2 crypto: caam - guard HMAC key hex dumps in hash_digest_key
Use print_hex_dump_devel() for dumping sensitive HMAC key bytes in hash_digest_key() to avoid leaking secrets at runtime when CONFIG_DYNAMIC_DEBUG is enabled.
---
This patch now depends on patch 1 in the series.
Changes in v3:
- Convert single CAAM patch into a 2-patch series
- Use print_hex_dump_devel() helper from patch 1/2 to keep call sites compiled (Herbert)
- Link to v2: https://lore.kernel.org/lkml/[email protected]/
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 | 4 ++-- drivers/crypto/caam/caamhash.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/caam/caamalg_qi2.c +2 -2
@@ -3269,7 +3269,7 @@ 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__)": ", + print_hex_dump_devel("key_in@" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); print_hex_dump_debug("shdesc@" __stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
@@ -3289,7 +3289,7 @@ 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__)": ", + print_hex_dump_devel("digested key@" __stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, digestsize,1 ); }
drivers/crypto/caam/caamhash.c +2 -2
@@ -393,7 +393,7 @@ 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__)": ", + print_hex_dump_devel("key_in@"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, *keylen,1 ); print_hex_dump_debug("jobdesc@"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
@@ -408,7 +408,7 @@ 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__)": ", + print_hex_dump_devel("digested key@"__stringify(__LINE__)": ",DUMP_PREFIX_ADDRESS ,16 ,4 , key, digestsize,1 ); }
John Ogness
maintainerQuoted 19 lines · Thorsten Blum
Add
print_hex_dump_devel()as the hex dump equivalent ofpr_devel(), which emits output only when DEBUG is enabled, but keeps call sites compiled otherwise.Suggested-by Herbert Xu <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- include/linux/printk.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)include/linux/printk.h +1
-0@@ -801,6 +801,19 @@ static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, }#endif +#if defined(DEBUG )
include/linux/printk.h static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, · line 814
Quoted 10 lines
include/linux/printk.h +10
-0+#define print_hex_dump_devel (prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) +#else +static inline void print_hex_dump_devel (const char *prefix_str,int prefix_type, +int rowsize,int groupsize, +const void *buf,size_t len,bool ascii) +{ +}
If you look at the implementation of pr_devel(), it is using no_printk() in the !DEBUG case. I believe this is to validate correct arg formatting, even if the code will optimized out.
John Ogness
Quoted 6 lines · John Ogness
Quoted 6 lines
include/linux/printk.h +6
-0+#define print_hex_dump_devel (prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) +#else +static inline void print_hex_dump_devel(const char *prefix_str, int prefix_type,
Quoted 8 lines
include/linux/printk.h static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type, · line 814
Quoted 4 lines
include/linux/printk.h +4
-0+ int rowsize, int groupsize, + const void *buf, size_t len, bool ascii) +{ +}If you look at the implementation of
pr_devel(), it is usingno_printk()in the !DEBUG case. I believe this is to validate correct arg formatting, even if the code will optimized out.
Sorry, print_hex_dump() has no printf formatting.
Herbert Xu
maintainerQuoted 9 lines · Thorsten Blum
Add
print_hex_dump_devel()as the hex dump equivalent ofpr_devel(), which emits output only when DEBUG is enabled, but keeps call sites compiled otherwise.Suggested-by Herbert Xu <[email protected]>Signed-off-by Thorsten Blum <[email protected]>--- include/linux/printk.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
All 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