Skip to contentSkip to conversation

auditd: complete rewrite of auditd signal infrastructure

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 auditd: complete rewrite of auditd signal infrastructure

The kernel/userspace boundary for logging signals to auditd is quite crappy (to be polite) it is racy and doesn't send all the information that might be nice to have. It's also built around binary data flying back and forth with no way for userspace to know precisely what information it is being given. We also don't currently know if the signal info we got from the kernel is actually even for the signal we are auditing. Onward:

This patch adds a new audit message AUDIT_SIG_INFO_VERS. This new message sends data back and forth and at version one looks like

/* 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];
};

This message MUST maintain binary compatability in the first 2 fields. As long as version and signal don't move we can easily support arbitrary new information across this boundary. Userspace can tell the kernel what version of data it can support and the kernel can do the same. Compatibility on both ends is done easily by casting the data to the right version structure and then proceeding from there.

This is backwards compatible to current kernels and the only user visible change will be that new signal messages will have the new fields:

type=DAEMON_RESUME msg=audit(1208370239.512:8484): auditd signal from uid=-1 auid=0 ses=-1 pid=24063 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 and there will be some SELINUX_ERR messages that selinux didn't know how
to handle the new audit message type.

New kernel + old auditd won't have anything changes.

New kernel + new auditd will be like above only uid and ses will be filled out.

Comments?

---

lib/libaudit.c +28 -2
diff -Naupr audit-1.7.orig/lib/libaudit.c audit-1.7/lib/libaudit.c
@@ -77,6 +77,9 @@ static const struct nv_list failure_acti
 
 int audit_archadded hidden = 0;
 int audit_syscalladded hidden = 0;
+/* set to highest version we know */
+int audit_signal_version = 1;
+
 unsigned int audit_elf hidden = 0U;
 static struct libaudit_conf config;
 
@@ -492,9 +495,32 @@ int audit_request_rules_list_data(int fd
 	return rc;
 }
 
