005-busybox-1.23.0-modprobe.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --- busybox-1.23.0/modutils/depmod.c
  2. +++ busybox-1.23.0-modprobe/modutils/depmod.c
  3. @@ -51,7 +51,11 @@ static int FAST_FUNC parse_module(const
  4. info->dnext = info->dprev = info;
  5. info->name = xstrdup(fname + 2); /* skip "./" */
  6. - info->modname = xstrdup(filename2modname(fname, modname));
  7. + info->modname = xstrdup(
  8. + filename2modname(
  9. + bb_get_last_path_component_nostrip(fname),
  10. + modname
  11. + ));
  12. for (ptr = image; ptr < image + len - 10; ptr++) {
  13. if (strncmp(ptr, "depends=", 8) == 0) {
  14. char *u;
  15. @@ -242,17 +246,18 @@ int depmod_main(int argc UNUSED_PARAM, c
  16. if (!(option_mask32 & OPT_n))
  17. xfreopen_write("modules.alias", stdout);
  18. for (m = modules; m != NULL; m = m->next) {
  19. + char modname[MODULE_NAME_LEN];
  20. const char *fname = bb_basename(m->name);
  21. - int fnlen = strchrnul(fname, '.') - fname;
  22. + filename2modname(fname, modname);
  23. while (m->aliases) {
  24. /* Last word can well be m->modname instead,
  25. * but depmod from module-init-tools 3.4
  26. * uses module basename, i.e., no s/-/_/g.
  27. * (pathname and .ko.* are still stripped)
  28. * Mimicking that... */
  29. - printf("alias %s %.*s\n",
  30. + printf("alias %s %s\n",
  31. (char*)llist_pop(&m->aliases),
  32. - fnlen, fname);
  33. + modname);
  34. }
  35. }
  36. #endif
  37. @@ -260,12 +265,13 @@ int depmod_main(int argc UNUSED_PARAM, c
  38. if (!(option_mask32 & OPT_n))
  39. xfreopen_write("modules.symbols", stdout);
  40. for (m = modules; m != NULL; m = m->next) {
  41. + char modname[MODULE_NAME_LEN];
  42. const char *fname = bb_basename(m->name);
  43. - int fnlen = strchrnul(fname, '.') - fname;
  44. + filename2modname(fname, modname);
  45. while (m->symbols) {
  46. - printf("alias symbol:%s %.*s\n",
  47. + printf("alias symbol:%s %s\n",
  48. (char*)llist_pop(&m->symbols),
  49. - fnlen, fname);
  50. + modname);
  51. }
  52. }
  53. #endif
  54. --- busybox-1.23.0/modutils/modprobe.c
  55. +++ busybox-1.23.0-modprobe/modutils/modprobe.c
  56. @@ -238,17 +238,6 @@ static void add_probe(const char *name)
  57. {
  58. struct module_entry *m;
  59. - /*
  60. - * get_or_add_modentry() strips path from name and works
  61. - * on remaining basename.
  62. - * This would make "rmmod dir/name" and "modprobe dir/name"
  63. - * to work like "rmmod name" and "modprobe name",
  64. - * which is wrong, and can be abused via implicit modprobing:
  65. - * "ifconfig /usbserial up" tries to modprobe netdev-/usbserial.
  66. - */
  67. - if (strchr(name, '/'))
  68. - bb_error_msg_and_die("malformed module name '%s'", name);
  69. -
  70. m = get_or_add_modentry(name);
  71. if (!(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
  72. && (m->flags & MODULE_FLAG_LOADED)
  73. --- busybox-1.23.0/modutils/modprobe-small.c
  74. +++ busybox-1.23.0-modprobe/modutils/modprobe-small.c
  75. @@ -149,9 +149,13 @@ static void replace(char *s, char what,
  76. static char *filename2modname(const char *filename, char *modname)
  77. {
  78. int i;
  79. - char *from;
  80. + const char *from;
  81. - from = bb_get_last_path_component_nostrip(filename);
  82. + // Disabled since otherwise "modprobe dir/name" would work
  83. + // as if it is "modprobe name". It is unclear why
  84. + // 'basenamization' was here in the first place.
  85. + //from = bb_get_last_path_component_nostrip(filename);
  86. + from = filename;
  87. for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
  88. modname[i] = (from[i] == '-') ? '_' : from[i];
  89. modname[i] = '\0';
  90. --- busybox-1.23.0/modutils/modutils.c
  91. +++ busybox-1.23.0-modprobe/modutils/modutils.c
  92. @@ -48,13 +48,17 @@ int FAST_FUNC string_to_llist(char *stri
  93. char* FAST_FUNC filename2modname(const char *filename, char *modname)
  94. {
  95. int i;
  96. - char *from;
  97. + const char *from;
  98. if (filename == NULL)
  99. return NULL;
  100. if (modname == NULL)
  101. modname = xmalloc(MODULE_NAME_LEN);
  102. - from = bb_get_last_path_component_nostrip(filename);
  103. + // Disabled since otherwise "modprobe dir/name" would work
  104. + // as if it is "modprobe name". It is unclear why
  105. + // 'basenamization' was here in the first place.
  106. + //from = bb_get_last_path_component_nostrip(filename);
  107. + from = filename;
  108. for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
  109. modname[i] = (from[i] == '-') ? '_' : from[i];
  110. modname[i] = '\0';