aboutsummaryrefslogtreecommitdiff
path: root/modutils
diff options
context:
space:
mode:
Diffstat (limited to 'modutils')
-rw-r--r--modutils/depmod.c20
-rw-r--r--modutils/modprobe-small.c27
-rw-r--r--modutils/modprobe.c31
-rw-r--r--modutils/modutils.c8
4 files changed, 49 insertions, 37 deletions
diff --git a/modutils/depmod.c b/modutils/depmod.c
index aa228ec85..a41b3e440 100644
--- a/modutils/depmod.c
+++ b/modutils/depmod.c
@@ -51,7 +51,11 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
51 51
52 info->dnext = info->dprev = info; 52 info->dnext = info->dprev = info;
53 info->name = xstrdup(fname + 2); /* skip "./" */ 53 info->name = xstrdup(fname + 2); /* skip "./" */
54 info->modname = xstrdup(filename2modname(fname, modname)); 54 info->modname = xstrdup(
55 filename2modname(
56 bb_get_last_path_component_nostrip(fname),
57 modname
58 ));
55 for (ptr = image; ptr < image + len - 10; ptr++) { 59 for (ptr = image; ptr < image + len - 10; ptr++) {
56 if (strncmp(ptr, "depends=", 8) == 0) { 60 if (strncmp(ptr, "depends=", 8) == 0) {
57 char *u; 61 char *u;
@@ -242,17 +246,18 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
242 if (!(option_mask32 & OPT_n)) 246 if (!(option_mask32 & OPT_n))
243 xfreopen_write("modules.alias", stdout); 247 xfreopen_write("modules.alias", stdout);
244 for (m = modules; m != NULL; m = m->next) { 248 for (m = modules; m != NULL; m = m->next) {
249 char modname[MODULE_NAME_LEN];
245 const char *fname = bb_basename(m->name); 250 const char *fname = bb_basename(m->name);
246 int fnlen = strchrnul(fname, '.') - fname; 251 filename2modname(fname, modname);
247 while (m->aliases) { 252 while (m->aliases) {
248 /* Last word can well be m->modname instead, 253 /* Last word can well be m->modname instead,
249 * but depmod from module-init-tools 3.4 254 * but depmod from module-init-tools 3.4
250 * uses module basename, i.e., no s/-/_/g. 255 * uses module basename, i.e., no s/-/_/g.
251 * (pathname and .ko.* are still stripped) 256 * (pathname and .ko.* are still stripped)
252 * Mimicking that... */ 257 * Mimicking that... */
253 printf("alias %s %.*s\n", 258 printf("alias %s %s\n",
254 (char*)llist_pop(&m->aliases), 259 (char*)llist_pop(&m->aliases),
255 fnlen, fname); 260 modname);
256 } 261 }
257 } 262 }
258#endif 263#endif
@@ -260,12 +265,13 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
260 if (!(option_mask32 & OPT_n)) 265 if (!(option_mask32 & OPT_n))
261 xfreopen_write("modules.symbols", stdout); 266 xfreopen_write("modules.symbols", stdout);
262 for (m = modules; m != NULL; m = m->next) { 267 for (m = modules; m != NULL; m = m->next) {
268 char modname[MODULE_NAME_LEN];
263 const char *fname = bb_basename(m->name); 269 const char *fname = bb_basename(m->name);
264 int fnlen = strchrnul(fname, '.') - fname; 270 filename2modname(fname, modname);
265 while (m->symbols) { 271 while (m->symbols) {
266 printf("alias symbol:%s %.*s\n", 272 printf("alias symbol:%s %s\n",
267 (char*)llist_pop(&m->symbols), 273 (char*)llist_pop(&m->symbols),
268 fnlen, fname); 274 modname);
269 } 275 }
270 } 276 }
271#endif 277#endif
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index b7990bff1..cf8a3f0fe 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -149,9 +149,13 @@ static void replace(char *s, char what, char with)
149static char *filename2modname(const char *filename, char *modname) 149static char *filename2modname(const char *filename, char *modname)
150{ 150{
151 int i; 151 int i;
152 char *from; 152 const char *from;
153 153
154 from = bb_get_last_path_component_nostrip(filename); 154 // Disabled since otherwise "modprobe dir/name" would work
155 // as if it is "modprobe name". It is unclear why
156 // 'basenamization' was here in the first place.
157 //from = bb_get_last_path_component_nostrip(filename);
158 from = filename;
155 for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++) 159 for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
156 modname[i] = (from[i] == '-') ? '_' : from[i]; 160 modname[i] = (from[i] == '-') ? '_' : from[i];
157 modname[i] = '\0'; 161 modname[i] = '\0';
@@ -631,6 +635,14 @@ static void process_module(char *name, const char *cmdline_options)
631 infovec = find_alias(name); 635 infovec = find_alias(name);
632 } 636 }
633 637
638 if (!infovec) {
639 /* both dirscan and find_alias found nothing */
640 if (!is_rmmod && applet_name[0] != 'd') /* it wasn't rmmod or depmod */
641 bb_error_msg("module '%s' not found", name);
642//TODO: _and_die()? or should we continue (un)loading modules listed on cmdline?
643 goto ret;
644 }
645
634 /* There can be more than one module for the given alias. For example, 646 /* There can be more than one module for the given alias. For example,
635 * "pci:v00008086d00007010sv00000000sd00000000bc01sc01i80" matches 647 * "pci:v00008086d00007010sv00000000sd00000000bc01sc01i80" matches
636 * ata_piix because it has alias "pci:v00008086d00007010sv*sd*bc*sc*i*" 648 * ata_piix because it has alias "pci:v00008086d00007010sv*sd*bc*sc*i*"
@@ -646,7 +658,8 @@ static void process_module(char *name, const char *cmdline_options)
646 int r; 658 int r;
647 char modname[MODULE_NAME_LEN]; 659 char modname[MODULE_NAME_LEN];
648 660
649 filename2modname(info->pathname, modname); 661 filename2modname(
662 bb_get_last_path_component_nostrip(info->pathname), modname);
650 r = delete_module(modname, O_NONBLOCK | O_EXCL); 663 r = delete_module(modname, O_NONBLOCK | O_EXCL);
651 dbg1_error_msg("delete_module('%s', O_NONBLOCK | O_EXCL):%d", modname, r); 664 dbg1_error_msg("delete_module('%s', O_NONBLOCK | O_EXCL):%d", modname, r);
652 if (r != 0) { 665 if (r != 0) {
@@ -669,14 +682,6 @@ static void process_module(char *name, const char *cmdline_options)
669 */ 682 */
670 } 683 }
671 684
672 if (!infovec) {
673 /* both dirscan and find_alias found nothing */
674 if (!is_rmmod && applet_name[0] != 'd') /* it wasn't rmmod or depmod */
675 bb_error_msg("module '%s' not found", name);
676//TODO: _and_die()? or should we continue (un)loading modules listed on cmdline?
677 goto ret;
678 }
679
680 infoidx = 0; 685 infoidx = 0;
681 while ((info = infovec[infoidx++]) != NULL) { 686 while ((info = infovec[infoidx++]) != NULL) {
682 /* Iterate thru dependencies, trying to (un)load them */ 687 /* Iterate thru dependencies, trying to (un)load them */
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
229{ 229{
230 return helper_get_module(module, 1); 230 return helper_get_module(module, 1);
231} 231}
232static ALWAYS_INLINE struct module_entry *get_modentry(const char *module) 232/* So far this function always gets a module pathname, never an alias name.
233 * The crucial difference is that pathname needs dirname stripping,
234 * while alias name must NOT do it!
235 * Testcase where dirname stripping is likely to go wrong: "modprobe devname:snd/timer"
236 */
237static ALWAYS_INLINE struct module_entry *get_modentry(const char *pathname)
233{ 238{
234 return helper_get_module(module, 0); 239 return helper_get_module(bb_get_last_path_component_nostrip(pathname), 0);
235} 240}
236 241
237static void add_probe(const char *name) 242static void add_probe(const char *name)
238{ 243{
239 struct module_entry *m; 244 struct module_entry *m;
240 245
241 /*
242 * get_or_add_modentry() strips path from name and works
243 * on remaining basename.
244 * This would make "rmmod dir/name" and "modprobe dir/name"
245 * to work like "rmmod name" and "modprobe name",
246 * which is wrong, and can be abused via implicit modprobing:
247 * "ifconfig /usbserial up" tries to modprobe netdev-/usbserial.
248 */
249 if (strchr(name, '/'))
250 bb_error_msg_and_die("malformed module name '%s'", name);
251
252 m = get_or_add_modentry(name); 246 m = get_or_add_modentry(name);
253 if (!(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS)) 247 if (!(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
254 && (m->flags & MODULE_FLAG_LOADED) 248 && (m->flags & MODULE_FLAG_LOADED)
@@ -428,7 +422,7 @@ static int do_modprobe(struct module_entry *m)
428 422
429 rc = 0; 423 rc = 0;
430 fn = llist_pop(&m->deps); /* we leak it */ 424 fn = llist_pop(&m->deps); /* we leak it */
431 m2 = get_or_add_modentry(fn); 425 m2 = get_or_add_modentry(bb_get_last_path_component_nostrip(fn));
432 426
433 if (option_mask32 & OPT_REMOVE) { 427 if (option_mask32 & OPT_REMOVE) {
434 /* modprobe -r */ 428 /* modprobe -r */
@@ -510,7 +504,7 @@ static void load_modules_dep(void)
510 colon = last_char_is(tokens[0], ':'); 504 colon = last_char_is(tokens[0], ':');
511 if (colon == NULL) 505 if (colon == NULL)
512 continue; 506 continue;
513 *colon = 0; 507 *colon = '\0';
514 508
515 m = get_modentry(tokens[0]); 509 m = get_modentry(tokens[0]);
516 if (m == NULL) 510 if (m == NULL)
@@ -557,7 +551,6 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
557 551
558 if (opt & OPT_LIST_ONLY) { 552 if (opt & OPT_LIST_ONLY) {
559 int i; 553 int i;
560 char name[MODULE_NAME_LEN];
561 char *colon, *tokens[2]; 554 char *colon, *tokens[2];
562 parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read); 555 parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
563 556
@@ -569,10 +562,14 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
569 if (!colon) 562 if (!colon)
570 continue; 563 continue;
571 *colon = '\0'; 564 *colon = '\0';
572 filename2modname(tokens[0], name);
573 if (!argv[0]) 565 if (!argv[0])
574 puts(tokens[0]); 566 puts(tokens[0]);
575 else { 567 else {
568 char name[MODULE_NAME_LEN];
569 filename2modname(
570 bb_get_last_path_component_nostrip(tokens[0]),
571 name
572 );
576 for (i = 0; argv[i]; i++) { 573 for (i = 0; argv[i]; i++) {
577 if (fnmatch(argv[i], name, 0) == 0) { 574 if (fnmatch(argv[i], name, 0) == 0) {
578 puts(tokens[0]); 575 puts(tokens[0]);
diff --git a/modutils/modutils.c b/modutils/modutils.c
index 6187ca72f..ff79d3fac 100644
--- a/modutils/modutils.c
+++ b/modutils/modutils.c
@@ -48,13 +48,17 @@ int FAST_FUNC string_to_llist(char *string, llist_t **llist, const char *delim)
48char* FAST_FUNC filename2modname(const char *filename, char *modname) 48char* FAST_FUNC filename2modname(const char *filename, char *modname)
49{ 49{
50 int i; 50 int i;
51 char *from; 51 const char *from;
52 52
53 if (filename == NULL) 53 if (filename == NULL)
54 return NULL; 54 return NULL;
55 if (modname == NULL) 55 if (modname == NULL)
56 modname = xmalloc(MODULE_NAME_LEN); 56 modname = xmalloc(MODULE_NAME_LEN);
57 from = bb_get_last_path_component_nostrip(filename); 57 // Disabled since otherwise "modprobe dir/name" would work
58 // as if it is "modprobe name". It is unclear why
59 // 'basenamization' was here in the first place.
60 //from = bb_get_last_path_component_nostrip(filename);
61 from = filename;
58 for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++) 62 for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
59 modname[i] = (from[i] == '-') ? '_' : from[i]; 63 modname[i] = (from[i] == '-') ? '_' : from[i];
60 modname[i] = '\0'; 64 modname[i] = '\0';