Skip to contentSkip to conversation

kernel/audit: add new AUDIG_SIG_INFO_VERS audit messages

RFC PATCH New Eric Paris 1 participant 1 message Apr 16, 2008

Subsystems (2)
lore
Share & tools
lore

Eric Paris

author maintainer
#0 lore raw

RFC PATCH 1/1 kernel/audit: add new AUDIG_SIG_INFO_VERS audit messages

This adds a new versioned audit signal request response mechanism. This new versioned mechanism will allow arbitrary future information to be passed along this boundary which is impossible with the present situation. The kernel always replies back to a userspace request so we can easily tell the highest version supported by userspace and just return EINVAL if userspace requests a version we don't know.

We should also notice that I added a new array of user information right beside the current audit_sig_* stuff. So we don't have the current problem where a SIGUSR1 quickly followed by SIGUSR2 would result in both userspace requests getting information from the same sending process. Its still possible that we may have races between multiple of the same signal, but at least none of the data we get will be wrong.

comments?

-Eric

 include/linux/audit.h       |   22 +++++++++-
 kernel/audit.c              |  101 +++++++++++++++++++++++++++++++++++--------
 kernel/audit.h              |   17 +++++++
 kernel/auditsc.c            |   24 +++++++++-
 security/selinux/nlmsgtab.c |    1 +
 5 files changed, 143 insertions(+), 22 deletions(-)
include/linux/audit.h +21 -1
index 2af9ec0..1549c9f 100644
@@ -59,7 +59,7 @@
 #define AUDIT_WATCH_INS		1007	/* Insert file/dir watch entry */
 #define AUDIT_WATCH_REM		1008	/* Remove file/dir watch entry */
 #define AUDIT_WATCH_LIST	1009	/* List all file/dir watches */
-#define AUDIT_SIGNAL_INFO	1010	/* Get info about sender of signal to auditd */
+#define AUDIT_SIGNAL_INFO	1010	/* deprecated in favor of AUDIT_SIGNAL_INFO_VERS */
 #define AUDIT_ADD_RULE		1011	/* Add syscall filtering rule */
 #define AUDIT_DEL_RULE		1012	/* Delete syscall filtering rule */
 #define AUDIT_LIST_RULES	1013	/* List syscall filtering rules */
@@ -67,6 +67,7 @@
 #define AUDIT_MAKE_EQUIV	1015	/* Append to watched tree */
 #define AUDIT_TTY_GET		1016	/* Get TTY auditing status */
 #define AUDIT_TTY_SET		1017	/* Set TTY auditing status */
+#define AUDIT_SIGNAL_INFO_VERS	1018	/* Version controlled signal sender info request */
 
 #define AUDIT_FIRST_USER_MSG	1100	/* Userspace messages mostly uninteresting to kernel */
 #define AUDIT_USER_AVC		1107	/* We filter this differently */
@@ -340,6 +341,25 @@ struct audit_rule {		/* for AUDIT_LIST, AUDIT_ADD, and AUDIT_DEL */
 #ifdef __KERNEL__
 #include <linux/sched.h>
 
+struct audit_usr_info {
+	uid_t		uid;
+	uid_t		auid;
+	pid_t		pid;
+	__u32		session;
+	__u32		sid;
+};
+
+/* version then sig MUST be the first 2 fields of all sig_info versions  */
+struct audit_sig_info_ver1 {
+	__u32		version;
+	__u32		sig;
+	uid_t		uid;
+	uid_t		auid;
+	pid_t		pid;
+	__u32		session;
+	char		ctx[0];
+};
+
 struct audit_sig_info {
 	uid_t		uid;
 	pid_t		pid;
kernel/audit.c +82 -19

132 lines not on this page · raw message

kernel/audit.h +17 -0
index 2554bd5..4401e3a 100644
@@ -109,6 +109,23 @@ static inline int audit_hash_ino(u32 ino)
 	return (ino & (AUDIT_INODE_BUCKETS-1));
 }
 
+/* offsets into signal arrays */
+static inline int audit_signal_to_offset(int sig)
+{
+	switch (sig) {
+	case SIGTERM:
+		return 0;
+	case SIGHUP:
+		return 1;
+	case SIGUSR1:
+		return 2;
+	case SIGUSR2:
+		return 3;
+	default:
+		BUG();
+	};
+}
+
 extern int audit_match_class(int class, unsigned syscall);
 extern int audit_comparator(const u32 left, const u32 op, const u32 right);
 extern int audit_compare_dname_path(const char *dname, const char *path,
kernel/auditsc.c +22 -2
index 782262e..f3c4045 100644
@@ -2360,18 +2360,38 @@ int __audit_signal_info(int sig, struct task_struct *t)
 	struct audit_aux_data_pids *axp;
 	struct task_struct *tsk = current;
 	struct audit_context *ctx = tsk->audit_context;
+
+	extern struct audit_usr_info audit_usr_sig_info[];
+
+
 	extern pid_t audit_sig_pid;
 	extern uid_t audit_sig_uid;
 	extern u32 audit_sig_sid;
 
 	if (audit_pid && t->tgid == audit_pid) {
-		if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1) {
+		/*
+		 * if the change the number of signals here you need to update
+		 * the size of the _array structures and update _to_offset()
+		 */
+		if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1 ||
+		    sig == SIGUSR2) {
+			int offset = audit_signal_to_offset(sig);
+			u32 sid;
+
+			selinux_get_task_sid(tsk, &sid);
+
 			audit_sig_pid = tsk->pid;
 			if (tsk->loginuid != -1)
 				audit_sig_uid = tsk->loginuid;
 			else
 				audit_sig_uid = tsk->uid;
-			selinux_get_task_sid(tsk, &audit_sig_sid);
+			audit_sig_sid = sid;
+
+			audit_usr_sig_info[offset].pid = tsk->pid;
+			audit_usr_sig_info[offset].uid = tsk->uid;
+			audit_usr_sig_info[offset].auid = tsk->loginuid;
+			audit_usr_sig_info[offset].session = tsk->sessionid;
+			audit_usr_sig_info[offset].sid = sid;
 		}
 		if (!audit_signals || audit_dummy_context())
 			return 0;
security/selinux/nlmsgtab.c +1 -0
index eddc7b4..3378659 100644
@@ -112,6 +112,7 @@ static struct nlmsg_perm nlmsg_audit_perms[] =
 	{ AUDIT_SIGNAL_INFO,	NETLINK_AUDIT_SOCKET__NLMSG_READ     },
 	{ AUDIT_TTY_GET,	NETLINK_AUDIT_SOCKET__NLMSG_READ     },
 	{ AUDIT_TTY_SET,	NETLINK_AUDIT_SOCKET__NLMSG_WRITE    },
+	{ AUDIT_SIGNAL_INFO_VERS, NETLINK_AUDIT_SOCKET__NLMSG_READ     },
 };