[PATCH v4] ima: silence measurement list hexdump during kexec

From: Bruno Meneguele
Date: Tue Dec 28 2021 - 21:03:52 EST


Direclty calling print_hex_dump() dumps the IMA measurement list on soft
resets (kexec) straight to the syslog (kmsg/dmesg) without considering the
DEBUG flag or the dynamic debug state, causing the output to be always
printed, including during boot time.

Since this output is only valid for IMA debugging, but not necessary on
normal kexec operation, print_hex_dump_debug() adheres to the pr_debug()
behavior: the dump is only printed to syslog when DEBUG is defined or when
explicitly requested by the user through dynamic debugging.

Signed-off-by: Bruno Meneguele <bmeneg@xxxxxxxxxx>
---
Changelog:
- v3:
- after more in depth testing it was defined that v1 and v2 solution
matches with the expected behavior instead of the one proposed on v3.
- clarify/simplify the patch description.
- v2: guard call with #ifdef instead of using print_hex_dump_debug, which
would not completely solve the case.
- v1: update commit log with more information.

security/integrity/ima/ima_kexec.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c
index f799cc278a9a..13753136f03f 100644
--- a/security/integrity/ima/ima_kexec.c
+++ b/security/integrity/ima/ima_kexec.c
@@ -61,9 +61,9 @@ static int ima_dump_measurement_list(unsigned long *buffer_size, void **buffer,
}
memcpy(file.buf, &khdr, sizeof(khdr));

- print_hex_dump(KERN_DEBUG, "ima dump: ", DUMP_PREFIX_NONE,
- 16, 1, file.buf,
- file.count < 100 ? file.count : 100, true);
+ print_hex_dump_debug("ima dump: ", DUMP_PREFIX_NONE, 16, 1,
+ file.buf, file.count < 100 ? file.count : 100,
+ true);

*buffer_size = file.count;
*buffer = file.buf;
--
2.33.1