diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 252 |
1 files changed, 146 insertions, 106 deletions
diff --git a/kernel/module.c b/kernel/module.c index 5aad477ddc79..fb404299082e 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <linux/device.h> | 39 | #include <linux/device.h> |
40 | #include <linux/string.h> | 40 | #include <linux/string.h> |
41 | #include <linux/sched.h> | 41 | #include <linux/sched.h> |
42 | #include <linux/mutex.h> | ||
42 | #include <asm/uaccess.h> | 43 | #include <asm/uaccess.h> |
43 | #include <asm/semaphore.h> | 44 | #include <asm/semaphore.h> |
44 | #include <asm/cacheflush.h> | 45 | #include <asm/cacheflush.h> |
@@ -60,18 +61,18 @@ | |||
60 | static DEFINE_SPINLOCK(modlist_lock); | 61 | static DEFINE_SPINLOCK(modlist_lock); |
61 | 62 | ||
62 | /* List of modules, protected by module_mutex AND modlist_lock */ | 63 | /* List of modules, protected by module_mutex AND modlist_lock */ |
63 | static DECLARE_MUTEX(module_mutex); | 64 | static DEFINE_MUTEX(module_mutex); |
64 | static LIST_HEAD(modules); | 65 | static LIST_HEAD(modules); |
65 | 66 | ||
66 | static DECLARE_MUTEX(notify_mutex); | 67 | static DEFINE_MUTEX(notify_mutex); |
67 | static struct notifier_block * module_notify_list; | 68 | static struct notifier_block * module_notify_list; |
68 | 69 | ||
69 | int register_module_notifier(struct notifier_block * nb) | 70 | int register_module_notifier(struct notifier_block * nb) |
70 | { | 71 | { |
71 | int err; | 72 | int err; |
72 | down(¬ify_mutex); | 73 | mutex_lock(¬ify_mutex); |
73 | err = notifier_chain_register(&module_notify_list, nb); | 74 | err = notifier_chain_register(&module_notify_list, nb); |
74 | up(¬ify_mutex); | 75 | mutex_unlock(¬ify_mutex); |
75 | return err; | 76 | return err; |
76 | } | 77 | } |
77 | EXPORT_SYMBOL(register_module_notifier); | 78 | EXPORT_SYMBOL(register_module_notifier); |
@@ -79,9 +80,9 @@ EXPORT_SYMBOL(register_module_notifier); | |||
79 | int unregister_module_notifier(struct notifier_block * nb) | 80 | int unregister_module_notifier(struct notifier_block * nb) |
80 | { | 81 | { |
81 | int err; | 82 | int err; |
82 | down(¬ify_mutex); | 83 | mutex_lock(¬ify_mutex); |
83 | err = notifier_chain_unregister(&module_notify_list, nb); | 84 | err = notifier_chain_unregister(&module_notify_list, nb); |
84 | up(¬ify_mutex); | 85 | mutex_unlock(¬ify_mutex); |
85 | return err; | 86 | return err; |
86 | } | 87 | } |
87 | EXPORT_SYMBOL(unregister_module_notifier); | 88 | EXPORT_SYMBOL(unregister_module_notifier); |
@@ -126,8 +127,11 @@ extern const struct kernel_symbol __start___ksymtab[]; | |||
126 | extern const struct kernel_symbol __stop___ksymtab[]; | 127 | extern const struct kernel_symbol __stop___ksymtab[]; |
127 | extern const struct kernel_symbol __start___ksymtab_gpl[]; | 128 | extern const struct kernel_symbol __start___ksymtab_gpl[]; |
128 | extern const struct kernel_symbol __stop___ksymtab_gpl[]; | 129 | extern const struct kernel_symbol __stop___ksymtab_gpl[]; |
130 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; | ||
131 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; | ||
129 | extern const unsigned long __start___kcrctab[]; | 132 | extern const unsigned long __start___kcrctab[]; |
130 | extern const unsigned long __start___kcrctab_gpl[]; | 133 | extern const unsigned long __start___kcrctab_gpl[]; |
134 | extern const unsigned long __start___kcrctab_gpl_future[]; | ||
131 | 135 | ||
132 | #ifndef CONFIG_MODVERSIONS | 136 | #ifndef CONFIG_MODVERSIONS |
133 | #define symversion(base, idx) NULL | 137 | #define symversion(base, idx) NULL |
@@ -135,6 +139,18 @@ extern const unsigned long __start___kcrctab_gpl[]; | |||
135 | #define symversion(base, idx) ((base) ? ((base) + (idx)) : NULL) | 139 | #define symversion(base, idx) ((base) ? ((base) + (idx)) : NULL) |
136 | #endif | 140 | #endif |
137 | 141 | ||
142 | /* lookup symbol in given range of kernel_symbols */ | ||
143 | static const struct kernel_symbol *lookup_symbol(const char *name, | ||
144 | const struct kernel_symbol *start, | ||
145 | const struct kernel_symbol *stop) | ||
146 | { | ||
147 | const struct kernel_symbol *ks = start; | ||
148 | for (; ks < stop; ks++) | ||
149 | if (strcmp(ks->name, name) == 0) | ||
150 | return ks; | ||
151 | return NULL; | ||
152 | } | ||
153 | |||
138 | /* Find a symbol, return value, crc and module which owns it */ | 154 | /* Find a symbol, return value, crc and module which owns it */ |
139 | static unsigned long __find_symbol(const char *name, | 155 | static unsigned long __find_symbol(const char *name, |
140 | struct module **owner, | 156 | struct module **owner, |
@@ -142,40 +158,75 @@ static unsigned long __find_symbol(const char *name, | |||
142 | int gplok) | 158 | int gplok) |
143 | { | 159 | { |
144 | struct module *mod; | 160 | struct module *mod; |
145 | unsigned int i; | 161 | const struct kernel_symbol *ks; |
146 | 162 | ||
147 | /* Core kernel first. */ | 163 | /* Core kernel first. */ |
148 | *owner = NULL; | 164 | *owner = NULL; |
149 | for (i = 0; __start___ksymtab+i < __stop___ksymtab; i++) { | 165 | ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab); |
150 | if (strcmp(__start___ksymtab[i].name, name) == 0) { | 166 | if (ks) { |
151 | *crc = symversion(__start___kcrctab, i); | 167 | *crc = symversion(__start___kcrctab, (ks - __start___ksymtab)); |
152 | return __start___ksymtab[i].value; | 168 | return ks->value; |
153 | } | ||
154 | } | 169 | } |
155 | if (gplok) { | 170 | if (gplok) { |
156 | for (i = 0; __start___ksymtab_gpl+i<__stop___ksymtab_gpl; i++) | 171 | ks = lookup_symbol(name, __start___ksymtab_gpl, |
157 | if (strcmp(__start___ksymtab_gpl[i].name, name) == 0) { | 172 | __stop___ksymtab_gpl); |
158 | *crc = symversion(__start___kcrctab_gpl, i); | 173 | if (ks) { |
159 | return __start___ksymtab_gpl[i].value; | 174 | *crc = symversion(__start___kcrctab_gpl, |
160 | } | 175 | (ks - __start___ksymtab_gpl)); |
176 | return ks->value; | ||
177 | } | ||
178 | } | ||
179 | ks = lookup_symbol(name, __start___ksymtab_gpl_future, | ||
180 | __stop___ksymtab_gpl_future); | ||
181 | if (ks) { | ||
182 | if (!gplok) { | ||
183 | printk(KERN_WARNING "Symbol %s is being used " | ||
184 | "by a non-GPL module, which will not " | ||
185 | "be allowed in the future\n", name); | ||
186 | printk(KERN_WARNING "Please see the file " | ||
187 | "Documentation/feature-removal-schedule.txt " | ||
188 | "in the kernel source tree for more " | ||
189 | "details.\n"); | ||
190 | } | ||
191 | *crc = symversion(__start___kcrctab_gpl_future, | ||
192 | (ks - __start___ksymtab_gpl_future)); | ||
193 | return ks->value; | ||
161 | } | 194 | } |
162 | 195 | ||
163 | /* Now try modules. */ | 196 | /* Now try modules. */ |
164 | list_for_each_entry(mod, &modules, list) { | 197 | list_for_each_entry(mod, &modules, list) { |
165 | *owner = mod; | 198 | *owner = mod; |
166 | for (i = 0; i < mod->num_syms; i++) | 199 | ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms); |
167 | if (strcmp(mod->syms[i].name, name) == 0) { | 200 | if (ks) { |
168 | *crc = symversion(mod->crcs, i); | 201 | *crc = symversion(mod->crcs, (ks - mod->syms)); |
169 | return mod->syms[i].value; | 202 | return ks->value; |
170 | } | 203 | } |
171 | 204 | ||
172 | if (gplok) { | 205 | if (gplok) { |
173 | for (i = 0; i < mod->num_gpl_syms; i++) { | 206 | ks = lookup_symbol(name, mod->gpl_syms, |
174 | if (strcmp(mod->gpl_syms[i].name, name) == 0) { | 207 | mod->gpl_syms + mod->num_gpl_syms); |
175 | *crc = symversion(mod->gpl_crcs, i); | 208 | if (ks) { |
176 | return mod->gpl_syms[i].value; | 209 | *crc = symversion(mod->gpl_crcs, |
177 | } | 210 | (ks - mod->gpl_syms)); |
211 | return ks->value; | ||
212 | } | ||
213 | } | ||
214 | ks = lookup_symbol(name, mod->gpl_future_syms, | ||
215 | (mod->gpl_future_syms + | ||
216 | mod->num_gpl_future_syms)); | ||
217 | if (ks) { | ||
218 | if (!gplok) { | ||
219 | printk(KERN_WARNING "Symbol %s is being used " | ||
220 | "by a non-GPL module, which will not " | ||
221 | "be allowed in the future\n", name); | ||
222 | printk(KERN_WARNING "Please see the file " | ||
223 | "Documentation/feature-removal-schedule.txt " | ||
224 | "in the kernel source tree for more " | ||
225 | "details.\n"); | ||
178 | } | 226 | } |
227 | *crc = symversion(mod->gpl_future_crcs, | ||
228 | (ks - mod->gpl_future_syms)); | ||
229 | return ks->value; | ||
179 | } | 230 | } |
180 | } | 231 | } |
181 | DEBUGP("Failed to find symbol %s\n", name); | 232 | DEBUGP("Failed to find symbol %s\n", name); |
@@ -379,7 +430,6 @@ static inline void percpu_modcopy(void *pcpudst, const void *src, | |||
379 | } | 430 | } |
380 | #endif /* CONFIG_SMP */ | 431 | #endif /* CONFIG_SMP */ |
381 | 432 | ||
382 | #ifdef CONFIG_MODULE_UNLOAD | ||
383 | #define MODINFO_ATTR(field) \ | 433 | #define MODINFO_ATTR(field) \ |
384 | static void setup_modinfo_##field(struct module *mod, const char *s) \ | 434 | static void setup_modinfo_##field(struct module *mod, const char *s) \ |
385 | { \ | 435 | { \ |
@@ -411,12 +461,7 @@ static struct module_attribute modinfo_##field = { \ | |||
411 | MODINFO_ATTR(version); | 461 | MODINFO_ATTR(version); |
412 | MODINFO_ATTR(srcversion); | 462 | MODINFO_ATTR(srcversion); |
413 | 463 | ||
414 | static struct module_attribute *modinfo_attrs[] = { | 464 | #ifdef CONFIG_MODULE_UNLOAD |
415 | &modinfo_version, | ||
416 | &modinfo_srcversion, | ||
417 | NULL, | ||
418 | }; | ||
419 | |||
420 | /* Init the unload section of the module. */ | 465 | /* Init the unload section of the module. */ |
421 | static void module_unload_init(struct module *mod) | 466 | static void module_unload_init(struct module *mod) |
422 | { | 467 | { |
@@ -557,7 +602,7 @@ static void free_module(struct module *mod); | |||
557 | static void wait_for_zero_refcount(struct module *mod) | 602 | static void wait_for_zero_refcount(struct module *mod) |
558 | { | 603 | { |
559 | /* Since we might sleep for some time, drop the semaphore first */ | 604 | /* Since we might sleep for some time, drop the semaphore first */ |
560 | up(&module_mutex); | 605 | mutex_unlock(&module_mutex); |
561 | for (;;) { | 606 | for (;;) { |
562 | DEBUGP("Looking at refcount...\n"); | 607 | DEBUGP("Looking at refcount...\n"); |
563 | set_current_state(TASK_UNINTERRUPTIBLE); | 608 | set_current_state(TASK_UNINTERRUPTIBLE); |
@@ -566,7 +611,7 @@ static void wait_for_zero_refcount(struct module *mod) | |||
566 | schedule(); | 611 | schedule(); |
567 | } | 612 | } |
568 | current->state = TASK_RUNNING; | 613 | current->state = TASK_RUNNING; |
569 | down(&module_mutex); | 614 | mutex_lock(&module_mutex); |
570 | } | 615 | } |
571 | 616 | ||
572 | asmlinkage long | 617 | asmlinkage long |
@@ -583,7 +628,7 @@ sys_delete_module(const char __user *name_user, unsigned int flags) | |||
583 | return -EFAULT; | 628 | return -EFAULT; |
584 | name[MODULE_NAME_LEN-1] = '\0'; | 629 | name[MODULE_NAME_LEN-1] = '\0'; |
585 | 630 | ||
586 | if (down_interruptible(&module_mutex) != 0) | 631 | if (mutex_lock_interruptible(&module_mutex) != 0) |
587 | return -EINTR; | 632 | return -EINTR; |
588 | 633 | ||
589 | mod = find_module(name); | 634 | mod = find_module(name); |
@@ -632,14 +677,14 @@ sys_delete_module(const char __user *name_user, unsigned int flags) | |||
632 | 677 | ||
633 | /* Final destruction now noone is using it. */ | 678 | /* Final destruction now noone is using it. */ |
634 | if (mod->exit != NULL) { | 679 | if (mod->exit != NULL) { |
635 | up(&module_mutex); | 680 | mutex_unlock(&module_mutex); |
636 | mod->exit(); | 681 | mod->exit(); |
637 | down(&module_mutex); | 682 | mutex_lock(&module_mutex); |
638 | } | 683 | } |
639 | free_module(mod); | 684 | free_module(mod); |
640 | 685 | ||
641 | out: | 686 | out: |
642 | up(&module_mutex); | 687 | mutex_unlock(&module_mutex); |
643 | return ret; | 688 | return ret; |
644 | } | 689 | } |
645 | 690 | ||
@@ -731,6 +776,15 @@ static inline void module_unload_init(struct module *mod) | |||
731 | } | 776 | } |
732 | #endif /* CONFIG_MODULE_UNLOAD */ | 777 | #endif /* CONFIG_MODULE_UNLOAD */ |
733 | 778 | ||
779 | static struct module_attribute *modinfo_attrs[] = { | ||
780 | &modinfo_version, | ||
781 | &modinfo_srcversion, | ||
782 | #ifdef CONFIG_MODULE_UNLOAD | ||
783 | &refcnt, | ||
784 | #endif | ||
785 | NULL, | ||
786 | }; | ||
787 | |||
734 | #ifdef CONFIG_OBSOLETE_MODPARM | 788 | #ifdef CONFIG_OBSOLETE_MODPARM |
735 | /* Bounds checking done below */ | 789 | /* Bounds checking done below */ |
736 | static int obsparm_copy_string(const char *val, struct kernel_param *kp) | 790 | static int obsparm_copy_string(const char *val, struct kernel_param *kp) |
@@ -1056,37 +1110,28 @@ static inline void remove_sect_attrs(struct module *mod) | |||
1056 | } | 1110 | } |
1057 | #endif /* CONFIG_KALLSYMS */ | 1111 | #endif /* CONFIG_KALLSYMS */ |
1058 | 1112 | ||
1059 | |||
1060 | #ifdef CONFIG_MODULE_UNLOAD | ||
1061 | static inline int module_add_refcnt_attr(struct module *mod) | ||
1062 | { | ||
1063 | return sysfs_create_file(&mod->mkobj.kobj, &refcnt.attr); | ||
1064 | } | ||
1065 | static void module_remove_refcnt_attr(struct module *mod) | ||
1066 | { | ||
1067 | return sysfs_remove_file(&mod->mkobj.kobj, &refcnt.attr); | ||
1068 | } | ||
1069 | #else | ||
1070 | static inline int module_add_refcnt_attr(struct module *mod) | ||
1071 | { | ||
1072 | return 0; | ||
1073 | } | ||
1074 | static void module_remove_refcnt_attr(struct module *mod) | ||
1075 | { | ||
1076 | } | ||
1077 | #endif | ||
1078 | |||
1079 | #ifdef CONFIG_MODULE_UNLOAD | ||
1080 | static int module_add_modinfo_attrs(struct module *mod) | 1113 | static int module_add_modinfo_attrs(struct module *mod) |
1081 | { | 1114 | { |
1082 | struct module_attribute *attr; | 1115 | struct module_attribute *attr; |
1116 | struct module_attribute *temp_attr; | ||
1083 | int error = 0; | 1117 | int error = 0; |
1084 | int i; | 1118 | int i; |
1085 | 1119 | ||
1120 | mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) * | ||
1121 | (ARRAY_SIZE(modinfo_attrs) + 1)), | ||
1122 | GFP_KERNEL); | ||
1123 | if (!mod->modinfo_attrs) | ||
1124 | return -ENOMEM; | ||
1125 | |||
1126 | temp_attr = mod->modinfo_attrs; | ||
1086 | for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { | 1127 | for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { |
1087 | if (!attr->test || | 1128 | if (!attr->test || |
1088 | (attr->test && attr->test(mod))) | 1129 | (attr->test && attr->test(mod))) { |
1089 | error = sysfs_create_file(&mod->mkobj.kobj,&attr->attr); | 1130 | memcpy(temp_attr, attr, sizeof(*temp_attr)); |
1131 | temp_attr->attr.owner = mod; | ||
1132 | error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr); | ||
1133 | ++temp_attr; | ||
1134 | } | ||
1090 | } | 1135 | } |
1091 | return error; | 1136 | return error; |
1092 | } | 1137 | } |
@@ -1096,12 +1141,16 @@ static void module_remove_modinfo_attrs(struct module *mod) | |||
1096 | struct module_attribute *attr; | 1141 | struct module_attribute *attr; |
1097 | int i; | 1142 | int i; |
1098 | 1143 | ||
1099 | for (i = 0; (attr = modinfo_attrs[i]); i++) { | 1144 | for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) { |
1145 | /* pick a field to test for end of list */ | ||
1146 | if (!attr->attr.name) | ||
1147 | break; | ||
1100 | sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); | 1148 | sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); |
1101 | attr->free(mod); | 1149 | if (attr->free) |
1150 | attr->free(mod); | ||
1102 | } | 1151 | } |
1152 | kfree(mod->modinfo_attrs); | ||
1103 | } | 1153 | } |
1104 | #endif | ||
1105 | 1154 | ||
1106 | static int mod_sysfs_setup(struct module *mod, | 1155 | static int mod_sysfs_setup(struct module *mod, |
1107 | struct kernel_param *kparam, | 1156 | struct kernel_param *kparam, |
@@ -1119,19 +1168,13 @@ static int mod_sysfs_setup(struct module *mod, | |||
1119 | if (err) | 1168 | if (err) |
1120 | goto out; | 1169 | goto out; |
1121 | 1170 | ||
1122 | err = module_add_refcnt_attr(mod); | ||
1123 | if (err) | ||
1124 | goto out_unreg; | ||
1125 | |||
1126 | err = module_param_sysfs_setup(mod, kparam, num_params); | 1171 | err = module_param_sysfs_setup(mod, kparam, num_params); |
1127 | if (err) | 1172 | if (err) |
1128 | goto out_unreg; | 1173 | goto out_unreg; |
1129 | 1174 | ||
1130 | #ifdef CONFIG_MODULE_UNLOAD | ||
1131 | err = module_add_modinfo_attrs(mod); | 1175 | err = module_add_modinfo_attrs(mod); |
1132 | if (err) | 1176 | if (err) |
1133 | goto out_unreg; | 1177 | goto out_unreg; |
1134 | #endif | ||
1135 | 1178 | ||
1136 | return 0; | 1179 | return 0; |
1137 | 1180 | ||
@@ -1143,10 +1186,7 @@ out: | |||
1143 | 1186 | ||
1144 | static void mod_kobject_remove(struct module *mod) | 1187 | static void mod_kobject_remove(struct module *mod) |
1145 | { | 1188 | { |
1146 | #ifdef CONFIG_MODULE_UNLOAD | ||
1147 | module_remove_modinfo_attrs(mod); | 1189 | module_remove_modinfo_attrs(mod); |
1148 | #endif | ||
1149 | module_remove_refcnt_attr(mod); | ||
1150 | module_param_sysfs_remove(mod); | 1190 | module_param_sysfs_remove(mod); |
1151 | 1191 | ||
1152 | kobject_unregister(&mod->mkobj.kobj); | 1192 | kobject_unregister(&mod->mkobj.kobj); |
@@ -1424,7 +1464,6 @@ static char *get_modinfo(Elf_Shdr *sechdrs, | |||
1424 | return NULL; | 1464 | return NULL; |
1425 | } | 1465 | } |
1426 | 1466 | ||
1427 | #ifdef CONFIG_MODULE_UNLOAD | ||
1428 | static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, | 1467 | static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, |
1429 | unsigned int infoindex) | 1468 | unsigned int infoindex) |
1430 | { | 1469 | { |
@@ -1439,23 +1478,17 @@ static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, | |||
1439 | attr->attr.name)); | 1478 | attr->attr.name)); |
1440 | } | 1479 | } |
1441 | } | 1480 | } |
1442 | #endif | ||
1443 | 1481 | ||
1444 | #ifdef CONFIG_KALLSYMS | 1482 | #ifdef CONFIG_KALLSYMS |
1445 | int is_exported(const char *name, const struct module *mod) | 1483 | int is_exported(const char *name, const struct module *mod) |
1446 | { | 1484 | { |
1447 | unsigned int i; | 1485 | if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab)) |
1448 | 1486 | return 1; | |
1449 | if (!mod) { | 1487 | else |
1450 | for (i = 0; __start___ksymtab+i < __stop___ksymtab; i++) | 1488 | if (lookup_symbol(name, mod->syms, mod->syms + mod->num_syms)) |
1451 | if (strcmp(__start___ksymtab[i].name, name) == 0) | ||
1452 | return 1; | ||
1453 | return 0; | ||
1454 | } | ||
1455 | for (i = 0; i < mod->num_syms; i++) | ||
1456 | if (strcmp(mod->syms[i].name, name) == 0) | ||
1457 | return 1; | 1489 | return 1; |
1458 | return 0; | 1490 | else |
1491 | return 0; | ||
1459 | } | 1492 | } |
1460 | 1493 | ||
1461 | /* As per nm */ | 1494 | /* As per nm */ |
@@ -1537,7 +1570,8 @@ static struct module *load_module(void __user *umod, | |||
1537 | char *secstrings, *args, *modmagic, *strtab = NULL; | 1570 | char *secstrings, *args, *modmagic, *strtab = NULL; |
1538 | unsigned int i, symindex = 0, strindex = 0, setupindex, exindex, | 1571 | unsigned int i, symindex = 0, strindex = 0, setupindex, exindex, |
1539 | exportindex, modindex, obsparmindex, infoindex, gplindex, | 1572 | exportindex, modindex, obsparmindex, infoindex, gplindex, |
1540 | crcindex, gplcrcindex, versindex, pcpuindex; | 1573 | crcindex, gplcrcindex, versindex, pcpuindex, gplfutureindex, |
1574 | gplfuturecrcindex; | ||
1541 | long arglen; | 1575 | long arglen; |
1542 | struct module *mod; | 1576 | struct module *mod; |
1543 | long err = 0; | 1577 | long err = 0; |
@@ -1618,8 +1652,10 @@ static struct module *load_module(void __user *umod, | |||
1618 | /* Optional sections */ | 1652 | /* Optional sections */ |
1619 | exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); | 1653 | exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); |
1620 | gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); | 1654 | gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); |
1655 | gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future"); | ||
1621 | crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); | 1656 | crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); |
1622 | gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); | 1657 | gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); |
1658 | gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future"); | ||
1623 | setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); | 1659 | setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); |
1624 | exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); | 1660 | exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); |
1625 | obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); | 1661 | obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); |
@@ -1755,10 +1791,8 @@ static struct module *load_module(void __user *umod, | |||
1755 | if (strcmp(mod->name, "driverloader") == 0) | 1791 | if (strcmp(mod->name, "driverloader") == 0) |
1756 | add_taint(TAINT_PROPRIETARY_MODULE); | 1792 | add_taint(TAINT_PROPRIETARY_MODULE); |
1757 | 1793 | ||
1758 | #ifdef CONFIG_MODULE_UNLOAD | ||
1759 | /* Set up MODINFO_ATTR fields */ | 1794 | /* Set up MODINFO_ATTR fields */ |
1760 | setup_modinfo(mod, sechdrs, infoindex); | 1795 | setup_modinfo(mod, sechdrs, infoindex); |
1761 | #endif | ||
1762 | 1796 | ||
1763 | /* Fix up syms, so that st_value is a pointer to location. */ | 1797 | /* Fix up syms, so that st_value is a pointer to location. */ |
1764 | err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, | 1798 | err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, |
@@ -1775,10 +1809,16 @@ static struct module *load_module(void __user *umod, | |||
1775 | mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; | 1809 | mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; |
1776 | if (gplcrcindex) | 1810 | if (gplcrcindex) |
1777 | mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; | 1811 | mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; |
1812 | mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / | ||
1813 | sizeof(*mod->gpl_future_syms); | ||
1814 | mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; | ||
1815 | if (gplfuturecrcindex) | ||
1816 | mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; | ||
1778 | 1817 | ||
1779 | #ifdef CONFIG_MODVERSIONS | 1818 | #ifdef CONFIG_MODVERSIONS |
1780 | if ((mod->num_syms && !crcindex) || | 1819 | if ((mod->num_syms && !crcindex) || |
1781 | (mod->num_gpl_syms && !gplcrcindex)) { | 1820 | (mod->num_gpl_syms && !gplcrcindex) || |
1821 | (mod->num_gpl_future_syms && !gplfuturecrcindex)) { | ||
1782 | printk(KERN_WARNING "%s: No versions for exported symbols." | 1822 | printk(KERN_WARNING "%s: No versions for exported symbols." |
1783 | " Tainting kernel.\n", mod->name); | 1823 | " Tainting kernel.\n", mod->name); |
1784 | add_taint(TAINT_FORCED_MODULE); | 1824 | add_taint(TAINT_FORCED_MODULE); |
@@ -1933,13 +1973,13 @@ sys_init_module(void __user *umod, | |||
1933 | return -EPERM; | 1973 | return -EPERM; |
1934 | 1974 | ||
1935 | /* Only one module load at a time, please */ | 1975 | /* Only one module load at a time, please */ |
1936 | if (down_interruptible(&module_mutex) != 0) | 1976 | if (mutex_lock_interruptible(&module_mutex) != 0) |
1937 | return -EINTR; | 1977 | return -EINTR; |
1938 | 1978 | ||
1939 | /* Do all the hard work */ | 1979 | /* Do all the hard work */ |
1940 | mod = load_module(umod, len, uargs); | 1980 | mod = load_module(umod, len, uargs); |
1941 | if (IS_ERR(mod)) { | 1981 | if (IS_ERR(mod)) { |
1942 | up(&module_mutex); | 1982 | mutex_unlock(&module_mutex); |
1943 | return PTR_ERR(mod); | 1983 | return PTR_ERR(mod); |
1944 | } | 1984 | } |
1945 | 1985 | ||
@@ -1948,11 +1988,11 @@ sys_init_module(void __user *umod, | |||
1948 | stop_machine_run(__link_module, mod, NR_CPUS); | 1988 | stop_machine_run(__link_module, mod, NR_CPUS); |
1949 | 1989 | ||
1950 | /* Drop lock so they can recurse */ | 1990 | /* Drop lock so they can recurse */ |
1951 | up(&module_mutex); | 1991 | mutex_unlock(&module_mutex); |
1952 | 1992 | ||
1953 | down(¬ify_mutex); | 1993 | mutex_lock(¬ify_mutex); |
1954 | notifier_call_chain(&module_notify_list, MODULE_STATE_COMING, mod); | 1994 | notifier_call_chain(&module_notify_list, MODULE_STATE_COMING, mod); |
1955 | up(¬ify_mutex); | 1995 | mutex_unlock(¬ify_mutex); |
1956 | 1996 | ||
1957 | /* Start the module */ | 1997 | /* Start the module */ |
1958 | if (mod->init != NULL) | 1998 | if (mod->init != NULL) |
@@ -1967,15 +2007,15 @@ sys_init_module(void __user *umod, | |||
1967 | mod->name); | 2007 | mod->name); |
1968 | else { | 2008 | else { |
1969 | module_put(mod); | 2009 | module_put(mod); |
1970 | down(&module_mutex); | 2010 | mutex_lock(&module_mutex); |
1971 | free_module(mod); | 2011 | free_module(mod); |
1972 | up(&module_mutex); | 2012 | mutex_unlock(&module_mutex); |
1973 | } | 2013 | } |
1974 | return ret; | 2014 | return ret; |
1975 | } | 2015 | } |
1976 | 2016 | ||
1977 | /* Now it's a first class citizen! */ | 2017 | /* Now it's a first class citizen! */ |
1978 | down(&module_mutex); | 2018 | mutex_lock(&module_mutex); |
1979 | mod->state = MODULE_STATE_LIVE; | 2019 | mod->state = MODULE_STATE_LIVE; |
1980 | /* Drop initial reference. */ | 2020 | /* Drop initial reference. */ |
1981 | module_put(mod); | 2021 | module_put(mod); |
@@ -1983,7 +2023,7 @@ sys_init_module(void __user *umod, | |||
1983 | mod->module_init = NULL; | 2023 | mod->module_init = NULL; |
1984 | mod->init_size = 0; | 2024 | mod->init_size = 0; |
1985 | mod->init_text_size = 0; | 2025 | mod->init_text_size = 0; |
1986 | up(&module_mutex); | 2026 | mutex_unlock(&module_mutex); |
1987 | 2027 | ||
1988 | return 0; | 2028 | return 0; |
1989 | } | 2029 | } |
@@ -2073,7 +2113,7 @@ struct module *module_get_kallsym(unsigned int symnum, | |||
2073 | { | 2113 | { |
2074 | struct module *mod; | 2114 | struct module *mod; |
2075 | 2115 | ||
2076 | down(&module_mutex); | 2116 | mutex_lock(&module_mutex); |
2077 | list_for_each_entry(mod, &modules, list) { | 2117 | list_for_each_entry(mod, &modules, list) { |
2078 | if (symnum < mod->num_symtab) { | 2118 | if (symnum < mod->num_symtab) { |
2079 | *value = mod->symtab[symnum].st_value; | 2119 | *value = mod->symtab[symnum].st_value; |
@@ -2081,12 +2121,12 @@ struct module *module_get_kallsym(unsigned int symnum, | |||
2081 | strncpy(namebuf, | 2121 | strncpy(namebuf, |
2082 | mod->strtab + mod->symtab[symnum].st_name, | 2122 | mod->strtab + mod->symtab[symnum].st_name, |
2083 | 127); | 2123 | 127); |
2084 | up(&module_mutex); | 2124 | mutex_unlock(&module_mutex); |
2085 | return mod; | 2125 | return mod; |
2086 | } | 2126 | } |
2087 | symnum -= mod->num_symtab; | 2127 | symnum -= mod->num_symtab; |
2088 | } | 2128 | } |
2089 | up(&module_mutex); | 2129 | mutex_unlock(&module_mutex); |
2090 | return NULL; | 2130 | return NULL; |
2091 | } | 2131 | } |
2092 | 2132 | ||
@@ -2129,7 +2169,7 @@ static void *m_start(struct seq_file *m, loff_t *pos) | |||
2129 | struct list_head *i; | 2169 | struct list_head *i; |
2130 | loff_t n = 0; | 2170 | loff_t n = 0; |
2131 | 2171 | ||
2132 | down(&module_mutex); | 2172 | mutex_lock(&module_mutex); |
2133 | list_for_each(i, &modules) { | 2173 | list_for_each(i, &modules) { |
2134 | if (n++ == *pos) | 2174 | if (n++ == *pos) |
2135 | break; | 2175 | break; |
@@ -2150,7 +2190,7 @@ static void *m_next(struct seq_file *m, void *p, loff_t *pos) | |||
2150 | 2190 | ||
2151 | static void m_stop(struct seq_file *m, void *p) | 2191 | static void m_stop(struct seq_file *m, void *p) |
2152 | { | 2192 | { |
2153 | up(&module_mutex); | 2193 | mutex_unlock(&module_mutex); |
2154 | } | 2194 | } |
2155 | 2195 | ||
2156 | static int m_show(struct seq_file *m, void *p) | 2196 | static int m_show(struct seq_file *m, void *p) |