Skip to content

Commit 95e0b46

Browse files
lrq-maxpcmoore
authored andcommitted
audit: fix a memleak caused by auditing load module
module.name will be allocated unconditionally when auditing load module, and audit_log_start() can fail with other reasons, or audit_log_exit maybe not called, caused module.name is not freed so free module.name in audit_free_context and __audit_syscall_exit unreferenced object 0xffff88af90837d20 (size 8): comm "modprobe", pid 1036, jiffies 4294704867 (age 3069.138s) hex dump (first 8 bytes): 69 78 67 62 65 00 ff ff ixgbe... backtrace: [<0000000008da28fe>] __audit_log_kern_module+0x33/0x80 [<00000000c1491e61>] load_module+0x64f/0x3850 [<000000007fc9ae3f>] __do_sys_init_module+0x218/0x250 [<0000000000d4a478>] do_syscall_64+0x117/0x400 [<000000004924ded8>] entry_SYSCALL_64_after_hwframe+0x49/0xbe [<000000007dc331dd>] 0xffffffffffffffff Fixes: ca86cad ("audit: log module name on init_module") Signed-off-by: Zhang Yu <zhangyu31@baidu.com> Signed-off-by: Li RongQing <lirongqing@baidu.com> [PM: manual merge fixup in __audit_syscall_exit()] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 9e98c67 commit 95e0b46

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎kernel/auditsc.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,13 @@ static inline void audit_proctitle_free(struct audit_context *context)
840840
context->proctitle.len = 0;
841841
}
842842

843+
static inline void audit_free_module(struct audit_context *context)
844+
{
845+
if (context->type == AUDIT_KERN_MODULE) {
846+
kfree(context->module.name);
847+
context->module.name = NULL;
848+
}
849+
}
843850
static inline void audit_free_names(struct audit_context *context)
844851
{
845852
struct audit_names *n, *next;
@@ -923,6 +930,7 @@ int audit_alloc(struct task_struct *tsk)
923930

924931
static inline void audit_free_context(struct audit_context *context)
925932
{
933+
audit_free_module(context);
926934
audit_free_names(context);
927935
unroll_tree_refs(context, NULL, 0);
928936
free_tree_refs(context);
@@ -1266,7 +1274,6 @@ static void show_special(struct audit_context *context, int *call_panic)
12661274
audit_log_format(ab, "name=");
12671275
if (context->module.name) {
12681276
audit_log_untrustedstring(ab, context->module.name);
1269-
kfree(context->module.name);
12701277
} else
12711278
audit_log_format(ab, "(null)");
12721279

@@ -1697,6 +1704,7 @@ void __audit_syscall_exit(int success, long return_code)
16971704
context->in_syscall = 0;
16981705
context->prio = context->state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0;
16991706

1707+
audit_free_module(context);
17001708
audit_free_names(context);
17011709
unroll_tree_refs(context, NULL, 0);
17021710
audit_free_aux(context);

0 commit comments

Comments
 (0)