diff options
Diffstat (limited to 'kernel/module.c')
| -rw-r--r-- | kernel/module.c | 387 |
1 files changed, 233 insertions, 154 deletions
diff --git a/kernel/module.c b/kernel/module.c index ba22484a987e..c268a771595c 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
| @@ -51,6 +51,7 @@ | |||
| 51 | #include <linux/tracepoint.h> | 51 | #include <linux/tracepoint.h> |
| 52 | #include <linux/ftrace.h> | 52 | #include <linux/ftrace.h> |
| 53 | #include <linux/async.h> | 53 | #include <linux/async.h> |
| 54 | #include <linux/percpu.h> | ||
| 54 | 55 | ||
| 55 | #if 0 | 56 | #if 0 |
| 56 | #define DEBUGP printk | 57 | #define DEBUGP printk |
| @@ -67,7 +68,8 @@ | |||
| 67 | 68 | ||
| 68 | /* List of modules, protected by module_mutex or preempt_disable | 69 | /* List of modules, protected by module_mutex or preempt_disable |
| 69 | * (delete uses stop_machine/add uses RCU list operations). */ | 70 | * (delete uses stop_machine/add uses RCU list operations). */ |
| 70 | static DEFINE_MUTEX(module_mutex); | 71 | DEFINE_MUTEX(module_mutex); |
| 72 | EXPORT_SYMBOL_GPL(module_mutex); | ||
| 71 | static LIST_HEAD(modules); | 73 | static LIST_HEAD(modules); |
| 72 | 74 | ||
| 73 | /* Waiting for a module to finish initializing? */ | 75 | /* Waiting for a module to finish initializing? */ |
| @@ -75,7 +77,7 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq); | |||
| 75 | 77 | ||
| 76 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); | 78 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); |
| 77 | 79 | ||
| 78 | /* Bounds of module allocation, for speeding __module_text_address */ | 80 | /* Bounds of module allocation, for speeding __module_address */ |
| 79 | static unsigned long module_addr_min = -1UL, module_addr_max = 0; | 81 | static unsigned long module_addr_min = -1UL, module_addr_max = 0; |
| 80 | 82 | ||
| 81 | int register_module_notifier(struct notifier_block * nb) | 83 | int register_module_notifier(struct notifier_block * nb) |
| @@ -185,17 +187,6 @@ extern const unsigned long __start___kcrctab_unused_gpl[]; | |||
| 185 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) | 187 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) |
| 186 | #endif | 188 | #endif |
| 187 | 189 | ||
| 188 | struct symsearch { | ||
| 189 | const struct kernel_symbol *start, *stop; | ||
| 190 | const unsigned long *crcs; | ||
| 191 | enum { | ||
| 192 | NOT_GPL_ONLY, | ||
| 193 | GPL_ONLY, | ||
| 194 | WILL_BE_GPL_ONLY, | ||
| 195 | } licence; | ||
| 196 | bool unused; | ||
| 197 | }; | ||
| 198 | |||
| 199 | static bool each_symbol_in_section(const struct symsearch *arr, | 190 | static bool each_symbol_in_section(const struct symsearch *arr, |
| 200 | unsigned int arrsize, | 191 | unsigned int arrsize, |
| 201 | struct module *owner, | 192 | struct module *owner, |
| @@ -216,10 +207,8 @@ static bool each_symbol_in_section(const struct symsearch *arr, | |||
| 216 | } | 207 | } |
| 217 | 208 | ||
| 218 | /* Returns true as soon as fn returns true, otherwise false. */ | 209 | /* Returns true as soon as fn returns true, otherwise false. */ |
| 219 | static bool each_symbol(bool (*fn)(const struct symsearch *arr, | 210 | bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, |
| 220 | struct module *owner, | 211 | unsigned int symnum, void *data), void *data) |
| 221 | unsigned int symnum, void *data), | ||
| 222 | void *data) | ||
| 223 | { | 212 | { |
| 224 | struct module *mod; | 213 | struct module *mod; |
| 225 | const struct symsearch arr[] = { | 214 | const struct symsearch arr[] = { |
| @@ -272,6 +261,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr, | |||
| 272 | } | 261 | } |
| 273 | return false; | 262 | return false; |
| 274 | } | 263 | } |
| 264 | EXPORT_SYMBOL_GPL(each_symbol); | ||
| 275 | 265 | ||
| 276 | struct find_symbol_arg { | 266 | struct find_symbol_arg { |
| 277 | /* Input */ | 267 | /* Input */ |
| @@ -282,7 +272,7 @@ struct find_symbol_arg { | |||
| 282 | /* Output */ | 272 | /* Output */ |
| 283 | struct module *owner; | 273 | struct module *owner; |
| 284 | const unsigned long *crc; | 274 | const unsigned long *crc; |
| 285 | unsigned long value; | 275 | const struct kernel_symbol *sym; |
| 286 | }; | 276 | }; |
| 287 | 277 | ||
| 288 | static bool find_symbol_in_section(const struct symsearch *syms, | 278 | static bool find_symbol_in_section(const struct symsearch *syms, |
| @@ -323,17 +313,17 @@ static bool find_symbol_in_section(const struct symsearch *syms, | |||
| 323 | 313 | ||
| 324 | fsa->owner = owner; | 314 | fsa->owner = owner; |
| 325 | fsa->crc = symversion(syms->crcs, symnum); | 315 | fsa->crc = symversion(syms->crcs, symnum); |
| 326 | fsa->value = syms->start[symnum].value; | 316 | fsa->sym = &syms->start[symnum]; |
| 327 | return true; | 317 | return true; |
| 328 | } | 318 | } |
| 329 | 319 | ||
| 330 | /* Find a symbol, return value, (optional) crc and (optional) module | 320 | /* Find a symbol and return it, along with, (optional) crc and |
| 331 | * which owns it */ | 321 | * (optional) module which owns it */ |
| 332 | static unsigned long find_symbol(const char *name, | 322 | const struct kernel_symbol *find_symbol(const char *name, |
| 333 | struct module **owner, | 323 | struct module **owner, |
| 334 | const unsigned long **crc, | 324 | const unsigned long **crc, |
| 335 | bool gplok, | 325 | bool gplok, |
| 336 | bool warn) | 326 | bool warn) |
| 337 | { | 327 | { |
| 338 | struct find_symbol_arg fsa; | 328 | struct find_symbol_arg fsa; |
| 339 | 329 | ||
| @@ -346,15 +336,16 @@ static unsigned long find_symbol(const char *name, | |||
| 346 | *owner = fsa.owner; | 336 | *owner = fsa.owner; |
| 347 | if (crc) | 337 | if (crc) |
| 348 | *crc = fsa.crc; | 338 | *crc = fsa.crc; |
| 349 | return fsa.value; | 339 | return fsa.sym; |
| 350 | } | 340 | } |
| 351 | 341 | ||
| 352 | DEBUGP("Failed to find symbol %s\n", name); | 342 | DEBUGP("Failed to find symbol %s\n", name); |
| 353 | return -ENOENT; | 343 | return NULL; |
| 354 | } | 344 | } |
| 345 | EXPORT_SYMBOL_GPL(find_symbol); | ||
| 355 | 346 | ||
| 356 | /* Search for module by name: must hold module_mutex. */ | 347 | /* Search for module by name: must hold module_mutex. */ |
| 357 | static struct module *find_module(const char *name) | 348 | struct module *find_module(const char *name) |
| 358 | { | 349 | { |
| 359 | struct module *mod; | 350 | struct module *mod; |
| 360 | 351 | ||
| @@ -364,8 +355,37 @@ static struct module *find_module(const char *name) | |||
| 364 | } | 355 | } |
| 365 | return NULL; | 356 | return NULL; |
| 366 | } | 357 | } |
| 358 | EXPORT_SYMBOL_GPL(find_module); | ||
| 367 | 359 | ||
| 368 | #ifdef CONFIG_SMP | 360 | #ifdef CONFIG_SMP |
| 361 | |||
| 362 | #ifdef CONFIG_HAVE_DYNAMIC_PER_CPU_AREA | ||
| 363 | |||
| 364 | static void *percpu_modalloc(unsigned long size, unsigned long align, | ||
| 365 | const char *name) | ||
| 366 | { | ||
| 367 | void *ptr; | ||
| 368 | |||
| 369 | if (align > PAGE_SIZE) { | ||
| 370 | printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", | ||
| 371 | name, align, PAGE_SIZE); | ||
| 372 | align = PAGE_SIZE; | ||
| 373 | } | ||
| 374 | |||
| 375 | ptr = __alloc_reserved_percpu(size, align); | ||
| 376 | if (!ptr) | ||
| 377 | printk(KERN_WARNING | ||
| 378 | "Could not allocate %lu bytes percpu data\n", size); | ||
| 379 | return ptr; | ||
| 380 | } | ||
| 381 | |||
| 382 | static void percpu_modfree(void *freeme) | ||
| 383 | { | ||
| 384 | free_percpu(freeme); | ||
| 385 | } | ||
| 386 | |||
| 387 | #else /* ... !CONFIG_HAVE_DYNAMIC_PER_CPU_AREA */ | ||
| 388 | |||
| 369 | /* Number of blocks used and allocated. */ | 389 | /* Number of blocks used and allocated. */ |
| 370 | static unsigned int pcpu_num_used, pcpu_num_allocated; | 390 | static unsigned int pcpu_num_used, pcpu_num_allocated; |
| 371 | /* Size of each block. -ve means used. */ | 391 | /* Size of each block. -ve means used. */ |
| @@ -480,21 +500,6 @@ static void percpu_modfree(void *freeme) | |||
| 480 | } | 500 | } |
| 481 | } | 501 | } |
| 482 | 502 | ||
| 483 | static unsigned int find_pcpusec(Elf_Ehdr *hdr, | ||
| 484 | Elf_Shdr *sechdrs, | ||
| 485 | const char *secstrings) | ||
| 486 | { | ||
| 487 | return find_sec(hdr, sechdrs, secstrings, ".data.percpu"); | ||
| 488 | } | ||
| 489 | |||
| 490 | static void percpu_modcopy(void *pcpudest, const void *from, unsigned long size) | ||
| 491 | { | ||
| 492 | int cpu; | ||
| 493 | |||
| 494 | for_each_possible_cpu(cpu) | ||
| 495 | memcpy(pcpudest + per_cpu_offset(cpu), from, size); | ||
| 496 | } | ||
| 497 | |||
| 498 | static int percpu_modinit(void) | 503 | static int percpu_modinit(void) |
| 499 | { | 504 | { |
| 500 | pcpu_num_used = 2; | 505 | pcpu_num_used = 2; |
| @@ -513,7 +518,26 @@ static int percpu_modinit(void) | |||
| 513 | return 0; | 518 | return 0; |
| 514 | } | 519 | } |
| 515 | __initcall(percpu_modinit); | 520 | __initcall(percpu_modinit); |
| 521 | |||
| 522 | #endif /* CONFIG_HAVE_DYNAMIC_PER_CPU_AREA */ | ||
| 523 | |||
| 524 | static unsigned int find_pcpusec(Elf_Ehdr *hdr, | ||
| 525 | Elf_Shdr *sechdrs, | ||
| 526 | const char *secstrings) | ||
| 527 | { | ||
| 528 | return find_sec(hdr, sechdrs, secstrings, ".data.percpu"); | ||
| 529 | } | ||
| 530 | |||
| 531 | static void percpu_modcopy(void *pcpudest, const void *from, unsigned long size) | ||
| 532 | { | ||
| 533 | int cpu; | ||
| 534 | |||
| 535 | for_each_possible_cpu(cpu) | ||
| 536 | memcpy(pcpudest + per_cpu_offset(cpu), from, size); | ||
| 537 | } | ||
| 538 | |||
| 516 | #else /* ... !CONFIG_SMP */ | 539 | #else /* ... !CONFIG_SMP */ |
| 540 | |||
| 517 | static inline void *percpu_modalloc(unsigned long size, unsigned long align, | 541 | static inline void *percpu_modalloc(unsigned long size, unsigned long align, |
| 518 | const char *name) | 542 | const char *name) |
| 519 | { | 543 | { |
| @@ -535,6 +559,7 @@ static inline void percpu_modcopy(void *pcpudst, const void *src, | |||
| 535 | /* pcpusec should be 0, and size of that section should be 0. */ | 559 | /* pcpusec should be 0, and size of that section should be 0. */ |
| 536 | BUG_ON(size != 0); | 560 | BUG_ON(size != 0); |
| 537 | } | 561 | } |
| 562 | |||
| 538 | #endif /* CONFIG_SMP */ | 563 | #endif /* CONFIG_SMP */ |
| 539 | 564 | ||
| 540 | #define MODINFO_ATTR(field) \ | 565 | #define MODINFO_ATTR(field) \ |
| @@ -607,7 +632,7 @@ static int already_uses(struct module *a, struct module *b) | |||
| 607 | } | 632 | } |
| 608 | 633 | ||
| 609 | /* Module a uses b */ | 634 | /* Module a uses b */ |
| 610 | static int use_module(struct module *a, struct module *b) | 635 | int use_module(struct module *a, struct module *b) |
| 611 | { | 636 | { |
| 612 | struct module_use *use; | 637 | struct module_use *use; |
| 613 | int no_warn, err; | 638 | int no_warn, err; |
| @@ -640,6 +665,7 @@ static int use_module(struct module *a, struct module *b) | |||
| 640 | no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); | 665 | no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); |
| 641 | return 1; | 666 | return 1; |
| 642 | } | 667 | } |
| 668 | EXPORT_SYMBOL_GPL(use_module); | ||
| 643 | 669 | ||
| 644 | /* Clear the unload stuff of the module. */ | 670 | /* Clear the unload stuff of the module. */ |
| 645 | static void module_unload_free(struct module *mod) | 671 | static void module_unload_free(struct module *mod) |
| @@ -822,7 +848,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, | |||
| 822 | mutex_lock(&module_mutex); | 848 | mutex_lock(&module_mutex); |
| 823 | /* Store the name of the last unloaded module for diagnostic purposes */ | 849 | /* Store the name of the last unloaded module for diagnostic purposes */ |
| 824 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); | 850 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); |
| 825 | unregister_dynamic_debug_module(mod->name); | 851 | ddebug_remove_module(mod->name); |
| 826 | free_module(mod); | 852 | free_module(mod); |
| 827 | 853 | ||
| 828 | out: | 854 | out: |
| @@ -860,7 +886,7 @@ void __symbol_put(const char *symbol) | |||
| 860 | struct module *owner; | 886 | struct module *owner; |
| 861 | 887 | ||
| 862 | preempt_disable(); | 888 | preempt_disable(); |
| 863 | if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false))) | 889 | if (!find_symbol(symbol, &owner, NULL, true, false)) |
| 864 | BUG(); | 890 | BUG(); |
| 865 | module_put(owner); | 891 | module_put(owner); |
| 866 | preempt_enable(); | 892 | preempt_enable(); |
| @@ -874,8 +900,10 @@ void symbol_put_addr(void *addr) | |||
| 874 | if (core_kernel_text((unsigned long)addr)) | 900 | if (core_kernel_text((unsigned long)addr)) |
| 875 | return; | 901 | return; |
| 876 | 902 | ||
| 877 | if (!(modaddr = module_text_address((unsigned long)addr))) | 903 | /* module_text_address is safe here: we're supposed to have reference |
| 878 | BUG(); | 904 | * to module from symbol_get, so it can't go away. */ |
| 905 | modaddr = __module_text_address((unsigned long)addr); | ||
| 906 | BUG_ON(!modaddr); | ||
| 879 | module_put(modaddr); | 907 | module_put(modaddr); |
| 880 | } | 908 | } |
| 881 | EXPORT_SYMBOL_GPL(symbol_put_addr); | 909 | EXPORT_SYMBOL_GPL(symbol_put_addr); |
| @@ -915,10 +943,11 @@ static inline void module_unload_free(struct module *mod) | |||
| 915 | { | 943 | { |
| 916 | } | 944 | } |
| 917 | 945 | ||
| 918 | static inline int use_module(struct module *a, struct module *b) | 946 | int use_module(struct module *a, struct module *b) |
| 919 | { | 947 | { |
| 920 | return strong_try_module_get(b) == 0; | 948 | return strong_try_module_get(b) == 0; |
| 921 | } | 949 | } |
| 950 | EXPORT_SYMBOL_GPL(use_module); | ||
| 922 | 951 | ||
| 923 | static inline void module_unload_init(struct module *mod) | 952 | static inline void module_unload_init(struct module *mod) |
| 924 | { | 953 | { |
| @@ -961,12 +990,12 @@ static struct module_attribute *modinfo_attrs[] = { | |||
| 961 | 990 | ||
| 962 | static const char vermagic[] = VERMAGIC_STRING; | 991 | static const char vermagic[] = VERMAGIC_STRING; |
| 963 | 992 | ||
| 964 | 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) |
| 965 | { | 994 | { |
| 966 | #ifdef CONFIG_MODULE_FORCE_LOAD | 995 | #ifdef CONFIG_MODULE_FORCE_LOAD |
| 967 | if (!test_taint(TAINT_FORCED_MODULE)) | 996 | if (!test_taint(TAINT_FORCED_MODULE)) |
| 968 | printk("%s: no version for \"%s\" found: kernel tainted.\n", | 997 | printk(KERN_WARNING "%s: %s: kernel tainted.\n", |
| 969 | mod->name, symname); | 998 | mod->name, reason); |
| 970 | add_taint_module(mod, TAINT_FORCED_MODULE); | 999 | add_taint_module(mod, TAINT_FORCED_MODULE); |
| 971 | return 0; | 1000 | return 0; |
| 972 | #else | 1001 | #else |
| @@ -1023,9 +1052,9 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs, | |||
| 1023 | { | 1052 | { |
| 1024 | const unsigned long *crc; | 1053 | const unsigned long *crc; |
| 1025 | 1054 | ||
| 1026 | if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false))) | 1055 | if (!find_symbol("module_layout", NULL, &crc, true, false)) |
| 1027 | BUG(); | 1056 | BUG(); |
| 1028 | return check_version(sechdrs, versindex, "struct_module", mod, crc); | 1057 | return check_version(sechdrs, versindex, "module_layout", mod, crc); |
| 1029 | } | 1058 | } |
| 1030 | 1059 | ||
| 1031 | /* First part is kernel version, which we ignore if module has crcs. */ | 1060 | /* First part is kernel version, which we ignore if module has crcs. */ |
| @@ -1064,25 +1093,25 @@ static inline int same_magic(const char *amagic, const char *bmagic, | |||
| 1064 | 1093 | ||
| 1065 | /* Resolve a symbol for this module. I.e. if we find one, record usage. | 1094 | /* Resolve a symbol for this module. I.e. if we find one, record usage. |
| 1066 | Must be holding module_mutex. */ | 1095 | Must be holding module_mutex. */ |
| 1067 | static unsigned long resolve_symbol(Elf_Shdr *sechdrs, | 1096 | static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, |
| 1068 | unsigned int versindex, | 1097 | unsigned int versindex, |
| 1069 | const char *name, | 1098 | const char *name, |
| 1070 | struct module *mod) | 1099 | struct module *mod) |
| 1071 | { | 1100 | { |
| 1072 | struct module *owner; | 1101 | struct module *owner; |
| 1073 | unsigned long ret; | 1102 | const struct kernel_symbol *sym; |
| 1074 | const unsigned long *crc; | 1103 | const unsigned long *crc; |
| 1075 | 1104 | ||
| 1076 | ret = find_symbol(name, &owner, &crc, | 1105 | sym = find_symbol(name, &owner, &crc, |
| 1077 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); | 1106 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); |
| 1078 | if (!IS_ERR_VALUE(ret)) { | 1107 | /* use_module can fail due to OOM, |
| 1079 | /* use_module can fail due to OOM, | 1108 | or module initialization or unloading */ |
| 1080 | or module initialization or unloading */ | 1109 | if (sym) { |
| 1081 | if (!check_version(sechdrs, versindex, name, mod, crc) || | 1110 | if (!check_version(sechdrs, versindex, name, mod, crc) || |
| 1082 | !use_module(mod, owner)) | 1111 | !use_module(mod, owner)) |
| 1083 | ret = -EINVAL; | 1112 | sym = NULL; |
| 1084 | } | 1113 | } |
| 1085 | return ret; | 1114 | return sym; |
| 1086 | } | 1115 | } |
| 1087 | 1116 | ||
| 1088 | /* | 1117 | /* |
| @@ -1457,6 +1486,9 @@ static void free_module(struct module *mod) | |||
| 1457 | /* Module unload stuff */ | 1486 | /* Module unload stuff */ |
| 1458 | module_unload_free(mod); | 1487 | module_unload_free(mod); |
| 1459 | 1488 | ||
| 1489 | /* Free any allocated parameters. */ | ||
| 1490 | destroy_params(mod->kp, mod->num_kp); | ||
| 1491 | |||
| 1460 | /* release any pointers to mcount in this module */ | 1492 | /* release any pointers to mcount in this module */ |
| 1461 | ftrace_release(mod->module_core, mod->core_size); | 1493 | ftrace_release(mod->module_core, mod->core_size); |
| 1462 | 1494 | ||
| @@ -1479,17 +1511,15 @@ static void free_module(struct module *mod) | |||
| 1479 | void *__symbol_get(const char *symbol) | 1511 | void *__symbol_get(const char *symbol) |
| 1480 | { | 1512 | { |
| 1481 | struct module *owner; | 1513 | struct module *owner; |
| 1482 | unsigned long value; | 1514 | const struct kernel_symbol *sym; |
| 1483 | 1515 | ||
| 1484 | preempt_disable(); | 1516 | preempt_disable(); |
| 1485 | value = find_symbol(symbol, &owner, NULL, true, true); | 1517 | sym = find_symbol(symbol, &owner, NULL, true, true); |
| 1486 | if (IS_ERR_VALUE(value)) | 1518 | if (sym && strong_try_module_get(owner)) |
| 1487 | value = 0; | 1519 | sym = NULL; |
| 1488 | else if (strong_try_module_get(owner)) | ||
| 1489 | value = 0; | ||
| 1490 | preempt_enable(); | 1520 | preempt_enable(); |
| 1491 | 1521 | ||
| 1492 | return (void *)value; | 1522 | return sym ? (void *)sym->value : NULL; |
| 1493 | } | 1523 | } |
| 1494 | EXPORT_SYMBOL_GPL(__symbol_get); | 1524 | EXPORT_SYMBOL_GPL(__symbol_get); |
| 1495 | 1525 | ||
| @@ -1517,8 +1547,7 @@ static int verify_export_symbols(struct module *mod) | |||
| 1517 | 1547 | ||
| 1518 | for (i = 0; i < ARRAY_SIZE(arr); i++) { | 1548 | for (i = 0; i < ARRAY_SIZE(arr); i++) { |
| 1519 | for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { | 1549 | for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { |
| 1520 | if (!IS_ERR_VALUE(find_symbol(s->name, &owner, | 1550 | if (find_symbol(s->name, &owner, NULL, true, false)) { |
| 1521 | NULL, true, false))) { | ||
| 1522 | printk(KERN_ERR | 1551 | printk(KERN_ERR |
| 1523 | "%s: exports duplicate symbol %s" | 1552 | "%s: exports duplicate symbol %s" |
| 1524 | " (owned by %s)\n", | 1553 | " (owned by %s)\n", |
| @@ -1542,6 +1571,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
| 1542 | unsigned long secbase; | 1571 | unsigned long secbase; |
| 1543 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | 1572 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); |
| 1544 | int ret = 0; | 1573 | int ret = 0; |
| 1574 | const struct kernel_symbol *ksym; | ||
| 1545 | 1575 | ||
| 1546 | for (i = 1; i < n; i++) { | 1576 | for (i = 1; i < n; i++) { |
| 1547 | switch (sym[i].st_shndx) { | 1577 | switch (sym[i].st_shndx) { |
| @@ -1561,13 +1591,14 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
| 1561 | break; | 1591 | break; |
| 1562 | 1592 | ||
| 1563 | case SHN_UNDEF: | 1593 | case SHN_UNDEF: |
| 1564 | sym[i].st_value | 1594 | ksym = resolve_symbol(sechdrs, versindex, |
| 1565 | = resolve_symbol(sechdrs, versindex, | 1595 | strtab + sym[i].st_name, mod); |
| 1566 | strtab + sym[i].st_name, mod); | ||
| 1567 | |||
| 1568 | /* Ok if resolved. */ | 1596 | /* Ok if resolved. */ |
| 1569 | if (!IS_ERR_VALUE(sym[i].st_value)) | 1597 | if (ksym) { |
| 1598 | sym[i].st_value = ksym->value; | ||
| 1570 | break; | 1599 | break; |
| 1600 | } | ||
| 1601 | |||
| 1571 | /* Ok if weak. */ | 1602 | /* Ok if weak. */ |
| 1572 | if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) | 1603 | if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) |
| 1573 | break; | 1604 | break; |
| @@ -1642,8 +1673,7 @@ static void layout_sections(struct module *mod, | |||
| 1642 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1673 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
| 1643 | || (s->sh_flags & masks[m][1]) | 1674 | || (s->sh_flags & masks[m][1]) |
| 1644 | || s->sh_entsize != ~0UL | 1675 | || s->sh_entsize != ~0UL |
| 1645 | || strncmp(secstrings + s->sh_name, | 1676 | || strstarts(secstrings + s->sh_name, ".init")) |
| 1646 | ".init", 5) == 0) | ||
| 1647 | continue; | 1677 | continue; |
| 1648 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); | 1678 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); |
| 1649 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1679 | DEBUGP("\t%s\n", secstrings + s->sh_name); |
| @@ -1660,8 +1690,7 @@ static void layout_sections(struct module *mod, | |||
| 1660 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1690 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
| 1661 | || (s->sh_flags & masks[m][1]) | 1691 | || (s->sh_flags & masks[m][1]) |
| 1662 | || s->sh_entsize != ~0UL | 1692 | || s->sh_entsize != ~0UL |
| 1663 | || strncmp(secstrings + s->sh_name, | 1693 | || !strstarts(secstrings + s->sh_name, ".init")) |
| 1664 | ".init", 5) != 0) | ||
| 1665 | continue; | 1694 | continue; |
| 1666 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) | 1695 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) |
| 1667 | | INIT_OFFSET_MASK); | 1696 | | INIT_OFFSET_MASK); |
| @@ -1794,8 +1823,7 @@ static char elf_type(const Elf_Sym *sym, | |||
| 1794 | else | 1823 | else |
| 1795 | return 'b'; | 1824 | return 'b'; |
| 1796 | } | 1825 | } |
| 1797 | if (strncmp(secstrings + sechdrs[sym->st_shndx].sh_name, | 1826 | if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug")) |
| 1798 | ".debug", strlen(".debug")) == 0) | ||
| 1799 | return 'n'; | 1827 | return 'n'; |
| 1800 | return '?'; | 1828 | return '?'; |
| 1801 | } | 1829 | } |
| @@ -1827,19 +1855,13 @@ static inline void add_kallsyms(struct module *mod, | |||
| 1827 | } | 1855 | } |
| 1828 | #endif /* CONFIG_KALLSYMS */ | 1856 | #endif /* CONFIG_KALLSYMS */ |
| 1829 | 1857 | ||
| 1830 | static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num) | 1858 | static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) |
| 1831 | { | 1859 | { |
| 1832 | #ifdef CONFIG_DYNAMIC_PRINTK_DEBUG | 1860 | #ifdef CONFIG_DYNAMIC_DEBUG |
| 1833 | unsigned int i; | 1861 | if (ddebug_add_module(debug, num, debug->modname)) |
| 1834 | 1862 | printk(KERN_ERR "dynamic debug error adding module: %s\n", | |
| 1835 | for (i = 0; i < num; i++) { | 1863 | debug->modname); |
| 1836 | register_dynamic_debug_module(debug[i].modname, | 1864 | #endif |
| 1837 | debug[i].type, | ||
| 1838 | debug[i].logical_modname, | ||
| 1839 | debug[i].flag_names, | ||
| 1840 | debug[i].hash, debug[i].hash2); | ||
| 1841 | } | ||
| 1842 | #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ | ||
| 1843 | } | 1865 | } |
| 1844 | 1866 | ||
| 1845 | static void *module_alloc_update_bounds(unsigned long size) | 1867 | static void *module_alloc_update_bounds(unsigned long size) |
| @@ -1870,8 +1892,7 @@ static noinline struct module *load_module(void __user *umod, | |||
| 1870 | unsigned int symindex = 0; | 1892 | unsigned int symindex = 0; |
| 1871 | unsigned int strindex = 0; | 1893 | unsigned int strindex = 0; |
| 1872 | unsigned int modindex, versindex, infoindex, pcpuindex; | 1894 | unsigned int modindex, versindex, infoindex, pcpuindex; |
| 1873 | unsigned int num_kp, num_mcount; | 1895 | unsigned int num_mcount; |
| 1874 | struct kernel_param *kp; | ||
| 1875 | struct module *mod; | 1896 | struct module *mod; |
| 1876 | long err = 0; | 1897 | long err = 0; |
| 1877 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ | 1898 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ |
| @@ -1888,12 +1909,6 @@ static noinline struct module *load_module(void __user *umod, | |||
| 1888 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) | 1909 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) |
| 1889 | return ERR_PTR(-ENOMEM); | 1910 | return ERR_PTR(-ENOMEM); |
| 1890 | 1911 | ||
| 1891 | /* Create stop_machine threads since the error path relies on | ||
| 1892 | * a non-failing stop_machine call. */ | ||
| 1893 | err = stop_machine_create(); | ||
| 1894 | if (err) | ||
| 1895 | goto free_hdr; | ||
| 1896 | |||
| 1897 | if (copy_from_user(hdr, umod, len) != 0) { | 1912 | if (copy_from_user(hdr, umod, len) != 0) { |
| 1898 | err = -EFAULT; | 1913 | err = -EFAULT; |
| 1899 | goto free_hdr; | 1914 | goto free_hdr; |
| @@ -1934,9 +1949,12 @@ static noinline struct module *load_module(void __user *umod, | |||
| 1934 | } | 1949 | } |
| 1935 | #ifndef CONFIG_MODULE_UNLOAD | 1950 | #ifndef CONFIG_MODULE_UNLOAD |
| 1936 | /* Don't load .exit sections */ | 1951 | /* Don't load .exit sections */ |
| 1937 | if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) == 0) | 1952 | if (strstarts(secstrings+sechdrs[i].sh_name, ".exit")) |
| 1938 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; | 1953 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; |
| 1939 | #endif | 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; | ||
| 1940 | } | 1958 | } |
| 1941 | 1959 | ||
| 1942 | modindex = find_sec(hdr, sechdrs, secstrings, | 1960 | modindex = find_sec(hdr, sechdrs, secstrings, |
| @@ -1978,7 +1996,7 @@ static noinline struct module *load_module(void __user *umod, | |||
| 1978 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); | 1996 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); |
| 1979 | /* This is allowed: modprobe --force will invalidate it. */ | 1997 | /* This is allowed: modprobe --force will invalidate it. */ |
| 1980 | if (!modmagic) { | 1998 | if (!modmagic) { |
| 1981 | err = try_to_force_load(mod, "magic"); | 1999 | err = try_to_force_load(mod, "bad vermagic"); |
| 1982 | if (err) | 2000 | if (err) |
| 1983 | goto free_hdr; | 2001 | goto free_hdr; |
| 1984 | } else if (!same_magic(modmagic, vermagic, versindex)) { | 2002 | } else if (!same_magic(modmagic, vermagic, versindex)) { |
| @@ -2015,14 +2033,6 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2015 | if (err < 0) | 2033 | if (err < 0) |
| 2016 | goto free_mod; | 2034 | goto free_mod; |
| 2017 | 2035 | ||
| 2018 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | ||
| 2019 | mod->refptr = percpu_modalloc(sizeof(local_t), __alignof__(local_t), | ||
| 2020 | mod->name); | ||
| 2021 | if (!mod->refptr) { | ||
| 2022 | err = -ENOMEM; | ||
| 2023 | goto free_mod; | ||
| 2024 | } | ||
| 2025 | #endif | ||
| 2026 | if (pcpuindex) { | 2036 | if (pcpuindex) { |
| 2027 | /* We have a special allocation for this section. */ | 2037 | /* We have a special allocation for this section. */ |
| 2028 | percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size, | 2038 | percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size, |
| @@ -2030,7 +2040,7 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2030 | mod->name); | 2040 | mod->name); |
| 2031 | if (!percpu) { | 2041 | if (!percpu) { |
| 2032 | err = -ENOMEM; | 2042 | err = -ENOMEM; |
| 2033 | goto free_percpu; | 2043 | goto free_mod; |
| 2034 | } | 2044 | } |
| 2035 | sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | 2045 | sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC; |
| 2036 | mod->percpu = percpu; | 2046 | mod->percpu = percpu; |
| @@ -2082,6 +2092,14 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2082 | /* Module has been moved. */ | 2092 | /* Module has been moved. */ |
| 2083 | mod = (void *)sechdrs[modindex].sh_addr; | 2093 | mod = (void *)sechdrs[modindex].sh_addr; |
| 2084 | 2094 | ||
| 2095 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | ||
| 2096 | mod->refptr = percpu_modalloc(sizeof(local_t), __alignof__(local_t), | ||
| 2097 | mod->name); | ||
| 2098 | if (!mod->refptr) { | ||
| 2099 | err = -ENOMEM; | ||
| 2100 | goto free_init; | ||
| 2101 | } | ||
| 2102 | #endif | ||
| 2085 | /* Now we've moved module, initialize linked lists, etc. */ | 2103 | /* Now we've moved module, initialize linked lists, etc. */ |
| 2086 | module_unload_init(mod); | 2104 | module_unload_init(mod); |
| 2087 | 2105 | ||
| @@ -2116,8 +2134,8 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2116 | 2134 | ||
| 2117 | /* Now we've got everything in the final locations, we can | 2135 | /* Now we've got everything in the final locations, we can |
| 2118 | * find optional sections. */ | 2136 | * find optional sections. */ |
| 2119 | kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), | 2137 | mod->kp = section_objs(hdr, sechdrs, secstrings, "__param", |
| 2120 | &num_kp); | 2138 | sizeof(*mod->kp), &mod->num_kp); |
| 2121 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", | 2139 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", |
| 2122 | sizeof(*mod->syms), &mod->num_syms); | 2140 | sizeof(*mod->syms), &mod->num_syms); |
| 2123 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); | 2141 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); |
| @@ -2167,8 +2185,8 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2167 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) | 2185 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) |
| 2168 | #endif | 2186 | #endif |
| 2169 | ) { | 2187 | ) { |
| 2170 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); | 2188 | err = try_to_force_load(mod, |
| 2171 | err = try_to_force_load(mod, "nocrc"); | 2189 | "no versions for exported symbols"); |
| 2172 | if (err) | 2190 | if (err) |
| 2173 | goto cleanup; | 2191 | goto cleanup; |
| 2174 | } | 2192 | } |
| @@ -2213,12 +2231,13 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2213 | add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); | 2231 | add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); |
| 2214 | 2232 | ||
| 2215 | if (!mod->taints) { | 2233 | if (!mod->taints) { |
| 2216 | struct mod_debug *debug; | 2234 | struct _ddebug *debug; |
| 2217 | unsigned int num_debug; | 2235 | unsigned int num_debug; |
| 2218 | 2236 | ||
| 2219 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", | 2237 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", |
| 2220 | sizeof(*debug), &num_debug); | 2238 | sizeof(*debug), &num_debug); |
| 2221 | dynamic_printk_setup(debug, num_debug); | 2239 | if (debug) |
| 2240 | dynamic_debug_setup(debug, num_debug); | ||
| 2222 | } | 2241 | } |
| 2223 | 2242 | ||
| 2224 | /* sechdrs[0].sh_size is always zero */ | 2243 | /* sechdrs[0].sh_size is always zero */ |
| @@ -2262,11 +2281,11 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2262 | */ | 2281 | */ |
| 2263 | list_add_rcu(&mod->list, &modules); | 2282 | list_add_rcu(&mod->list, &modules); |
| 2264 | 2283 | ||
| 2265 | 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); |
| 2266 | if (err < 0) | 2285 | if (err < 0) |
| 2267 | goto unlink; | 2286 | goto unlink; |
| 2268 | 2287 | ||
| 2269 | err = mod_sysfs_setup(mod, kp, num_kp); | 2288 | err = mod_sysfs_setup(mod, mod->kp, mod->num_kp); |
| 2270 | if (err < 0) | 2289 | if (err < 0) |
| 2271 | goto unlink; | 2290 | goto unlink; |
| 2272 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2291 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
| @@ -2275,12 +2294,13 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2275 | /* Get rid of temporary copy */ | 2294 | /* Get rid of temporary copy */ |
| 2276 | vfree(hdr); | 2295 | vfree(hdr); |
| 2277 | 2296 | ||
| 2278 | stop_machine_destroy(); | ||
| 2279 | /* Done! */ | 2297 | /* Done! */ |
| 2280 | return mod; | 2298 | return mod; |
| 2281 | 2299 | ||
| 2282 | unlink: | 2300 | unlink: |
| 2283 | stop_machine(__unlink_module, mod, NULL); | 2301 | /* Unlink carefully: kallsyms could be walking list. */ |
| 2302 | list_del_rcu(&mod->list); | ||
| 2303 | synchronize_sched(); | ||
| 2284 | module_arch_cleanup(mod); | 2304 | module_arch_cleanup(mod); |
| 2285 | cleanup: | 2305 | cleanup: |
| 2286 | kobject_del(&mod->mkobj.kobj); | 2306 | kobject_del(&mod->mkobj.kobj); |
| @@ -2288,20 +2308,21 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2288 | ftrace_release(mod->module_core, mod->core_size); | 2308 | ftrace_release(mod->module_core, mod->core_size); |
| 2289 | free_unload: | 2309 | free_unload: |
| 2290 | module_unload_free(mod); | 2310 | module_unload_free(mod); |
| 2311 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | ||
| 2312 | free_init: | ||
| 2313 | percpu_modfree(mod->refptr); | ||
| 2314 | #endif | ||
| 2291 | module_free(mod, mod->module_init); | 2315 | module_free(mod, mod->module_init); |
| 2292 | free_core: | 2316 | free_core: |
| 2293 | module_free(mod, mod->module_core); | 2317 | module_free(mod, mod->module_core); |
| 2318 | /* mod will be freed with core. Don't access it beyond this line! */ | ||
| 2294 | free_percpu: | 2319 | free_percpu: |
| 2295 | if (percpu) | 2320 | if (percpu) |
| 2296 | percpu_modfree(percpu); | 2321 | percpu_modfree(percpu); |
| 2297 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | ||
| 2298 | percpu_modfree(mod->refptr); | ||
| 2299 | #endif | ||
| 2300 | free_mod: | 2322 | free_mod: |
| 2301 | kfree(args); | 2323 | kfree(args); |
| 2302 | free_hdr: | 2324 | free_hdr: |
| 2303 | vfree(hdr); | 2325 | vfree(hdr); |
| 2304 | stop_machine_destroy(); | ||
| 2305 | return ERR_PTR(err); | 2326 | return ERR_PTR(err); |
| 2306 | 2327 | ||
| 2307 | truncated: | 2328 | truncated: |
| @@ -2578,6 +2599,25 @@ unsigned long module_kallsyms_lookup_name(const char *name) | |||
| 2578 | preempt_enable(); | 2599 | preempt_enable(); |
| 2579 | return ret; | 2600 | return ret; |
| 2580 | } | 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 | } | ||
| 2581 | #endif /* CONFIG_KALLSYMS */ | 2621 | #endif /* CONFIG_KALLSYMS */ |
| 2582 | 2622 | ||
| 2583 | static char *module_flags(struct module *mod, char *buf) | 2623 | static char *module_flags(struct module *mod, char *buf) |
| @@ -2713,29 +2753,31 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) | |||
| 2713 | } | 2753 | } |
| 2714 | 2754 | ||
| 2715 | /* | 2755 | /* |
| 2716 | * 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). | ||
| 2717 | */ | 2761 | */ |
| 2718 | int is_module_address(unsigned long addr) | 2762 | bool is_module_address(unsigned long addr) |
| 2719 | { | 2763 | { |
| 2720 | struct module *mod; | 2764 | bool ret; |
| 2721 | 2765 | ||
| 2722 | preempt_disable(); | 2766 | preempt_disable(); |
| 2723 | 2767 | ret = __module_address(addr) != NULL; | |
| 2724 | list_for_each_entry_rcu(mod, &modules, list) { | ||
| 2725 | if (within_module_core(addr, mod)) { | ||
| 2726 | preempt_enable(); | ||
| 2727 | return 1; | ||
| 2728 | } | ||
| 2729 | } | ||
| 2730 | |||
| 2731 | preempt_enable(); | 2768 | preempt_enable(); |
| 2732 | 2769 | ||
| 2733 | return 0; | 2770 | return ret; |
| 2734 | } | 2771 | } |
| 2735 | 2772 | ||
| 2736 | 2773 | /* | |
| 2737 | /* Is this a valid kernel address? */ | 2774 | * __module_address - get the module which contains an address. |
| 2738 | __notrace_funcgraph struct module *__module_text_address(unsigned long addr) | 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 | struct module *__module_address(unsigned long addr) | ||
| 2739 | { | 2781 | { |
| 2740 | struct module *mod; | 2782 | struct module *mod; |
| 2741 | 2783 | ||
| @@ -2743,22 +2785,51 @@ __notrace_funcgraph struct module *__module_text_address(unsigned long addr) | |||
| 2743 | return NULL; | 2785 | return NULL; |
| 2744 | 2786 | ||
| 2745 | list_for_each_entry_rcu(mod, &modules, list) | 2787 | list_for_each_entry_rcu(mod, &modules, list) |
| 2746 | if (within(addr, mod->module_init, mod->init_text_size) | 2788 | if (within_module_core(addr, mod) |
| 2747 | || within(addr, mod->module_core, mod->core_text_size)) | 2789 | || within_module_init(addr, mod)) |
| 2748 | return mod; | 2790 | return mod; |
| 2749 | return NULL; | 2791 | return NULL; |
| 2750 | } | 2792 | } |
| 2793 | EXPORT_SYMBOL_GPL(__module_address); | ||
| 2751 | 2794 | ||
| 2752 | 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) | ||
| 2753 | { | 2804 | { |
| 2754 | struct module *mod; | 2805 | bool ret; |
| 2755 | 2806 | ||
| 2756 | preempt_disable(); | 2807 | preempt_disable(); |
| 2757 | mod = __module_text_address(addr); | 2808 | ret = __module_text_address(addr) != NULL; |
| 2758 | preempt_enable(); | 2809 | preempt_enable(); |
| 2759 | 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 | } | ||
| 2760 | return mod; | 2830 | return mod; |
| 2761 | } | 2831 | } |
| 2832 | EXPORT_SYMBOL_GPL(__module_text_address); | ||
| 2762 | 2833 | ||
| 2763 | /* Don't grab lock, we're oopsing. */ | 2834 | /* Don't grab lock, we're oopsing. */ |
| 2764 | void print_modules(void) | 2835 | void print_modules(void) |
| @@ -2778,9 +2849,17 @@ void print_modules(void) | |||
| 2778 | } | 2849 | } |
| 2779 | 2850 | ||
| 2780 | #ifdef CONFIG_MODVERSIONS | 2851 | #ifdef CONFIG_MODVERSIONS |
| 2781 | /* Generate the signature for struct module here, too, for modversions. */ | 2852 | /* Generate the signature for all relevant module structures here. |
| 2782 | void struct_module(struct module *mod) { return; } | 2853 | * If these change, we don't want to try to parse the module. */ |
| 2783 | EXPORT_SYMBOL(struct_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); | ||
| 2784 | #endif | 2863 | #endif |
| 2785 | 2864 | ||
| 2786 | #ifdef CONFIG_MARKERS | 2865 | #ifdef CONFIG_MARKERS |
