tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Don't load kernel modules from the current directory, second diff
Thanks to all that replied to my initial diff. This second version is
better, it allows to load a module from the filesystem with either an
absolute path starting with '/' or a relative path starting with '.'.
So you can still load a module from the CWD using
modload ./mymodule.kmod
module_load_vfs() is changed in two ways: When a module is loaded from
the path given to modload, it must start with either '.' or '/'. If a
path is constructed to load the module from the system module area, it
must not start with '.' or '/'.
kobj_load_vfs() will only load an object with a path starting with
either '/' or '.'
Comments?
Index: sys/kern/kern_module_vfs.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_module_vfs.c,v
retrieving revision 1.10
diff -u -p -r1.10 kern_module_vfs.c
--- sys/kern/kern_module_vfs.c 28 Nov 2010 00:26:38 -0000 1.10
+++ sys/kern/kern_module_vfs.c 4 Aug 2011 10:34:36 -0000
@@ -77,15 +77,21 @@ module_load_vfs(const char *name, int fl
path = PNBUF_GET();
if (!autoload) {
- nochroot = false;
- snprintf(path, MAXPATHLEN, "%s", name);
- error = kobj_load_vfs(&mod->mod_kobj, path, nochroot);
+ if (*name == '/' || *name == '.') {
+ 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 (*name != '/' && *name != '.') {
+ 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: sys/kern/subr_kobj_vfs.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_kobj_vfs.c,v
retrieving revision 1.4
diff -u -p -r1.4 subr_kobj_vfs.c
--- sys/kern/subr_kobj_vfs.c 19 Nov 2010 06:44:43 -0000 1.4
+++ sys/kern/subr_kobj_vfs.c 4 Aug 2011 10:34:36 -0000
@@ -139,6 +139,10 @@ kobj_load_vfs(kobj_t *kop, const char *p
int error;
kobj_t ko;
+ KASSERT(path != NULL);
+ if (*path != '/' && *path != '.')
+ return ENOENT;
+
cred = kauth_cred_get();
ko = kmem_zalloc(sizeof(*ko), KM_SLEEP);
Home |
Main Index |
Thread Index |
Old Index