Audit: fix handling of 'strings' with NULL characters
A message that is not in the archive (sent off-list or not yet received): 1542533951.1702681237470446245.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com
PATCH 1/1 Audit: fix handling of 'strings' with NULL characters
Hello,
this appears to have been lost somewhere...
Mirek
currently audit_log_n_untrustedstring() uses audit_string_contains_control() to check if the 'string' has any control characters. If the 'string' has an embedded NULL audit_string_contains_control() will return that the data has no control characters and will then pass the string to audit_log_n_string with the total length, not the length up to the first NULL. audit_log_n_string does a memcpy of the entire length and so the actual audit record emitted may then contain a NULL and then whatever random memory is after the NULL.
Since we want to log the entire octet stream (if we can't trust the data to be a string we can't trust that a NULL isn't actually a part of it) we should just consider NULL as a control character. If the caller is certain they want to stop at the first NULL they should be using audit_log_untrustedstring.
---
Miloslav, this is also going to take care of nulls in the TTY_AUDIT_USER message from userspace. Is it going to be common to have control characters on that code path as well? Do you want to change audit_receive_msg() to also use the hex encoding directly instead of the _n_untrustedstring interface?
kernel/audit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/audit.c +1 -1
@@ -1370,7 +1370,7 @@ void audit_log_n_string(struct audit_buffer *ab, const char *string,int audit_string_contains_control (const char *string,size_t len) {const unsigned char *p; -for (p = string; p < (const unsigned char *)string + len && *p; p++) { +for (p = string; p < (const unsigned char *)string + len; p++) {if (*p =='"' || *p <0x21 || *p >0x7e )return 1 ; }