Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-module-and-param

* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-module-and-param:
module: use strstarts()
strstarts: helper function for !strncmp(str, prefix, strlen(prefix))
arm: allow usage of string functions in linux/string.h
module: don't use stop_machine on module load
module: create a request_module_nowait()
module: include other structures in module version check
module: remove the SHF_ALLOC flag on the __versions section.
module: clarify the force-loading taint message.
module: Export symbols needed for Ksplice
Ksplice: Add functions for walking kallsyms symbols
module: remove module_text_address()
module: __module_address
module: Make find_symbol return a struct kernel_symbol
kernel/module.c: fix an unused goto label
param: fix charp parameters set via sysfs

Fix trivial conflicts in kernel/extable.c manually.

+319 -137
+4 -1
arch/arm/boot/compressed/misc.c
··· 18 18 19 19 unsigned int __machine_arch_type; 20 20 21 - #include <linux/string.h> 21 + #include <linux/compiler.h> /* for inline */ 22 + #include <linux/types.h> /* for size_t */ 23 + #include <linux/stddef.h> /* for NULL */ 24 + #include <asm/string.h> 22 25 23 26 #ifdef STANDALONE_DEBUG 24 27 #define putstr printf
+2 -2
drivers/mtd/nand/nand_base.c
··· 2720 2720 return chip->scan_bbt(mtd); 2721 2721 } 2722 2722 2723 - /* module_text_address() isn't exported, and it's mostly a pointless 2723 + /* is_module_text_address() isn't exported, and it's mostly a pointless 2724 2724 test if this is a module _anyway_ -- they'd have to try _really_ hard 2725 2725 to call us from in-kernel code if the core NAND support is modular. */ 2726 2726 #ifdef MODULE 2727 2727 #define caller_is_module() (1) 2728 2728 #else 2729 2729 #define caller_is_module() \ 2730 - module_text_address((unsigned long)__builtin_return_address(0)) 2730 + is_module_text_address((unsigned long)__builtin_return_address(0)) 2731 2731 #endif 2732 2732 2733 2733 /**
+15
include/linux/kallsyms.h
··· 13 13 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ 14 14 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) 15 15 16 + struct module; 17 + 16 18 #ifdef CONFIG_KALLSYMS 17 19 /* Lookup the address for a symbol. Returns 0 if not found. */ 18 20 unsigned long kallsyms_lookup_name(const char *name); 21 + 22 + /* Call a function on each kallsyms symbol in the core kernel */ 23 + int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *, 24 + unsigned long), 25 + void *data); 19 26 20 27 extern int kallsyms_lookup_size_offset(unsigned long addr, 21 28 unsigned long *symbolsize, ··· 46 39 #else /* !CONFIG_KALLSYMS */ 47 40 48 41 static inline unsigned long kallsyms_lookup_name(const char *name) 42 + { 43 + return 0; 44 + } 45 + 46 + static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *, 47 + struct module *, 48 + unsigned long), 49 + void *data) 49 50 { 50 51 return 0; 51 52 }
+8 -3
include/linux/kmod.h
··· 29 29 #ifdef CONFIG_MODULES 30 30 /* modprobe exit status on success, -ve on error. Return value 31 31 * usually useless though. */ 32 - extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2))); 33 - #define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x))) 32 + extern int __request_module(bool wait, const char *name, ...) \ 33 + __attribute__((format(printf, 2, 3))); 34 + #define request_module(mod...) __request_module(true, mod) 35 + #define request_module_nowait(mod...) __request_module(false, mod) 36 + #define try_then_request_module(x, mod...) \ 37 + ((x) ?: (__request_module(false, mod), (x))) 34 38 #else 35 - static inline int request_module(const char * name, ...) { return -ENOSYS; } 39 + static inline int request_module(const char *name, ...) { return -ENOSYS; } 40 + static inline int request_module_nowait(const char *name, ...) { return -ENOSYS; } 36 41 #define try_then_request_module(x, mod...) (x) 37 42 #endif 38 43
+55 -8
include/linux/module.h
··· 248 248 const unsigned long *crcs; 249 249 unsigned int num_syms; 250 250 251 + /* Kernel parameters. */ 252 + struct kernel_param *kp; 253 + unsigned int num_kp; 254 + 251 255 /* GPL-only exported symbols. */ 252 256 unsigned int num_gpl_syms; 253 257 const struct kernel_symbol *gpl_syms; ··· 354 350 #define MODULE_ARCH_INIT {} 355 351 #endif 356 352 353 + extern struct mutex module_mutex; 354 + 357 355 /* FIXME: It'd be nice to isolate modules during init, too, so they 358 356 aren't used before they (may) fail. But presently too much code 359 357 (IDE & SCSI) require entry into the module during init.*/ ··· 364 358 return mod->state != MODULE_STATE_GOING; 365 359 } 366 360 367 - /* Is this address in a module? (second is with no locks, for oops) */ 368 - struct module *module_text_address(unsigned long addr); 369 361 struct module *__module_text_address(unsigned long addr); 370 - int is_module_address(unsigned long addr); 362 + struct module *__module_address(unsigned long addr); 363 + bool is_module_address(unsigned long addr); 364 + bool is_module_text_address(unsigned long addr); 371 365 372 366 static inline int within_module_core(unsigned long addr, struct module *mod) 373 367 { ··· 381 375 addr < (unsigned long)mod->module_init + mod->init_size; 382 376 } 383 377 378 + /* Search for module by name: must hold module_mutex. */ 379 + struct module *find_module(const char *name); 380 + 381 + struct symsearch { 382 + const struct kernel_symbol *start, *stop; 383 + const unsigned long *crcs; 384 + enum { 385 + NOT_GPL_ONLY, 386 + GPL_ONLY, 387 + WILL_BE_GPL_ONLY, 388 + } licence; 389 + bool unused; 390 + }; 391 + 392 + /* Search for an exported symbol by name. */ 393 + const struct kernel_symbol *find_symbol(const char *name, 394 + struct module **owner, 395 + const unsigned long **crc, 396 + bool gplok, 397 + bool warn); 398 + 399 + /* Walk the exported symbol table */ 400 + bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, 401 + unsigned int symnum, void *data), void *data); 402 + 384 403 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if 385 404 symnum out of range. */ 386 405 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, ··· 413 382 414 383 /* Look for this name: can be of form module:name. */ 415 384 unsigned long module_kallsyms_lookup_name(const char *name); 385 + 386 + int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 387 + struct module *, unsigned long), 388 + void *data); 416 389 417 390 extern void __module_put_and_exit(struct module *mod, long code) 418 391 __attribute__((noreturn)); ··· 479 444 #define symbol_put_addr(p) do { } while(0) 480 445 481 446 #endif /* CONFIG_MODULE_UNLOAD */ 447 + int use_module(struct module *a, struct module *b); 482 448 483 449 /* This is a #define so the string doesn't get put in every .o file */ 484 450 #define module_name(mod) \ ··· 526 490 return NULL; 527 491 } 528 492 529 - /* Is this address in a module? */ 530 - static inline struct module *module_text_address(unsigned long addr) 493 + static inline struct module *__module_address(unsigned long addr) 531 494 { 532 495 return NULL; 533 496 } 534 497 535 - /* Is this address in a module? (don't take a lock, we're oopsing) */ 536 498 static inline struct module *__module_text_address(unsigned long addr) 537 499 { 538 500 return NULL; 539 501 } 540 502 541 - static inline int is_module_address(unsigned long addr) 503 + static inline bool is_module_address(unsigned long addr) 542 504 { 543 - return 0; 505 + return false; 506 + } 507 + 508 + static inline bool is_module_text_address(unsigned long addr) 509 + { 510 + return false; 544 511 } 545 512 546 513 /* Get/put a kernel symbol (calls should be symmetric) */ ··· 594 555 } 595 556 596 557 static inline unsigned long module_kallsyms_lookup_name(const char *name) 558 + { 559 + return 0; 560 + } 561 + 562 + static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 563 + struct module *, 564 + unsigned long), 565 + void *data) 597 566 { 598 567 return 0; 599 568 }
+10
include/linux/moduleparam.h
··· 138 138 unsigned num, 139 139 int (*unknown)(char *param, char *val)); 140 140 141 + /* Called by module remove. */ 142 + #ifdef CONFIG_SYSFS 143 + extern void destroy_params(const struct kernel_param *params, unsigned num); 144 + #else 145 + static inline void destroy_params(const struct kernel_param *params, 146 + unsigned num) 147 + { 148 + } 149 + #endif /* !CONFIG_SYSFS */ 150 + 141 151 /* All the helper functions */ 142 152 /* The macros to do compile-time type checking stolen from Jakub 143 153 Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
+9
include/linux/string.h
··· 122 122 extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos, 123 123 const void *from, size_t available); 124 124 125 + /** 126 + * strstarts - does @str start with @prefix? 127 + * @str: string to examine 128 + * @prefix: prefix to look for. 129 + */ 130 + static inline bool strstarts(const char *str, const char *prefix) 131 + { 132 + return strncmp(str, prefix, strlen(prefix)) == 0; 133 + } 125 134 #endif 126 135 #endif /* _LINUX_STRING_H_ */
+3 -3
kernel/extable.c
··· 65 65 { 66 66 if (core_kernel_text(addr)) 67 67 return 1; 68 - if (__module_text_address(addr)) 68 + if (is_module_text_address(addr)) 69 69 return 1; 70 70 /* 71 71 * There might be init symbols in saved stacktraces. ··· 84 84 { 85 85 if (core_kernel_text(addr)) 86 86 return 1; 87 - return module_text_address(addr) != NULL; 87 + return is_module_text_address(addr); 88 88 } 89 89 90 90 /* ··· 100 100 addr = (unsigned long) dereference_function_descriptor(ptr); 101 101 if (core_kernel_text(addr)) 102 102 return 1; 103 - return module_text_address(addr) != NULL; 103 + return is_module_text_address(addr); 104 104 }
+19
kernel/kallsyms.c
··· 161 161 return module_kallsyms_lookup_name(name); 162 162 } 163 163 164 + int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *, 165 + unsigned long), 166 + void *data) 167 + { 168 + char namebuf[KSYM_NAME_LEN]; 169 + unsigned long i; 170 + unsigned int off; 171 + int ret; 172 + 173 + for (i = 0, off = 0; i < kallsyms_num_syms; i++) { 174 + off = kallsyms_expand_symbol(off, namebuf); 175 + ret = fn(data, namebuf, NULL, kallsyms_addresses[i]); 176 + if (ret != 0) 177 + return ret; 178 + } 179 + return module_kallsyms_on_each_symbol(fn, data); 180 + } 181 + EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol); 182 + 164 183 static unsigned long get_symbol_pos(unsigned long addr, 165 184 unsigned long *symbolsize, 166 185 unsigned long *offset)
+6 -4
kernel/kmod.c
··· 50 50 char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe"; 51 51 52 52 /** 53 - * request_module - try to load a kernel module 53 + * __request_module - try to load a kernel module 54 + * @wait: wait (or not) for the operation to complete 54 55 * @fmt: printf style format string for the name of the module 55 56 * @...: arguments as specified in the format string 56 57 * ··· 64 63 * If module auto-loading support is disabled then this function 65 64 * becomes a no-operation. 66 65 */ 67 - int request_module(const char *fmt, ...) 66 + int __request_module(bool wait, const char *fmt, ...) 68 67 { 69 68 va_list args; 70 69 char module_name[MODULE_NAME_LEN]; ··· 109 108 return -ENOMEM; 110 109 } 111 110 112 - ret = call_usermodehelper(modprobe_path, argv, envp, 1); 111 + ret = call_usermodehelper(modprobe_path, argv, envp, 112 + wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC); 113 113 atomic_dec(&kmod_concurrent); 114 114 return ret; 115 115 } 116 - EXPORT_SYMBOL(request_module); 116 + EXPORT_SYMBOL(__request_module); 117 117 #endif /* CONFIG_MODULES */ 118 118 119 119 struct subprocess_info {
+161 -113
kernel/module.c
··· 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? */ ··· 77 76 78 77 static BLOCKING_NOTIFIER_HEAD(module_notify_list); 79 78 80 - /* Bounds of module allocation, for speeding __module_text_address */ 79 + /* Bounds of module allocation, for speeding __module_address */ 81 80 static unsigned long module_addr_min = -1UL, module_addr_max = 0; 82 81 83 82 int register_module_notifier(struct notifier_block * nb) ··· 187 186 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) 188 187 #endif 189 188 190 - struct symsearch { 191 - const struct kernel_symbol *start, *stop; 192 - const unsigned long *crcs; 193 - enum { 194 - NOT_GPL_ONLY, 195 - GPL_ONLY, 196 - WILL_BE_GPL_ONLY, 197 - } licence; 198 - bool unused; 199 - }; 200 - 201 189 static bool each_symbol_in_section(const struct symsearch *arr, 202 190 unsigned int arrsize, 203 191 struct module *owner, ··· 207 217 } 208 218 209 219 /* Returns true as soon as fn returns true, otherwise false. */ 210 - static bool each_symbol(bool (*fn)(const struct symsearch *arr, 211 - struct module *owner, 212 - unsigned int symnum, void *data), 213 - void *data) 220 + bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, 221 + unsigned int symnum, void *data), void *data) 214 222 { 215 223 struct module *mod; 216 224 const struct symsearch arr[] = { ··· 261 273 } 262 274 return false; 263 275 } 276 + EXPORT_SYMBOL_GPL(each_symbol); 264 277 265 278 struct find_symbol_arg { 266 279 /* Input */ ··· 272 283 /* Output */ 273 284 struct module *owner; 274 285 const unsigned long *crc; 275 - unsigned long value; 286 + const struct kernel_symbol *sym; 276 287 }; 277 288 278 289 static bool find_symbol_in_section(const struct symsearch *syms, ··· 313 324 314 325 fsa->owner = owner; 315 326 fsa->crc = symversion(syms->crcs, symnum); 316 - fsa->value = syms->start[symnum].value; 327 + fsa->sym = &syms->start[symnum]; 317 328 return true; 318 329 } 319 330 320 - /* Find a symbol, return value, (optional) crc and (optional) module 321 - * which owns it */ 322 - static unsigned long find_symbol(const char *name, 323 - struct module **owner, 324 - const unsigned long **crc, 325 - bool gplok, 326 - bool warn) 331 + /* Find a symbol and return it, along with, (optional) crc and 332 + * (optional) module which owns it */ 333 + const struct kernel_symbol *find_symbol(const char *name, 334 + struct module **owner, 335 + const unsigned long **crc, 336 + bool gplok, 337 + bool warn) 327 338 { 328 339 struct find_symbol_arg fsa; 329 340 ··· 336 347 *owner = fsa.owner; 337 348 if (crc) 338 349 *crc = fsa.crc; 339 - return fsa.value; 350 + return fsa.sym; 340 351 } 341 352 342 353 DEBUGP("Failed to find symbol %s\n", name); 343 - return -ENOENT; 354 + return NULL; 344 355 } 356 + EXPORT_SYMBOL_GPL(find_symbol); 345 357 346 358 /* Search for module by name: must hold module_mutex. */ 347 - static struct module *find_module(const char *name) 359 + struct module *find_module(const char *name) 348 360 { 349 361 struct module *mod; 350 362 ··· 355 365 } 356 366 return NULL; 357 367 } 368 + EXPORT_SYMBOL_GPL(find_module); 358 369 359 370 #ifdef CONFIG_SMP 360 371 ··· 632 641 } 633 642 634 643 /* Module a uses b */ 635 - static int use_module(struct module *a, struct module *b) 644 + int use_module(struct module *a, struct module *b) 636 645 { 637 646 struct module_use *use; 638 647 int no_warn, err; ··· 665 674 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); 666 675 return 1; 667 676 } 677 + EXPORT_SYMBOL_GPL(use_module); 668 678 669 679 /* Clear the unload stuff of the module. */ 670 680 static void module_unload_free(struct module *mod) ··· 886 894 struct module *owner; 887 895 888 896 preempt_disable(); 889 - if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false))) 897 + if (!find_symbol(symbol, &owner, NULL, true, false)) 890 898 BUG(); 891 899 module_put(owner); 892 900 preempt_enable(); ··· 900 908 if (core_kernel_text((unsigned long)addr)) 901 909 return; 902 910 903 - if (!(modaddr = module_text_address((unsigned long)addr))) 904 - BUG(); 911 + /* module_text_address is safe here: we're supposed to have reference 912 + * to module from symbol_get, so it can't go away. */ 913 + modaddr = __module_text_address((unsigned long)addr); 914 + BUG_ON(!modaddr); 905 915 module_put(modaddr); 906 916 } 907 917 EXPORT_SYMBOL_GPL(symbol_put_addr); ··· 943 949 { 944 950 } 945 951 946 - static inline int use_module(struct module *a, struct module *b) 952 + int use_module(struct module *a, struct module *b) 947 953 { 948 954 return strong_try_module_get(b) == 0; 949 955 } 956 + EXPORT_SYMBOL_GPL(use_module); 950 957 951 958 static inline void module_unload_init(struct module *mod) 952 959 { ··· 990 995 991 996 static const char vermagic[] = VERMAGIC_STRING; 992 997 993 - static int try_to_force_load(struct module *mod, const char *symname) 998 + static int try_to_force_load(struct module *mod, const char *reason) 994 999 { 995 1000 #ifdef CONFIG_MODULE_FORCE_LOAD 996 1001 if (!test_taint(TAINT_FORCED_MODULE)) 997 - printk("%s: no version for \"%s\" found: kernel tainted.\n", 998 - mod->name, symname); 1002 + printk(KERN_WARNING "%s: %s: kernel tainted.\n", 1003 + mod->name, reason); 999 1004 add_taint_module(mod, TAINT_FORCED_MODULE); 1000 1005 return 0; 1001 1006 #else ··· 1052 1057 { 1053 1058 const unsigned long *crc; 1054 1059 1055 - if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false))) 1060 + if (!find_symbol("module_layout", NULL, &crc, true, false)) 1056 1061 BUG(); 1057 - return check_version(sechdrs, versindex, "struct_module", mod, crc); 1062 + return check_version(sechdrs, versindex, "module_layout", mod, crc); 1058 1063 } 1059 1064 1060 1065 /* First part is kernel version, which we ignore if module has crcs. */ ··· 1093 1098 1094 1099 /* Resolve a symbol for this module. I.e. if we find one, record usage. 1095 1100 Must be holding module_mutex. */ 1096 - static unsigned long resolve_symbol(Elf_Shdr *sechdrs, 1097 - unsigned int versindex, 1098 - const char *name, 1099 - struct module *mod) 1101 + static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, 1102 + unsigned int versindex, 1103 + const char *name, 1104 + struct module *mod) 1100 1105 { 1101 1106 struct module *owner; 1102 - unsigned long ret; 1107 + const struct kernel_symbol *sym; 1103 1108 const unsigned long *crc; 1104 1109 1105 - ret = find_symbol(name, &owner, &crc, 1110 + sym = find_symbol(name, &owner, &crc, 1106 1111 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); 1107 - if (!IS_ERR_VALUE(ret)) { 1108 - /* use_module can fail due to OOM, 1109 - or module initialization or unloading */ 1112 + /* use_module can fail due to OOM, 1113 + or module initialization or unloading */ 1114 + if (sym) { 1110 1115 if (!check_version(sechdrs, versindex, name, mod, crc) || 1111 1116 !use_module(mod, owner)) 1112 - ret = -EINVAL; 1117 + sym = NULL; 1113 1118 } 1114 - return ret; 1119 + return sym; 1115 1120 } 1116 1121 1117 1122 /* ··· 1486 1491 /* Module unload stuff */ 1487 1492 module_unload_free(mod); 1488 1493 1494 + /* Free any allocated parameters. */ 1495 + destroy_params(mod->kp, mod->num_kp); 1496 + 1489 1497 /* release any pointers to mcount in this module */ 1490 1498 ftrace_release(mod->module_core, mod->core_size); 1491 1499 ··· 1511 1513 void *__symbol_get(const char *symbol) 1512 1514 { 1513 1515 struct module *owner; 1514 - unsigned long value; 1516 + const struct kernel_symbol *sym; 1515 1517 1516 1518 preempt_disable(); 1517 - value = find_symbol(symbol, &owner, NULL, true, true); 1518 - if (IS_ERR_VALUE(value)) 1519 - value = 0; 1520 - else if (strong_try_module_get(owner)) 1521 - value = 0; 1519 + sym = find_symbol(symbol, &owner, NULL, true, true); 1520 + if (sym && strong_try_module_get(owner)) 1521 + sym = NULL; 1522 1522 preempt_enable(); 1523 1523 1524 - return (void *)value; 1524 + return sym ? (void *)sym->value : NULL; 1525 1525 } 1526 1526 EXPORT_SYMBOL_GPL(__symbol_get); 1527 1527 ··· 1547 1551 1548 1552 for (i = 0; i < ARRAY_SIZE(arr); i++) { 1549 1553 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { 1550 - if (!IS_ERR_VALUE(find_symbol(s->name, &owner, 1551 - NULL, true, false))) { 1554 + if (find_symbol(s->name, &owner, NULL, true, false)) { 1552 1555 printk(KERN_ERR 1553 1556 "%s: exports duplicate symbol %s" 1554 1557 " (owned by %s)\n", ··· 1571 1576 unsigned long secbase; 1572 1577 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); 1573 1578 int ret = 0; 1579 + const struct kernel_symbol *ksym; 1574 1580 1575 1581 for (i = 1; i < n; i++) { 1576 1582 switch (sym[i].st_shndx) { ··· 1591 1595 break; 1592 1596 1593 1597 case SHN_UNDEF: 1594 - sym[i].st_value 1595 - = resolve_symbol(sechdrs, versindex, 1596 - strtab + sym[i].st_name, mod); 1597 - 1598 + ksym = resolve_symbol(sechdrs, versindex, 1599 + strtab + sym[i].st_name, mod); 1598 1600 /* Ok if resolved. */ 1599 - if (!IS_ERR_VALUE(sym[i].st_value)) 1601 + if (ksym) { 1602 + sym[i].st_value = ksym->value; 1600 1603 break; 1604 + } 1605 + 1601 1606 /* Ok if weak. */ 1602 1607 if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) 1603 1608 break; ··· 1673 1676 if ((s->sh_flags & masks[m][0]) != masks[m][0] 1674 1677 || (s->sh_flags & masks[m][1]) 1675 1678 || s->sh_entsize != ~0UL 1676 - || strncmp(secstrings + s->sh_name, 1677 - ".init", 5) == 0) 1679 + || strstarts(secstrings + s->sh_name, ".init")) 1678 1680 continue; 1679 1681 s->sh_entsize = get_offset(mod, &mod->core_size, s, i); 1680 1682 DEBUGP("\t%s\n", secstrings + s->sh_name); ··· 1690 1694 if ((s->sh_flags & masks[m][0]) != masks[m][0] 1691 1695 || (s->sh_flags & masks[m][1]) 1692 1696 || s->sh_entsize != ~0UL 1693 - || strncmp(secstrings + s->sh_name, 1694 - ".init", 5) != 0) 1697 + || !strstarts(secstrings + s->sh_name, ".init")) 1695 1698 continue; 1696 1699 s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) 1697 1700 | INIT_OFFSET_MASK); ··· 1823 1828 else 1824 1829 return 'b'; 1825 1830 } 1826 - if (strncmp(secstrings + sechdrs[sym->st_shndx].sh_name, 1827 - ".debug", strlen(".debug")) == 0) 1831 + if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug")) 1828 1832 return 'n'; 1829 1833 return '?'; 1830 1834 } ··· 1892 1898 unsigned int symindex = 0; 1893 1899 unsigned int strindex = 0; 1894 1900 unsigned int modindex, versindex, infoindex, pcpuindex; 1895 - unsigned int num_kp, num_mcount; 1896 - struct kernel_param *kp; 1901 + unsigned int num_mcount; 1897 1902 struct module *mod; 1898 1903 long err = 0; 1899 1904 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ ··· 1908 1915 /* vmalloc barfs on "unusual" numbers. Check here */ 1909 1916 if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) 1910 1917 return ERR_PTR(-ENOMEM); 1911 - 1912 - /* Create stop_machine threads since the error path relies on 1913 - * a non-failing stop_machine call. */ 1914 - err = stop_machine_create(); 1915 - if (err) 1916 - goto free_hdr; 1917 1918 1918 1919 if (copy_from_user(hdr, umod, len) != 0) { 1919 1920 err = -EFAULT; ··· 1949 1962 } 1950 1963 #ifndef CONFIG_MODULE_UNLOAD 1951 1964 /* Don't load .exit sections */ 1952 - if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) == 0) 1965 + if (strstarts(secstrings+sechdrs[i].sh_name, ".exit")) 1953 1966 sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; 1954 1967 #endif 1968 + /* Don't keep __versions around; it's just for loading. */ 1969 + if (strcmp(secstrings + sechdrs[i].sh_name, "__versions") == 0) 1970 + sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; 1955 1971 } 1956 1972 1957 1973 modindex = find_sec(hdr, sechdrs, secstrings, ··· 1996 2006 modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); 1997 2007 /* This is allowed: modprobe --force will invalidate it. */ 1998 2008 if (!modmagic) { 1999 - err = try_to_force_load(mod, "magic"); 2009 + err = try_to_force_load(mod, "bad vermagic"); 2000 2010 if (err) 2001 2011 goto free_hdr; 2002 2012 } else if (!same_magic(modmagic, vermagic, versindex)) { ··· 2134 2144 2135 2145 /* Now we've got everything in the final locations, we can 2136 2146 * find optional sections. */ 2137 - kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), 2138 - &num_kp); 2147 + mod->kp = section_objs(hdr, sechdrs, secstrings, "__param", 2148 + sizeof(*mod->kp), &mod->num_kp); 2139 2149 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", 2140 2150 sizeof(*mod->syms), &mod->num_syms); 2141 2151 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); ··· 2185 2195 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) 2186 2196 #endif 2187 2197 ) { 2188 - printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); 2189 - err = try_to_force_load(mod, "nocrc"); 2198 + err = try_to_force_load(mod, 2199 + "no versions for exported symbols"); 2190 2200 if (err) 2191 2201 goto cleanup; 2192 2202 } ··· 2281 2291 */ 2282 2292 list_add_rcu(&mod->list, &modules); 2283 2293 2284 - err = parse_args(mod->name, mod->args, kp, num_kp, NULL); 2294 + err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); 2285 2295 if (err < 0) 2286 2296 goto unlink; 2287 2297 2288 - err = mod_sysfs_setup(mod, kp, num_kp); 2298 + err = mod_sysfs_setup(mod, mod->kp, mod->num_kp); 2289 2299 if (err < 0) 2290 2300 goto unlink; 2291 2301 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); ··· 2294 2304 /* Get rid of temporary copy */ 2295 2305 vfree(hdr); 2296 2306 2297 - stop_machine_destroy(); 2298 2307 /* Done! */ 2299 2308 return mod; 2300 2309 2301 2310 unlink: 2302 - stop_machine(__unlink_module, mod, NULL); 2311 + /* Unlink carefully: kallsyms could be walking list. */ 2312 + list_del_rcu(&mod->list); 2313 + synchronize_sched(); 2303 2314 module_arch_cleanup(mod); 2304 2315 cleanup: 2305 2316 kobject_del(&mod->mkobj.kobj); ··· 2308 2317 ftrace_release(mod->module_core, mod->core_size); 2309 2318 free_unload: 2310 2319 module_unload_free(mod); 2311 - free_init: 2312 2320 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) 2321 + free_init: 2313 2322 percpu_modfree(mod->refptr); 2314 2323 #endif 2315 2324 module_free(mod, mod->module_init); ··· 2323 2332 kfree(args); 2324 2333 free_hdr: 2325 2334 vfree(hdr); 2326 - stop_machine_destroy(); 2327 2335 return ERR_PTR(err); 2328 2336 2329 2337 truncated: ··· 2599 2609 preempt_enable(); 2600 2610 return ret; 2601 2611 } 2612 + 2613 + int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 2614 + struct module *, unsigned long), 2615 + void *data) 2616 + { 2617 + struct module *mod; 2618 + unsigned int i; 2619 + int ret; 2620 + 2621 + list_for_each_entry(mod, &modules, list) { 2622 + for (i = 0; i < mod->num_symtab; i++) { 2623 + ret = fn(data, mod->strtab + mod->symtab[i].st_name, 2624 + mod, mod->symtab[i].st_value); 2625 + if (ret != 0) 2626 + return ret; 2627 + } 2628 + } 2629 + return 0; 2630 + } 2602 2631 #endif /* CONFIG_KALLSYMS */ 2603 2632 2604 2633 static char *module_flags(struct module *mod, char *buf) ··· 2753 2744 } 2754 2745 2755 2746 /* 2756 - * Is this a valid module address? 2747 + * is_module_address - is this address inside a module? 2748 + * @addr: the address to check. 2749 + * 2750 + * See is_module_text_address() if you simply want to see if the address 2751 + * is code (not data). 2757 2752 */ 2758 - int is_module_address(unsigned long addr) 2753 + bool is_module_address(unsigned long addr) 2759 2754 { 2760 - struct module *mod; 2755 + bool ret; 2761 2756 2762 2757 preempt_disable(); 2763 - 2764 - list_for_each_entry_rcu(mod, &modules, list) { 2765 - if (within_module_core(addr, mod)) { 2766 - preempt_enable(); 2767 - return 1; 2768 - } 2769 - } 2770 - 2758 + ret = __module_address(addr) != NULL; 2771 2759 preempt_enable(); 2772 2760 2773 - return 0; 2761 + return ret; 2774 2762 } 2775 2763 2776 - 2777 - /* Is this a valid kernel address? */ 2778 - __notrace_funcgraph struct module *__module_text_address(unsigned long addr) 2764 + /* 2765 + * __module_address - get the module which contains an address. 2766 + * @addr: the address. 2767 + * 2768 + * Must be called with preempt disabled or module mutex held so that 2769 + * module doesn't get freed during this. 2770 + */ 2771 + __notrace_funcgraph struct module *__module_address(unsigned long addr) 2779 2772 { 2780 2773 struct module *mod; 2781 2774 ··· 2785 2774 return NULL; 2786 2775 2787 2776 list_for_each_entry_rcu(mod, &modules, list) 2788 - if (within(addr, mod->module_init, mod->init_text_size) 2789 - || within(addr, mod->module_core, mod->core_text_size)) 2777 + if (within_module_core(addr, mod) 2778 + || within_module_init(addr, mod)) 2790 2779 return mod; 2791 2780 return NULL; 2792 2781 } 2782 + EXPORT_SYMBOL_GPL(__module_address); 2793 2783 2794 - struct module *module_text_address(unsigned long addr) 2784 + /* 2785 + * is_module_text_address - is this address inside module code? 2786 + * @addr: the address to check. 2787 + * 2788 + * See is_module_address() if you simply want to see if the address is 2789 + * anywhere in a module. See kernel_text_address() for testing if an 2790 + * address corresponds to kernel or module code. 2791 + */ 2792 + bool is_module_text_address(unsigned long addr) 2795 2793 { 2796 - struct module *mod; 2794 + bool ret; 2797 2795 2798 2796 preempt_disable(); 2799 - mod = __module_text_address(addr); 2797 + ret = __module_text_address(addr) != NULL; 2800 2798 preempt_enable(); 2801 2799 2800 + return ret; 2801 + } 2802 + 2803 + /* 2804 + * __module_text_address - get the module whose code contains an address. 2805 + * @addr: the address. 2806 + * 2807 + * Must be called with preempt disabled or module mutex held so that 2808 + * module doesn't get freed during this. 2809 + */ 2810 + struct module *__module_text_address(unsigned long addr) 2811 + { 2812 + struct module *mod = __module_address(addr); 2813 + if (mod) { 2814 + /* Make sure it's within the text section. */ 2815 + if (!within(addr, mod->module_init, mod->init_text_size) 2816 + && !within(addr, mod->module_core, mod->core_text_size)) 2817 + mod = NULL; 2818 + } 2802 2819 return mod; 2803 2820 } 2821 + EXPORT_SYMBOL_GPL(__module_text_address); 2804 2822 2805 2823 /* Don't grab lock, we're oopsing. */ 2806 2824 void print_modules(void) ··· 2849 2809 } 2850 2810 2851 2811 #ifdef CONFIG_MODVERSIONS 2852 - /* Generate the signature for struct module here, too, for modversions. */ 2853 - void struct_module(struct module *mod) { return; } 2854 - EXPORT_SYMBOL(struct_module); 2812 + /* Generate the signature for all relevant module structures here. 2813 + * If these change, we don't want to try to parse the module. */ 2814 + void module_layout(struct module *mod, 2815 + struct modversion_info *ver, 2816 + struct kernel_param *kp, 2817 + struct kernel_symbol *ks, 2818 + struct marker *marker, 2819 + struct tracepoint *tp) 2820 + { 2821 + } 2822 + EXPORT_SYMBOL(module_layout); 2855 2823 #endif 2856 2824 2857 2825 #ifdef CONFIG_MARKERS
+25 -1
kernel/params.c
··· 24 24 #include <linux/err.h> 25 25 #include <linux/slab.h> 26 26 27 + /* We abuse the high bits of "perm" to record whether we kmalloc'ed. */ 28 + #define KPARAM_KMALLOCED 0x80000000 29 + 27 30 #if 0 28 31 #define DEBUGP printk 29 32 #else ··· 220 217 return -ENOSPC; 221 218 } 222 219 223 - *(char **)kp->arg = (char *)val; 220 + if (kp->perm & KPARAM_KMALLOCED) 221 + kfree(*(char **)kp->arg); 222 + 223 + /* This is a hack. We can't need to strdup in early boot, and we 224 + * don't need to; this mangled commandline is preserved. */ 225 + if (slab_is_available()) { 226 + kp->perm |= KPARAM_KMALLOCED; 227 + *(char **)kp->arg = kstrdup(val, GFP_KERNEL); 228 + if (!kp->arg) 229 + return -ENOMEM; 230 + } else 231 + *(const char **)kp->arg = val; 232 + 224 233 return 0; 225 234 } 226 235 ··· 585 570 } 586 571 } 587 572 #endif 573 + 574 + void destroy_params(const struct kernel_param *params, unsigned num) 575 + { 576 + unsigned int i; 577 + 578 + for (i = 0; i < num; i++) 579 + if (params[i].perm & KPARAM_KMALLOCED) 580 + kfree(*(char **)params[i].arg); 581 + } 588 582 589 583 static void __init kernel_add_sysfs_param(const char *name, 590 584 struct kernel_param *kparam,
+2 -2
scripts/mod/modpost.c
··· 1607 1607 1608 1608 parse_elf_finish(&info); 1609 1609 1610 - /* Our trick to get versioning for struct_module - it's 1610 + /* Our trick to get versioning for module struct etc. - it's 1611 1611 * never passed as an argument to an exported function, so 1612 1612 * the automatic versioning doesn't pick it up, but it's really 1613 1613 * important anyhow */ 1614 1614 if (modversions) 1615 - mod->unres = alloc_symbol("struct_module", 0, mod->unres); 1615 + mod->unres = alloc_symbol("module_layout", 0, mod->unres); 1616 1616 } 1617 1617 1618 1618 #define SZ 500