[PATCH -v2] Audit: add uid, loginuid, and comm to OBJ_PID records

Eric Paris eparis at redhat.com
Wed Dec 12 19:43:19 UTC 2007


Add uid, loginuid, and comm collection to OBJ_PID records.  This just
gives users a little more information about the task that received a
signal.  pid is rather meaningless after the fact, and even though comm
isn't great we can't collect exe reasonably on this code path for
performance reasons.

Signed-off-by: Eric Paris <eparis at redhat.com>

---

#kill a program in a different domain, running as a test user originally logged in as root
type=OBJ_PID msg=audit(12/12/2007 14:21:37.718:45) : opid=2314  obj=root:system_r:httpd_t:s0-s0:c0.c1023 uid=test auid=root comm=bash 
type=SYSCALL msg=audit(12/12/2007 14:21:37.718:45) : arch=x86_64 syscall=kill success=yes exit=0 a0=90a a1=f a2=0 a3=0 items=0 ppid=2233 pid=2238 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts1 comm=bash exe=/bin/bash subj=root:system_r:unconfined_t:s0-s0:c0.c1023 key=(null) 

#signal 2 threads in a thread group
type=OBJ_PID msg=audit(12/12/2007 13:56:29.104:18) : opid=2231  obj=root:system_r:unconfined_t:s0-s0:c0.c1023 uid=root auid=root comm=tmp 
type=OBJ_PID msg=audit(12/12/2007 13:56:29.104:18) : opid=2230  obj=root:system_r:unconfined_t:s0-s0:c0.c1023 uid=root auid=root comm=tmp 
type=SYSCALL msg=audit(12/12/2007 13:56:29.104:18) : arch=x86_64 syscall=kill success=yes exit=0 a0=fffff74a a1=9 a2=0 a3=0 items=0 ppid=2195 pid=2229 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 comm=tmp exe=/tmp/tmp subj=root:system_r:unconfined_t:s0-s0:c0.c1023 key=(null) 

 kernel/auditsc.c |   29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index bce9ecd..b548044 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -176,7 +176,10 @@ struct audit_aux_data_fd_pair {
 struct audit_aux_data_pids {
 	struct audit_aux_data	d;
 	pid_t			target_pid[AUDIT_AUX_PIDS];
+	pid_t			target_uid[AUDIT_AUX_PIDS];
+	pid_t			target_auid[AUDIT_AUX_PIDS];
 	u32			target_sid[AUDIT_AUX_PIDS];
+	char 			target_comm[AUDIT_AUX_PIDS][TASK_COMM_LEN];
 	int			pid_count;
 };
 
@@ -215,7 +218,10 @@ struct audit_context {
 	int		    arch;
 
 	pid_t		    target_pid;
+	pid_t		    target_uid;
+	pid_t		    target_auid;
 	u32		    target_sid;
+	char		    target_comm[TASK_COMM_LEN];
 
 	struct audit_tree_refs *trees, *first_trees;
 	int tree_count;
@@ -922,7 +928,7 @@ static void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk
 }
 
 static int audit_log_pid_context(struct audit_context *context, pid_t pid,
-				 u32 sid)
+				 pid_t uid, pid_t auid, u32 sid, char *comm)
 {
 	struct audit_buffer *ab;
 	char *s = NULL;
@@ -937,7 +943,9 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid,
 		audit_log_format(ab, "opid=%d obj=(none)", pid);
 		rc = 1;
 	} else
-		audit_log_format(ab, "opid=%d  obj=%s", pid, s);
+		audit_log_format(ab, "opid=%d obj=%s", pid, s);
+	audit_log_format(ab, " uid=%d auid=%d comm=", uid, auid);
+	audit_log_untrustedstring(ab, comm);
 	audit_log_end(ab);
 	kfree(s);
 
@@ -1168,13 +1176,17 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
 
 		for (i = 0; i < axs->pid_count; i++)
 			if (audit_log_pid_context(context, axs->target_pid[i],
-						  axs->target_sid[i]))
+						  axs->target_uid[i],
+						  axs->target_auid[i],
+						  axs->target_sid[i],
+						  axs->target_comm[i]))
 				call_panic = 1;
 	}
 
 	if (context->target_pid &&
 	    audit_log_pid_context(context, context->target_pid,
-				  context->target_sid))
+				  context->target_uid, context->target_auid,
+				  context->target_sid, context->target_comm))
 			call_panic = 1;
 
 	if (context->pwd && context->pwdmnt) {
@@ -2193,7 +2205,10 @@ void __audit_ptrace(struct task_struct *t)
 	struct audit_context *context = current->audit_context;
 
 	context->target_pid = t->pid;
+	context->target_uid = t->uid;
+	context->target_auid = audit_get_loginuid(t->audit_context);
 	selinux_get_task_sid(t, &context->target_sid);
+	memcpy(context->target_comm, t->comm, TASK_COMM_LEN);
 }
 
 /**
@@ -2230,7 +2245,10 @@ int __audit_signal_info(int sig, struct task_struct *t)
 	 * in audit_context */
 	if (!ctx->target_pid) {
 		ctx->target_pid = t->tgid;
+		ctx->target_uid = t->uid;
+		ctx->target_auid = audit_get_loginuid(t->audit_context);
 		selinux_get_task_sid(t, &ctx->target_sid);
+		memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN);
 		return 0;
 	}
 
@@ -2247,7 +2265,10 @@ int __audit_signal_info(int sig, struct task_struct *t)
 	BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS);
 
 	axp->target_pid[axp->pid_count] = t->tgid;
+	axp->target_uid[axp->pid_count] = t->uid;
+	axp->target_auid[axp->pid_count] = audit_get_loginuid(t->audit_context);
 	selinux_get_task_sid(t, &axp->target_sid[axp->pid_count]);
+	memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN);
 	axp->pid_count++;
 
 	return 0;





More information about the Linux-audit mailing list