]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lsm: Add audit_log_lsm_data() helper
authorMickaël Salaün <mic@digikod.net>
Thu, 20 Mar 2025 19:06:50 +0000 (20:06 +0100)
committerMickaël Salaün <mic@digikod.net>
Wed, 26 Mar 2025 12:59:33 +0000 (13:59 +0100)
Extract code from dump_common_audit_data() into the audit_log_lsm_data()
helper. This helps reuse common LSM audit data while not abusing
AUDIT_AVC records because of the common_lsm_audit() helper.

Depends-on: 7ccbe076d987 ("lsm: Only build lsm_audit.c if CONFIG_SECURITY and CONFIG_AUDIT are set")
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <jmorris@namei.org>
Cc: Serge E. Hallyn <serge@hallyn.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Link: https://lore.kernel.org/r/20250320190717.2287696-2-mic@digikod.net
Reviewed-by: Günther Noack <gnoack3000@gmail.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
include/linux/lsm_audit.h
security/lsm_audit.c

index e13d2f947b517bbe3df74f7f4980a601d877ea22..bddd694f7c4cd1b87b4952ecc3e24868763c2132 100644 (file)
@@ -132,6 +132,9 @@ void common_lsm_audit(struct common_audit_data *a,
        void (*pre_audit)(struct audit_buffer *, void *),
        void (*post_audit)(struct audit_buffer *, void *));
 
+void audit_log_lsm_data(struct audit_buffer *ab,
+                       const struct common_audit_data *a);
+
 #else /* CONFIG_AUDIT */
 
 static inline void common_lsm_audit(struct common_audit_data *a,
@@ -140,6 +143,11 @@ static inline void common_lsm_audit(struct common_audit_data *a,
 {
 }
 
+static inline void audit_log_lsm_data(struct audit_buffer *ab,
+                       const struct common_audit_data *a)
+{
+}
+
 #endif /* CONFIG_AUDIT */
 
 #endif
index 52db886dbba8ab9a7d786cdd5b599d61c5441721..a61c7ebdb6a75edea2e0f7e849586f2b0ca59500 100644 (file)
@@ -189,16 +189,13 @@ static inline void print_ipv4_addr(struct audit_buffer *ab, __be32 addr,
 }
 
 /**
- * dump_common_audit_data - helper to dump common audit data
+ * audit_log_lsm_data - helper to log common LSM audit data
  * @ab : the audit buffer
  * @a : common audit data
- *
  */
-static void dump_common_audit_data(struct audit_buffer *ab,
-                                  struct common_audit_data *a)
+void audit_log_lsm_data(struct audit_buffer *ab,
+                       const struct common_audit_data *a)
 {
-       char comm[sizeof(current->comm)];
-
        /*
         * To keep stack sizes in check force programmers to notice if they
         * start making this union too large!  See struct lsm_network_audit
@@ -206,9 +203,6 @@ static void dump_common_audit_data(struct audit_buffer *ab,
         */
        BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
 
-       audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current));
-       audit_log_untrustedstring(ab, get_task_comm(comm, current));
-
        switch (a->type) {
        case LSM_AUDIT_DATA_NONE:
                return;
@@ -431,6 +425,21 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        } /* switch (a->type) */
 }
 
+/**
+ * dump_common_audit_data - helper to dump common audit data
+ * @ab : the audit buffer
+ * @a : common audit data
+ */
+static void dump_common_audit_data(struct audit_buffer *ab,
+                                  const struct common_audit_data *a)
+{
+       char comm[sizeof(current->comm)];
+
+       audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current));
+       audit_log_untrustedstring(ab, get_task_comm(comm, current));
+       audit_log_lsm_data(ab, a);
+}
+
 /**
  * common_lsm_audit - generic LSM auditing function
  * @a:  auxiliary audit data