Skip to content

Commit ca86cad

Browse files
rgbriggspcmoore
authored andcommitted
audit: log module name on init_module
This adds a new auxiliary record MODULE_INIT to the SYSCALL event. We get finit_module for free since it made most sense to hook this in to load_module(). linux-audit/audit-kernel#7 https://github.com/linux-audit/audit-kernel/wiki/RFE-Module-Load-Record-Format Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Acked-by: Jessica Yu <jeyu@redhat.com> [PM: corrected links in the commit description] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 62bc306 commit ca86cad

5 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎include/linux/audit.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
360360
const struct cred *old);
361361
extern void __audit_log_capset(const struct cred *new, const struct cred *old);
362362
extern void __audit_mmap_fd(int fd, int flags);
363+
extern void __audit_log_kern_module(char *name);
363364

364365
static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
365366
{
@@ -450,6 +451,12 @@ static inline void audit_mmap_fd(int fd, int flags)
450451
__audit_mmap_fd(fd, flags);
451452
}
452453

454+
static inline void audit_log_kern_module(char *name)
455+
{
456+
if (!audit_dummy_context())
457+
__audit_log_kern_module(name);
458+
}
459+
453460
extern int audit_n_rules;
454461
extern int audit_signals;
455462
#else /* CONFIG_AUDITSYSCALL */
@@ -561,6 +568,11 @@ static inline void audit_log_capset(const struct cred *new,
561568
{ }
562569
static inline void audit_mmap_fd(int fd, int flags)
563570
{ }
571+
572+
static inline void audit_log_kern_module(char *name)
573+
{
574+
}
575+
564576
static inline void audit_ptrace(struct task_struct *t)
565577
{ }
566578
#define audit_n_rules 0

‎include/uapi/linux/audit.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#define AUDIT_PROCTITLE 1327 /* Proctitle emit event */
112112
#define AUDIT_FEATURE_CHANGE 1328 /* audit log listing feature changes */
113113
#define AUDIT_REPLACE 1329 /* Replace auditd if this packet unanswerd */
114+
#define AUDIT_KERN_MODULE 1330 /* Kernel Module events */
114115

115116
#define AUDIT_AVC 1400 /* SE Linux avc denial or grant */
116117
#define AUDIT_SELINUX_ERR 1401 /* Internal SE Linux Errors */

‎kernel/audit.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ struct audit_context {
199199
struct {
200200
int argc;
201201
} execve;
202+
struct {
203+
char *name;
204+
} module;
202205
};
203206
int fds[2];
204207
struct audit_proctitle proctitle;

‎kernel/auditsc.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,11 @@ static void show_special(struct audit_context *context, int *call_panic)
12681268
case AUDIT_EXECVE: {
12691269
audit_log_execve_info(context, &ab);
12701270
break; }
1271+
case AUDIT_KERN_MODULE:
1272+
audit_log_format(ab, "name=");
1273+
audit_log_untrustedstring(ab, context->module.name);
1274+
kfree(context->module.name);
1275+
break;
12711276
}
12721277
audit_log_end(ab);
12731278
}
@@ -2368,6 +2373,15 @@ void __audit_mmap_fd(int fd, int flags)
23682373
context->type = AUDIT_MMAP;
23692374
}
23702375

2376+
void __audit_log_kern_module(char *name)
2377+
{
2378+
struct audit_context *context = current->audit_context;
2379+
2380+
context->module.name = kmalloc(strlen(name) + 1, GFP_KERNEL);
2381+
strcpy(context->module.name, name);
2382+
context->type = AUDIT_KERN_MODULE;
2383+
}
2384+
23712385
static void audit_log_task(struct audit_buffer *ab)
23722386
{
23732387
kuid_t auid, uid;

‎kernel/module.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <linux/pfn.h>
6262
#include <linux/bsearch.h>
6363
#include <linux/dynamic_debug.h>
64+
#include <linux/audit.h>
6465
#include <uapi/linux/module.h>
6566
#include "module-internal.h"
6667

@@ -3593,6 +3594,8 @@ static int load_module(struct load_info *info, const char __user *uargs,
35933594
goto free_copy;
35943595
}
35953596

3597+
audit_log_kern_module(mod->name);
3598+
35963599
/* Reserve our place in the list. */
35973600
err = add_unformed_module(mod);
35983601
if (err)
@@ -3681,7 +3684,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
36813684
mod->name, after_dashes);
36823685
}
36833686

3684-
/* Link in to syfs. */
3687+
/* Link in to sysfs. */
36853688
err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp);
36863689
if (err < 0)
36873690
goto coming_cleanup;

0 commit comments

Comments
 (0)