-int audit_request_signal_info(int fd)
+int audit_request_signal_info(int fd, int sig)
 {
-	int rc = audit_send(fd, AUDIT_SIGNAL_INFO, NULL, 0);
+	int rc = 0;
+
+	while (audit_signal_version) {
+		struct audit_sig_info_ver1 siginfo;
+
+		/*
+		 * we should be safe to always send _ver1 to the kernel as long
+ 		 * .version and .sig are always the first 2 entries in all
+ 		 * future versions.  These are the only 2 the kernel cares 
+ 		 * about getting from userspace.
+ 		 */
+		siginfo.version = audit_signal_version;
+		siginfo.sig = sig;
+
+		rc = audit_send(fd, AUDIT_SIGNAL_INFO_VERS, &siginfo, sizeof(siginfo));
+		if (rc == -EINVAL || rc == -EPERM)
+			audit_signal_version--;
+		else
+			break;
+	}
+
+	if (!audit_signal_version)
+		rc = audit_send(fd, AUDIT_SIGNAL_INFO, NULL, 0);
+
 	if (rc < 0)
 		audit_msg(LOG_WARNING,
 			"Error sending signal_info request (%s)",
lib/libaudit.h +18 -3
diff -Naupr audit-1.7.orig/lib/libaudit.h audit-1.7/lib/libaudit.h
@@ -373,11 +373,21 @@ struct audit_rule_data {
 //
 /* data structure for who signaled the audit daemon */
 struct audit_sig_info {
-        uid_t           uid;
-        pid_t           pid;
+	uid_t		uid;
+	pid_t		pid;
 	char		ctx[0];
 };
 
+struct audit_sig_info_ver1 {
+	uint32_t	version;
+	uint32_t	sig;
+	uid_t		uid;
+	uid_t		auid;
+	pid_t		pid;
+	uint32_t	session;
+	char		ctx[0];
+};
+ 
 /* defines for audit subsystem */
 #define MAX_AUDIT_MESSAGE_LENGTH    8970 // PATH_MAX*2+CONTEXT_SIZE*2+11+256+1
 struct audit_message {
@@ -404,6 +414,7 @@ struct audit_reply {
 	const char              *message;
 	struct nlmsgerr         *error;
 	struct audit_sig_info   *signal_info;
+	struct audit_sig_info_ver1   *signal_info_ver1;
 	struct daemon_conf      *conf;
 	};
 };
@@ -450,6 +461,10 @@ extern int  audit_get_reply(int fd, stru
 extern uid_t audit_getloginuid(void);
 extern int  audit_setloginuid(uid_t uid);
 extern int  audit_detect_machine(void);
+extern int audit_fill_siginfo(struct audit_reply *rep,
+			      struct audit_sig_info_ver1 *sig_info,
+			      char **ctx);
+
 
 /* Translation functions */
 extern int        audit_name_to_field(const char *field);
@@ -487,7 +502,7 @@ extern int  audit_set_backlog_limit(int 
 extern int  audit_request_rules_list_data(int fd);
 
 /* SIGNAL_INFO */
-extern int audit_request_signal_info(int fd);
+extern int audit_request_signal_info(int fd, int sig);
 
 /* AUDIT_WATCH */
 extern int audit_update_watch_perms(struct audit_rule_data *rule, int perms);
lib/netlink.c +4 -0
diff -Naupr audit-1.7.orig/lib/netlink.c audit-1.7/lib/netlink.c
@@ -147,6 +147,7 @@ static int adjust_reply(struct audit_rep
 	rep->message  = NULL;
 	rep->error    = NULL;
 	rep->signal_info = NULL;
+	rep->signal_info_ver1 = NULL;
 	rep->conf     = NULL;
 	if (!NLMSG_OK(rep->nlh, (unsigned int)len)) {
 		if (len == sizeof(rep->msg)) {
@@ -187,6 +188,9 @@ static int adjust_reply(struct audit_rep
 		case AUDIT_SIGNAL_INFO:
 			rep->signal_info = NLMSG_DATA(rep->nlh);
 			break;
+		case AUDIT_SIGNAL_INFO_VERS:
+			rep->signal_info_ver1 = NLMSG_DATA(rep->nlh);
+			break;
 	}
 	return len;
 }
src/auditd.c +154 -62

271 lines not on this page · raw message

src/auditd-config.c +2 -0
diff -Naupr audit-1.7.orig/src/auditd-config.c audit-1.7/src/auditd-config.c
@@ -202,7 +202,9 @@ static void clear_config(struct daemon_c
 {
 	config->qos = QOS_NON_BLOCKING;
 	config->sender_uid = 0;
+	config->sender_auid = 0;
 	config->sender_pid = 0;
+	config->sender_session = 0;
 	config->sender_ctx = NULL;
 	config->log_file = strdup("/var/log/audit/audit.log");
 	config->log_format = LF_RAW;
src/auditd-config.h +3 -2
diff -Naupr audit-1.7.orig/src/auditd-config.h audit-1.7/src/auditd-config.h
@@ -40,12 +40,13 @@ typedef enum { QOS_NON_BLOCKING, QOS_BLO
 typedef enum { TEST_AUDITD, TEST_SEARCH } log_test_t;
 typedef enum { N_NONE, N_HOSTNAME, N_FQD, N_NUMERIC, N_USER } node_t;
 
-struct daemon_conf
-{
+struct daemon_conf {
 	daemon_t daemonize;
 	qos_t qos;		/* use blocking/non-blocking sockets */
 	uid_t sender_uid;	/* the uid for sender of sighup */
+	uid_t sender_auid;	/* auid of the sighup sender */
 	pid_t sender_pid;	/* the pid for sender of sighup */
+	uint32_t sender_session;/* session of the signal sender */
 	const char *sender_ctx;	/* the context for the sender of sighup */
 	const char *log_file;
 	logging_formats log_format;
src/auditd-event.c +6 -4
diff -Naupr audit-1.7.orig/src/auditd-event.c audit-1.7/src/auditd-event.c
@@ -875,7 +875,9 @@ static void reconfigure(struct auditd_co
 	struct daemon_conf *nconf = data->head->reply.conf;
 	struct daemon_conf *oconf = data->config;
 	uid_t uid = nconf->sender_uid;
+	uid_t auid = nconf->sender_auid;
 	pid_t pid = nconf->sender_pid;
+	uint32_t session = nconf->sender_session;
 	const char *ctx = nconf->sender_ctx;
 	struct timeval tv;
 	char txt[MAX_AUDIT_MESSAGE_LENGTH];
@@ -884,8 +886,8 @@ static void reconfigure(struct auditd_co
 	int need_size_check = 0, need_reopen = 0, need_space_check = 0;
 
 	snprintf(txt, sizeof(txt),
-		"config change requested by pid=%d auid=%u subj=%s",
-		pid, uid, ctx);
+		"config change requested by uid=%d auid=%u ses=%d pid=%d subj=%s",
+		uid, auid, session, pid, ctx);
 	audit_msg(LOG_NOTICE, txt);
 
 	/* Do the reconfiguring. These are done in a specific
@@ -1131,8 +1133,8 @@ static void reconfigure(struct auditd_co
         }
 
 	data->head->reply.len = snprintf(txt, sizeof(txt), 
-		"%s config changed, auid=%u pid=%d subj=%s res=success", date, 
-		uid, pid, ctx );
+		"%s config changed, uid=%d auid=%u ses=%d pid=%d subj=%s res=success", date, 
+		uid, auid, session, pid, ctx );
 	audit_msg(LOG_NOTICE, txt);
 	data->head->reply.type = AUDIT_DAEMON_CONFIG;
 	data->head->reply.message = strdup(txt);
src/auditd-reconfig.c +28 -25

90 lines not on this page · raw message