diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 257 |
1 files changed, 190 insertions, 67 deletions
diff --git a/kernel/module.c b/kernel/module.c index 250092c1d57d..0925c9a71975 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -188,6 +188,7 @@ struct load_info { | |||
188 | ongoing or failed initialization etc. */ | 188 | ongoing or failed initialization etc. */ |
189 | static inline int strong_try_module_get(struct module *mod) | 189 | static inline int strong_try_module_get(struct module *mod) |
190 | { | 190 | { |
191 | BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED); | ||
191 | if (mod && mod->state == MODULE_STATE_COMING) | 192 | if (mod && mod->state == MODULE_STATE_COMING) |
192 | return -EBUSY; | 193 | return -EBUSY; |
193 | if (try_module_get(mod)) | 194 | if (try_module_get(mod)) |
@@ -196,9 +197,10 @@ static inline int strong_try_module_get(struct module *mod) | |||
196 | return -ENOENT; | 197 | return -ENOENT; |
197 | } | 198 | } |
198 | 199 | ||
199 | static inline void add_taint_module(struct module *mod, unsigned flag) | 200 | static inline void add_taint_module(struct module *mod, unsigned flag, |
201 | enum lockdep_ok lockdep_ok) | ||
200 | { | 202 | { |
201 | add_taint(flag); | 203 | add_taint(flag, lockdep_ok); |
202 | mod->taints |= (1U << flag); | 204 | mod->taints |= (1U << flag); |
203 | } | 205 | } |
204 | 206 | ||
@@ -343,6 +345,9 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr, | |||
343 | #endif | 345 | #endif |
344 | }; | 346 | }; |
345 | 347 | ||
348 | if (mod->state == MODULE_STATE_UNFORMED) | ||
349 | continue; | ||
350 | |||
346 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) | 351 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) |
347 | return true; | 352 | return true; |
348 | } | 353 | } |
@@ -450,16 +455,24 @@ const struct kernel_symbol *find_symbol(const char *name, | |||
450 | EXPORT_SYMBOL_GPL(find_symbol); | 455 | EXPORT_SYMBOL_GPL(find_symbol); |
451 | 456 | ||
452 | /* Search for module by name: must hold module_mutex. */ | 457 | /* Search for module by name: must hold module_mutex. */ |
453 | struct module *find_module(const char *name) | 458 | static struct module *find_module_all(const char *name, |
459 | bool even_unformed) | ||
454 | { | 460 | { |
455 | struct module *mod; | 461 | struct module *mod; |
456 | 462 | ||
457 | list_for_each_entry(mod, &modules, list) { | 463 | list_for_each_entry(mod, &modules, list) { |
464 | if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) | ||
465 | continue; | ||
458 | if (strcmp(mod->name, name) == 0) | 466 | if (strcmp(mod->name, name) == 0) |
459 | return mod; | 467 | return mod; |
460 | } | 468 | } |
461 | return NULL; | 469 | return NULL; |
462 | } | 470 | } |
471 | |||
472 | struct module *find_module(const char *name) | ||
473 | { | ||
474 | return find_module_all(name, false); | ||
475 | } | ||
463 | EXPORT_SYMBOL_GPL(find_module); | 476 | EXPORT_SYMBOL_GPL(find_module); |
464 | 477 | ||
465 | #ifdef CONFIG_SMP | 478 | #ifdef CONFIG_SMP |
@@ -525,6 +538,8 @@ bool is_module_percpu_address(unsigned long addr) | |||
525 | preempt_disable(); | 538 | preempt_disable(); |
526 | 539 | ||
527 | list_for_each_entry_rcu(mod, &modules, list) { | 540 | list_for_each_entry_rcu(mod, &modules, list) { |
541 | if (mod->state == MODULE_STATE_UNFORMED) | ||
542 | continue; | ||
528 | if (!mod->percpu_size) | 543 | if (!mod->percpu_size) |
529 | continue; | 544 | continue; |
530 | for_each_possible_cpu(cpu) { | 545 | for_each_possible_cpu(cpu) { |
@@ -713,7 +728,7 @@ static inline int try_force_unload(unsigned int flags) | |||
713 | { | 728 | { |
714 | int ret = (flags & O_TRUNC); | 729 | int ret = (flags & O_TRUNC); |
715 | if (ret) | 730 | if (ret) |
716 | add_taint(TAINT_FORCED_RMMOD); | 731 | add_taint(TAINT_FORCED_RMMOD, LOCKDEP_NOW_UNRELIABLE); |
717 | return ret; | 732 | return ret; |
718 | } | 733 | } |
719 | #else | 734 | #else |
@@ -1048,6 +1063,8 @@ static ssize_t show_initstate(struct module_attribute *mattr, | |||
1048 | case MODULE_STATE_GOING: | 1063 | case MODULE_STATE_GOING: |
1049 | state = "going"; | 1064 | state = "going"; |
1050 | break; | 1065 | break; |
1066 | default: | ||
1067 | BUG(); | ||
1051 | } | 1068 | } |
1052 | return sprintf(buffer, "%s\n", state); | 1069 | return sprintf(buffer, "%s\n", state); |
1053 | } | 1070 | } |
@@ -1122,7 +1139,7 @@ static int try_to_force_load(struct module *mod, const char *reason) | |||
1122 | if (!test_taint(TAINT_FORCED_MODULE)) | 1139 | if (!test_taint(TAINT_FORCED_MODULE)) |
1123 | printk(KERN_WARNING "%s: %s: kernel tainted.\n", | 1140 | printk(KERN_WARNING "%s: %s: kernel tainted.\n", |
1124 | mod->name, reason); | 1141 | mod->name, reason); |
1125 | add_taint_module(mod, TAINT_FORCED_MODULE); | 1142 | add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE); |
1126 | return 0; | 1143 | return 0; |
1127 | #else | 1144 | #else |
1128 | return -ENOEXEC; | 1145 | return -ENOEXEC; |
@@ -1786,6 +1803,8 @@ void set_all_modules_text_rw(void) | |||
1786 | 1803 | ||
1787 | mutex_lock(&module_mutex); | 1804 | mutex_lock(&module_mutex); |
1788 | list_for_each_entry_rcu(mod, &modules, list) { | 1805 | list_for_each_entry_rcu(mod, &modules, list) { |
1806 | if (mod->state == MODULE_STATE_UNFORMED) | ||
1807 | continue; | ||
1789 | if ((mod->module_core) && (mod->core_text_size)) { | 1808 | if ((mod->module_core) && (mod->core_text_size)) { |
1790 | set_page_attributes(mod->module_core, | 1809 | set_page_attributes(mod->module_core, |
1791 | mod->module_core + mod->core_text_size, | 1810 | mod->module_core + mod->core_text_size, |
@@ -1807,6 +1826,8 @@ void set_all_modules_text_ro(void) | |||
1807 | 1826 | ||
1808 | mutex_lock(&module_mutex); | 1827 | mutex_lock(&module_mutex); |
1809 | list_for_each_entry_rcu(mod, &modules, list) { | 1828 | list_for_each_entry_rcu(mod, &modules, list) { |
1829 | if (mod->state == MODULE_STATE_UNFORMED) | ||
1830 | continue; | ||
1810 | if ((mod->module_core) && (mod->core_text_size)) { | 1831 | if ((mod->module_core) && (mod->core_text_size)) { |
1811 | set_page_attributes(mod->module_core, | 1832 | set_page_attributes(mod->module_core, |
1812 | mod->module_core + mod->core_text_size, | 1833 | mod->module_core + mod->core_text_size, |
@@ -2127,7 +2148,8 @@ static void set_license(struct module *mod, const char *license) | |||
2127 | if (!test_taint(TAINT_PROPRIETARY_MODULE)) | 2148 | if (!test_taint(TAINT_PROPRIETARY_MODULE)) |
2128 | printk(KERN_WARNING "%s: module license '%s' taints " | 2149 | printk(KERN_WARNING "%s: module license '%s' taints " |
2129 | "kernel.\n", mod->name, license); | 2150 | "kernel.\n", mod->name, license); |
2130 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 2151 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE, |
2152 | LOCKDEP_NOW_UNRELIABLE); | ||
2131 | } | 2153 | } |
2132 | } | 2154 | } |
2133 | 2155 | ||
@@ -2519,7 +2541,7 @@ static int copy_module_from_fd(int fd, struct load_info *info) | |||
2519 | if (err) | 2541 | if (err) |
2520 | goto out; | 2542 | goto out; |
2521 | 2543 | ||
2522 | err = vfs_getattr(file->f_vfsmnt, file->f_dentry, &stat); | 2544 | err = vfs_getattr(&file->f_path, &stat); |
2523 | if (err) | 2545 | if (err) |
2524 | goto out; | 2546 | goto out; |
2525 | 2547 | ||
@@ -2527,6 +2549,13 @@ static int copy_module_from_fd(int fd, struct load_info *info) | |||
2527 | err = -EFBIG; | 2549 | err = -EFBIG; |
2528 | goto out; | 2550 | goto out; |
2529 | } | 2551 | } |
2552 | |||
2553 | /* Don't hand 0 to vmalloc, it whines. */ | ||
2554 | if (stat.size == 0) { | ||
2555 | err = -EINVAL; | ||
2556 | goto out; | ||
2557 | } | ||
2558 | |||
2530 | info->hdr = vmalloc(stat.size); | 2559 | info->hdr = vmalloc(stat.size); |
2531 | if (!info->hdr) { | 2560 | if (!info->hdr) { |
2532 | err = -ENOMEM; | 2561 | err = -ENOMEM; |
@@ -2673,10 +2702,10 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) | |||
2673 | } | 2702 | } |
2674 | 2703 | ||
2675 | if (!get_modinfo(info, "intree")) | 2704 | if (!get_modinfo(info, "intree")) |
2676 | add_taint_module(mod, TAINT_OOT_MODULE); | 2705 | add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK); |
2677 | 2706 | ||
2678 | if (get_modinfo(info, "staging")) { | 2707 | if (get_modinfo(info, "staging")) { |
2679 | add_taint_module(mod, TAINT_CRAP); | 2708 | add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK); |
2680 | printk(KERN_WARNING "%s: module is from the staging directory," | 2709 | printk(KERN_WARNING "%s: module is from the staging directory," |
2681 | " the quality is unknown, you have been warned.\n", | 2710 | " the quality is unknown, you have been warned.\n", |
2682 | mod->name); | 2711 | mod->name); |
@@ -2842,15 +2871,17 @@ static int check_module_license_and_versions(struct module *mod) | |||
2842 | * using GPL-only symbols it needs. | 2871 | * using GPL-only symbols it needs. |
2843 | */ | 2872 | */ |
2844 | if (strcmp(mod->name, "ndiswrapper") == 0) | 2873 | if (strcmp(mod->name, "ndiswrapper") == 0) |
2845 | add_taint(TAINT_PROPRIETARY_MODULE); | 2874 | add_taint(TAINT_PROPRIETARY_MODULE, LOCKDEP_NOW_UNRELIABLE); |
2846 | 2875 | ||
2847 | /* driverloader was caught wrongly pretending to be under GPL */ | 2876 | /* driverloader was caught wrongly pretending to be under GPL */ |
2848 | if (strcmp(mod->name, "driverloader") == 0) | 2877 | if (strcmp(mod->name, "driverloader") == 0) |
2849 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 2878 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE, |
2879 | LOCKDEP_NOW_UNRELIABLE); | ||
2850 | 2880 | ||
2851 | /* lve claims to be GPL but upstream won't provide source */ | 2881 | /* lve claims to be GPL but upstream won't provide source */ |
2852 | if (strcmp(mod->name, "lve") == 0) | 2882 | if (strcmp(mod->name, "lve") == 0) |
2853 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 2883 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE, |
2884 | LOCKDEP_NOW_UNRELIABLE); | ||
2854 | 2885 | ||
2855 | #ifdef CONFIG_MODVERSIONS | 2886 | #ifdef CONFIG_MODVERSIONS |
2856 | if ((mod->num_syms && !mod->crcs) | 2887 | if ((mod->num_syms && !mod->crcs) |
@@ -2990,8 +3021,9 @@ static bool finished_loading(const char *name) | |||
2990 | bool ret; | 3021 | bool ret; |
2991 | 3022 | ||
2992 | mutex_lock(&module_mutex); | 3023 | mutex_lock(&module_mutex); |
2993 | mod = find_module(name); | 3024 | mod = find_module_all(name, true); |
2994 | ret = !mod || mod->state != MODULE_STATE_COMING; | 3025 | ret = !mod || mod->state == MODULE_STATE_LIVE |
3026 | || mod->state == MODULE_STATE_GOING; | ||
2995 | mutex_unlock(&module_mutex); | 3027 | mutex_unlock(&module_mutex); |
2996 | 3028 | ||
2997 | return ret; | 3029 | return ret; |
@@ -3013,6 +3045,12 @@ static int do_init_module(struct module *mod) | |||
3013 | { | 3045 | { |
3014 | int ret = 0; | 3046 | int ret = 0; |
3015 | 3047 | ||
3048 | /* | ||
3049 | * We want to find out whether @mod uses async during init. Clear | ||
3050 | * PF_USED_ASYNC. async_schedule*() will set it. | ||
3051 | */ | ||
3052 | current->flags &= ~PF_USED_ASYNC; | ||
3053 | |||
3016 | blocking_notifier_call_chain(&module_notify_list, | 3054 | blocking_notifier_call_chain(&module_notify_list, |
3017 | MODULE_STATE_COMING, mod); | 3055 | MODULE_STATE_COMING, mod); |
3018 | 3056 | ||
@@ -3058,8 +3096,25 @@ static int do_init_module(struct module *mod) | |||
3058 | blocking_notifier_call_chain(&module_notify_list, | 3096 | blocking_notifier_call_chain(&module_notify_list, |
3059 | MODULE_STATE_LIVE, mod); | 3097 | MODULE_STATE_LIVE, mod); |
3060 | 3098 | ||
3061 | /* We need to finish all async code before the module init sequence is done */ | 3099 | /* |
3062 | async_synchronize_full(); | 3100 | * We need to finish all async code before the module init sequence |
3101 | * is done. This has potential to deadlock. For example, a newly | ||
3102 | * detected block device can trigger request_module() of the | ||
3103 | * default iosched from async probing task. Once userland helper | ||
3104 | * reaches here, async_synchronize_full() will wait on the async | ||
3105 | * task waiting on request_module() and deadlock. | ||
3106 | * | ||
3107 | * This deadlock is avoided by perfomring async_synchronize_full() | ||
3108 | * iff module init queued any async jobs. This isn't a full | ||
3109 | * solution as it will deadlock the same if module loading from | ||
3110 | * async jobs nests more than once; however, due to the various | ||
3111 | * constraints, this hack seems to be the best option for now. | ||
3112 | * Please refer to the following thread for details. | ||
3113 | * | ||
3114 | * http://thread.gmane.org/gmane.linux.kernel/1420814 | ||
3115 | */ | ||
3116 | if (current->flags & PF_USED_ASYNC) | ||
3117 | async_synchronize_full(); | ||
3063 | 3118 | ||
3064 | mutex_lock(&module_mutex); | 3119 | mutex_lock(&module_mutex); |
3065 | /* Drop initial reference. */ | 3120 | /* Drop initial reference. */ |
@@ -3090,12 +3145,72 @@ static int may_init_module(void) | |||
3090 | return 0; | 3145 | return 0; |
3091 | } | 3146 | } |
3092 | 3147 | ||
3148 | /* | ||
3149 | * We try to place it in the list now to make sure it's unique before | ||
3150 | * we dedicate too many resources. In particular, temporary percpu | ||
3151 | * memory exhaustion. | ||
3152 | */ | ||
3153 | static int add_unformed_module(struct module *mod) | ||
3154 | { | ||
3155 | int err; | ||
3156 | struct module *old; | ||
3157 | |||
3158 | mod->state = MODULE_STATE_UNFORMED; | ||
3159 | |||
3160 | again: | ||
3161 | mutex_lock(&module_mutex); | ||
3162 | if ((old = find_module_all(mod->name, true)) != NULL) { | ||
3163 | if (old->state == MODULE_STATE_COMING | ||
3164 | || old->state == MODULE_STATE_UNFORMED) { | ||
3165 | /* Wait in case it fails to load. */ | ||
3166 | mutex_unlock(&module_mutex); | ||
3167 | err = wait_event_interruptible(module_wq, | ||
3168 | finished_loading(mod->name)); | ||
3169 | if (err) | ||
3170 | goto out_unlocked; | ||
3171 | goto again; | ||
3172 | } | ||
3173 | err = -EEXIST; | ||
3174 | goto out; | ||
3175 | } | ||
3176 | list_add_rcu(&mod->list, &modules); | ||
3177 | err = 0; | ||
3178 | |||
3179 | out: | ||
3180 | mutex_unlock(&module_mutex); | ||
3181 | out_unlocked: | ||
3182 | return err; | ||
3183 | } | ||
3184 | |||
3185 | static int complete_formation(struct module *mod, struct load_info *info) | ||
3186 | { | ||
3187 | int err; | ||
3188 | |||
3189 | mutex_lock(&module_mutex); | ||
3190 | |||
3191 | /* Find duplicate symbols (must be called under lock). */ | ||
3192 | err = verify_export_symbols(mod); | ||
3193 | if (err < 0) | ||
3194 | goto out; | ||
3195 | |||
3196 | /* This relies on module_mutex for list integrity. */ | ||
3197 | module_bug_finalize(info->hdr, info->sechdrs, mod); | ||
3198 | |||
3199 | /* Mark state as coming so strong_try_module_get() ignores us, | ||
3200 | * but kallsyms etc. can see us. */ | ||
3201 | mod->state = MODULE_STATE_COMING; | ||
3202 | |||
3203 | out: | ||
3204 | mutex_unlock(&module_mutex); | ||
3205 | return err; | ||
3206 | } | ||
3207 | |||
3093 | /* Allocate and load the module: note that size of section 0 is always | 3208 | /* Allocate and load the module: note that size of section 0 is always |
3094 | zero, and we rely on this for optional sections. */ | 3209 | zero, and we rely on this for optional sections. */ |
3095 | static int load_module(struct load_info *info, const char __user *uargs, | 3210 | static int load_module(struct load_info *info, const char __user *uargs, |
3096 | int flags) | 3211 | int flags) |
3097 | { | 3212 | { |
3098 | struct module *mod, *old; | 3213 | struct module *mod; |
3099 | long err; | 3214 | long err; |
3100 | 3215 | ||
3101 | err = module_sig_check(info); | 3216 | err = module_sig_check(info); |
@@ -3113,16 +3228,26 @@ static int load_module(struct load_info *info, const char __user *uargs, | |||
3113 | goto free_copy; | 3228 | goto free_copy; |
3114 | } | 3229 | } |
3115 | 3230 | ||
3231 | /* Reserve our place in the list. */ | ||
3232 | err = add_unformed_module(mod); | ||
3233 | if (err) | ||
3234 | goto free_module; | ||
3235 | |||
3116 | #ifdef CONFIG_MODULE_SIG | 3236 | #ifdef CONFIG_MODULE_SIG |
3117 | mod->sig_ok = info->sig_ok; | 3237 | mod->sig_ok = info->sig_ok; |
3118 | if (!mod->sig_ok) | 3238 | if (!mod->sig_ok) { |
3119 | add_taint_module(mod, TAINT_FORCED_MODULE); | 3239 | printk_once(KERN_NOTICE |
3240 | "%s: module verification failed: signature and/or" | ||
3241 | " required key missing - tainting kernel\n", | ||
3242 | mod->name); | ||
3243 | add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK); | ||
3244 | } | ||
3120 | #endif | 3245 | #endif |
3121 | 3246 | ||
3122 | /* Now module is in final location, initialize linked lists, etc. */ | 3247 | /* Now module is in final location, initialize linked lists, etc. */ |
3123 | err = module_unload_init(mod); | 3248 | err = module_unload_init(mod); |
3124 | if (err) | 3249 | if (err) |
3125 | goto free_module; | 3250 | goto unlink_mod; |
3126 | 3251 | ||
3127 | /* Now we've got everything in the final locations, we can | 3252 | /* Now we've got everything in the final locations, we can |
3128 | * find optional sections. */ | 3253 | * find optional sections. */ |
@@ -3157,54 +3282,23 @@ static int load_module(struct load_info *info, const char __user *uargs, | |||
3157 | goto free_arch_cleanup; | 3282 | goto free_arch_cleanup; |
3158 | } | 3283 | } |
3159 | 3284 | ||
3160 | /* Mark state as coming so strong_try_module_get() ignores us. */ | ||
3161 | mod->state = MODULE_STATE_COMING; | ||
3162 | |||
3163 | /* Now sew it into the lists so we can get lockdep and oops | ||
3164 | * info during argument parsing. No one should access us, since | ||
3165 | * strong_try_module_get() will fail. | ||
3166 | * lockdep/oops can run asynchronous, so use the RCU list insertion | ||
3167 | * function to insert in a way safe to concurrent readers. | ||
3168 | * The mutex protects against concurrent writers. | ||
3169 | */ | ||
3170 | again: | ||
3171 | mutex_lock(&module_mutex); | ||
3172 | if ((old = find_module(mod->name)) != NULL) { | ||
3173 | if (old->state == MODULE_STATE_COMING) { | ||
3174 | /* Wait in case it fails to load. */ | ||
3175 | mutex_unlock(&module_mutex); | ||
3176 | err = wait_event_interruptible(module_wq, | ||
3177 | finished_loading(mod->name)); | ||
3178 | if (err) | ||
3179 | goto free_arch_cleanup; | ||
3180 | goto again; | ||
3181 | } | ||
3182 | err = -EEXIST; | ||
3183 | goto unlock; | ||
3184 | } | ||
3185 | |||
3186 | /* This has to be done once we're sure module name is unique. */ | ||
3187 | dynamic_debug_setup(info->debug, info->num_debug); | 3285 | dynamic_debug_setup(info->debug, info->num_debug); |
3188 | 3286 | ||
3189 | /* Find duplicate symbols */ | 3287 | /* Finally it's fully formed, ready to start executing. */ |
3190 | err = verify_export_symbols(mod); | 3288 | err = complete_formation(mod, info); |
3191 | if (err < 0) | 3289 | if (err) |
3192 | goto ddebug; | 3290 | goto ddebug_cleanup; |
3193 | |||
3194 | module_bug_finalize(info->hdr, info->sechdrs, mod); | ||
3195 | list_add_rcu(&mod->list, &modules); | ||
3196 | mutex_unlock(&module_mutex); | ||
3197 | 3291 | ||
3198 | /* Module is ready to execute: parsing args may do that. */ | 3292 | /* Module is ready to execute: parsing args may do that. */ |
3199 | err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, | 3293 | err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, |
3200 | -32768, 32767, &ddebug_dyndbg_module_param_cb); | 3294 | -32768, 32767, &ddebug_dyndbg_module_param_cb); |
3201 | if (err < 0) | 3295 | if (err < 0) |
3202 | goto unlink; | 3296 | goto bug_cleanup; |
3203 | 3297 | ||
3204 | /* Link in to syfs. */ | 3298 | /* Link in to syfs. */ |
3205 | err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp); | 3299 | err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp); |
3206 | if (err < 0) | 3300 | if (err < 0) |
3207 | goto unlink; | 3301 | goto bug_cleanup; |
3208 | 3302 | ||
3209 | /* Get rid of temporary copy. */ | 3303 | /* Get rid of temporary copy. */ |
3210 | free_copy(info); | 3304 | free_copy(info); |
@@ -3214,16 +3308,13 @@ again: | |||
3214 | 3308 | ||
3215 | return do_init_module(mod); | 3309 | return do_init_module(mod); |
3216 | 3310 | ||
3217 | unlink: | 3311 | bug_cleanup: |
3312 | /* module_bug_cleanup needs module_mutex protection */ | ||
3218 | mutex_lock(&module_mutex); | 3313 | mutex_lock(&module_mutex); |
3219 | /* Unlink carefully: kallsyms could be walking list. */ | ||
3220 | list_del_rcu(&mod->list); | ||
3221 | module_bug_cleanup(mod); | 3314 | module_bug_cleanup(mod); |
3222 | wake_up_all(&module_wq); | ||
3223 | ddebug: | ||
3224 | dynamic_debug_remove(info->debug); | ||
3225 | unlock: | ||
3226 | mutex_unlock(&module_mutex); | 3315 | mutex_unlock(&module_mutex); |
3316 | ddebug_cleanup: | ||
3317 | dynamic_debug_remove(info->debug); | ||
3227 | synchronize_sched(); | 3318 | synchronize_sched(); |
3228 | kfree(mod->args); | 3319 | kfree(mod->args); |
3229 | free_arch_cleanup: | 3320 | free_arch_cleanup: |
@@ -3232,6 +3323,12 @@ again: | |||
3232 | free_modinfo(mod); | 3323 | free_modinfo(mod); |
3233 | free_unload: | 3324 | free_unload: |
3234 | module_unload_free(mod); | 3325 | module_unload_free(mod); |
3326 | unlink_mod: | ||
3327 | mutex_lock(&module_mutex); | ||
3328 | /* Unlink carefully: kallsyms could be walking list. */ | ||
3329 | list_del_rcu(&mod->list); | ||
3330 | wake_up_all(&module_wq); | ||
3331 | mutex_unlock(&module_mutex); | ||
3235 | free_module: | 3332 | free_module: |
3236 | module_deallocate(mod, info); | 3333 | module_deallocate(mod, info); |
3237 | free_copy: | 3334 | free_copy: |
@@ -3354,6 +3451,8 @@ const char *module_address_lookup(unsigned long addr, | |||
3354 | 3451 | ||
3355 | preempt_disable(); | 3452 | preempt_disable(); |
3356 | list_for_each_entry_rcu(mod, &modules, list) { | 3453 | list_for_each_entry_rcu(mod, &modules, list) { |
3454 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3455 | continue; | ||
3357 | if (within_module_init(addr, mod) || | 3456 | if (within_module_init(addr, mod) || |
3358 | within_module_core(addr, mod)) { | 3457 | within_module_core(addr, mod)) { |
3359 | if (modname) | 3458 | if (modname) |
@@ -3377,6 +3476,8 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) | |||
3377 | 3476 | ||
3378 | preempt_disable(); | 3477 | preempt_disable(); |
3379 | list_for_each_entry_rcu(mod, &modules, list) { | 3478 | list_for_each_entry_rcu(mod, &modules, list) { |
3479 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3480 | continue; | ||
3380 | if (within_module_init(addr, mod) || | 3481 | if (within_module_init(addr, mod) || |
3381 | within_module_core(addr, mod)) { | 3482 | within_module_core(addr, mod)) { |
3382 | const char *sym; | 3483 | const char *sym; |
@@ -3401,6 +3502,8 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, | |||
3401 | 3502 | ||
3402 | preempt_disable(); | 3503 | preempt_disable(); |
3403 | list_for_each_entry_rcu(mod, &modules, list) { | 3504 | list_for_each_entry_rcu(mod, &modules, list) { |
3505 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3506 | continue; | ||
3404 | if (within_module_init(addr, mod) || | 3507 | if (within_module_init(addr, mod) || |
3405 | within_module_core(addr, mod)) { | 3508 | within_module_core(addr, mod)) { |
3406 | const char *sym; | 3509 | const char *sym; |
@@ -3428,6 +3531,8 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | |||
3428 | 3531 | ||
3429 | preempt_disable(); | 3532 | preempt_disable(); |
3430 | list_for_each_entry_rcu(mod, &modules, list) { | 3533 | list_for_each_entry_rcu(mod, &modules, list) { |
3534 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3535 | continue; | ||
3431 | if (symnum < mod->num_symtab) { | 3536 | if (symnum < mod->num_symtab) { |
3432 | *value = mod->symtab[symnum].st_value; | 3537 | *value = mod->symtab[symnum].st_value; |
3433 | *type = mod->symtab[symnum].st_info; | 3538 | *type = mod->symtab[symnum].st_info; |
@@ -3470,9 +3575,12 @@ unsigned long module_kallsyms_lookup_name(const char *name) | |||
3470 | ret = mod_find_symname(mod, colon+1); | 3575 | ret = mod_find_symname(mod, colon+1); |
3471 | *colon = ':'; | 3576 | *colon = ':'; |
3472 | } else { | 3577 | } else { |
3473 | list_for_each_entry_rcu(mod, &modules, list) | 3578 | list_for_each_entry_rcu(mod, &modules, list) { |
3579 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3580 | continue; | ||
3474 | if ((ret = mod_find_symname(mod, name)) != 0) | 3581 | if ((ret = mod_find_symname(mod, name)) != 0) |
3475 | break; | 3582 | break; |
3583 | } | ||
3476 | } | 3584 | } |
3477 | preempt_enable(); | 3585 | preempt_enable(); |
3478 | return ret; | 3586 | return ret; |
@@ -3487,6 +3595,8 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, | |||
3487 | int ret; | 3595 | int ret; |
3488 | 3596 | ||
3489 | list_for_each_entry(mod, &modules, list) { | 3597 | list_for_each_entry(mod, &modules, list) { |
3598 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3599 | continue; | ||
3490 | for (i = 0; i < mod->num_symtab; i++) { | 3600 | for (i = 0; i < mod->num_symtab; i++) { |
3491 | ret = fn(data, mod->strtab + mod->symtab[i].st_name, | 3601 | ret = fn(data, mod->strtab + mod->symtab[i].st_name, |
3492 | mod, mod->symtab[i].st_value); | 3602 | mod, mod->symtab[i].st_value); |
@@ -3502,6 +3612,7 @@ static char *module_flags(struct module *mod, char *buf) | |||
3502 | { | 3612 | { |
3503 | int bx = 0; | 3613 | int bx = 0; |
3504 | 3614 | ||
3615 | BUG_ON(mod->state == MODULE_STATE_UNFORMED); | ||
3505 | if (mod->taints || | 3616 | if (mod->taints || |
3506 | mod->state == MODULE_STATE_GOING || | 3617 | mod->state == MODULE_STATE_GOING || |
3507 | mod->state == MODULE_STATE_COMING) { | 3618 | mod->state == MODULE_STATE_COMING) { |
@@ -3543,6 +3654,10 @@ static int m_show(struct seq_file *m, void *p) | |||
3543 | struct module *mod = list_entry(p, struct module, list); | 3654 | struct module *mod = list_entry(p, struct module, list); |
3544 | char buf[8]; | 3655 | char buf[8]; |
3545 | 3656 | ||
3657 | /* We always ignore unformed modules. */ | ||
3658 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3659 | return 0; | ||
3660 | |||
3546 | seq_printf(m, "%s %u", | 3661 | seq_printf(m, "%s %u", |
3547 | mod->name, mod->init_size + mod->core_size); | 3662 | mod->name, mod->init_size + mod->core_size); |
3548 | print_unload_info(m, mod); | 3663 | print_unload_info(m, mod); |
@@ -3603,6 +3718,8 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) | |||
3603 | 3718 | ||
3604 | preempt_disable(); | 3719 | preempt_disable(); |
3605 | list_for_each_entry_rcu(mod, &modules, list) { | 3720 | list_for_each_entry_rcu(mod, &modules, list) { |
3721 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3722 | continue; | ||
3606 | if (mod->num_exentries == 0) | 3723 | if (mod->num_exentries == 0) |
3607 | continue; | 3724 | continue; |
3608 | 3725 | ||
@@ -3651,10 +3768,13 @@ struct module *__module_address(unsigned long addr) | |||
3651 | if (addr < module_addr_min || addr > module_addr_max) | 3768 | if (addr < module_addr_min || addr > module_addr_max) |
3652 | return NULL; | 3769 | return NULL; |
3653 | 3770 | ||
3654 | list_for_each_entry_rcu(mod, &modules, list) | 3771 | list_for_each_entry_rcu(mod, &modules, list) { |
3772 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3773 | continue; | ||
3655 | if (within_module_core(addr, mod) | 3774 | if (within_module_core(addr, mod) |
3656 | || within_module_init(addr, mod)) | 3775 | || within_module_init(addr, mod)) |
3657 | return mod; | 3776 | return mod; |
3777 | } | ||
3658 | return NULL; | 3778 | return NULL; |
3659 | } | 3779 | } |
3660 | EXPORT_SYMBOL_GPL(__module_address); | 3780 | EXPORT_SYMBOL_GPL(__module_address); |
@@ -3707,8 +3827,11 @@ void print_modules(void) | |||
3707 | printk(KERN_DEFAULT "Modules linked in:"); | 3827 | printk(KERN_DEFAULT "Modules linked in:"); |
3708 | /* Most callers should already have preempt disabled, but make sure */ | 3828 | /* Most callers should already have preempt disabled, but make sure */ |
3709 | preempt_disable(); | 3829 | preempt_disable(); |
3710 | list_for_each_entry_rcu(mod, &modules, list) | 3830 | list_for_each_entry_rcu(mod, &modules, list) { |
3831 | if (mod->state == MODULE_STATE_UNFORMED) | ||
3832 | continue; | ||
3711 | printk(" %s%s", mod->name, module_flags(mod, buf)); | 3833 | printk(" %s%s", mod->name, module_flags(mod, buf)); |
3834 | } | ||
3712 | preempt_enable(); | 3835 | preempt_enable(); |
3713 | if (last_unloaded_module[0]) | 3836 | if (last_unloaded_module[0]) |
3714 | printk(" [last unloaded: %s]", last_unloaded_module); | 3837 | printk(" [last unloaded: %s]", last_unloaded_module); |