Skip to content

Commit 2a65406

Browse files
rgbriggsKPD
authored andcommitted
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. Link: https://issues.redhat.com/browse/RHEL-52839 Fixes: 02da2cb ("module: move check_modinfo() early to early_mod_check()") Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
1 parent d6fb02c commit 2a65406

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

include/linux/audit.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
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)
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)
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct audit_context {
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2864,7 +2864,7 @@ void __audit_openat2_how(struct open_how *how)
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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,7 +3284,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
32843284

32853285
module_allocated = true;
32863286

3287-
audit_log_kern_module(mod->name);
3287+
audit_log_kern_module(info->name);
32883288

32893289
/* Reserve our place in the list. */
32903290
err = add_unformed_module(mod);
@@ -3445,8 +3445,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
34453445
* failures once the proper module was allocated and
34463446
* before that.
34473447
*/
3448-
if (!module_allocated)
3448+
if (!module_allocated) {
3449+
audit_log_kern_module(info->name ? info->name : "(unavailable)");
34493450
mod_stat_bump_becoming(info, flags);
3451+
}
34503452
free_copy(info, flags);
34513453
return err;
34523454
}

0 commit comments

Comments
 (0)