Skip to content

Commit 9b08a16

Browse files
committed
lsm: Add audit_log_lsm_data() helper
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: 7ccbe07 ("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>
1 parent c5efa39 commit 9b08a16

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

include/linux/lsm_audit.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ void common_lsm_audit(struct common_audit_data *a,
132132
void (*pre_audit)(struct audit_buffer *, void *),
133133
void (*post_audit)(struct audit_buffer *, void *));
134134

135+
void audit_log_lsm_data(struct audit_buffer *ab,
136+
const struct common_audit_data *a);
137+
135138
#else /* CONFIG_AUDIT */
136139

137140
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,
140143
{
141144
}
142145

146+
static inline void audit_log_lsm_data(struct audit_buffer *ab,
147+
const struct common_audit_data *a)
148+
{
149+
}
150+
143151
#endif /* CONFIG_AUDIT */
144152

145153
#endif

security/lsm_audit.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,20 @@ static inline void print_ipv4_addr(struct audit_buffer *ab, __be32 addr,
189189
}
190190

191191
/**
192-
* dump_common_audit_data - helper to dump common audit data
192+
* audit_log_lsm_data - helper to log common LSM audit data
193193
* @ab : the audit buffer
194194
* @a : common audit data
195-
*
196195
*/
197-
static void dump_common_audit_data(struct audit_buffer *ab,
198-
struct common_audit_data *a)
196+
void audit_log_lsm_data(struct audit_buffer *ab,
197+
const struct common_audit_data *a)
199198
{
200-
char comm[sizeof(current->comm)];
201-
202199
/*
203200
* To keep stack sizes in check force programmers to notice if they
204201
* start making this union too large! See struct lsm_network_audit
205202
* as an example of how to deal with large data.
206203
*/
207204
BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
208205

209-
audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current));
210-
audit_log_untrustedstring(ab, get_task_comm(comm, current));
211-
212206
switch (a->type) {
213207
case LSM_AUDIT_DATA_NONE:
214208
return;
@@ -431,6 +425,21 @@ static void dump_common_audit_data(struct audit_buffer *ab,
431425
} /* switch (a->type) */
432426
}
433427

428+
/**
429+
* dump_common_audit_data - helper to dump common audit data
430+
* @ab : the audit buffer
431+
* @a : common audit data
432+
*/
433+
static void dump_common_audit_data(struct audit_buffer *ab,
434+
const struct common_audit_data *a)
435+
{
436+
char comm[sizeof(current->comm)];
437+
438+
audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current));
439+
audit_log_untrustedstring(ab, get_task_comm(comm, current));
440+
audit_log_lsm_data(ab, a);
441+
}
442+
434443
/**
435444
* common_lsm_audit - generic LSM auditing function
436445
* @a: auxiliary audit data

0 commit comments

Comments
 (0)