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
This commit is contained in:
mbalmer 2011-08-06 08:11:09 +00:00
parent f07d935b68
commit d1912e7839
3 changed files with 27 additions and 16 deletions

View File

@ -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 @@ The
.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

View File

@ -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 @@ module_load_vfs(const char *name, int flags, bool autoload,
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);

View File

@ -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 @@ kobj_load_vfs(kobj_t *kop, const char *path, const bool nochroot)
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);