[PATCH] Audit: Ignore terminating NUL in AUDIT_USER_TTY messages

Miloslav Trmač
2008-09-12T20:01:18Z

From: Miloslav Trmac <mitr@redhat.com>

AUDIT_USER_TTY, like all other messages sent from user-space, is sent
NUL-terminated. Unlike other user-space audit messages, which come only
from trusted sources, AUDIT_USER_TTY messages are processed using
audit_log_n_untrustedstring().

This patch modifies AUDIT_USER_TTY handling to ignore the trailing NUL
and use the "quoted_string" representation of the message if possible.

Signed-Off-By: Miloslav Trmac <mitr@redhat.com>
---
> 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?
AUDIT_USER_TTY will commonly contain spaces, but not always. This patch
cleans the AUDIT_USER_TTY messages up a bit.

kernel/audit.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/audit.c b/kernel/audit.c
index ccb8d68..f3d88c4 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -763,6 +763,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)

audit_log_format(ab, " msg=");
size = nlmsg_len(nlh);
+ if (size > 0 &&
+ ((unsigned char *)data)[size - 1] == '\0')
+ size--;
audit_log_n_untrustedstring(ab, data, size);
}
audit_set_pid(ab, pid);