public inbox for linux-audit@redhat.com
 help / color / mirror / Atom feed
* [PATCH] audit: Add cmdline to taskinfo output
@ 2013-10-28 23:50 William Roberts
  2013-10-29 15:14 ` Steve Grubb
  0 siblings, 1 reply; 29+ messages in thread
From: William Roberts @ 2013-10-28 23:50 UTC (permalink / raw)
  To: linux-audit; +Cc: rgb, William Roberts

On some devices, the cmdline and task info vary. For instance, on
Android, the cmdline is set to the package name, and the task info
is the name of the VM, which is not very helpful.

The additional cmdline output only runs if the audit feature
AUDIT_FEATURE_CMDLINE_OUTPUT is set high at runtime.

Signed-off-by: William Roberts <wroberts@tresys.com>
---

Sorry for the noise, the commit message got truncated last time.
This will apply to Richard's tree on branch audit-for-next.
This requires eparis's generic get/set patches.

 fs/proc/base.c             |    2 +-
 include/linux/proc_fs.h    |    1 +
 include/uapi/linux/audit.h |    4 +++-
 kernel/audit.c             |   38 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 03c8d74..cb1ba2f 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -200,7 +200,7 @@ static int proc_root_link(struct dentry *dentry, struct path *path)
 	return result;
 }
 
-static int proc_pid_cmdline(struct task_struct *task, char * buffer)
+int proc_pid_cmdline(struct task_struct *task, char *buffer)
 {
 	int res = 0;
 	unsigned int len;
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 608e60a..2f386b3 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -41,6 +41,7 @@ extern void *proc_get_parent_data(const struct inode *);
 extern void proc_remove(struct proc_dir_entry *);
 extern void remove_proc_entry(const char *, struct proc_dir_entry *);
 extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
+extern int proc_pid_cmdline(struct task_struct *, char *);
 
 #else /* CONFIG_PROC_FS */
 
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index e2f0d99..5d77124 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -388,7 +388,9 @@ struct audit_features {
 
 #define AUDIT_FEATURE_ONLY_UNSET_LOGINUID	0
 #define AUDIT_FEATURE_LOGINUID_IMMUTABLE	1
-#define AUDIT_LAST_FEATURE			AUDIT_FEATURE_LOGINUID_IMMUTABLE
+#define AUDIT_FEATURE_CMDLINE_OUTPUT		2
+#define AUDIT_LAST_FEATURE	AUDIT_FEATURE_CMDLINE_OUTPUT
+
 
 #define audit_feature_valid(x)		((x) >= 0 && (x) <= AUDIT_LAST_FEATURE)
 #define AUDIT_FEATURE_TO_MASK(x)	(1 << ((x) & 31)) /* mask for __u32 */
diff --git a/kernel/audit.c b/kernel/audit.c
index 8378c5e..bf4b1af 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -63,6 +63,7 @@
 #include <linux/freezer.h>
 #include <linux/tty.h>
 #include <linux/pid_namespace.h>
+#include <linux/proc_fs.h>
 
 #include "audit.h"
 
@@ -144,9 +145,10 @@ static struct audit_features af = {.vers = AUDIT_FEATURE_VERSION,
 				   .features = 0,
 				   .lock = 0,};
 
-static char *audit_feature_names[2] = {
+static char *audit_feature_names[3] = {
 	"only_unset_loginuid",
 	"loginuid_immutable",
+	"audit_output_cmdline",
 };
 
 
@@ -1691,6 +1693,39 @@ error_path:
 }
 EXPORT_SYMBOL(audit_log_task_context);
 
+static void audit_log_add_cmdline(struct audit_buffer *ab,
+				  struct task_struct *tsk)
+{
+	int len;
+	unsigned long page;
+
+	/* Ensure that the feature is set */
+	if (!is_audit_feature_set(AUDIT_FEATURE_CMDLINE_OUTPUT))
+		return;
+
+	/* Get the process cmdline */
+	page = __get_free_page(GFP_TEMPORARY);
+	if (!page)
+		return;
+
+	len = proc_pid_cmdline(tsk, (char *)page);
+	if (len <= 0) {
+		free_page(page);
+		return;
+	}
+
+	/*
+	* Ensure NULL terminated! Application could
+	* could be using setproctitle(3).
+	*/
+	((char *)page)[len-1] = '\0';
+
+	audit_log_format(ab, " cmdline=");
+	audit_log_untrustedstring(ab, (char *)page);
+
+	free_page(page);
+}
+
 void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
 {
 	const struct cred *cred;
@@ -1739,6 +1774,7 @@ void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
 		up_read(&mm->mmap_sem);
 	}
 	audit_log_task_context(ab);
+	audit_log_add_cmdline(ab, tsk);
 }
 EXPORT_SYMBOL(audit_log_task_info);
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 29+ messages in thread
* [PATCH] audit: Add cmdline to taskinfo output
@ 2013-10-28 23:47 William Roberts
  0 siblings, 0 replies; 29+ messages in thread
From: William Roberts @ 2013-10-28 23:47 UTC (permalink / raw)
  To: linux-audit; +Cc: rgb, William Roberts

On some devices, the cmdline and task info vary. For instance, on
Android, the cmdline is set to the package name, and the task info
is the name of the VM, which is not very helpful.

The additional cmdline output only runs if the audit feature
Signed-off-by: William Roberts <wroberts@tresys.com>
---

This will apply to Richard's tree on branch audit-for-next. This
requires eparis's generic get/set patches.

 fs/proc/base.c             |    2 +-
 include/linux/proc_fs.h    |    1 +
 include/uapi/linux/audit.h |    4 +++-
 kernel/audit.c             |   38 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 03c8d74..cb1ba2f 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -200,7 +200,7 @@ static int proc_root_link(struct dentry *dentry, struct path *path)
 	return result;
 }
 
-static int proc_pid_cmdline(struct task_struct *task, char * buffer)
+int proc_pid_cmdline(struct task_struct *task, char *buffer)
 {
 	int res = 0;
 	unsigned int len;
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 608e60a..2f386b3 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -41,6 +41,7 @@ extern void *proc_get_parent_data(const struct inode *);
 extern void proc_remove(struct proc_dir_entry *);
 extern void remove_proc_entry(const char *, struct proc_dir_entry *);
 extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
+extern int proc_pid_cmdline(struct task_struct *, char *);
 
 #else /* CONFIG_PROC_FS */
 
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index e2f0d99..5d77124 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -388,7 +388,9 @@ struct audit_features {
 
 #define AUDIT_FEATURE_ONLY_UNSET_LOGINUID	0
 #define AUDIT_FEATURE_LOGINUID_IMMUTABLE	1
-#define AUDIT_LAST_FEATURE			AUDIT_FEATURE_LOGINUID_IMMUTABLE
+#define AUDIT_FEATURE_CMDLINE_OUTPUT		2
+#define AUDIT_LAST_FEATURE	AUDIT_FEATURE_CMDLINE_OUTPUT
+
 
 #define audit_feature_valid(x)		((x) >= 0 && (x) <= AUDIT_LAST_FEATURE)
 #define AUDIT_FEATURE_TO_MASK(x)	(1 << ((x) & 31)) /* mask for __u32 */
diff --git a/kernel/audit.c b/kernel/audit.c
index 8378c5e..bf4b1af 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -63,6 +63,7 @@
 #include <linux/freezer.h>
 #include <linux/tty.h>
 #include <linux/pid_namespace.h>
+#include <linux/proc_fs.h>
 
 #include "audit.h"
 
@@ -144,9 +145,10 @@ static struct audit_features af = {.vers = AUDIT_FEATURE_VERSION,
 				   .features = 0,
 				   .lock = 0,};
 
-static char *audit_feature_names[2] = {
+static char *audit_feature_names[3] = {
 	"only_unset_loginuid",
 	"loginuid_immutable",
+	"audit_output_cmdline",
 };
 
 
@@ -1691,6 +1693,39 @@ error_path:
 }
 EXPORT_SYMBOL(audit_log_task_context);
 
+static void audit_log_add_cmdline(struct audit_buffer *ab,
+				  struct task_struct *tsk)
+{
+	int len;
+	unsigned long page;
+
+	/* Ensure that the feature is set */
+	if (!is_audit_feature_set(AUDIT_FEATURE_CMDLINE_OUTPUT))
+		return;
+
+	/* Get the process cmdline */
+	page = __get_free_page(GFP_TEMPORARY);
+	if (!page)
+		return;
+
+	len = proc_pid_cmdline(tsk, (char *)page);
+	if (len <= 0) {
+		free_page(page);
+		return;
+	}
+
+	/*
+	* Ensure NULL terminated! Application could
+	* could be using setproctitle(3).
+	*/
+	((char *)page)[len-1] = '\0';
+
+	audit_log_format(ab, " cmdline=");
+	audit_log_untrustedstring(ab, (char *)page);
+
+	free_page(page);
+}
+
 void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
 {
 	const struct cred *cred;
@@ -1739,6 +1774,7 @@ void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
 		up_read(&mm->mmap_sem);
 	}
 	audit_log_task_context(ab);
+	audit_log_add_cmdline(ab, tsk);
 }
 EXPORT_SYMBOL(audit_log_task_info);
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 29+ messages in thread
* [PATCH] audit: Add cmdline to taskinfo output
@ 2013-10-23 20:40 William Roberts
  2013-10-24 19:10 ` Richard Guy Briggs
  2013-10-28 13:48 ` William Roberts
  0 siblings, 2 replies; 29+ messages in thread
From: William Roberts @ 2013-10-23 20:40 UTC (permalink / raw)
  To: linux-audit


[-- Attachment #1.1: Type: text/plain, Size: 2641 bytes --]

>From 0a8623b8f9fa625da81364cf3b87d2799171f83e Mon Sep 17 00:00:00 2001
From: William Roberts <wroberts@tresys.com>
Date: Tue, 22 Oct 2013 14:23:27 -0700
Subject: [PATCH] audit: Add cmdline to taskinfo output

On some devices, the cmdline and task info vary. For instance, on
Android, the cmdline is set to the package name, and the task info
is the name of the VM, which is not very helpful.

Change-Id: I98a417c9ab3b95664c49aa1c7513cfd8296b6a2a
Signed-off-by: William Roberts <wroberts@tresys.com>
---
 fs/proc/base.c          |    2 +-
 include/linux/proc_fs.h |    1 +
 kernel/auditsc.c        |   24 ++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 2f198da..25b73d3 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -209,7 +209,7 @@ struct mm_struct *mm_for_maps(struct task_struct *task)
  return mm_access(task, PTRACE_MODE_READ);
 }

-static int proc_pid_cmdline(struct task_struct *task, char * buffer)
+int proc_pid_cmdline(struct task_struct *task, char *buffer)
 {
  int res = 0;
  unsigned int len;
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 85c5073..d85ac14 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -118,6 +118,7 @@ struct pid_namespace;

 extern int pid_ns_prepare_proc(struct pid_namespace *ns);
 extern void pid_ns_release_proc(struct pid_namespace *ns);
+extern int proc_pid_cmdline(struct task_struct *task, char *buffer);

 /*
  * proc_tty.c
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 27ad9dd..7f2bf41 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -67,6 +67,7 @@
 #include <linux/syscalls.h>
 #include <linux/capability.h>
 #include <linux/fs_struct.h>
+#include <linux/proc_fs.h>

 #include "audit.h"

@@ -1158,6 +1159,8 @@ static void audit_log_task_info(struct audit_buffer
*ab, struct task_struct *tsk
  char name[sizeof(tsk->comm)];
  struct mm_struct *mm = tsk->mm;
  struct vm_area_struct *vma;
+ unsigned long page;
+ int len;

  /* tsk == current */

@@ -1179,6 +1182,27 @@ static void audit_log_task_info(struct audit_buffer
*ab, struct task_struct *tsk
  }
  up_read(&mm->mmap_sem);
  }
+
+ /* Get the process cmdline */
+ page = __get_free_page(GFP_TEMPORARY);
+ if (!page)
+ goto out;
+
+ len = proc_pid_cmdline(tsk, (char *)page);
+ if (len <= 0)
+ goto free;
+
+ /*
+ * Ensure NULL terminated! Application could
+ * could be using setproctitle(3).
+ */
+ ((char *)page)[len-1] = '\0';
+
+ audit_log_format(ab, " cmdline=");
+ audit_log_untrustedstring(ab, (char *)page);
+free:
+ free_page(page);
+out:
  audit_log_task_context(ab);
 }

-- 
1.7.9.5

[-- Attachment #1.2: Type: text/html, Size: 5120 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2013-10-31 15:52 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-28 23:50 [PATCH] audit: Add cmdline to taskinfo output William Roberts
2013-10-29 15:14 ` Steve Grubb
2013-10-29 17:44   ` William Roberts
2013-10-29 17:55     ` William Roberts
2013-10-29 19:01     ` Steve Grubb
2013-10-29 19:12       ` William Roberts
2013-10-29 19:55         ` Steve Grubb
2013-10-29 20:25           ` William Roberts
2013-10-29 23:24             ` William Roberts
2013-10-30  0:43               ` William Roberts
2013-10-30 19:42                 ` Steve Grubb
2013-10-30 20:18                   ` William Roberts
2013-10-30 21:20                     ` Eric Paris
2013-10-30 21:52                       ` William Roberts
2013-10-31 14:36                     ` Steve Grubb
2013-10-31 15:24                       ` William Roberts
2013-10-31 15:28                         ` Richard Guy Briggs
2013-10-31 15:33                           ` William Roberts
2013-10-31 15:46                             ` Richard Guy Briggs
2013-10-31 15:51                               ` William Roberts
2013-10-31 15:52                                 ` William Roberts
  -- strict thread matches above, loose matches on Subject: below --
2013-10-28 23:47 William Roberts
2013-10-23 20:40 William Roberts
2013-10-24 19:10 ` Richard Guy Briggs
2013-10-28 13:48 ` William Roberts
2013-10-28 15:10   ` Richard Guy Briggs
2013-10-28 16:30     ` William Roberts
2013-10-28 19:02       ` William Roberts
2013-10-28 21:52         ` Richard Guy Briggs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox