aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c169
1 files changed, 70 insertions, 99 deletions
diff --git a/kernel/module.c b/kernel/module.c
index dc582749fa13..f5a3b1e8ec51 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -378,23 +378,21 @@ static bool check_symbol(const struct symsearch *syms,
378 if (syms->licence == GPL_ONLY) 378 if (syms->licence == GPL_ONLY)
379 return false; 379 return false;
380 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) { 380 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) {
381 printk(KERN_WARNING "Symbol %s is being used " 381 pr_warn("Symbol %s is being used by a non-GPL module, "
382 "by a non-GPL module, which will not " 382 "which will not be allowed in the future\n",
383 "be allowed in the future\n", fsa->name); 383 fsa->name);
384 } 384 }
385 } 385 }
386 386
387#ifdef CONFIG_UNUSED_SYMBOLS 387#ifdef CONFIG_UNUSED_SYMBOLS
388 if (syms->unused && fsa->warn) { 388 if (syms->unused && fsa->warn) {
389 printk(KERN_WARNING "Symbol %s is marked as UNUSED, " 389 pr_warn("Symbol %s is marked as UNUSED, however this module is "
390 "however this module is using it.\n", fsa->name); 390 "using it.\n", fsa->name);
391 printk(KERN_WARNING 391 pr_warn("This symbol will go away in the future.\n");
392 "This symbol will go away in the future.\n"); 392 pr_warn("Please evalute if this is the right api to use and if "
393 printk(KERN_WARNING 393 "it really is, submit a report the linux kernel "
394 "Please evalute if this is the right api to use and if " 394 "mailinglist together with submitting your code for "
395 "it really is, submit a report the linux kernel " 395 "inclusion.\n");
396 "mailinglist together with submitting your code for "
397 "inclusion.\n");
398 } 396 }
399#endif 397#endif
400 398
@@ -492,16 +490,15 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
492 return 0; 490 return 0;
493 491
494 if (align > PAGE_SIZE) { 492 if (align > PAGE_SIZE) {
495 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", 493 pr_warn("%s: per-cpu alignment %li > %li\n",
496 mod->name, align, PAGE_SIZE); 494 mod->name, align, PAGE_SIZE);
497 align = PAGE_SIZE; 495 align = PAGE_SIZE;
498 } 496 }
499 497
500 mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align); 498 mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align);
501 if (!mod->percpu) { 499 if (!mod->percpu) {
502 printk(KERN_WARNING 500 pr_warn("%s: Could not allocate %lu bytes percpu data\n",
503 "%s: Could not allocate %lu bytes percpu data\n", 501 mod->name, (unsigned long)pcpusec->sh_size);
504 mod->name, (unsigned long)pcpusec->sh_size);
505 return -ENOMEM; 502 return -ENOMEM;
506 } 503 }
507 mod->percpu_size = pcpusec->sh_size; 504 mod->percpu_size = pcpusec->sh_size;
@@ -644,8 +641,6 @@ static int module_unload_init(struct module *mod)
644 641
645 /* Hold reference count during initialization. */ 642 /* Hold reference count during initialization. */
646 __this_cpu_write(mod->refptr->incs, 1); 643 __this_cpu_write(mod->refptr->incs, 1);
647 /* Backwards compatibility macros put refcount during init. */
648 mod->waiter = current;
649 644
650 return 0; 645 return 0;
651} 646}
@@ -679,7 +674,7 @@ static int add_module_usage(struct module *a, struct module *b)
679 pr_debug("Allocating new usage for %s.\n", a->name); 674 pr_debug("Allocating new usage for %s.\n", a->name);
680 use = kmalloc(sizeof(*use), GFP_ATOMIC); 675 use = kmalloc(sizeof(*use), GFP_ATOMIC);
681 if (!use) { 676 if (!use) {
682 printk(KERN_WARNING "%s: out of memory loading\n", a->name); 677 pr_warn("%s: out of memory loading\n", a->name);
683 return -ENOMEM; 678 return -ENOMEM;
684 } 679 }
685 680
@@ -771,16 +766,9 @@ static int __try_stop_module(void *_sref)
771 766
772static int try_stop_module(struct module *mod, int flags, int *forced) 767static int try_stop_module(struct module *mod, int flags, int *forced)
773{ 768{
774 if (flags & O_NONBLOCK) { 769 struct stopref sref = { mod, flags, forced };
775 struct stopref sref = { mod, flags, forced };
776 770
777 return stop_machine(__try_stop_module, &sref, NULL); 771 return stop_machine(__try_stop_module, &sref, NULL);
778 } else {
779 /* We don't need to stop the machine for this. */
780 mod->state = MODULE_STATE_GOING;
781 synchronize_sched();
782 return 0;
783 }
784} 772}
785 773
786unsigned long module_refcount(struct module *mod) 774unsigned long module_refcount(struct module *mod)
@@ -813,21 +801,6 @@ EXPORT_SYMBOL(module_refcount);
813/* This exists whether we can unload or not */ 801/* This exists whether we can unload or not */
814static void free_module(struct module *mod); 802static void free_module(struct module *mod);
815 803
816static void wait_for_zero_refcount(struct module *mod)
817{
818 /* Since we might sleep for some time, release the mutex first */
819 mutex_unlock(&module_mutex);
820 for (;;) {
821 pr_debug("Looking at refcount...\n");
822 set_current_state(TASK_UNINTERRUPTIBLE);
823 if (module_refcount(mod) == 0)
824 break;
825 schedule();
826 }
827 current->state = TASK_RUNNING;
828 mutex_lock(&module_mutex);
829}
830
831SYSCALL_DEFINE2(delete_module, const char __user *, name_user, 804SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
832 unsigned int, flags) 805 unsigned int, flags)
833{ 806{
@@ -842,6 +815,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
842 return -EFAULT; 815 return -EFAULT;
843 name[MODULE_NAME_LEN-1] = '\0'; 816 name[MODULE_NAME_LEN-1] = '\0';
844 817
818 if (!(flags & O_NONBLOCK)) {
819 printk(KERN_WARNING
820 "waiting module removal not supported: please upgrade");
821 }
822
845 if (mutex_lock_interruptible(&module_mutex) != 0) 823 if (mutex_lock_interruptible(&module_mutex) != 0)
846 return -EINTR; 824 return -EINTR;
847 825
@@ -859,8 +837,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
859 837
860 /* Doing init or already dying? */ 838 /* Doing init or already dying? */
861 if (mod->state != MODULE_STATE_LIVE) { 839 if (mod->state != MODULE_STATE_LIVE) {
862 /* FIXME: if (force), slam module count and wake up 840 /* FIXME: if (force), slam module count damn the torpedoes */
863 waiter --RR */
864 pr_debug("%s already dying\n", mod->name); 841 pr_debug("%s already dying\n", mod->name);
865 ret = -EBUSY; 842 ret = -EBUSY;
866 goto out; 843 goto out;
@@ -876,18 +853,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
876 } 853 }
877 } 854 }
878 855
879 /* Set this up before setting mod->state */
880 mod->waiter = current;
881
882 /* Stop the machine so refcounts can't move and disable module. */ 856 /* Stop the machine so refcounts can't move and disable module. */
883 ret = try_stop_module(mod, flags, &forced); 857 ret = try_stop_module(mod, flags, &forced);
884 if (ret != 0) 858 if (ret != 0)
885 goto out; 859 goto out;
886 860
887 /* Never wait if forced. */
888 if (!forced && module_refcount(mod) != 0)
889 wait_for_zero_refcount(mod);
890
891 mutex_unlock(&module_mutex); 861 mutex_unlock(&module_mutex);
892 /* Final destruction now no one is using it. */ 862 /* Final destruction now no one is using it. */
893 if (mod->exit != NULL) 863 if (mod->exit != NULL)
@@ -1005,9 +975,6 @@ void module_put(struct module *module)
1005 __this_cpu_inc(module->refptr->decs); 975 __this_cpu_inc(module->refptr->decs);
1006 976
1007 trace_module_put(module, _RET_IP_); 977 trace_module_put(module, _RET_IP_);
1008 /* Maybe they're waiting for us to drop reference? */
1009 if (unlikely(!module_is_live(module)))
1010 wake_up_process(module->waiter);
1011 preempt_enable(); 978 preempt_enable();
1012 } 979 }
1013} 980}
@@ -1145,8 +1112,7 @@ static int try_to_force_load(struct module *mod, const char *reason)
1145{ 1112{
1146#ifdef CONFIG_MODULE_FORCE_LOAD 1113#ifdef CONFIG_MODULE_FORCE_LOAD
1147 if (!test_taint(TAINT_FORCED_MODULE)) 1114 if (!test_taint(TAINT_FORCED_MODULE))
1148 printk(KERN_WARNING "%s: %s: kernel tainted.\n", 1115 pr_warn("%s: %s: kernel tainted.\n", mod->name, reason);
1149 mod->name, reason);
1150 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE); 1116 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE);
1151 return 0; 1117 return 0;
1152#else 1118#else
@@ -1199,8 +1165,7 @@ static int check_version(Elf_Shdr *sechdrs,
1199 goto bad_version; 1165 goto bad_version;
1200 } 1166 }
1201 1167
1202 printk(KERN_WARNING "%s: no symbol version for %s\n", 1168 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
1203 mod->name, symname);
1204 return 0; 1169 return 0;
1205 1170
1206bad_version: 1171bad_version:
@@ -1309,8 +1274,8 @@ resolve_symbol_wait(struct module *mod,
1309 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner)) 1274 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner))
1310 || PTR_ERR(ksym) != -EBUSY, 1275 || PTR_ERR(ksym) != -EBUSY,
1311 30 * HZ) <= 0) { 1276 30 * HZ) <= 0) {
1312 printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", 1277 pr_warn("%s: gave up waiting for init of module %s.\n",
1313 mod->name, owner); 1278 mod->name, owner);
1314 } 1279 }
1315 return ksym; 1280 return ksym;
1316} 1281}
@@ -1626,15 +1591,14 @@ static int mod_sysfs_init(struct module *mod)
1626 struct kobject *kobj; 1591 struct kobject *kobj;
1627 1592
1628 if (!module_sysfs_initialized) { 1593 if (!module_sysfs_initialized) {
1629 printk(KERN_ERR "%s: module sysfs not initialized\n", 1594 pr_err("%s: module sysfs not initialized\n", mod->name);
1630 mod->name);
1631 err = -EINVAL; 1595 err = -EINVAL;
1632 goto out; 1596 goto out;
1633 } 1597 }
1634 1598
1635 kobj = kset_find_obj(module_kset, mod->name); 1599 kobj = kset_find_obj(module_kset, mod->name);
1636 if (kobj) { 1600 if (kobj) {
1637 printk(KERN_ERR "%s: module is already loaded\n", mod->name); 1601 pr_err("%s: module is already loaded\n", mod->name);
1638 kobject_put(kobj); 1602 kobject_put(kobj);
1639 err = -EINVAL; 1603 err = -EINVAL;
1640 goto out; 1604 goto out;
@@ -1961,8 +1925,7 @@ static int verify_export_symbols(struct module *mod)
1961 for (i = 0; i < ARRAY_SIZE(arr); i++) { 1925 for (i = 0; i < ARRAY_SIZE(arr); i++) {
1962 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { 1926 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
1963 if (find_symbol(s->name, &owner, NULL, true, false)) { 1927 if (find_symbol(s->name, &owner, NULL, true, false)) {
1964 printk(KERN_ERR 1928 pr_err("%s: exports duplicate symbol %s"
1965 "%s: exports duplicate symbol %s"
1966 " (owned by %s)\n", 1929 " (owned by %s)\n",
1967 mod->name, s->name, module_name(owner)); 1930 mod->name, s->name, module_name(owner));
1968 return -ENOEXEC; 1931 return -ENOEXEC;
@@ -2013,8 +1976,8 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
2013 if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK) 1976 if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
2014 break; 1977 break;
2015 1978
2016 printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", 1979 pr_warn("%s: Unknown symbol %s (err %li)\n",
2017 mod->name, name, PTR_ERR(ksym)); 1980 mod->name, name, PTR_ERR(ksym));
2018 ret = PTR_ERR(ksym) ?: -ENOENT; 1981 ret = PTR_ERR(ksym) ?: -ENOENT;
2019 break; 1982 break;
2020 1983
@@ -2168,8 +2131,8 @@ static void set_license(struct module *mod, const char *license)
2168 2131
2169 if (!license_is_gpl_compatible(license)) { 2132 if (!license_is_gpl_compatible(license)) {
2170 if (!test_taint(TAINT_PROPRIETARY_MODULE)) 2133 if (!test_taint(TAINT_PROPRIETARY_MODULE))
2171 printk(KERN_WARNING "%s: module license '%s' taints " 2134 pr_warn("%s: module license '%s' taints kernel.\n",
2172 "kernel.\n", mod->name, license); 2135 mod->name, license);
2173 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, 2136 add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
2174 LOCKDEP_NOW_UNRELIABLE); 2137 LOCKDEP_NOW_UNRELIABLE);
2175 } 2138 }
@@ -2405,8 +2368,8 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
2405 return; 2368 return;
2406#ifdef CONFIG_DYNAMIC_DEBUG 2369#ifdef CONFIG_DYNAMIC_DEBUG
2407 if (ddebug_add_module(debug, num, debug->modname)) 2370 if (ddebug_add_module(debug, num, debug->modname))
2408 printk(KERN_ERR "dynamic debug error adding module: %s\n", 2371 pr_err("dynamic debug error adding module: %s\n",
2409 debug->modname); 2372 debug->modname);
2410#endif 2373#endif
2411} 2374}
2412 2375
@@ -2619,8 +2582,7 @@ static int rewrite_section_headers(struct load_info *info, int flags)
2619 Elf_Shdr *shdr = &info->sechdrs[i]; 2582 Elf_Shdr *shdr = &info->sechdrs[i];
2620 if (shdr->sh_type != SHT_NOBITS 2583 if (shdr->sh_type != SHT_NOBITS
2621 && info->len < shdr->sh_offset + shdr->sh_size) { 2584 && info->len < shdr->sh_offset + shdr->sh_size) {
2622 printk(KERN_ERR "Module len %lu truncated\n", 2585 pr_err("Module len %lu truncated\n", info->len);
2623 info->len);
2624 return -ENOEXEC; 2586 return -ENOEXEC;
2625 } 2587 }
2626 2588
@@ -2682,15 +2644,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
2682 2644
2683 info->index.mod = find_sec(info, ".gnu.linkonce.this_module"); 2645 info->index.mod = find_sec(info, ".gnu.linkonce.this_module");
2684 if (!info->index.mod) { 2646 if (!info->index.mod) {
2685 printk(KERN_WARNING "No module found in object\n"); 2647 pr_warn("No module found in object\n");
2686 return ERR_PTR(-ENOEXEC); 2648 return ERR_PTR(-ENOEXEC);
2687 } 2649 }
2688 /* This is temporary: point mod into copy of data. */ 2650 /* This is temporary: point mod into copy of data. */
2689 mod = (void *)info->sechdrs[info->index.mod].sh_addr; 2651 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
2690 2652
2691 if (info->index.sym == 0) { 2653 if (info->index.sym == 0) {
2692 printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", 2654 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
2693 mod->name);
2694 return ERR_PTR(-ENOEXEC); 2655 return ERR_PTR(-ENOEXEC);
2695 } 2656 }
2696 2657
@@ -2717,7 +2678,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
2717 if (err) 2678 if (err)
2718 return err; 2679 return err;
2719 } else if (!same_magic(modmagic, vermagic, info->index.vers)) { 2680 } else if (!same_magic(modmagic, vermagic, info->index.vers)) {
2720 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", 2681 pr_err("%s: version magic '%s' should be '%s'\n",
2721 mod->name, modmagic, vermagic); 2682 mod->name, modmagic, vermagic);
2722 return -ENOEXEC; 2683 return -ENOEXEC;
2723 } 2684 }
@@ -2727,9 +2688,8 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
2727 2688
2728 if (get_modinfo(info, "staging")) { 2689 if (get_modinfo(info, "staging")) {
2729 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK); 2690 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK);
2730 printk(KERN_WARNING "%s: module is from the staging directory," 2691 pr_warn("%s: module is from the staging directory, the quality "
2731 " the quality is unknown, you have been warned.\n", 2692 "is unknown, you have been warned.\n", mod->name);
2732 mod->name);
2733 } 2693 }
2734 2694
2735 /* Set up license info based on the info section */ 2695 /* Set up license info based on the info section */
@@ -2738,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
2738 return 0; 2698 return 0;
2739} 2699}
2740 2700
2741static void find_module_sections(struct module *mod, struct load_info *info) 2701static int find_module_sections(struct module *mod, struct load_info *info)
2742{ 2702{
2743 mod->kp = section_objs(info, "__param", 2703 mod->kp = section_objs(info, "__param",
2744 sizeof(*mod->kp), &mod->num_kp); 2704 sizeof(*mod->kp), &mod->num_kp);
@@ -2768,6 +2728,18 @@ static void find_module_sections(struct module *mod, struct load_info *info)
2768#ifdef CONFIG_CONSTRUCTORS 2728#ifdef CONFIG_CONSTRUCTORS
2769 mod->ctors = section_objs(info, ".ctors", 2729 mod->ctors = section_objs(info, ".ctors",
2770 sizeof(*mod->ctors), &mod->num_ctors); 2730 sizeof(*mod->ctors), &mod->num_ctors);
2731 if (!mod->ctors)
2732 mod->ctors = section_objs(info, ".init_array",
2733 sizeof(*mod->ctors), &mod->num_ctors);
2734 else if (find_sec(info, ".init_array")) {
2735 /*
2736 * This shouldn't happen with same compiler and binutils
2737 * building all parts of the module.
2738 */
2739 printk(KERN_WARNING "%s: has both .ctors and .init_array.\n",
2740 mod->name);
2741 return -EINVAL;
2742 }
2771#endif 2743#endif
2772 2744
2773#ifdef CONFIG_TRACEPOINTS 2745#ifdef CONFIG_TRACEPOINTS
@@ -2801,11 +2773,12 @@ static void find_module_sections(struct module *mod, struct load_info *info)
2801 sizeof(*mod->extable), &mod->num_exentries); 2773 sizeof(*mod->extable), &mod->num_exentries);
2802 2774
2803 if (section_addr(info, "__obsparm")) 2775 if (section_addr(info, "__obsparm"))
2804 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", 2776 pr_warn("%s: Ignoring obsolete parameters\n", mod->name);
2805 mod->name);
2806 2777
2807 info->debug = section_objs(info, "__verbose", 2778 info->debug = section_objs(info, "__verbose",
2808 sizeof(*info->debug), &info->num_debug); 2779 sizeof(*info->debug), &info->num_debug);
2780
2781 return 0;
2809} 2782}
2810 2783
2811static int move_module(struct module *mod, struct load_info *info) 2784static int move_module(struct module *mod, struct load_info *info)
@@ -3078,11 +3051,10 @@ static int do_init_module(struct module *mod)
3078 return ret; 3051 return ret;
3079 } 3052 }
3080 if (ret > 0) { 3053 if (ret > 0) {
3081 printk(KERN_WARNING 3054 pr_warn("%s: '%s'->init suspiciously returned %d, it should "
3082"%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n" 3055 "follow 0/-E convention\n"
3083"%s: loading module anyway...\n", 3056 "%s: loading module anyway...\n",
3084 __func__, mod->name, ret, 3057 __func__, mod->name, ret, __func__);
3085 __func__);
3086 dump_stack(); 3058 dump_stack();
3087 } 3059 }
3088 3060
@@ -3205,10 +3177,8 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname)
3205{ 3177{
3206 /* Check for magic 'dyndbg' arg */ 3178 /* Check for magic 'dyndbg' arg */
3207 int ret = ddebug_dyndbg_module_param_cb(param, val, modname); 3179 int ret = ddebug_dyndbg_module_param_cb(param, val, modname);
3208 if (ret != 0) { 3180 if (ret != 0)
3209 printk(KERN_WARNING "%s: unknown parameter '%s' ignored\n", 3181 pr_warn("%s: unknown parameter '%s' ignored\n", modname, param);
3210 modname, param);
3211 }
3212 return 0; 3182 return 0;
3213} 3183}
3214 3184
@@ -3243,10 +3213,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
3243#ifdef CONFIG_MODULE_SIG 3213#ifdef CONFIG_MODULE_SIG
3244 mod->sig_ok = info->sig_ok; 3214 mod->sig_ok = info->sig_ok;
3245 if (!mod->sig_ok) { 3215 if (!mod->sig_ok) {
3246 printk_once(KERN_NOTICE 3216 pr_notice_once("%s: module verification failed: signature "
3247 "%s: module verification failed: signature and/or" 3217 "and/or required key missing - tainting "
3248 " required key missing - tainting kernel\n", 3218 "kernel\n", mod->name);
3249 mod->name);
3250 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK); 3219 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK);
3251 } 3220 }
3252#endif 3221#endif
@@ -3263,7 +3232,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
3263 3232
3264 /* Now we've got everything in the final locations, we can 3233 /* Now we've got everything in the final locations, we can
3265 * find optional sections. */ 3234 * find optional sections. */
3266 find_module_sections(mod, info); 3235 err = find_module_sections(mod, info);
3236 if (err)
3237 goto free_unload;
3267 3238
3268 err = check_module_license_and_versions(mod); 3239 err = check_module_license_and_versions(mod);
3269 if (err) 3240 if (err)