summaryrefslogtreecommitdiff
path: root/modutils/modprobe.c
diff options
context:
space:
mode:
Diffstat (limited to 'modutils/modprobe.c')
-rw-r--r--modutils/modprobe.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index f0904285b..aedde5c90 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -229,26 +229,20 @@ static ALWAYS_INLINE struct module_entry *get_or_add_modentry(const char *module
{
return helper_get_module(module, 1);
}
-static ALWAYS_INLINE struct module_entry *get_modentry(const char *module)
+/* So far this function always gets a module pathname, never an alias name.
+ * The crucial difference is that pathname needs dirname stripping,
+ * while alias name must NOT do it!
+ * Testcase where dirname stripping is likely to go wrong: "modprobe devname:snd/timer"
+ */
+static ALWAYS_INLINE struct module_entry *get_modentry(const char *pathname)
{
- return helper_get_module(module, 0);
+ return helper_get_module(bb_get_last_path_component_nostrip(pathname), 0);
}
static void add_probe(const char *name)
{
struct module_entry *m;
- /*
- * get_or_add_modentry() strips path from name and works
- * on remaining basename.
- * This would make "rmmod dir/name" and "modprobe dir/name"
- * to work like "rmmod name" and "modprobe name",
- * which is wrong, and can be abused via implicit modprobing:
- * "ifconfig /usbserial up" tries to modprobe netdev-/usbserial.
- */
- if (strchr(name, '/'))
- bb_error_msg_and_die("malformed module name '%s'", name);
-
m = get_or_add_modentry(name);
if (!(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
&& (m->flags & MODULE_FLAG_LOADED)
@@ -428,7 +422,7 @@ static int do_modprobe(struct module_entry *m)
rc = 0;
fn = llist_pop(&m->deps); /* we leak it */
- m2 = get_or_add_modentry(fn);
+ m2 = get_or_add_modentry(bb_get_last_path_component_nostrip(fn));
if (option_mask32 & OPT_REMOVE) {
/* modprobe -r */
@@ -510,7 +504,7 @@ static void load_modules_dep(void)
colon = last_char_is(tokens[0], ':');
if (colon == NULL)
continue;
- *colon = 0;
+ *colon = '\0';
m = get_modentry(tokens[0]);
if (m == NULL)
@@ -557,7 +551,6 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_LIST_ONLY) {
int i;
- char name[MODULE_NAME_LEN];
char *colon, *tokens[2];
parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
@@ -569,10 +562,14 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
if (!colon)
continue;
*colon = '\0';
- filename2modname(tokens[0], name);
if (!argv[0])
puts(tokens[0]);
else {
+ char name[MODULE_NAME_LEN];
+ filename2modname(
+ bb_get_last_path_component_nostrip(tokens[0]),
+ name
+ );
for (i = 0; argv[i]; i++) {
if (fnmatch(argv[i], name, 0) == 0) {
puts(tokens[0]);