Module Name:    src
Committed By:   pgoyette
Date:           Thu Jun 23 04:41:03 UTC 2016

Modified Files:
        src/sys/kern: kern_module.c

Log Message:
When importing modules from the boot loader we should check for duplicate
module names both in the built-in list and in the list of previously
"pushed" modules.

While here, delay allocating the new 'struct module' until we've passed
the duplicate-name checks.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/kern/kern_module.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_module.c
diff -u src/sys/kern/kern_module.c:1.111 src/sys/kern/kern_module.c:1.112
--- src/sys/kern/kern_module.c:1.111	Thu Jun 16 23:09:44 2016
+++ src/sys/kern/kern_module.c	Thu Jun 23 04:41:03 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_module.c,v 1.111 2016/06/16 23:09:44 pgoyette Exp $	*/
+/*	$NetBSD: kern_module.c,v 1.112 2016/06/23 04:41:03 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.111 2016/06/16 23:09:44 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.112 2016/06/23 04:41:03 pgoyette Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -1240,12 +1240,7 @@ module_prime(const char *name, void *bas
 	module_t *mod;
 	int error;
 
-	mod = module_newmodule(MODULE_SOURCE_BOOT);
-	if (mod == NULL) {
-		return ENOMEM;
-	}
-
-	/* Check for duplicate modules */
+	/* Check for module name same as a built-in module */
 
 	__link_set_foreach(mip, modules) {
 		if (*mip == &module_dummy)
@@ -1253,10 +1248,25 @@ module_prime(const char *name, void *bas
 		if (strcmp((*mip)->mi_name, name) == 0) {
 			module_error("module `%s' pushed by boot loader "
 			    "already exists", name);
-			kmem_free(mod, sizeof(*mod));
 			return EEXIST;
 		}
 	}
+
+	/* Also eliminate duplicate boolist entries */
+
+	TAILQ_FOREACH(mod, &module_bootlist, mod_chain) {
+		if (strcmp(mod->mod_info->mi_name, name) == 0) {
+			module_error("duplicate bootlist entry for module "
+			    "`%s'", name);
+			return EEXIST;
+		}
+	}
+
+	mod = module_newmodule(MODULE_SOURCE_BOOT);
+	if (mod == NULL) {
+		return ENOMEM;
+	}
+
 	error = kobj_load_mem(&mod->mod_kobj, name, base, size);
 	if (error != 0) {
 		kmem_free(mod, sizeof(*mod));

Reply via email to