Module Name: src Committed By: mbalmer Date: Sat Aug 6 08:11:10 UTC 2011
Modified Files: src/sbin/modload: modload.8 src/sys/kern: kern_module_vfs.c subr_kobj_vfs.c Log Message: Do not not look for modules in the current working directory first. This is to prevent from accidentally loading ./module.kmod when we actually wanted to load module from the system module area. To load a module from a filesystem path, the module name must contain at least on path separator character (/), to load a module from the system module areas, the name must not contain a path separator character: modload ./mymod.kmod # loads mymod.kmod from the curren directory modload mymod # loads mymod.kmod from the system module area To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/sbin/modload/modload.8 cvs rdiff -u -r1.10 -r1.11 src/sys/kern/kern_module_vfs.c cvs rdiff -u -r1.4 -r1.5 src/sys/kern/subr_kobj_vfs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/modload/modload.8 diff -u src/sbin/modload/modload.8:1.40 src/sbin/modload/modload.8:1.41 --- src/sbin/modload/modload.8:1.40 Tue Dec 14 16:23:59 2010 +++ src/sbin/modload/modload.8 Sat Aug 6 08:11:10 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: modload.8,v 1.40 2010/12/14 16:23:59 jruoho Exp $ +.\" $NetBSD: modload.8,v 1.41 2011/08/06 08:11:10 mbalmer Exp $ .\" .\" Copyright (c) 1993 Christopher G. Demetriou .\" All rights reserved. @@ -32,7 +32,7 @@ .\" .\" <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> .\" -.Dd December 14, 2010 +.Dd August 6, 2011 .Dt MODLOAD 8 .Os .Sh NAME @@ -57,10 +57,11 @@ .Nm utility loads a kernel module specified by the .Ar module -paramamter into the running system. +parameter into the running system. .Pp -The current working directory is first searched for the module object file. -If not found there, the default system module areas are searched. +Modules are loaded from the default system module areas unless the +.Ar module +parameter contains a path separator character (/). .Pp The options to .Nm Index: src/sys/kern/kern_module_vfs.c diff -u src/sys/kern/kern_module_vfs.c:1.10 src/sys/kern/kern_module_vfs.c:1.11 --- src/sys/kern/kern_module_vfs.c:1.10 Sun Nov 28 00:26:38 2010 +++ src/sys/kern/kern_module_vfs.c Sat Aug 6 08:11:09 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_module_vfs.c,v 1.10 2010/11/28 00:26:38 jnemeth Exp $ */ +/* $NetBSD: kern_module_vfs.c,v 1.11 2011/08/06 08:11:09 mbalmer Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_module_vfs.c,v 1.10 2010/11/28 00:26:38 jnemeth Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_module_vfs.c,v 1.11 2011/08/06 08:11:09 mbalmer Exp $"); #define _MODULE_INTERNAL #include <sys/param.h> @@ -77,15 +77,21 @@ path = PNBUF_GET(); if (!autoload) { - nochroot = false; - snprintf(path, MAXPATHLEN, "%s", name); - error = kobj_load_vfs(&mod->mod_kobj, path, nochroot); + if (strchr(name, '/') != NULL) { + nochroot = false; + snprintf(path, MAXPATHLEN, "%s", name); + error = kobj_load_vfs(&mod->mod_kobj, path, nochroot); + } else + error = ENOENT; } if (autoload || (error == ENOENT)) { - nochroot = true; - snprintf(path, MAXPATHLEN, "%s/%s/%s.kmod", - module_base, name, name); - error = kobj_load_vfs(&mod->mod_kobj, path, nochroot); + if (strchr(name, '/') == NULL) { + nochroot = true; + snprintf(path, MAXPATHLEN, "%s/%s/%s.kmod", + module_base, name, name); + error = kobj_load_vfs(&mod->mod_kobj, path, nochroot); + } else + error = ENOENT; } if (error != 0) { PNBUF_PUT(path); Index: src/sys/kern/subr_kobj_vfs.c diff -u src/sys/kern/subr_kobj_vfs.c:1.4 src/sys/kern/subr_kobj_vfs.c:1.5 --- src/sys/kern/subr_kobj_vfs.c:1.4 Fri Nov 19 06:44:43 2010 +++ src/sys/kern/subr_kobj_vfs.c Sat Aug 6 08:11:09 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj_vfs.c,v 1.4 2010/11/19 06:44:43 dholland Exp $ */ +/* $NetBSD: subr_kobj_vfs.c,v 1.5 2011/08/06 08:11:09 mbalmer Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -72,7 +72,7 @@ #include <sys/vnode.h> #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_kobj_vfs.c,v 1.4 2010/11/19 06:44:43 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj_vfs.c,v 1.5 2011/08/06 08:11:09 mbalmer Exp $"); static void kobj_close_vfs(kobj_t ko) @@ -139,6 +139,10 @@ int error; kobj_t ko; + KASSERT(path != NULL); + if (strchr(path, '/') == NULL) + return ENOENT; + cred = kauth_cred_get(); ko = kmem_zalloc(sizeof(*ko), KM_SLEEP);