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