public inbox for linux-audit@redhat.com
 help / color / mirror / Atom feed
From: William Roberts <bill.c.roberts@gmail.com>
To: sds@tycho.nsa.gov, rgb@redhat.com, linux-audit@redhat.com
Cc: William Roberts <wroberts@tresys.com>
Subject: [PATCH] squash: review-updates
Date: Tue,  7 Jan 2014 12:44:00 -0800	[thread overview]
Message-ID: <1389127440-974-2-git-send-email-wroberts@tresys.com> (raw)
In-Reply-To: <1389127440-974-1-git-send-email-wroberts@tresys.com>

Signed-off-by: William Roberts <wroberts@tresys.com>
---
 kernel/auditsc.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index a4c2003..9ba1f2a 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1292,9 +1292,20 @@ static void audit_log_cmdline(struct audit_buffer *ab, struct task_struct *tsk,
 		if (!buf)
 			goto out;
 		res = get_cmdline(tsk, buf, PATH_MAX);
-		/* Ensure NULL terminated */
-		if (buf[res-1] != '\0')
-			buf[res-1] = '\0';
+		if (res == 0) {
+			kfree(buf);
+			goto out;
+		}
+		/*
+		 * Ensure NULL terminated but don't clobber the end
+		 * unless the buffer is full. Worst case you end up
+		 * with 2 null bytes ending it. By doing it this way
+		 * one avoids additional branching. One checking if the
+		 * end is null and another to check if their should be
+		 * an increment before setting the null byte.
+		 */
+		res += res < PATH_MAX;
+		buf[res-1] = '\0';
 		context->cmdline = buf;
 	}
 	msg = context->cmdline;
@@ -1333,8 +1344,8 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
 			 context->name_count);
 
 	audit_log_task_info(ab, tsk);
-	audit_log_cmdline(ab, tsk, context);
 	audit_log_key(ab, context->filterkey);
+	audit_log_cmdline(ab, tsk, context);
 	audit_log_end(ab);
 
 	for (aux = context->aux; aux; aux = aux->next) {
-- 
1.7.9.5

  reply	other threads:[~2014-01-07 20:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-07 20:43 [RFC][PATCH] - auditing cmdline William Roberts
2014-01-07 20:44 ` William Roberts [this message]
2014-01-08 16:01   ` [PATCH] squash: review-updates William Roberts
2014-01-08 16:10   ` Richard Guy Briggs
2014-01-10 21:08   ` Eric Paris
2014-01-10 21:33     ` Eric Paris
2014-01-10 21:37     ` William Roberts
2014-01-10 21:42       ` William Roberts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1389127440-974-2-git-send-email-wroberts@tresys.com \
    --to=bill.c.roberts@gmail.com \
    --cc=linux-audit@redhat.com \
    --cc=rgb@redhat.com \
    --cc=sds@tycho.nsa.gov \
    --cc=wroberts@tresys.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox