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
417extern void __audit_log_capset(const struct cred *new, const struct cred *old);417extern void __audit_log_capset(const struct cred *new, const struct cred *old);
418extern void __audit_mmap_fd(int fd, int flags);418extern void __audit_mmap_fd(int fd, int flags);
419extern void __audit_openat2_how(struct open_how *how);419extern void __audit_openat2_how(struct open_how *how);
420extern void __audit_log_kern_module(char *name);420extern void __audit_log_kern_module(const char *name);
421extern void __audit_fanotify(u32 response, struct fanotify_response_info_audit_rule *friar);421extern void __audit_fanotify(u32 response, struct fanotify_response_info_audit_rule *friar);
422extern void __audit_tk_injoffset(struct timespec64 offset);422extern void __audit_tk_injoffset(struct timespec64 offset);
423extern void __audit_ntp_log(const struct audit_ntp_data *ad);423extern 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
519 __audit_openat2_how(how);519 __audit_openat2_how(how);
520}520}
521 521
522static inline void audit_log_kern_module(char *name)522static inline void audit_log_kern_module(const char *name)
523{523{
524 if (!audit_dummy_context())524 if (!audit_dummy_context())
525 __audit_log_kern_module(name);525 __audit_log_kern_module(name);
@@ -677,9 +677,8 @@ static inline void audit_mmap_fd(int fd, int flags) · 151 unmodified lines
677static inline void audit_openat2_how(struct open_how *how)677static inline void audit_openat2_how(struct open_how *how)
678{ }678{ }
679 679
680static inline void audit_log_kern_module(char *name)680static inline void audit_log_kern_module(const char *name)
681{681{ }
682}
683 682
684static inline void audit_fanotify(u32 response, struct fanotify_response_info_audit_rule *friar)683static inline void audit_fanotify(u32 response, struct fanotify_response_info_audit_rule *friar)
685{ }684{ }
kernel/audit.h+1−1
@@ -200,7 +200,7 @@ struct audit_context { · 199 unmodified lines
200 int argc;200 int argc;
201 } execve;201 } execve;
202 struct {202 struct {
203 char *name;203 const char *name;
204 } module;204 } module;
205 struct {205 struct {
206 struct audit_ntp_data ntp_data;206 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
2864 context->type = AUDIT_OPENAT2;2864 context->type = AUDIT_OPENAT2;
2865}2865}
2866 2866
2867void __audit_log_kern_module(char *name)2867void __audit_log_kern_module(const char *name)
2868{2868{
2869 struct audit_context *context = audit_context();2869 struct audit_context *context = audit_context();
2870 2870
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
3368 3368
3369 module_allocated = true;3369 module_allocated = true;
3370 3370
3371 audit_log_kern_module(mod->name);3371 audit_log_kern_module(info->name);
3372 3372
3373 /* Reserve our place in the list. */3373 /* Reserve our place in the list. */
3374 err = add_unformed_module(mod);3374 err = add_unformed_module(mod);
@@ -3532,8 +3532,10 @@ static int load_module(struct load_info *info, const char __user *uargs, · 157 unmodified lines
3532 * failures once the proper module was allocated and3532 * failures once the proper module was allocated and
3533 * before that.3533 * before that.
3534 */3534 */
3535 if (!module_allocated)3535 if (!module_allocated) {
3536 audit_log_kern_module(info->name ? info->name : "?");
3536 mod_stat_bump_becoming(info, flags);3537 mod_stat_bump_becoming(info, flags);
3538 }
3537 free_copy(info, flags);3539 free_copy(info, flags);
3538 return err;3540 return err;
3539}3541}