| @@ -68,7 +68,8 @@ · 67 unmodified lines |
| 68 | 68 | |
| 69 | 69 | /* List of modules, protected by module_mutex or preempt_disable |
| 70 | 70 | * (delete uses stop_machine/add uses RCU list operations). */ |
| 71 | | −static DEFINE_MUTEX(module_mutex); |
| 71 | +DEFINE_MUTEX(module_mutex); |
| 72 | +EXPORT_SYMBOL_GPL(module_mutex); |
| 72 | 73 | static LIST_HEAD(modules); |
| 73 | 74 | |
| 74 | 75 | /* Waiting for a module to finish initializing? */ |
| @@ -76,7 +77,7 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq); · 1 unmodified line |
| 76 | 77 | |
| 77 | 78 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); |
| 78 | 79 | |
| 79 | | −/* Bounds of module allocation, for speeding __module_text_address */ |
| 80 | +/* Bounds of module allocation, for speeding __module_address */ |
| 80 | 81 | static unsigned long module_addr_min = -1UL, module_addr_max = 0; |
| 81 | 82 | |
| 82 | 83 | int register_module_notifier(struct notifier_block * nb) |
| @@ -186,17 +187,6 @@ extern const unsigned long __start___kcrctab_unused_gpl[]; · 103 unmodified lines |
| 186 | 187 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) |
| 187 | 188 | #endif |
| 188 | 189 | |
| 189 | | −struct symsearch { |
| 190 | | − const struct kernel_symbol *start, *stop; |
| 191 | | − const unsigned long *crcs; |
| 192 | | − enum { |
| 193 | | − NOT_GPL_ONLY, |
| 194 | | − GPL_ONLY, |
| 195 | | − WILL_BE_GPL_ONLY, |
| 196 | | − } licence; |
| 197 | | − bool unused; |
| 198 | | −}; |
| 199 | | − |
| 200 | 190 | static bool each_symbol_in_section(const struct symsearch *arr, |
| 201 | 191 | unsigned int arrsize, |
| 202 | 192 | struct module *owner, |
| @@ -217,10 +207,8 @@ static bool each_symbol_in_section(const struct symsearch *arr, · 14 unmodified lines |
| 217 | 207 | } |
| 218 | 208 | |
| 219 | 209 | /* Returns true as soon as fn returns true, otherwise false. */ |
| 220 | | −static bool each_symbol(bool (*fn)(const struct symsearch *arr, |
| 221 | | − struct module *owner, |
| 222 | | − unsigned int symnum, void *data), |
| 223 | | − void *data) |
| 210 | +bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, |
| 211 | + unsigned int symnum, void *data), void *data) |
| 224 | 212 | { |
| 225 | 213 | struct module *mod; |
| 226 | 214 | const struct symsearch arr[] = { |
| @@ -273,6 +261,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr, · 46 unmodified lines |
| 273 | 261 | } |
| 274 | 262 | return false; |
| 275 | 263 | } |
| 264 | +EXPORT_SYMBOL_GPL(each_symbol); |
| 276 | 265 | |
| 277 | 266 | struct find_symbol_arg { |
| 278 | 267 | /* Input */ |
| @@ -283,7 +272,7 @@ struct find_symbol_arg { · 4 unmodified lines |
| 283 | 272 | /* Output */ |
| 284 | 273 | struct module *owner; |
| 285 | 274 | const unsigned long *crc; |
| 286 | | − unsigned long value; |
| 275 | + const struct kernel_symbol *sym; |
| 287 | 276 | }; |
| 288 | 277 | |
| 289 | 278 | static bool find_symbol_in_section(const struct symsearch *syms, |
| @@ -324,17 +313,17 @@ static bool find_symbol_in_section(const struct symsearch *syms, · 34 unmodified lines |
| 324 | 313 | |
| 325 | 314 | fsa->owner = owner; |
| 326 | 315 | fsa->crc = symversion(syms->crcs, symnum); |
| 327 | | − fsa->value = syms->start[symnum].value; |
| 316 | + fsa->sym = &syms->start[symnum]; |
| 328 | 317 | return true; |
| 329 | 318 | } |
| 330 | 319 | |
| 331 | | −/* Find a symbol, return value, (optional) crc and (optional) module |
| 332 | | − * which owns it */ |
| 333 | | −static unsigned long find_symbol(const char *name, |
| 334 | | − struct module **owner, |
| 335 | | − const unsigned long **crc, |
| 336 | | − bool gplok, |
| 337 | | − bool warn) |
| 320 | +/* Find a symbol and return it, along with, (optional) crc and |
| 321 | + * (optional) module which owns it */ |
| 322 | +const struct kernel_symbol *find_symbol(const char *name, |
| 323 | + struct module **owner, |
| 324 | + const unsigned long **crc, |
| 325 | + bool gplok, |
| 326 | + bool warn) |
| 338 | 327 | { |
| 339 | 328 | struct find_symbol_arg fsa; |
| 340 | 329 | |
| @@ -347,15 +336,16 @@ static unsigned long find_symbol(const char *name, · 6 unmodified lines |
| 347 | 336 | *owner = fsa.owner; |
| 348 | 337 | if (crc) |
| 349 | 338 | *crc = fsa.crc; |
| 350 | | − return fsa.value; |
| 339 | + return fsa.sym; |
| 351 | 340 | } |
| 352 | 341 | |
| 353 | 342 | DEBUGP("Failed to find symbol %s\n", name); |
| 354 | | − return -ENOENT; |
| 343 | + return NULL; |
| 355 | 344 | } |
| 345 | +EXPORT_SYMBOL_GPL(find_symbol); |
| 356 | 346 | |
| 357 | 347 | /* Search for module by name: must hold module_mutex. */ |
| 358 | | −static struct module *find_module(const char *name) |
| 348 | +struct module *find_module(const char *name) |
| 359 | 349 | { |
| 360 | 350 | struct module *mod; |
| 361 | 351 | |
| @@ -365,6 +355,7 @@ static struct module *find_module(const char *name) · 3 unmodified lines |
| 365 | 355 | } |
| 366 | 356 | return NULL; |
| 367 | 357 | } |
| 358 | +EXPORT_SYMBOL_GPL(find_module); |
| 368 | 359 | |
| 369 | 360 | #ifdef CONFIG_SMP |
| 370 | 361 | |
| @@ -641,7 +632,7 @@ static int already_uses(struct module *a, struct module *b) · 270 unmodified lines |
| 641 | 632 | } |
| 642 | 633 | |
| 643 | 634 | /* Module a uses b */ |
| 644 | | −static int use_module(struct module *a, struct module *b) |
| 635 | +int use_module(struct module *a, struct module *b) |
| 645 | 636 | { |
| 646 | 637 | struct module_use *use; |
| 647 | 638 | int no_warn, err; |
| @@ -674,6 +665,7 @@ static int use_module(struct module *a, struct module *b) · 26 unmodified lines |
| 674 | 665 | no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); |
| 675 | 666 | return 1; |
| 676 | 667 | } |
| 668 | +EXPORT_SYMBOL_GPL(use_module); |
| 677 | 669 | |
| 678 | 670 | /* Clear the unload stuff of the module. */ |
| 679 | 671 | static void module_unload_free(struct module *mod) |
| @@ -894,7 +886,7 @@ void __symbol_put(const char *symbol) · 214 unmodified lines |
| 894 | 886 | struct module *owner; |
| 895 | 887 | |
| 896 | 888 | preempt_disable(); |
| 897 | | − if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false))) |
| 889 | + if (!find_symbol(symbol, &owner, NULL, true, false)) |
| 898 | 890 | BUG(); |
| 899 | 891 | module_put(owner); |
| 900 | 892 | preempt_enable(); |
| @@ -908,8 +900,10 @@ void symbol_put_addr(void *addr) · 7 unmodified lines |
| 908 | 900 | if (core_kernel_text((unsigned long)addr)) |
| 909 | 901 | return; |
| 910 | 902 | |
| 911 | | − if (!(modaddr = module_text_address((unsigned long)addr))) |
| 912 | | − BUG(); |
| 903 | + /* module_text_address is safe here: we're supposed to have reference |
| 904 | + * to module from symbol_get, so it can't go away. */ |
| 905 | + modaddr = __module_text_address((unsigned long)addr); |
| 906 | + BUG_ON(!modaddr); |
| 913 | 907 | module_put(modaddr); |
| 914 | 908 | } |
| 915 | 909 | EXPORT_SYMBOL_GPL(symbol_put_addr); |
| @@ -949,10 +943,11 @@ static inline void module_unload_free(struct module *mod) · 33 unmodified lines |
| 949 | 943 | { |
| 950 | 944 | } |
| 951 | 945 | |
| 952 | | −static inline int use_module(struct module *a, struct module *b) |
| 946 | +int use_module(struct module *a, struct module *b) |
| 953 | 947 | { |
| 954 | 948 | return strong_try_module_get(b) == 0; |
| 955 | 949 | } |
| 950 | +EXPORT_SYMBOL_GPL(use_module); |
| 956 | 951 | |
| 957 | 952 | static inline void module_unload_init(struct module *mod) |
| 958 | 953 | { |
| @@ -995,12 +990,12 @@ static struct module_attribute *modinfo_attrs[] = { · 36 unmodified lines |
| 995 | 990 | |
| 996 | 991 | static const char vermagic[] = VERMAGIC_STRING; |
| 997 | 992 | |
| 998 | | −static int try_to_force_load(struct module *mod, const char *symname) |
| 993 | +static int try_to_force_load(struct module *mod, const char *reason) |
| 999 | 994 | { |
| 1000 | 995 | #ifdef CONFIG_MODULE_FORCE_LOAD |
| 1001 | 996 | if (!test_taint(TAINT_FORCED_MODULE)) |
| 1002 | | − printk("%s: no version for \"%s\" found: kernel tainted.\n", |
| 1003 | | − mod->name, symname); |
| 997 | + printk(KERN_WARNING "%s: %s: kernel tainted.\n", |
| 998 | + mod->name, reason); |
| 1004 | 999 | add_taint_module(mod, TAINT_FORCED_MODULE); |
| 1005 | 1000 | return 0; |
| 1006 | 1001 | #else |
| @@ -1057,9 +1052,9 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs, · 50 unmodified lines |
| 1057 | 1052 | { |
| 1058 | 1053 | const unsigned long *crc; |
| 1059 | 1054 | |
| 1060 | | − if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false))) |
| 1055 | + if (!find_symbol("module_layout", NULL, &crc, true, false)) |
| 1061 | 1056 | BUG(); |
| 1062 | | − return check_version(sechdrs, versindex, "struct_module", mod, crc); |
| 1057 | + return check_version(sechdrs, versindex, "module_layout", mod, crc); |
| 1063 | 1058 | } |
| 1064 | 1059 | |
| 1065 | 1060 | /* First part is kernel version, which we ignore if module has crcs. */ |
| @@ -1098,25 +1093,25 @@ static inline int same_magic(const char *amagic, const char *bmagic, · 32 unmodified lines |
| 1098 | 1093 | |
| 1099 | 1094 | /* Resolve a symbol for this module. I.e. if we find one, record usage. |
| 1100 | 1095 | Must be holding module_mutex. */ |
| 1101 | | −static unsigned long resolve_symbol(Elf_Shdr *sechdrs, |
| 1102 | | − unsigned int versindex, |
| 1103 | | − const char *name, |
| 1104 | | − struct module *mod) |
| 1096 | +static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, |
| 1097 | + unsigned int versindex, |
| 1098 | + const char *name, |
| 1099 | + struct module *mod) |
| 1105 | 1100 | { |
| 1106 | 1101 | struct module *owner; |
| 1107 | | − unsigned long ret; |
| 1102 | + const struct kernel_symbol *sym; |
| 1108 | 1103 | const unsigned long *crc; |
| 1109 | 1104 | |
| 1110 | | − ret = find_symbol(name, &owner, &crc, |
| 1105 | + sym = find_symbol(name, &owner, &crc, |
| 1111 | 1106 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); |
| 1112 | | − if (!IS_ERR_VALUE(ret)) { |
| 1113 | | − /* use_module can fail due to OOM, |
| 1114 | | − or module initialization or unloading */ |
| 1107 | + /* use_module can fail due to OOM, |
| 1108 | + or module initialization or unloading */ |
| 1109 | + if (sym) { |
| 1115 | 1110 | if (!check_version(sechdrs, versindex, name, mod, crc) || |
| 1116 | 1111 | !use_module(mod, owner)) |
| 1117 | | − ret = -EINVAL; |
| 1112 | + sym = NULL; |
| 1118 | 1113 | } |
| 1119 | | − return ret; |
| 1114 | + return sym; |
| 1120 | 1115 | } |
| 1121 | 1116 | |
| 1122 | 1117 | /* |
| @@ -1491,6 +1486,9 @@ static void free_module(struct module *mod) · 368 unmodified lines |
| 1491 | 1486 | /* Module unload stuff */ |
| 1492 | 1487 | module_unload_free(mod); |
| 1493 | 1488 | |
| 1489 | + /* Free any allocated parameters. */ |
| 1490 | + destroy_params(mod->kp, mod->num_kp); |
| 1491 | + |
| 1494 | 1492 | /* release any pointers to mcount in this module */ |
| 1495 | 1493 | ftrace_release(mod->module_core, mod->core_size); |
| 1496 | 1494 | |
| @@ -1513,17 +1511,15 @@ static void free_module(struct module *mod) · 16 unmodified lines |
| 1513 | 1511 | void *__symbol_get(const char *symbol) |
| 1514 | 1512 | { |
| 1515 | 1513 | struct module *owner; |
| 1516 | | − unsigned long value; |
| 1514 | + const struct kernel_symbol *sym; |
| 1517 | 1515 | |
| 1518 | 1516 | preempt_disable(); |
| 1519 | | − value = find_symbol(symbol, &owner, NULL, true, true); |
| 1520 | | − if (IS_ERR_VALUE(value)) |
| 1521 | | − value = 0; |
| 1522 | | − else if (strong_try_module_get(owner)) |
| 1523 | | − value = 0; |
| 1517 | + sym = find_symbol(symbol, &owner, NULL, true, true); |
| 1518 | + if (sym && strong_try_module_get(owner)) |
| 1519 | + sym = NULL; |
| 1524 | 1520 | preempt_enable(); |
| 1525 | 1521 | |
| 1526 | | − return (void *)value; |
| 1522 | + return sym ? (void *)sym->value : NULL; |
| 1527 | 1523 | } |
| 1528 | 1524 | EXPORT_SYMBOL_GPL(__symbol_get); |
| 1529 | 1525 | |
| @@ -1551,8 +1547,7 @@ static int verify_export_symbols(struct module *mod) · 21 unmodified lines |
| 1551 | 1547 | |
| 1552 | 1548 | for (i = 0; i < ARRAY_SIZE(arr); i++) { |
| 1553 | 1549 | for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { |
| 1554 | | − if (!IS_ERR_VALUE(find_symbol(s->name, &owner, |
| 1555 | | − NULL, true, false))) { |
| 1550 | + if (find_symbol(s->name, &owner, NULL, true, false)) { |
| 1556 | 1551 | printk(KERN_ERR |
| 1557 | 1552 | "%s: exports duplicate symbol %s" |
| 1558 | 1553 | " (owned by %s)\n", |
| @@ -1576,6 +1571,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs, · 17 unmodified lines |
| 1576 | 1571 | unsigned long secbase; |
| 1577 | 1572 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); |
| 1578 | 1573 | int ret = 0; |
| 1574 | + const struct kernel_symbol *ksym; |
| 1579 | 1575 | |
| 1580 | 1576 | for (i = 1; i < n; i++) { |
| 1581 | 1577 | switch (sym[i].st_shndx) { |
| @@ -1595,13 +1591,14 @@ static int simplify_symbols(Elf_Shdr *sechdrs, · 13 unmodified lines |
| 1595 | 1591 | break; |
| 1596 | 1592 | |
| 1597 | 1593 | case SHN_UNDEF: |
| 1598 | | − sym[i].st_value |
| 1599 | | − = resolve_symbol(sechdrs, versindex, |
| 1600 | | − strtab + sym[i].st_name, mod); |
| 1601 | | − |
| 1594 | + ksym = resolve_symbol(sechdrs, versindex, |
| 1595 | + strtab + sym[i].st_name, mod); |
| 1602 | 1596 | /* Ok if resolved. */ |
| 1603 | | − if (!IS_ERR_VALUE(sym[i].st_value)) |
| 1597 | + if (ksym) { |
| 1598 | + sym[i].st_value = ksym->value; |
| 1604 | 1599 | break; |
| 1600 | + } |
| 1601 | + |
| 1605 | 1602 | /* Ok if weak. */ |
| 1606 | 1603 | if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) |
| 1607 | 1604 | break; |
| @@ -1676,8 +1673,7 @@ static void layout_sections(struct module *mod, · 68 unmodified lines |
| 1676 | 1673 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
| 1677 | 1674 | || (s->sh_flags & masks[m][1]) |
| 1678 | 1675 | || s->sh_entsize != ~0UL |
| 1679 | | − || strncmp(secstrings + s->sh_name, |
| 1680 | | − ".init", 5) == 0) |
| 1676 | + || strstarts(secstrings + s->sh_name, ".init")) |
| 1681 | 1677 | continue; |
| 1682 | 1678 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); |
| 1683 | 1679 | DEBUGP("\t%s\n", secstrings + s->sh_name); |
| @@ -1694,8 +1690,7 @@ static void layout_sections(struct module *mod, · 10 unmodified lines |
| 1694 | 1690 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
| 1695 | 1691 | || (s->sh_flags & masks[m][1]) |
| 1696 | 1692 | || s->sh_entsize != ~0UL |
| 1697 | | − || strncmp(secstrings + s->sh_name, |
| 1698 | | − ".init", 5) != 0) |
| 1693 | + || !strstarts(secstrings + s->sh_name, ".init")) |
| 1699 | 1694 | continue; |
| 1700 | 1695 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) |
| 1701 | 1696 | | INIT_OFFSET_MASK); |
| @@ -1828,8 +1823,7 @@ static char elf_type(const Elf_Sym *sym, · 126 unmodified lines |
| 1828 | 1823 | else |
| 1829 | 1824 | return 'b'; |
| 1830 | 1825 | } |
| 1831 | | − if (strncmp(secstrings + sechdrs[sym->st_shndx].sh_name, |
| 1832 | | − ".debug", strlen(".debug")) == 0) |
| 1826 | + if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug")) |
| 1833 | 1827 | return 'n'; |
| 1834 | 1828 | return '?'; |
| 1835 | 1829 | } |
| @@ -1898,8 +1892,7 @@ static noinline struct module *load_module(void __user *umod, · 62 unmodified lines |
| 1898 | 1892 | unsigned int symindex = 0; |
| 1899 | 1893 | unsigned int strindex = 0; |
| 1900 | 1894 | unsigned int modindex, versindex, infoindex, pcpuindex; |
| 1901 | | − unsigned int num_kp, num_mcount; |
| 1902 | | − struct kernel_param *kp; |
| 1895 | + unsigned int num_mcount; |
| 1903 | 1896 | struct module *mod; |
| 1904 | 1897 | long err = 0; |
| 1905 | 1898 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ |
| @@ -1916,12 +1909,6 @@ static noinline struct module *load_module(void __user *umod, · 10 unmodified lines |
| 1916 | 1909 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) |
| 1917 | 1910 | return ERR_PTR(-ENOMEM); |
| 1918 | 1911 | |
| 1919 | | − /* Create stop_machine threads since the error path relies on |
| 1920 | | − * a non-failing stop_machine call. */ |
| 1921 | | − err = stop_machine_create(); |
| 1922 | | − if (err) |
| 1923 | | − goto free_hdr; |
| 1924 | | − |
| 1925 | 1912 | if (copy_from_user(hdr, umod, len) != 0) { |
| 1926 | 1913 | err = -EFAULT; |
| 1927 | 1914 | goto free_hdr; |
| @@ -1962,9 +1949,12 @@ static noinline struct module *load_module(void __user *umod, · 34 unmodified lines |
| 1962 | 1949 | } |
| 1963 | 1950 | #ifndef CONFIG_MODULE_UNLOAD |
| 1964 | 1951 | /* Don't load .exit sections */ |
| 1965 | | − if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) == 0) |
| 1952 | + if (strstarts(secstrings+sechdrs[i].sh_name, ".exit")) |
| 1966 | 1953 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; |
| 1967 | 1954 | #endif |
| 1955 | + /* Don't keep __versions around; it's just for loading. */ |
| 1956 | + if (strcmp(secstrings + sechdrs[i].sh_name, "__versions") == 0) |
| 1957 | + sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; |
| 1968 | 1958 | } |
| 1969 | 1959 | |
| 1970 | 1960 | modindex = find_sec(hdr, sechdrs, secstrings, |
| @@ -2006,7 +1996,7 @@ static noinline struct module *load_module(void __user *umod, · 35 unmodified lines |
| 2006 | 1996 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); |
| 2007 | 1997 | /* This is allowed: modprobe --force will invalidate it. */ |
| 2008 | 1998 | if (!modmagic) { |
| 2009 | | − err = try_to_force_load(mod, "magic"); |
| 1999 | + err = try_to_force_load(mod, "bad vermagic"); |
| 2010 | 2000 | if (err) |
| 2011 | 2001 | goto free_hdr; |
| 2012 | 2002 | } else if (!same_magic(modmagic, vermagic, versindex)) { |
| @@ -2144,8 +2134,8 @@ static noinline struct module *load_module(void __user *umod, · 131 unmodified lines |
| 2144 | 2134 | |
| 2145 | 2135 | /* Now we've got everything in the final locations, we can |
| 2146 | 2136 | * find optional sections. */ |
| 2147 | | − kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), |
| 2148 | | − &num_kp); |
| 2137 | + mod->kp = section_objs(hdr, sechdrs, secstrings, "__param", |
| 2138 | + sizeof(*mod->kp), &mod->num_kp); |
| 2149 | 2139 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", |
| 2150 | 2140 | sizeof(*mod->syms), &mod->num_syms); |
| 2151 | 2141 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); |
| @@ -2195,8 +2185,8 @@ static noinline struct module *load_module(void __user *umod, · 43 unmodified lines |
| 2195 | 2185 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) |
| 2196 | 2186 | #endif |
| 2197 | 2187 | ) { |
| 2198 | | − printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); |
| 2199 | | − err = try_to_force_load(mod, "nocrc"); |
| 2188 | + err = try_to_force_load(mod, |
| 2189 | + "no versions for exported symbols"); |
| 2200 | 2190 | if (err) |
| 2201 | 2191 | goto cleanup; |
| 2202 | 2192 | } |
| @@ -2291,11 +2281,11 @@ static noinline struct module *load_module(void __user *umod, · 88 unmodified lines |
| 2291 | 2281 | */ |
| 2292 | 2282 | list_add_rcu(&mod->list, &modules); |
| 2293 | 2283 | |
| 2294 | | − err = parse_args(mod->name, mod->args, kp, num_kp, NULL); |
| 2284 | + err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); |
| 2295 | 2285 | if (err < 0) |
| 2296 | 2286 | goto unlink; |
| 2297 | 2287 | |
| 2298 | | − err = mod_sysfs_setup(mod, kp, num_kp); |
| 2288 | + err = mod_sysfs_setup(mod, mod->kp, mod->num_kp); |
| 2299 | 2289 | if (err < 0) |
| 2300 | 2290 | goto unlink; |
| 2301 | 2291 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
| @@ -2304,12 +2294,13 @@ static noinline struct module *load_module(void __user *umod, · 2 unmodified lines |
| 2304 | 2294 | /* Get rid of temporary copy */ |
| 2305 | 2295 | vfree(hdr); |
| 2306 | 2296 | |
| 2307 | | − stop_machine_destroy(); |
| 2308 | 2297 | /* Done! */ |
| 2309 | 2298 | return mod; |
| 2310 | 2299 | |
| 2311 | 2300 | unlink: |
| 2312 | | − stop_machine(__unlink_module, mod, NULL); |
| 2301 | + /* Unlink carefully: kallsyms could be walking list. */ |
| 2302 | + list_del_rcu(&mod->list); |
| 2303 | + synchronize_sched(); |
| 2313 | 2304 | module_arch_cleanup(mod); |
| 2314 | 2305 | cleanup: |
| 2315 | 2306 | kobject_del(&mod->mkobj.kobj); |
| @@ -2317,8 +2308,8 @@ static noinline struct module *load_module(void __user *umod, · 1 unmodified line |
| 2317 | 2308 | ftrace_release(mod->module_core, mod->core_size); |
| 2318 | 2309 | free_unload: |
| 2319 | 2310 | module_unload_free(mod); |
| 2320 | | − free_init: |
| 2321 | 2311 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) |
| 2312 | + free_init: |
| 2322 | 2313 | percpu_modfree(mod->refptr); |
| 2323 | 2314 | #endif |
| 2324 | 2315 | module_free(mod, mod->module_init); |
| @@ -2332,7 +2323,6 @@ static noinline struct module *load_module(void __user *umod, · 7 unmodified lines |
| 2332 | 2323 | kfree(args); |
| 2333 | 2324 | free_hdr: |
| 2334 | 2325 | vfree(hdr); |
| 2335 | | − stop_machine_destroy(); |
| 2336 | 2326 | return ERR_PTR(err); |
| 2337 | 2327 | |
| 2338 | 2328 | truncated: |
| @@ -2609,6 +2599,25 @@ unsigned long module_kallsyms_lookup_name(const char *name) · 270 unmodified lines |
| 2609 | 2599 | preempt_enable(); |
| 2610 | 2600 | return ret; |
| 2611 | 2601 | } |
| 2602 | + |
| 2603 | +int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, |
| 2604 | + struct module *, unsigned long), |
| 2605 | + void *data) |
| 2606 | +{ |
| 2607 | + struct module *mod; |
| 2608 | + unsigned int i; |
| 2609 | + int ret; |
| 2610 | + |
| 2611 | + list_for_each_entry(mod, &modules, list) { |
| 2612 | + for (i = 0; i < mod->num_symtab; i++) { |
| 2613 | + ret = fn(data, mod->strtab + mod->symtab[i].st_name, |
| 2614 | + mod, mod->symtab[i].st_value); |
| 2615 | + if (ret != 0) |
| 2616 | + return ret; |
| 2617 | + } |
| 2618 | + } |
| 2619 | + return 0; |
| 2620 | +} |
| 2612 | 2621 | #endif /* CONFIG_KALLSYMS */ |
| 2613 | 2622 | |
| 2614 | 2623 | static char *module_flags(struct module *mod, char *buf) |
| @@ -2744,29 +2753,31 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) · 129 unmodified lines |
| 2744 | 2753 | } |
| 2745 | 2754 | |
| 2746 | 2755 | /* |
| 2747 | | − * Is this a valid module address? |
| 2756 | + * is_module_address - is this address inside a module? |
| 2757 | + * @addr: the address to check. |
| 2758 | + * |
| 2759 | + * See is_module_text_address() if you simply want to see if the address |
| 2760 | + * is code (not data). |
| 2748 | 2761 | */ |
| 2749 | | −int is_module_address(unsigned long addr) |
| 2762 | +bool is_module_address(unsigned long addr) |
| 2750 | 2763 | { |
| 2751 | | − struct module *mod; |
| 2764 | + bool ret; |
| 2752 | 2765 | |
| 2753 | 2766 | preempt_disable(); |
| 2754 | | − |
| 2755 | | − list_for_each_entry_rcu(mod, &modules, list) { |
| 2756 | | − if (within_module_core(addr, mod)) { |
| 2757 | | − preempt_enable(); |
| 2758 | | − return 1; |
| 2759 | | − } |
| 2760 | | − } |
| 2761 | | − |
| 2767 | + ret = __module_address(addr) != NULL; |
| 2762 | 2768 | preempt_enable(); |
| 2763 | 2769 | |
| 2764 | | − return 0; |
| 2770 | + return ret; |
| 2765 | 2771 | } |
| 2766 | 2772 | |
| 2767 | | − |
| 2768 | | −/* Is this a valid kernel address? */ |
| 2769 | | −__notrace_funcgraph struct module *__module_text_address(unsigned long addr) |
| 2773 | +/* |
| 2774 | + * __module_address - get the module which contains an address. |
| 2775 | + * @addr: the address. |
| 2776 | + * |
| 2777 | + * Must be called with preempt disabled or module mutex held so that |
| 2778 | + * module doesn't get freed during this. |
| 2779 | + */ |
| 2780 | +__notrace_funcgraph struct module *__module_address(unsigned long addr) |
| 2770 | 2781 | { |
| 2771 | 2782 | struct module *mod; |
| 2772 | 2783 | |
| @@ -2774,22 +2785,51 @@ __notrace_funcgraph struct module *__module_text_address(unsigned long addr) · 1 unmodified line |
| 2774 | 2785 | return NULL; |
| 2775 | 2786 | |
| 2776 | 2787 | list_for_each_entry_rcu(mod, &modules, list) |
| 2777 | | − if (within(addr, mod->module_init, mod->init_text_size) |
| 2778 | | − || within(addr, mod->module_core, mod->core_text_size)) |
| 2788 | + if (within_module_core(addr, mod) |
| 2789 | + || within_module_init(addr, mod)) |
| 2779 | 2790 | return mod; |
| 2780 | 2791 | return NULL; |
| 2781 | 2792 | } |
| 2793 | +EXPORT_SYMBOL_GPL(__module_address); |
| 2782 | 2794 | |
| 2783 | | −struct module *module_text_address(unsigned long addr) |
| 2795 | +/* |
| 2796 | + * is_module_text_address - is this address inside module code? |
| 2797 | + * @addr: the address to check. |
| 2798 | + * |
| 2799 | + * See is_module_address() if you simply want to see if the address is |
| 2800 | + * anywhere in a module. See kernel_text_address() for testing if an |
| 2801 | + * address corresponds to kernel or module code. |
| 2802 | + */ |
| 2803 | +bool is_module_text_address(unsigned long addr) |
| 2784 | 2804 | { |
| 2785 | | − struct module *mod; |
| 2805 | + bool ret; |
| 2786 | 2806 | |
| 2787 | 2807 | preempt_disable(); |
| 2788 | | − mod = __module_text_address(addr); |
| 2808 | + ret = __module_text_address(addr) != NULL; |
| 2789 | 2809 | preempt_enable(); |
| 2790 | 2810 | |
| 2811 | + return ret; |
| 2812 | +} |
| 2813 | + |
| 2814 | +/* |
| 2815 | + * __module_text_address - get the module whose code contains an address. |
| 2816 | + * @addr: the address. |
| 2817 | + * |
| 2818 | + * Must be called with preempt disabled or module mutex held so that |
| 2819 | + * module doesn't get freed during this. |
| 2820 | + */ |
| 2821 | +struct module *__module_text_address(unsigned long addr) |
| 2822 | +{ |
| 2823 | + struct module *mod = __module_address(addr); |
| 2824 | + if (mod) { |
| 2825 | + /* Make sure it's within the text section. */ |
| 2826 | + if (!within(addr, mod->module_init, mod->init_text_size) |
| 2827 | + && !within(addr, mod->module_core, mod->core_text_size)) |
| 2828 | + mod = NULL; |
| 2829 | + } |
| 2791 | 2830 | return mod; |
| 2792 | 2831 | } |
| 2832 | +EXPORT_SYMBOL_GPL(__module_text_address); |
| 2793 | 2833 | |
| 2794 | 2834 | /* Don't grab lock, we're oopsing. */ |
| 2795 | 2835 | void print_modules(void) |
| @@ -2809,9 +2849,17 @@ void print_modules(void) · 13 unmodified lines |
| 2809 | 2849 | } |
| 2810 | 2850 | |
| 2811 | 2851 | #ifdef CONFIG_MODVERSIONS |
| 2812 | | −/* Generate the signature for struct module here, too, for modversions. */ |
| 2813 | | −void struct_module(struct module *mod) { return; } |
| 2814 | | −EXPORT_SYMBOL(struct_module); |
| 2852 | +/* Generate the signature for all relevant module structures here. |
| 2853 | + * If these change, we don't want to try to parse the module. */ |
| 2854 | +void module_layout(struct module *mod, |
| 2855 | + struct modversion_info *ver, |
| 2856 | + struct kernel_param *kp, |
| 2857 | + struct kernel_symbol *ks, |
| 2858 | + struct marker *marker, |
| 2859 | + struct tracepoint *tp) |
| 2860 | +{ |
| 2861 | +} |
| 2862 | +EXPORT_SYMBOL(module_layout); |
| 2815 | 2863 | #endif |
| 2816 | 2864 | |
| 2817 | 2865 | #ifdef CONFIG_MARKERS |