[RHEL7,COMMIT] ms/audit: fix potential null dereference 'context->module.name'

Submitted by Konstantin Khorenko on June 16, 2020, 11:05 a.m.

Details

Message ID 202006161105.05GB5hml031072@finist-ce7.sw.ru
State New
Headers show

Patch hide | download patch | download mbox

diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 1c5733e369199..1ab4049439641 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1277,8 +1277,12 @@  static void show_special(struct audit_context *context, int *call_panic)
 		break;
 	case AUDIT_KERN_MODULE:
 		audit_log_format(ab, "name=");
-		audit_log_untrustedstring(ab, context->module.name);
-		kfree(context->module.name);
+		if (context->module.name) {
+			audit_log_untrustedstring(ab, context->module.name);
+			kfree(context->module.name);
+		} else
+			audit_log_format(ab, "(null)");
+
 		break;
 	}
 	audit_log_end(ab);
@@ -2431,8 +2435,9 @@  void __audit_log_kern_module(char *name)
 {
 	struct audit_context *context = current->audit_context;
 
-	context->module.name = kmalloc(strlen(name) + 1, GFP_KERNEL);
-	strcpy(context->module.name, name);
+	context->module.name = kstrdup(name, GFP_KERNEL);
+	if (!context->module.name)
+		audit_log_lost("out of memory in __audit_log_kern_module");
 	context->type = AUDIT_KERN_MODULE;
 }