* [PATCH] Audit: fix handling of 'strings' with NULL characters
@ 2008-09-11 21:48 Eric Paris
2008-09-12 0:09 ` Andrew Morton
2008-09-12 19:59 ` [PATCH] Audit: Ignore terminating NUL in AUDIT_USER_TTY messages Miloslav Trmač
0 siblings, 2 replies; 4+ messages in thread
From: Eric Paris @ 2008-09-11 21:48 UTC (permalink / raw)
To: linux-audit, linux-kernel; +Cc: viro, jdennis, mitr, akpm, sgrubb
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.
Signed-off-by: Eric Paris <eparis@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? 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(-)
diff --git a/kernel/audit.c b/kernel/audit.c
index 4414e93..ccb8d68 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -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;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Audit: fix handling of 'strings' with NULL characters
2008-09-11 21:48 [PATCH] Audit: fix handling of 'strings' with NULL characters Eric Paris
@ 2008-09-12 0:09 ` Andrew Morton
2008-09-12 20:03 ` Miloslav Trmač
2008-09-12 19:59 ` [PATCH] Audit: Ignore terminating NUL in AUDIT_USER_TTY messages Miloslav Trmač
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2008-09-12 0:09 UTC (permalink / raw)
To: Eric Paris; +Cc: linux-audit, linux-kernel, viro, jdennis, mitr, sgrubb
On Thu, 11 Sep 2008 17:48:39 -0400
Eric Paris <eparis@redhat.com> wrote:
> 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.
>
> Signed-off-by: Eric Paris <eparis@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? Do you want to change
> audit_receive_msg() to also use the hex encoding directly instead of the
> _n_untrustedstring interface?
OK, I am now officially confused about the relationship between this
patch, Miloslav's two patches and 2.6.27/2.6.26/2.6.25.
Think I'll go into hiding for a while - please wake us up when it's all
sorted out.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Audit: Ignore terminating NUL in AUDIT_USER_TTY messages
2008-09-11 21:48 [PATCH] Audit: fix handling of 'strings' with NULL characters Eric Paris
2008-09-12 0:09 ` Andrew Morton
@ 2008-09-12 19:59 ` Miloslav Trmač
1 sibling, 0 replies; 4+ messages in thread
From: Miloslav Trmač @ 2008-09-12 19:59 UTC (permalink / raw)
To: Eric Paris, viro; +Cc: linux-audit, linux-kernel, jdennis, akpm, sgrubb
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);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Audit: fix handling of 'strings' with NULL characters
2008-09-12 0:09 ` Andrew Morton
@ 2008-09-12 20:03 ` Miloslav Trmač
0 siblings, 0 replies; 4+ messages in thread
From: Miloslav Trmač @ 2008-09-12 20:03 UTC (permalink / raw)
To: Andrew Morton
Cc: Eric Paris, linux-audit, linux-kernel, viro, jdennis, sgrubb
Andrew Morton píše v Čt 11. 09. 2008 v 17:09 -0700:
> OK, I am now officially confused about the relationship between this
> patch, Miloslav's two patches and 2.6.27/2.6.26/2.6.25.
>
> Think I'll go into hiding for a while - please wake us up when it's all
> sorted out.
Eric's patch ["Audit: fix handling of 'strings' with NULL characters"]
replaces my 1/2 ["audit: fix NUL handling in untrusted strings"], and
makes my 2/2 ["audit: Handle embedded NUL in TTY input auditing"]
technically unnecessary - but from the semantics POV 2/2 should still be
applied.
Either Eric's patch or my 2/2 should go to the stable releases. The
other patches do not have to.
Mirek
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-09-12 20:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-11 21:48 [PATCH] Audit: fix handling of 'strings' with NULL characters Eric Paris
2008-09-12 0:09 ` Andrew Morton
2008-09-12 20:03 ` Miloslav Trmač
2008-09-12 19:59 ` [PATCH] Audit: Ignore terminating NUL in AUDIT_USER_TTY messages Miloslav Trmač
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox