diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 199 |
1 files changed, 119 insertions, 80 deletions
diff --git a/kernel/module.c b/kernel/module.c index 5aad477ddc79..77764f22f021 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -126,8 +126,11 @@ extern const struct kernel_symbol __start___ksymtab[]; | |||
126 | extern const struct kernel_symbol __stop___ksymtab[]; | 126 | extern const struct kernel_symbol __stop___ksymtab[]; |
127 | extern const struct kernel_symbol __start___ksymtab_gpl[]; | 127 | extern const struct kernel_symbol __start___ksymtab_gpl[]; |
128 | extern const struct kernel_symbol __stop___ksymtab_gpl[]; | 128 | extern const struct kernel_symbol __stop___ksymtab_gpl[]; |
129 | extern const struct kernel_symbol __start___ksymtab_gpl_future[]; | ||
130 | extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; | ||
129 | extern const unsigned long __start___kcrctab[]; | 131 | extern const unsigned long __start___kcrctab[]; |
130 | extern const unsigned long __start___kcrctab_gpl[]; | 132 | extern const unsigned long __start___kcrctab_gpl[]; |
133 | extern const unsigned long __start___kcrctab_gpl_future[]; | ||
131 | 134 | ||
132 | #ifndef CONFIG_MODVERSIONS | 135 | #ifndef CONFIG_MODVERSIONS |
133 | #define symversion(base, idx) NULL | 136 | #define symversion(base, idx) NULL |
@@ -135,6 +138,18 @@ extern const unsigned long __start___kcrctab_gpl[]; | |||
135 | #define symversion(base, idx) ((base) ? ((base) + (idx)) : NULL) | 138 | #define symversion(base, idx) ((base) ? ((base) + (idx)) : NULL) |
136 | #endif | 139 | #endif |
137 | 140 | ||
141 | /* lookup symbol in given range of kernel_symbols */ | ||
142 | static const struct kernel_symbol *lookup_symbol(const char *name, | ||
143 | const struct kernel_symbol *start, | ||
144 | const struct kernel_symbol *stop) | ||
145 | { | ||
146 | const struct kernel_symbol *ks = start; | ||
147 | for (; ks < stop; ks++) | ||
148 | if (strcmp(ks->name, name) == 0) | ||
149 | return ks; | ||
150 | return NULL; | ||
151 | } | ||
152 | |||
138 | /* Find a symbol, return value, crc and module which owns it */ | 153 | /* Find a symbol, return value, crc and module which owns it */ |
139 | static unsigned long __find_symbol(const char *name, | 154 | static unsigned long __find_symbol(const char *name, |
140 | struct module **owner, | 155 | struct module **owner, |
@@ -142,40 +157,75 @@ static unsigned long __find_symbol(const char *name, | |||
142 | int gplok) | 157 | int gplok) |
143 | { | 158 | { |
144 | struct module *mod; | 159 | struct module *mod; |
145 | unsigned int i; | 160 | const struct kernel_symbol *ks; |
146 | 161 | ||
147 | /* Core kernel first. */ | 162 | /* Core kernel first. */ |
148 | *owner = NULL; | 163 | *owner = NULL; |
149 | for (i = 0; __start___ksymtab+i < __stop___ksymtab; i++) { | 164 | ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab); |
150 | if (strcmp(__start___ksymtab[i].name, name) == 0) { | 165 | if (ks) { |
151 | *crc = symversion(__start___kcrctab, i); | 166 | *crc = symversion(__start___kcrctab, (ks - __start___ksymtab)); |
152 | return __start___ksymtab[i].value; | 167 | return ks->value; |
153 | } | ||
154 | } | 168 | } |
155 | if (gplok) { | 169 | if (gplok) { |
156 | for (i = 0; __start___ksymtab_gpl+i<__stop___ksymtab_gpl; i++) | 170 | ks = lookup_symbol(name, __start___ksymtab_gpl, |
157 | if (strcmp(__start___ksymtab_gpl[i].name, name) == 0) { | 171 | __stop___ksymtab_gpl); |
158 | *crc = symversion(__start___kcrctab_gpl, i); | 172 | if (ks) { |
159 | return __start___ksymtab_gpl[i].value; | 173 | *crc = symversion(__start___kcrctab_gpl, |
160 | } | 174 | (ks - __start___ksymtab_gpl)); |
175 | return ks->value; | ||
176 | } | ||
177 | } | ||
178 | ks = lookup_symbol(name, __start___ksymtab_gpl_future, | ||
179 | __stop___ksymtab_gpl_future); | ||
180 | if (ks) { | ||
181 | if (!gplok) { | ||
182 | printk(KERN_WARNING "Symbol %s is being used " | ||
183 | "by a non-GPL module, which will not " | ||
184 | "be allowed in the future\n", name); | ||
185 | printk(KERN_WARNING "Please see the file " | ||
186 | "Documentation/feature-removal-schedule.txt " | ||
187 | "in the kernel source tree for more " | ||
188 | "details.\n"); | ||
189 | } | ||
190 | *crc = symversion(__start___kcrctab_gpl_future, | ||
191 | (ks - __start___ksymtab_gpl_future)); | ||
192 | return ks->value; | ||
161 | } | 193 | } |
162 | 194 | ||
163 | /* Now try modules. */ | 195 | /* Now try modules. */ |
164 | list_for_each_entry(mod, &modules, list) { | 196 | list_for_each_entry(mod, &modules, list) { |
165 | *owner = mod; | 197 | *owner = mod; |
166 | for (i = 0; i < mod->num_syms; i++) | 198 | ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms); |
167 | if (strcmp(mod->syms[i].name, name) == 0) { | 199 | if (ks) { |
168 | *crc = symversion(mod->crcs, i); | 200 | *crc = symversion(mod->crcs, (ks - mod->syms)); |
169 | return mod->syms[i].value; | 201 | return ks->value; |
170 | } | 202 | } |
171 | 203 | ||
172 | if (gplok) { | 204 | if (gplok) { |
173 | for (i = 0; i < mod->num_gpl_syms; i++) { | 205 | ks = lookup_symbol(name, mod->gpl_syms, |
174 | if (strcmp(mod->gpl_syms[i].name, name) == 0) { | 206 | mod->gpl_syms + mod->num_gpl_syms); |
175 | *crc = symversion(mod->gpl_crcs, i); | 207 | if (ks) { |
176 | return mod->gpl_syms[i].value; | 208 | *crc = symversion(mod->gpl_crcs, |
177 | } | 209 | (ks - mod->gpl_syms)); |
210 | return ks->value; | ||
211 | } | ||
212 | } | ||
213 | ks = lookup_symbol(name, mod->gpl_future_syms, | ||
214 | (mod->gpl_future_syms + | ||
215 | mod->num_gpl_future_syms)); | ||
216 | if (ks) { | ||
217 | if (!gplok) { | ||
218 | printk(KERN_WARNING "Symbol %s is being used " | ||
219 | "by a non-GPL module, which will not " | ||
220 | "be allowed in the future\n", name); | ||
221 | printk(KERN_WARNING "Please see the file " | ||
222 | "Documentation/feature-removal-schedule.txt " | ||
223 | "in the kernel source tree for more " | ||
224 | "details.\n"); | ||
178 | } | 225 | } |
226 | *crc = symversion(mod->gpl_future_crcs, | ||
227 | (ks - mod->gpl_future_syms)); | ||
228 | return ks->value; | ||
179 | } | 229 | } |
180 | } | 230 | } |
181 | DEBUGP("Failed to find symbol %s\n", name); | 231 | DEBUGP("Failed to find symbol %s\n", name); |
@@ -379,7 +429,6 @@ static inline void percpu_modcopy(void *pcpudst, const void *src, | |||
379 | } | 429 | } |
380 | #endif /* CONFIG_SMP */ | 430 | #endif /* CONFIG_SMP */ |
381 | 431 | ||
382 | #ifdef CONFIG_MODULE_UNLOAD | ||
383 | #define MODINFO_ATTR(field) \ | 432 | #define MODINFO_ATTR(field) \ |
384 | static void setup_modinfo_##field(struct module *mod, const char *s) \ | 433 | static void setup_modinfo_##field(struct module *mod, const char *s) \ |
385 | { \ | 434 | { \ |
@@ -411,12 +460,7 @@ static struct module_attribute modinfo_##field = { \ | |||
411 | MODINFO_ATTR(version); | 460 | MODINFO_ATTR(version); |
412 | MODINFO_ATTR(srcversion); | 461 | MODINFO_ATTR(srcversion); |
413 | 462 | ||
414 | static struct module_attribute *modinfo_attrs[] = { | 463 | #ifdef CONFIG_MODULE_UNLOAD |
415 | &modinfo_version, | ||
416 | &modinfo_srcversion, | ||
417 | NULL, | ||
418 | }; | ||
419 | |||
420 | /* Init the unload section of the module. */ | 464 | /* Init the unload section of the module. */ |
421 | static void module_unload_init(struct module *mod) | 465 | static void module_unload_init(struct module *mod) |
422 | { | 466 | { |
@@ -731,6 +775,15 @@ static inline void module_unload_init(struct module *mod) | |||
731 | } | 775 | } |
732 | #endif /* CONFIG_MODULE_UNLOAD */ | 776 | #endif /* CONFIG_MODULE_UNLOAD */ |
733 | 777 | ||
778 | static struct module_attribute *modinfo_attrs[] = { | ||
779 | &modinfo_version, | ||
780 | &modinfo_srcversion, | ||
781 | #ifdef CONFIG_MODULE_UNLOAD | ||
782 | &refcnt, | ||
783 | #endif | ||
784 | NULL, | ||
785 | }; | ||
786 | |||
734 | #ifdef CONFIG_OBSOLETE_MODPARM | 787 | #ifdef CONFIG_OBSOLETE_MODPARM |
735 | /* Bounds checking done below */ | 788 | /* Bounds checking done below */ |
736 | static int obsparm_copy_string(const char *val, struct kernel_param *kp) | 789 | static int obsparm_copy_string(const char *val, struct kernel_param *kp) |
@@ -1056,37 +1109,28 @@ static inline void remove_sect_attrs(struct module *mod) | |||
1056 | } | 1109 | } |
1057 | #endif /* CONFIG_KALLSYMS */ | 1110 | #endif /* CONFIG_KALLSYMS */ |
1058 | 1111 | ||
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) | 1112 | static int module_add_modinfo_attrs(struct module *mod) |
1081 | { | 1113 | { |
1082 | struct module_attribute *attr; | 1114 | struct module_attribute *attr; |
1115 | struct module_attribute *temp_attr; | ||
1083 | int error = 0; | 1116 | int error = 0; |
1084 | int i; | 1117 | int i; |
1085 | 1118 | ||
1119 | mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) * | ||
1120 | (ARRAY_SIZE(modinfo_attrs) + 1)), | ||
1121 | GFP_KERNEL); | ||
1122 | if (!mod->modinfo_attrs) | ||
1123 | return -ENOMEM; | ||
1124 | |||
1125 | temp_attr = mod->modinfo_attrs; | ||
1086 | for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { | 1126 | for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { |
1087 | if (!attr->test || | 1127 | if (!attr->test || |
1088 | (attr->test && attr->test(mod))) | 1128 | (attr->test && attr->test(mod))) { |
1089 | error = sysfs_create_file(&mod->mkobj.kobj,&attr->attr); | 1129 | memcpy(temp_attr, attr, sizeof(*temp_attr)); |
1130 | temp_attr->attr.owner = mod; | ||
1131 | error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr); | ||
1132 | ++temp_attr; | ||
1133 | } | ||
1090 | } | 1134 | } |
1091 | return error; | 1135 | return error; |
1092 | } | 1136 | } |
@@ -1096,12 +1140,16 @@ static void module_remove_modinfo_attrs(struct module *mod) | |||
1096 | struct module_attribute *attr; | 1140 | struct module_attribute *attr; |
1097 | int i; | 1141 | int i; |
1098 | 1142 | ||
1099 | for (i = 0; (attr = modinfo_attrs[i]); i++) { | 1143 | for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) { |
1144 | /* pick a field to test for end of list */ | ||
1145 | if (!attr->attr.name) | ||
1146 | break; | ||
1100 | sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); | 1147 | sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); |
1101 | attr->free(mod); | 1148 | if (attr->free) |
1149 | attr->free(mod); | ||
1102 | } | 1150 | } |
1151 | kfree(mod->modinfo_attrs); | ||
1103 | } | 1152 | } |
1104 | #endif | ||
1105 | 1153 | ||
1106 | static int mod_sysfs_setup(struct module *mod, | 1154 | static int mod_sysfs_setup(struct module *mod, |
1107 | struct kernel_param *kparam, | 1155 | struct kernel_param *kparam, |
@@ -1119,19 +1167,13 @@ static int mod_sysfs_setup(struct module *mod, | |||
1119 | if (err) | 1167 | if (err) |
1120 | goto out; | 1168 | goto out; |
1121 | 1169 | ||
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); | 1170 | err = module_param_sysfs_setup(mod, kparam, num_params); |
1127 | if (err) | 1171 | if (err) |
1128 | goto out_unreg; | 1172 | goto out_unreg; |
1129 | 1173 | ||
1130 | #ifdef CONFIG_MODULE_UNLOAD | ||
1131 | err = module_add_modinfo_attrs(mod); | 1174 | err = module_add_modinfo_attrs(mod); |
1132 | if (err) | 1175 | if (err) |
1133 | goto out_unreg; | 1176 | goto out_unreg; |
1134 | #endif | ||
1135 | 1177 | ||
1136 | return 0; | 1178 | return 0; |
1137 | 1179 | ||
@@ -1143,10 +1185,7 @@ out: | |||
1143 | 1185 | ||
1144 | static void mod_kobject_remove(struct module *mod) | 1186 | static void mod_kobject_remove(struct module *mod) |
1145 | { | 1187 | { |
1146 | #ifdef CONFIG_MODULE_UNLOAD | ||
1147 | module_remove_modinfo_attrs(mod); | 1188 | module_remove_modinfo_attrs(mod); |
1148 | #endif | ||
1149 | module_remove_refcnt_attr(mod); | ||
1150 | module_param_sysfs_remove(mod); | 1189 | module_param_sysfs_remove(mod); |
1151 | 1190 | ||
1152 | kobject_unregister(&mod->mkobj.kobj); | 1191 | kobject_unregister(&mod->mkobj.kobj); |
@@ -1424,7 +1463,6 @@ static char *get_modinfo(Elf_Shdr *sechdrs, | |||
1424 | return NULL; | 1463 | return NULL; |
1425 | } | 1464 | } |
1426 | 1465 | ||
1427 | #ifdef CONFIG_MODULE_UNLOAD | ||
1428 | static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, | 1466 | static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, |
1429 | unsigned int infoindex) | 1467 | unsigned int infoindex) |
1430 | { | 1468 | { |
@@ -1439,23 +1477,17 @@ static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, | |||
1439 | attr->attr.name)); | 1477 | attr->attr.name)); |
1440 | } | 1478 | } |
1441 | } | 1479 | } |
1442 | #endif | ||
1443 | 1480 | ||
1444 | #ifdef CONFIG_KALLSYMS | 1481 | #ifdef CONFIG_KALLSYMS |
1445 | int is_exported(const char *name, const struct module *mod) | 1482 | int is_exported(const char *name, const struct module *mod) |
1446 | { | 1483 | { |
1447 | unsigned int i; | 1484 | if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab)) |
1448 | 1485 | return 1; | |
1449 | if (!mod) { | 1486 | else |
1450 | for (i = 0; __start___ksymtab+i < __stop___ksymtab; i++) | 1487 | 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; | 1488 | return 1; |
1458 | return 0; | 1489 | else |
1490 | return 0; | ||
1459 | } | 1491 | } |
1460 | 1492 | ||
1461 | /* As per nm */ | 1493 | /* As per nm */ |
@@ -1537,7 +1569,8 @@ static struct module *load_module(void __user *umod, | |||
1537 | char *secstrings, *args, *modmagic, *strtab = NULL; | 1569 | char *secstrings, *args, *modmagic, *strtab = NULL; |
1538 | unsigned int i, symindex = 0, strindex = 0, setupindex, exindex, | 1570 | unsigned int i, symindex = 0, strindex = 0, setupindex, exindex, |
1539 | exportindex, modindex, obsparmindex, infoindex, gplindex, | 1571 | exportindex, modindex, obsparmindex, infoindex, gplindex, |
1540 | crcindex, gplcrcindex, versindex, pcpuindex; | 1572 | crcindex, gplcrcindex, versindex, pcpuindex, gplfutureindex, |
1573 | gplfuturecrcindex; | ||
1541 | long arglen; | 1574 | long arglen; |
1542 | struct module *mod; | 1575 | struct module *mod; |
1543 | long err = 0; | 1576 | long err = 0; |
@@ -1618,8 +1651,10 @@ static struct module *load_module(void __user *umod, | |||
1618 | /* Optional sections */ | 1651 | /* Optional sections */ |
1619 | exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); | 1652 | exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); |
1620 | gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); | 1653 | gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); |
1654 | gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future"); | ||
1621 | crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); | 1655 | crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); |
1622 | gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); | 1656 | gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); |
1657 | gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future"); | ||
1623 | setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); | 1658 | setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); |
1624 | exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); | 1659 | exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); |
1625 | obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); | 1660 | obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); |
@@ -1755,10 +1790,8 @@ static struct module *load_module(void __user *umod, | |||
1755 | if (strcmp(mod->name, "driverloader") == 0) | 1790 | if (strcmp(mod->name, "driverloader") == 0) |
1756 | add_taint(TAINT_PROPRIETARY_MODULE); | 1791 | add_taint(TAINT_PROPRIETARY_MODULE); |
1757 | 1792 | ||
1758 | #ifdef CONFIG_MODULE_UNLOAD | ||
1759 | /* Set up MODINFO_ATTR fields */ | 1793 | /* Set up MODINFO_ATTR fields */ |
1760 | setup_modinfo(mod, sechdrs, infoindex); | 1794 | setup_modinfo(mod, sechdrs, infoindex); |
1761 | #endif | ||
1762 | 1795 | ||
1763 | /* Fix up syms, so that st_value is a pointer to location. */ | 1796 | /* Fix up syms, so that st_value is a pointer to location. */ |
1764 | err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, | 1797 | err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, |
@@ -1775,10 +1808,16 @@ static struct module *load_module(void __user *umod, | |||
1775 | mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; | 1808 | mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; |
1776 | if (gplcrcindex) | 1809 | if (gplcrcindex) |
1777 | mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; | 1810 | mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; |
1811 | mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / | ||
1812 | sizeof(*mod->gpl_future_syms); | ||
1813 | mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; | ||
1814 | if (gplfuturecrcindex) | ||
1815 | mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; | ||
1778 | 1816 | ||
1779 | #ifdef CONFIG_MODVERSIONS | 1817 | #ifdef CONFIG_MODVERSIONS |
1780 | if ((mod->num_syms && !crcindex) || | 1818 | if ((mod->num_syms && !crcindex) || |
1781 | (mod->num_gpl_syms && !gplcrcindex)) { | 1819 | (mod->num_gpl_syms && !gplcrcindex) || |
1820 | (mod->num_gpl_future_syms && !gplfuturecrcindex)) { | ||
1782 | printk(KERN_WARNING "%s: No versions for exported symbols." | 1821 | printk(KERN_WARNING "%s: No versions for exported symbols." |
1783 | " Tainting kernel.\n", mod->name); | 1822 | " Tainting kernel.\n", mod->name); |
1784 | add_taint(TAINT_FORCED_MODULE); | 1823 | add_taint(TAINT_FORCED_MODULE); |