History

audit,module: restore audit logging in load failure case

The move of the module sanity check to earlier skipped the audit logging call in the case of failure and to a place where the previously used context is unavailable. Add an audit logging call for the module loading failure case and get the module name when possible.

Richard Guy Briggs committed 1 year ago

Commit ae1ae111 parent 19272b34 files · +10 −9Browse files

Unified · Split

4 files
  1. include/linux/audit.h +4 −5
  2. kernel/audit.h +1 −1
  3. kernel/auditsc.c +1 −1
  4. kernel/module/main.c +4 −2
include/linux/audit.h+4−5
@@ -417,7 +417,7 @@ extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm, · 416 unmodified lines
417417 extern void __audit_log_capset(const struct cred *new, const struct cred *old);
418418 extern void __audit_mmap_fd(int fd, int flags);
419419 extern void __audit_openat2_how(struct open_how *how);
420−extern void __audit_log_kern_module(char *name);
420+extern void __audit_log_kern_module(const char *name);
421421 extern void __audit_fanotify(u32 response, struct fanotify_response_info_audit_rule *friar);
422422 extern void __audit_tk_injoffset(struct timespec64 offset);
423423 extern void __audit_ntp_log(const struct audit_ntp_data *ad);
@@ -519,7 +519,7 @@ static inline void audit_openat2_how(struct open_how *how) · 95 unmodified lines
519519 __audit_openat2_how(how);
520520 }
521521
522−static inline void audit_log_kern_module(char *name)
522+static inline void audit_log_kern_module(const char *name)
523523 {
524524 if (!audit_dummy_context())
525525 __audit_log_kern_module(name);
@@ -677,9 +677,8 @@ static inline void audit_mmap_fd(int fd, int flags) · 151 unmodified lines
677677 static inline void audit_openat2_how(struct open_how *how)
678678 { }
679679
680−static inline void audit_log_kern_module(char *name)
681−{
682−}
680+static inline void audit_log_kern_module(const char *name)
681+{ }
683682
684683 static inline void audit_fanotify(u32 response, struct fanotify_response_info_audit_rule *friar)
685684 { }
kernel/audit.h+1−1
@@ -200,7 +200,7 @@ struct audit_context { · 199 unmodified lines
200200 int argc;
201201 } execve;
202202 struct {
203− char *name;
203+ const char *name;
204204 } module;
205205 struct {
206206 struct audit_ntp_data ntp_data;
kernel/auditsc.c+1−1
@@ -2864,7 +2864,7 @@ void __audit_openat2_how(struct open_how *how) · 2863 unmodified lines
28642864 context->type = AUDIT_OPENAT2;
28652865 }
28662866
2867−void __audit_log_kern_module(char *name)
2867+void __audit_log_kern_module(const char *name)
28682868 {
28692869 struct audit_context *context = audit_context();
28702870
kernel/module/main.c+4−2
@@ -3368,7 +3368,7 @@ static int load_module(struct load_info *info, const char __user *uargs, · 3367 unmodified lines
33683368
33693369 module_allocated = true;
33703370
3371− audit_log_kern_module(mod->name);
3371+ audit_log_kern_module(info->name);
33723372
33733373 /* Reserve our place in the list. */
33743374 err = add_unformed_module(mod);
@@ -3532,8 +3532,10 @@ static int load_module(struct load_info *info, const char __user *uargs, · 157 unmodified lines
35323532 * failures once the proper module was allocated and
35333533 * before that.
35343534 */
3535− if (!module_allocated)
3535+ if (!module_allocated) {
3536+ audit_log_kern_module(info->name ? info->name : "?");
35363537 mod_stat_bump_becoming(info, flags);
3538+ }
35373539 free_copy(info, flags);
35383540 return err;
35393541 }