diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 1088 |
1 files changed, 581 insertions, 507 deletions
diff --git a/kernel/module.c b/kernel/module.c index 6c562828c85c..d0b5f8db11b4 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 2002 Richard Henderson | 2 | Copyright (C) 2002 Richard Henderson |
3 | Copyright (C) 2001 Rusty Russell, 2002 Rusty Russell IBM. | 3 | Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -110,6 +110,20 @@ int unregister_module_notifier(struct notifier_block * nb) | |||
110 | } | 110 | } |
111 | EXPORT_SYMBOL(unregister_module_notifier); | 111 | EXPORT_SYMBOL(unregister_module_notifier); |
112 | 112 | ||
113 | struct load_info { | ||
114 | Elf_Ehdr *hdr; | ||
115 | unsigned long len; | ||
116 | Elf_Shdr *sechdrs; | ||
117 | char *secstrings, *strtab; | ||
118 | unsigned long *strmap; | ||
119 | unsigned long symoffs, stroffs; | ||
120 | struct _ddebug *debug; | ||
121 | unsigned int num_debug; | ||
122 | struct { | ||
123 | unsigned int sym, str, mod, vers, info, pcpu; | ||
124 | } index; | ||
125 | }; | ||
126 | |||
113 | /* We require a truly strong try_module_get(): 0 means failure due to | 127 | /* We require a truly strong try_module_get(): 0 means failure due to |
114 | ongoing or failed initialization etc. */ | 128 | ongoing or failed initialization etc. */ |
115 | static inline int strong_try_module_get(struct module *mod) | 129 | static inline int strong_try_module_get(struct module *mod) |
@@ -140,42 +154,38 @@ void __module_put_and_exit(struct module *mod, long code) | |||
140 | EXPORT_SYMBOL(__module_put_and_exit); | 154 | EXPORT_SYMBOL(__module_put_and_exit); |
141 | 155 | ||
142 | /* Find a module section: 0 means not found. */ | 156 | /* Find a module section: 0 means not found. */ |
143 | static unsigned int find_sec(Elf_Ehdr *hdr, | 157 | static unsigned int find_sec(const struct load_info *info, const char *name) |
144 | Elf_Shdr *sechdrs, | ||
145 | const char *secstrings, | ||
146 | const char *name) | ||
147 | { | 158 | { |
148 | unsigned int i; | 159 | unsigned int i; |
149 | 160 | ||
150 | for (i = 1; i < hdr->e_shnum; i++) | 161 | for (i = 1; i < info->hdr->e_shnum; i++) { |
162 | Elf_Shdr *shdr = &info->sechdrs[i]; | ||
151 | /* Alloc bit cleared means "ignore it." */ | 163 | /* Alloc bit cleared means "ignore it." */ |
152 | if ((sechdrs[i].sh_flags & SHF_ALLOC) | 164 | if ((shdr->sh_flags & SHF_ALLOC) |
153 | && strcmp(secstrings+sechdrs[i].sh_name, name) == 0) | 165 | && strcmp(info->secstrings + shdr->sh_name, name) == 0) |
154 | return i; | 166 | return i; |
167 | } | ||
155 | return 0; | 168 | return 0; |
156 | } | 169 | } |
157 | 170 | ||
158 | /* Find a module section, or NULL. */ | 171 | /* Find a module section, or NULL. */ |
159 | static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs, | 172 | static void *section_addr(const struct load_info *info, const char *name) |
160 | const char *secstrings, const char *name) | ||
161 | { | 173 | { |
162 | /* Section 0 has sh_addr 0. */ | 174 | /* Section 0 has sh_addr 0. */ |
163 | return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr; | 175 | return (void *)info->sechdrs[find_sec(info, name)].sh_addr; |
164 | } | 176 | } |
165 | 177 | ||
166 | /* Find a module section, or NULL. Fill in number of "objects" in section. */ | 178 | /* Find a module section, or NULL. Fill in number of "objects" in section. */ |
167 | static void *section_objs(Elf_Ehdr *hdr, | 179 | static void *section_objs(const struct load_info *info, |
168 | Elf_Shdr *sechdrs, | ||
169 | const char *secstrings, | ||
170 | const char *name, | 180 | const char *name, |
171 | size_t object_size, | 181 | size_t object_size, |
172 | unsigned int *num) | 182 | unsigned int *num) |
173 | { | 183 | { |
174 | unsigned int sec = find_sec(hdr, sechdrs, secstrings, name); | 184 | unsigned int sec = find_sec(info, name); |
175 | 185 | ||
176 | /* Section 0 has sh_addr 0 and sh_size 0. */ | 186 | /* Section 0 has sh_addr 0 and sh_size 0. */ |
177 | *num = sechdrs[sec].sh_size / object_size; | 187 | *num = info->sechdrs[sec].sh_size / object_size; |
178 | return (void *)sechdrs[sec].sh_addr; | 188 | return (void *)info->sechdrs[sec].sh_addr; |
179 | } | 189 | } |
180 | 190 | ||
181 | /* Provided by the linker */ | 191 | /* Provided by the linker */ |
@@ -227,7 +237,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, | |||
227 | unsigned int symnum, void *data), void *data) | 237 | unsigned int symnum, void *data), void *data) |
228 | { | 238 | { |
229 | struct module *mod; | 239 | struct module *mod; |
230 | const struct symsearch arr[] = { | 240 | static const struct symsearch arr[] = { |
231 | { __start___ksymtab, __stop___ksymtab, __start___kcrctab, | 241 | { __start___ksymtab, __stop___ksymtab, __start___kcrctab, |
232 | NOT_GPL_ONLY, false }, | 242 | NOT_GPL_ONLY, false }, |
233 | { __start___ksymtab_gpl, __stop___ksymtab_gpl, | 243 | { __start___ksymtab_gpl, __stop___ksymtab_gpl, |
@@ -392,7 +402,8 @@ static int percpu_modalloc(struct module *mod, | |||
392 | mod->percpu = __alloc_reserved_percpu(size, align); | 402 | mod->percpu = __alloc_reserved_percpu(size, align); |
393 | if (!mod->percpu) { | 403 | if (!mod->percpu) { |
394 | printk(KERN_WARNING | 404 | printk(KERN_WARNING |
395 | "Could not allocate %lu bytes percpu data\n", size); | 405 | "%s: Could not allocate %lu bytes percpu data\n", |
406 | mod->name, size); | ||
396 | return -ENOMEM; | 407 | return -ENOMEM; |
397 | } | 408 | } |
398 | mod->percpu_size = size; | 409 | mod->percpu_size = size; |
@@ -404,11 +415,9 @@ static void percpu_modfree(struct module *mod) | |||
404 | free_percpu(mod->percpu); | 415 | free_percpu(mod->percpu); |
405 | } | 416 | } |
406 | 417 | ||
407 | static unsigned int find_pcpusec(Elf_Ehdr *hdr, | 418 | static unsigned int find_pcpusec(struct load_info *info) |
408 | Elf_Shdr *sechdrs, | ||
409 | const char *secstrings) | ||
410 | { | 419 | { |
411 | return find_sec(hdr, sechdrs, secstrings, ".data..percpu"); | 420 | return find_sec(info, ".data..percpu"); |
412 | } | 421 | } |
413 | 422 | ||
414 | static void percpu_modcopy(struct module *mod, | 423 | static void percpu_modcopy(struct module *mod, |
@@ -468,9 +477,7 @@ static inline int percpu_modalloc(struct module *mod, | |||
468 | static inline void percpu_modfree(struct module *mod) | 477 | static inline void percpu_modfree(struct module *mod) |
469 | { | 478 | { |
470 | } | 479 | } |
471 | static inline unsigned int find_pcpusec(Elf_Ehdr *hdr, | 480 | static unsigned int find_pcpusec(struct load_info *info) |
472 | Elf_Shdr *sechdrs, | ||
473 | const char *secstrings) | ||
474 | { | 481 | { |
475 | return 0; | 482 | return 0; |
476 | } | 483 | } |
@@ -524,21 +531,21 @@ static char last_unloaded_module[MODULE_NAME_LEN+1]; | |||
524 | EXPORT_TRACEPOINT_SYMBOL(module_get); | 531 | EXPORT_TRACEPOINT_SYMBOL(module_get); |
525 | 532 | ||
526 | /* Init the unload section of the module. */ | 533 | /* Init the unload section of the module. */ |
527 | static void module_unload_init(struct module *mod) | 534 | static int module_unload_init(struct module *mod) |
528 | { | 535 | { |
529 | int cpu; | 536 | mod->refptr = alloc_percpu(struct module_ref); |
537 | if (!mod->refptr) | ||
538 | return -ENOMEM; | ||
530 | 539 | ||
531 | INIT_LIST_HEAD(&mod->source_list); | 540 | INIT_LIST_HEAD(&mod->source_list); |
532 | INIT_LIST_HEAD(&mod->target_list); | 541 | INIT_LIST_HEAD(&mod->target_list); |
533 | for_each_possible_cpu(cpu) { | ||
534 | per_cpu_ptr(mod->refptr, cpu)->incs = 0; | ||
535 | per_cpu_ptr(mod->refptr, cpu)->decs = 0; | ||
536 | } | ||
537 | 542 | ||
538 | /* Hold reference count during initialization. */ | 543 | /* Hold reference count during initialization. */ |
539 | __this_cpu_write(mod->refptr->incs, 1); | 544 | __this_cpu_write(mod->refptr->incs, 1); |
540 | /* Backwards compatibility macros put refcount during init. */ | 545 | /* Backwards compatibility macros put refcount during init. */ |
541 | mod->waiter = current; | 546 | mod->waiter = current; |
547 | |||
548 | return 0; | ||
542 | } | 549 | } |
543 | 550 | ||
544 | /* Does a already use b? */ | 551 | /* Does a already use b? */ |
@@ -618,6 +625,8 @@ static void module_unload_free(struct module *mod) | |||
618 | kfree(use); | 625 | kfree(use); |
619 | } | 626 | } |
620 | mutex_unlock(&module_mutex); | 627 | mutex_unlock(&module_mutex); |
628 | |||
629 | free_percpu(mod->refptr); | ||
621 | } | 630 | } |
622 | 631 | ||
623 | #ifdef CONFIG_MODULE_FORCE_UNLOAD | 632 | #ifdef CONFIG_MODULE_FORCE_UNLOAD |
@@ -891,8 +900,9 @@ int ref_module(struct module *a, struct module *b) | |||
891 | } | 900 | } |
892 | EXPORT_SYMBOL_GPL(ref_module); | 901 | EXPORT_SYMBOL_GPL(ref_module); |
893 | 902 | ||
894 | static inline void module_unload_init(struct module *mod) | 903 | static inline int module_unload_init(struct module *mod) |
895 | { | 904 | { |
905 | return 0; | ||
896 | } | 906 | } |
897 | #endif /* CONFIG_MODULE_UNLOAD */ | 907 | #endif /* CONFIG_MODULE_UNLOAD */ |
898 | 908 | ||
@@ -1051,10 +1061,9 @@ static inline int same_magic(const char *amagic, const char *bmagic, | |||
1051 | #endif /* CONFIG_MODVERSIONS */ | 1061 | #endif /* CONFIG_MODVERSIONS */ |
1052 | 1062 | ||
1053 | /* Resolve a symbol for this module. I.e. if we find one, record usage. */ | 1063 | /* Resolve a symbol for this module. I.e. if we find one, record usage. */ |
1054 | static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, | 1064 | static const struct kernel_symbol *resolve_symbol(struct module *mod, |
1055 | unsigned int versindex, | 1065 | const struct load_info *info, |
1056 | const char *name, | 1066 | const char *name, |
1057 | struct module *mod, | ||
1058 | char ownername[]) | 1067 | char ownername[]) |
1059 | { | 1068 | { |
1060 | struct module *owner; | 1069 | struct module *owner; |
@@ -1068,7 +1077,8 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, | |||
1068 | if (!sym) | 1077 | if (!sym) |
1069 | goto unlock; | 1078 | goto unlock; |
1070 | 1079 | ||
1071 | if (!check_version(sechdrs, versindex, name, mod, crc, owner)) { | 1080 | if (!check_version(info->sechdrs, info->index.vers, name, mod, crc, |
1081 | owner)) { | ||
1072 | sym = ERR_PTR(-EINVAL); | 1082 | sym = ERR_PTR(-EINVAL); |
1073 | goto getname; | 1083 | goto getname; |
1074 | } | 1084 | } |
@@ -1087,21 +1097,20 @@ unlock: | |||
1087 | return sym; | 1097 | return sym; |
1088 | } | 1098 | } |
1089 | 1099 | ||
1090 | static const struct kernel_symbol *resolve_symbol_wait(Elf_Shdr *sechdrs, | 1100 | static const struct kernel_symbol * |
1091 | unsigned int versindex, | 1101 | resolve_symbol_wait(struct module *mod, |
1092 | const char *name, | 1102 | const struct load_info *info, |
1093 | struct module *mod) | 1103 | const char *name) |
1094 | { | 1104 | { |
1095 | const struct kernel_symbol *ksym; | 1105 | const struct kernel_symbol *ksym; |
1096 | char ownername[MODULE_NAME_LEN]; | 1106 | char owner[MODULE_NAME_LEN]; |
1097 | 1107 | ||
1098 | if (wait_event_interruptible_timeout(module_wq, | 1108 | if (wait_event_interruptible_timeout(module_wq, |
1099 | !IS_ERR(ksym = resolve_symbol(sechdrs, versindex, name, | 1109 | !IS_ERR(ksym = resolve_symbol(mod, info, name, owner)) |
1100 | mod, ownername)) || | 1110 | || PTR_ERR(ksym) != -EBUSY, |
1101 | PTR_ERR(ksym) != -EBUSY, | ||
1102 | 30 * HZ) <= 0) { | 1111 | 30 * HZ) <= 0) { |
1103 | printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", | 1112 | printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", |
1104 | mod->name, ownername); | 1113 | mod->name, owner); |
1105 | } | 1114 | } |
1106 | return ksym; | 1115 | return ksym; |
1107 | } | 1116 | } |
@@ -1110,8 +1119,9 @@ static const struct kernel_symbol *resolve_symbol_wait(Elf_Shdr *sechdrs, | |||
1110 | * /sys/module/foo/sections stuff | 1119 | * /sys/module/foo/sections stuff |
1111 | * J. Corbet <corbet@lwn.net> | 1120 | * J. Corbet <corbet@lwn.net> |
1112 | */ | 1121 | */ |
1113 | #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) | 1122 | #ifdef CONFIG_SYSFS |
1114 | 1123 | ||
1124 | #ifdef CONFIG_KALLSYMS | ||
1115 | static inline bool sect_empty(const Elf_Shdr *sect) | 1125 | static inline bool sect_empty(const Elf_Shdr *sect) |
1116 | { | 1126 | { |
1117 | return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; | 1127 | return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; |
@@ -1148,8 +1158,7 @@ static void free_sect_attrs(struct module_sect_attrs *sect_attrs) | |||
1148 | kfree(sect_attrs); | 1158 | kfree(sect_attrs); |
1149 | } | 1159 | } |
1150 | 1160 | ||
1151 | static void add_sect_attrs(struct module *mod, unsigned int nsect, | 1161 | static void add_sect_attrs(struct module *mod, const struct load_info *info) |
1152 | char *secstrings, Elf_Shdr *sechdrs) | ||
1153 | { | 1162 | { |
1154 | unsigned int nloaded = 0, i, size[2]; | 1163 | unsigned int nloaded = 0, i, size[2]; |
1155 | struct module_sect_attrs *sect_attrs; | 1164 | struct module_sect_attrs *sect_attrs; |
@@ -1157,8 +1166,8 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect, | |||
1157 | struct attribute **gattr; | 1166 | struct attribute **gattr; |
1158 | 1167 | ||
1159 | /* Count loaded sections and allocate structures */ | 1168 | /* Count loaded sections and allocate structures */ |
1160 | for (i = 0; i < nsect; i++) | 1169 | for (i = 0; i < info->hdr->e_shnum; i++) |
1161 | if (!sect_empty(&sechdrs[i])) | 1170 | if (!sect_empty(&info->sechdrs[i])) |
1162 | nloaded++; | 1171 | nloaded++; |
1163 | size[0] = ALIGN(sizeof(*sect_attrs) | 1172 | size[0] = ALIGN(sizeof(*sect_attrs) |
1164 | + nloaded * sizeof(sect_attrs->attrs[0]), | 1173 | + nloaded * sizeof(sect_attrs->attrs[0]), |
@@ -1175,11 +1184,12 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect, | |||
1175 | sect_attrs->nsections = 0; | 1184 | sect_attrs->nsections = 0; |
1176 | sattr = §_attrs->attrs[0]; | 1185 | sattr = §_attrs->attrs[0]; |
1177 | gattr = §_attrs->grp.attrs[0]; | 1186 | gattr = §_attrs->grp.attrs[0]; |
1178 | for (i = 0; i < nsect; i++) { | 1187 | for (i = 0; i < info->hdr->e_shnum; i++) { |
1179 | if (sect_empty(&sechdrs[i])) | 1188 | Elf_Shdr *sec = &info->sechdrs[i]; |
1189 | if (sect_empty(sec)) | ||
1180 | continue; | 1190 | continue; |
1181 | sattr->address = sechdrs[i].sh_addr; | 1191 | sattr->address = sec->sh_addr; |
1182 | sattr->name = kstrdup(secstrings + sechdrs[i].sh_name, | 1192 | sattr->name = kstrdup(info->secstrings + sec->sh_name, |
1183 | GFP_KERNEL); | 1193 | GFP_KERNEL); |
1184 | if (sattr->name == NULL) | 1194 | if (sattr->name == NULL) |
1185 | goto out; | 1195 | goto out; |
@@ -1247,8 +1257,7 @@ static void free_notes_attrs(struct module_notes_attrs *notes_attrs, | |||
1247 | kfree(notes_attrs); | 1257 | kfree(notes_attrs); |
1248 | } | 1258 | } |
1249 | 1259 | ||
1250 | static void add_notes_attrs(struct module *mod, unsigned int nsect, | 1260 | static void add_notes_attrs(struct module *mod, const struct load_info *info) |
1251 | char *secstrings, Elf_Shdr *sechdrs) | ||
1252 | { | 1261 | { |
1253 | unsigned int notes, loaded, i; | 1262 | unsigned int notes, loaded, i; |
1254 | struct module_notes_attrs *notes_attrs; | 1263 | struct module_notes_attrs *notes_attrs; |
@@ -1260,9 +1269,9 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, | |||
1260 | 1269 | ||
1261 | /* Count notes sections and allocate structures. */ | 1270 | /* Count notes sections and allocate structures. */ |
1262 | notes = 0; | 1271 | notes = 0; |
1263 | for (i = 0; i < nsect; i++) | 1272 | for (i = 0; i < info->hdr->e_shnum; i++) |
1264 | if (!sect_empty(&sechdrs[i]) && | 1273 | if (!sect_empty(&info->sechdrs[i]) && |
1265 | (sechdrs[i].sh_type == SHT_NOTE)) | 1274 | (info->sechdrs[i].sh_type == SHT_NOTE)) |
1266 | ++notes; | 1275 | ++notes; |
1267 | 1276 | ||
1268 | if (notes == 0) | 1277 | if (notes == 0) |
@@ -1276,15 +1285,15 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, | |||
1276 | 1285 | ||
1277 | notes_attrs->notes = notes; | 1286 | notes_attrs->notes = notes; |
1278 | nattr = ¬es_attrs->attrs[0]; | 1287 | nattr = ¬es_attrs->attrs[0]; |
1279 | for (loaded = i = 0; i < nsect; ++i) { | 1288 | for (loaded = i = 0; i < info->hdr->e_shnum; ++i) { |
1280 | if (sect_empty(&sechdrs[i])) | 1289 | if (sect_empty(&info->sechdrs[i])) |
1281 | continue; | 1290 | continue; |
1282 | if (sechdrs[i].sh_type == SHT_NOTE) { | 1291 | if (info->sechdrs[i].sh_type == SHT_NOTE) { |
1283 | sysfs_bin_attr_init(nattr); | 1292 | sysfs_bin_attr_init(nattr); |
1284 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; | 1293 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; |
1285 | nattr->attr.mode = S_IRUGO; | 1294 | nattr->attr.mode = S_IRUGO; |
1286 | nattr->size = sechdrs[i].sh_size; | 1295 | nattr->size = info->sechdrs[i].sh_size; |
1287 | nattr->private = (void *) sechdrs[i].sh_addr; | 1296 | nattr->private = (void *) info->sechdrs[i].sh_addr; |
1288 | nattr->read = module_notes_read; | 1297 | nattr->read = module_notes_read; |
1289 | ++nattr; | 1298 | ++nattr; |
1290 | } | 1299 | } |
@@ -1315,8 +1324,8 @@ static void remove_notes_attrs(struct module *mod) | |||
1315 | 1324 | ||
1316 | #else | 1325 | #else |
1317 | 1326 | ||
1318 | static inline void add_sect_attrs(struct module *mod, unsigned int nsect, | 1327 | static inline void add_sect_attrs(struct module *mod, |
1319 | char *sectstrings, Elf_Shdr *sechdrs) | 1328 | const struct load_info *info) |
1320 | { | 1329 | { |
1321 | } | 1330 | } |
1322 | 1331 | ||
@@ -1324,17 +1333,16 @@ static inline void remove_sect_attrs(struct module *mod) | |||
1324 | { | 1333 | { |
1325 | } | 1334 | } |
1326 | 1335 | ||
1327 | static inline void add_notes_attrs(struct module *mod, unsigned int nsect, | 1336 | static inline void add_notes_attrs(struct module *mod, |
1328 | char *sectstrings, Elf_Shdr *sechdrs) | 1337 | const struct load_info *info) |
1329 | { | 1338 | { |
1330 | } | 1339 | } |
1331 | 1340 | ||
1332 | static inline void remove_notes_attrs(struct module *mod) | 1341 | static inline void remove_notes_attrs(struct module *mod) |
1333 | { | 1342 | { |
1334 | } | 1343 | } |
1335 | #endif | 1344 | #endif /* CONFIG_KALLSYMS */ |
1336 | 1345 | ||
1337 | #ifdef CONFIG_SYSFS | ||
1338 | static void add_usage_links(struct module *mod) | 1346 | static void add_usage_links(struct module *mod) |
1339 | { | 1347 | { |
1340 | #ifdef CONFIG_MODULE_UNLOAD | 1348 | #ifdef CONFIG_MODULE_UNLOAD |
@@ -1439,6 +1447,7 @@ out: | |||
1439 | } | 1447 | } |
1440 | 1448 | ||
1441 | static int mod_sysfs_setup(struct module *mod, | 1449 | static int mod_sysfs_setup(struct module *mod, |
1450 | const struct load_info *info, | ||
1442 | struct kernel_param *kparam, | 1451 | struct kernel_param *kparam, |
1443 | unsigned int num_params) | 1452 | unsigned int num_params) |
1444 | { | 1453 | { |
@@ -1463,6 +1472,8 @@ static int mod_sysfs_setup(struct module *mod, | |||
1463 | goto out_unreg_param; | 1472 | goto out_unreg_param; |
1464 | 1473 | ||
1465 | add_usage_links(mod); | 1474 | add_usage_links(mod); |
1475 | add_sect_attrs(mod, info); | ||
1476 | add_notes_attrs(mod, info); | ||
1466 | 1477 | ||
1467 | kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); | 1478 | kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); |
1468 | return 0; | 1479 | return 0; |
@@ -1479,33 +1490,26 @@ out: | |||
1479 | 1490 | ||
1480 | static void mod_sysfs_fini(struct module *mod) | 1491 | static void mod_sysfs_fini(struct module *mod) |
1481 | { | 1492 | { |
1493 | remove_notes_attrs(mod); | ||
1494 | remove_sect_attrs(mod); | ||
1482 | kobject_put(&mod->mkobj.kobj); | 1495 | kobject_put(&mod->mkobj.kobj); |
1483 | } | 1496 | } |
1484 | 1497 | ||
1485 | #else /* CONFIG_SYSFS */ | 1498 | #else /* !CONFIG_SYSFS */ |
1486 | |||
1487 | static inline int mod_sysfs_init(struct module *mod) | ||
1488 | { | ||
1489 | return 0; | ||
1490 | } | ||
1491 | 1499 | ||
1492 | static inline int mod_sysfs_setup(struct module *mod, | 1500 | static int mod_sysfs_setup(struct module *mod, |
1501 | const struct load_info *info, | ||
1493 | struct kernel_param *kparam, | 1502 | struct kernel_param *kparam, |
1494 | unsigned int num_params) | 1503 | unsigned int num_params) |
1495 | { | 1504 | { |
1496 | return 0; | 1505 | return 0; |
1497 | } | 1506 | } |
1498 | 1507 | ||
1499 | static inline int module_add_modinfo_attrs(struct module *mod) | 1508 | static void mod_sysfs_fini(struct module *mod) |
1500 | { | ||
1501 | return 0; | ||
1502 | } | ||
1503 | |||
1504 | static inline void module_remove_modinfo_attrs(struct module *mod) | ||
1505 | { | 1509 | { |
1506 | } | 1510 | } |
1507 | 1511 | ||
1508 | static void mod_sysfs_fini(struct module *mod) | 1512 | static void module_remove_modinfo_attrs(struct module *mod) |
1509 | { | 1513 | { |
1510 | } | 1514 | } |
1511 | 1515 | ||
@@ -1515,7 +1519,7 @@ static void del_usage_links(struct module *mod) | |||
1515 | 1519 | ||
1516 | #endif /* CONFIG_SYSFS */ | 1520 | #endif /* CONFIG_SYSFS */ |
1517 | 1521 | ||
1518 | static void mod_kobject_remove(struct module *mod) | 1522 | static void mod_sysfs_teardown(struct module *mod) |
1519 | { | 1523 | { |
1520 | del_usage_links(mod); | 1524 | del_usage_links(mod); |
1521 | module_remove_modinfo_attrs(mod); | 1525 | module_remove_modinfo_attrs(mod); |
@@ -1545,9 +1549,7 @@ static void free_module(struct module *mod) | |||
1545 | mutex_lock(&module_mutex); | 1549 | mutex_lock(&module_mutex); |
1546 | stop_machine(__unlink_module, mod, NULL); | 1550 | stop_machine(__unlink_module, mod, NULL); |
1547 | mutex_unlock(&module_mutex); | 1551 | mutex_unlock(&module_mutex); |
1548 | remove_notes_attrs(mod); | 1552 | mod_sysfs_teardown(mod); |
1549 | remove_sect_attrs(mod); | ||
1550 | mod_kobject_remove(mod); | ||
1551 | 1553 | ||
1552 | /* Remove dynamic debug info */ | 1554 | /* Remove dynamic debug info */ |
1553 | ddebug_remove_module(mod->name); | 1555 | ddebug_remove_module(mod->name); |
@@ -1565,10 +1567,7 @@ static void free_module(struct module *mod) | |||
1565 | module_free(mod, mod->module_init); | 1567 | module_free(mod, mod->module_init); |
1566 | kfree(mod->args); | 1568 | kfree(mod->args); |
1567 | percpu_modfree(mod); | 1569 | percpu_modfree(mod); |
1568 | #if defined(CONFIG_MODULE_UNLOAD) | 1570 | |
1569 | if (mod->refptr) | ||
1570 | free_percpu(mod->refptr); | ||
1571 | #endif | ||
1572 | /* Free lock-classes: */ | 1571 | /* Free lock-classes: */ |
1573 | lockdep_free_key_range(mod->module_core, mod->core_size); | 1572 | lockdep_free_key_range(mod->module_core, mod->core_size); |
1574 | 1573 | ||
@@ -1634,25 +1633,23 @@ static int verify_export_symbols(struct module *mod) | |||
1634 | } | 1633 | } |
1635 | 1634 | ||
1636 | /* Change all symbols so that st_value encodes the pointer directly. */ | 1635 | /* Change all symbols so that st_value encodes the pointer directly. */ |
1637 | static int simplify_symbols(Elf_Shdr *sechdrs, | 1636 | static int simplify_symbols(struct module *mod, const struct load_info *info) |
1638 | unsigned int symindex, | 1637 | { |
1639 | const char *strtab, | 1638 | Elf_Shdr *symsec = &info->sechdrs[info->index.sym]; |
1640 | unsigned int versindex, | 1639 | Elf_Sym *sym = (void *)symsec->sh_addr; |
1641 | unsigned int pcpuindex, | ||
1642 | struct module *mod) | ||
1643 | { | ||
1644 | Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr; | ||
1645 | unsigned long secbase; | 1640 | unsigned long secbase; |
1646 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | 1641 | unsigned int i; |
1647 | int ret = 0; | 1642 | int ret = 0; |
1648 | const struct kernel_symbol *ksym; | 1643 | const struct kernel_symbol *ksym; |
1649 | 1644 | ||
1650 | for (i = 1; i < n; i++) { | 1645 | for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) { |
1646 | const char *name = info->strtab + sym[i].st_name; | ||
1647 | |||
1651 | switch (sym[i].st_shndx) { | 1648 | switch (sym[i].st_shndx) { |
1652 | case SHN_COMMON: | 1649 | case SHN_COMMON: |
1653 | /* We compiled with -fno-common. These are not | 1650 | /* We compiled with -fno-common. These are not |
1654 | supposed to happen. */ | 1651 | supposed to happen. */ |
1655 | DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name); | 1652 | DEBUGP("Common symbol: %s\n", name); |
1656 | printk("%s: please compile with -fno-common\n", | 1653 | printk("%s: please compile with -fno-common\n", |
1657 | mod->name); | 1654 | mod->name); |
1658 | ret = -ENOEXEC; | 1655 | ret = -ENOEXEC; |
@@ -1665,9 +1662,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
1665 | break; | 1662 | break; |
1666 | 1663 | ||
1667 | case SHN_UNDEF: | 1664 | case SHN_UNDEF: |
1668 | ksym = resolve_symbol_wait(sechdrs, versindex, | 1665 | ksym = resolve_symbol_wait(mod, info, name); |
1669 | strtab + sym[i].st_name, | ||
1670 | mod); | ||
1671 | /* Ok if resolved. */ | 1666 | /* Ok if resolved. */ |
1672 | if (ksym && !IS_ERR(ksym)) { | 1667 | if (ksym && !IS_ERR(ksym)) { |
1673 | sym[i].st_value = ksym->value; | 1668 | sym[i].st_value = ksym->value; |
@@ -1679,17 +1674,16 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
1679 | break; | 1674 | break; |
1680 | 1675 | ||
1681 | printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", | 1676 | printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", |
1682 | mod->name, strtab + sym[i].st_name, | 1677 | mod->name, name, PTR_ERR(ksym)); |
1683 | PTR_ERR(ksym)); | ||
1684 | ret = PTR_ERR(ksym) ?: -ENOENT; | 1678 | ret = PTR_ERR(ksym) ?: -ENOENT; |
1685 | break; | 1679 | break; |
1686 | 1680 | ||
1687 | default: | 1681 | default: |
1688 | /* Divert to percpu allocation if a percpu var. */ | 1682 | /* Divert to percpu allocation if a percpu var. */ |
1689 | if (sym[i].st_shndx == pcpuindex) | 1683 | if (sym[i].st_shndx == info->index.pcpu) |
1690 | secbase = (unsigned long)mod_percpu(mod); | 1684 | secbase = (unsigned long)mod_percpu(mod); |
1691 | else | 1685 | else |
1692 | secbase = sechdrs[sym[i].st_shndx].sh_addr; | 1686 | secbase = info->sechdrs[sym[i].st_shndx].sh_addr; |
1693 | sym[i].st_value += secbase; | 1687 | sym[i].st_value += secbase; |
1694 | break; | 1688 | break; |
1695 | } | 1689 | } |
@@ -1698,6 +1692,35 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
1698 | return ret; | 1692 | return ret; |
1699 | } | 1693 | } |
1700 | 1694 | ||
1695 | static int apply_relocations(struct module *mod, const struct load_info *info) | ||
1696 | { | ||
1697 | unsigned int i; | ||
1698 | int err = 0; | ||
1699 | |||
1700 | /* Now do relocations. */ | ||
1701 | for (i = 1; i < info->hdr->e_shnum; i++) { | ||
1702 | unsigned int infosec = info->sechdrs[i].sh_info; | ||
1703 | |||
1704 | /* Not a valid relocation section? */ | ||
1705 | if (infosec >= info->hdr->e_shnum) | ||
1706 | continue; | ||
1707 | |||
1708 | /* Don't bother with non-allocated sections */ | ||
1709 | if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC)) | ||
1710 | continue; | ||
1711 | |||
1712 | if (info->sechdrs[i].sh_type == SHT_REL) | ||
1713 | err = apply_relocate(info->sechdrs, info->strtab, | ||
1714 | info->index.sym, i, mod); | ||
1715 | else if (info->sechdrs[i].sh_type == SHT_RELA) | ||
1716 | err = apply_relocate_add(info->sechdrs, info->strtab, | ||
1717 | info->index.sym, i, mod); | ||
1718 | if (err < 0) | ||
1719 | break; | ||
1720 | } | ||
1721 | return err; | ||
1722 | } | ||
1723 | |||
1701 | /* Additional bytes needed by arch in front of individual sections */ | 1724 | /* Additional bytes needed by arch in front of individual sections */ |
1702 | unsigned int __weak arch_mod_section_prepend(struct module *mod, | 1725 | unsigned int __weak arch_mod_section_prepend(struct module *mod, |
1703 | unsigned int section) | 1726 | unsigned int section) |
@@ -1722,10 +1745,7 @@ static long get_offset(struct module *mod, unsigned int *size, | |||
1722 | might -- code, read-only data, read-write data, small data. Tally | 1745 | might -- code, read-only data, read-write data, small data. Tally |
1723 | sizes, and place the offsets into sh_entsize fields: high bit means it | 1746 | sizes, and place the offsets into sh_entsize fields: high bit means it |
1724 | belongs in init. */ | 1747 | belongs in init. */ |
1725 | static void layout_sections(struct module *mod, | 1748 | static void layout_sections(struct module *mod, struct load_info *info) |
1726 | const Elf_Ehdr *hdr, | ||
1727 | Elf_Shdr *sechdrs, | ||
1728 | const char *secstrings) | ||
1729 | { | 1749 | { |
1730 | static unsigned long const masks[][2] = { | 1750 | static unsigned long const masks[][2] = { |
1731 | /* NOTE: all executable code must be the first section | 1751 | /* NOTE: all executable code must be the first section |
@@ -1738,21 +1758,22 @@ static void layout_sections(struct module *mod, | |||
1738 | }; | 1758 | }; |
1739 | unsigned int m, i; | 1759 | unsigned int m, i; |
1740 | 1760 | ||
1741 | for (i = 0; i < hdr->e_shnum; i++) | 1761 | for (i = 0; i < info->hdr->e_shnum; i++) |
1742 | sechdrs[i].sh_entsize = ~0UL; | 1762 | info->sechdrs[i].sh_entsize = ~0UL; |
1743 | 1763 | ||
1744 | DEBUGP("Core section allocation order:\n"); | 1764 | DEBUGP("Core section allocation order:\n"); |
1745 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { | 1765 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { |
1746 | for (i = 0; i < hdr->e_shnum; ++i) { | 1766 | for (i = 0; i < info->hdr->e_shnum; ++i) { |
1747 | Elf_Shdr *s = &sechdrs[i]; | 1767 | Elf_Shdr *s = &info->sechdrs[i]; |
1768 | const char *sname = info->secstrings + s->sh_name; | ||
1748 | 1769 | ||
1749 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1770 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
1750 | || (s->sh_flags & masks[m][1]) | 1771 | || (s->sh_flags & masks[m][1]) |
1751 | || s->sh_entsize != ~0UL | 1772 | || s->sh_entsize != ~0UL |
1752 | || strstarts(secstrings + s->sh_name, ".init")) | 1773 | || strstarts(sname, ".init")) |
1753 | continue; | 1774 | continue; |
1754 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); | 1775 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); |
1755 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1776 | DEBUGP("\t%s\n", name); |
1756 | } | 1777 | } |
1757 | if (m == 0) | 1778 | if (m == 0) |
1758 | mod->core_text_size = mod->core_size; | 1779 | mod->core_text_size = mod->core_size; |
@@ -1760,17 +1781,18 @@ static void layout_sections(struct module *mod, | |||
1760 | 1781 | ||
1761 | DEBUGP("Init section allocation order:\n"); | 1782 | DEBUGP("Init section allocation order:\n"); |
1762 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { | 1783 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { |
1763 | for (i = 0; i < hdr->e_shnum; ++i) { | 1784 | for (i = 0; i < info->hdr->e_shnum; ++i) { |
1764 | Elf_Shdr *s = &sechdrs[i]; | 1785 | Elf_Shdr *s = &info->sechdrs[i]; |
1786 | const char *sname = info->secstrings + s->sh_name; | ||
1765 | 1787 | ||
1766 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1788 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
1767 | || (s->sh_flags & masks[m][1]) | 1789 | || (s->sh_flags & masks[m][1]) |
1768 | || s->sh_entsize != ~0UL | 1790 | || s->sh_entsize != ~0UL |
1769 | || !strstarts(secstrings + s->sh_name, ".init")) | 1791 | || !strstarts(sname, ".init")) |
1770 | continue; | 1792 | continue; |
1771 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) | 1793 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) |
1772 | | INIT_OFFSET_MASK); | 1794 | | INIT_OFFSET_MASK); |
1773 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1795 | DEBUGP("\t%s\n", sname); |
1774 | } | 1796 | } |
1775 | if (m == 0) | 1797 | if (m == 0) |
1776 | mod->init_text_size = mod->init_size; | 1798 | mod->init_text_size = mod->init_size; |
@@ -1809,33 +1831,28 @@ static char *next_string(char *string, unsigned long *secsize) | |||
1809 | return string; | 1831 | return string; |
1810 | } | 1832 | } |
1811 | 1833 | ||
1812 | static char *get_modinfo(Elf_Shdr *sechdrs, | 1834 | static char *get_modinfo(struct load_info *info, const char *tag) |
1813 | unsigned int info, | ||
1814 | const char *tag) | ||
1815 | { | 1835 | { |
1816 | char *p; | 1836 | char *p; |
1817 | unsigned int taglen = strlen(tag); | 1837 | unsigned int taglen = strlen(tag); |
1818 | unsigned long size = sechdrs[info].sh_size; | 1838 | Elf_Shdr *infosec = &info->sechdrs[info->index.info]; |
1839 | unsigned long size = infosec->sh_size; | ||
1819 | 1840 | ||
1820 | for (p = (char *)sechdrs[info].sh_addr; p; p = next_string(p, &size)) { | 1841 | for (p = (char *)infosec->sh_addr; p; p = next_string(p, &size)) { |
1821 | if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') | 1842 | if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') |
1822 | return p + taglen + 1; | 1843 | return p + taglen + 1; |
1823 | } | 1844 | } |
1824 | return NULL; | 1845 | return NULL; |
1825 | } | 1846 | } |
1826 | 1847 | ||
1827 | static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, | 1848 | static void setup_modinfo(struct module *mod, struct load_info *info) |
1828 | unsigned int infoindex) | ||
1829 | { | 1849 | { |
1830 | struct module_attribute *attr; | 1850 | struct module_attribute *attr; |
1831 | int i; | 1851 | int i; |
1832 | 1852 | ||
1833 | for (i = 0; (attr = modinfo_attrs[i]); i++) { | 1853 | for (i = 0; (attr = modinfo_attrs[i]); i++) { |
1834 | if (attr->setup) | 1854 | if (attr->setup) |
1835 | attr->setup(mod, | 1855 | attr->setup(mod, get_modinfo(info, attr->attr.name)); |
1836 | get_modinfo(sechdrs, | ||
1837 | infoindex, | ||
1838 | attr->attr.name)); | ||
1839 | } | 1856 | } |
1840 | } | 1857 | } |
1841 | 1858 | ||
@@ -1876,11 +1893,10 @@ static int is_exported(const char *name, unsigned long value, | |||
1876 | } | 1893 | } |
1877 | 1894 | ||
1878 | /* As per nm */ | 1895 | /* As per nm */ |
1879 | static char elf_type(const Elf_Sym *sym, | 1896 | static char elf_type(const Elf_Sym *sym, const struct load_info *info) |
1880 | Elf_Shdr *sechdrs, | ||
1881 | const char *secstrings, | ||
1882 | struct module *mod) | ||
1883 | { | 1897 | { |
1898 | const Elf_Shdr *sechdrs = info->sechdrs; | ||
1899 | |||
1884 | if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { | 1900 | if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { |
1885 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT) | 1901 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT) |
1886 | return 'v'; | 1902 | return 'v'; |
@@ -1910,8 +1926,10 @@ static char elf_type(const Elf_Sym *sym, | |||
1910 | else | 1926 | else |
1911 | return 'b'; | 1927 | return 'b'; |
1912 | } | 1928 | } |
1913 | if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug")) | 1929 | if (strstarts(info->secstrings + sechdrs[sym->st_shndx].sh_name, |
1930 | ".debug")) { | ||
1914 | return 'n'; | 1931 | return 'n'; |
1932 | } | ||
1915 | return '?'; | 1933 | return '?'; |
1916 | } | 1934 | } |
1917 | 1935 | ||
@@ -1936,127 +1954,96 @@ static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs, | |||
1936 | return true; | 1954 | return true; |
1937 | } | 1955 | } |
1938 | 1956 | ||
1939 | static unsigned long layout_symtab(struct module *mod, | 1957 | static void layout_symtab(struct module *mod, struct load_info *info) |
1940 | Elf_Shdr *sechdrs, | ||
1941 | unsigned int symindex, | ||
1942 | unsigned int strindex, | ||
1943 | const Elf_Ehdr *hdr, | ||
1944 | const char *secstrings, | ||
1945 | unsigned long *pstroffs, | ||
1946 | unsigned long *strmap) | ||
1947 | { | 1958 | { |
1948 | unsigned long symoffs; | 1959 | Elf_Shdr *symsect = info->sechdrs + info->index.sym; |
1949 | Elf_Shdr *symsect = sechdrs + symindex; | 1960 | Elf_Shdr *strsect = info->sechdrs + info->index.str; |
1950 | Elf_Shdr *strsect = sechdrs + strindex; | ||
1951 | const Elf_Sym *src; | 1961 | const Elf_Sym *src; |
1952 | const char *strtab; | ||
1953 | unsigned int i, nsrc, ndst; | 1962 | unsigned int i, nsrc, ndst; |
1954 | 1963 | ||
1955 | /* Put symbol section at end of init part of module. */ | 1964 | /* Put symbol section at end of init part of module. */ |
1956 | symsect->sh_flags |= SHF_ALLOC; | 1965 | symsect->sh_flags |= SHF_ALLOC; |
1957 | symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect, | 1966 | symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect, |
1958 | symindex) | INIT_OFFSET_MASK; | 1967 | info->index.sym) | INIT_OFFSET_MASK; |
1959 | DEBUGP("\t%s\n", secstrings + symsect->sh_name); | 1968 | DEBUGP("\t%s\n", info->secstrings + symsect->sh_name); |
1960 | 1969 | ||
1961 | src = (void *)hdr + symsect->sh_offset; | 1970 | src = (void *)info->hdr + symsect->sh_offset; |
1962 | nsrc = symsect->sh_size / sizeof(*src); | 1971 | nsrc = symsect->sh_size / sizeof(*src); |
1963 | strtab = (void *)hdr + strsect->sh_offset; | ||
1964 | for (ndst = i = 1; i < nsrc; ++i, ++src) | 1972 | for (ndst = i = 1; i < nsrc; ++i, ++src) |
1965 | if (is_core_symbol(src, sechdrs, hdr->e_shnum)) { | 1973 | if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) { |
1966 | unsigned int j = src->st_name; | 1974 | unsigned int j = src->st_name; |
1967 | 1975 | ||
1968 | while(!__test_and_set_bit(j, strmap) && strtab[j]) | 1976 | while (!__test_and_set_bit(j, info->strmap) |
1977 | && info->strtab[j]) | ||
1969 | ++j; | 1978 | ++j; |
1970 | ++ndst; | 1979 | ++ndst; |
1971 | } | 1980 | } |
1972 | 1981 | ||
1973 | /* Append room for core symbols at end of core part. */ | 1982 | /* Append room for core symbols at end of core part. */ |
1974 | symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1); | 1983 | info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1); |
1975 | mod->core_size = symoffs + ndst * sizeof(Elf_Sym); | 1984 | mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym); |
1976 | 1985 | ||
1977 | /* Put string table section at end of init part of module. */ | 1986 | /* Put string table section at end of init part of module. */ |
1978 | strsect->sh_flags |= SHF_ALLOC; | 1987 | strsect->sh_flags |= SHF_ALLOC; |
1979 | strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect, | 1988 | strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect, |
1980 | strindex) | INIT_OFFSET_MASK; | 1989 | info->index.str) | INIT_OFFSET_MASK; |
1981 | DEBUGP("\t%s\n", secstrings + strsect->sh_name); | 1990 | DEBUGP("\t%s\n", info->secstrings + strsect->sh_name); |
1982 | 1991 | ||
1983 | /* Append room for core symbols' strings at end of core part. */ | 1992 | /* Append room for core symbols' strings at end of core part. */ |
1984 | *pstroffs = mod->core_size; | 1993 | info->stroffs = mod->core_size; |
1985 | __set_bit(0, strmap); | 1994 | __set_bit(0, info->strmap); |
1986 | mod->core_size += bitmap_weight(strmap, strsect->sh_size); | 1995 | mod->core_size += bitmap_weight(info->strmap, strsect->sh_size); |
1987 | |||
1988 | return symoffs; | ||
1989 | } | 1996 | } |
1990 | 1997 | ||
1991 | static void add_kallsyms(struct module *mod, | 1998 | static void add_kallsyms(struct module *mod, const struct load_info *info) |
1992 | Elf_Shdr *sechdrs, | ||
1993 | unsigned int shnum, | ||
1994 | unsigned int symindex, | ||
1995 | unsigned int strindex, | ||
1996 | unsigned long symoffs, | ||
1997 | unsigned long stroffs, | ||
1998 | const char *secstrings, | ||
1999 | unsigned long *strmap) | ||
2000 | { | 1999 | { |
2001 | unsigned int i, ndst; | 2000 | unsigned int i, ndst; |
2002 | const Elf_Sym *src; | 2001 | const Elf_Sym *src; |
2003 | Elf_Sym *dst; | 2002 | Elf_Sym *dst; |
2004 | char *s; | 2003 | char *s; |
2004 | Elf_Shdr *symsec = &info->sechdrs[info->index.sym]; | ||
2005 | 2005 | ||
2006 | mod->symtab = (void *)sechdrs[symindex].sh_addr; | 2006 | mod->symtab = (void *)symsec->sh_addr; |
2007 | mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | 2007 | mod->num_symtab = symsec->sh_size / sizeof(Elf_Sym); |
2008 | mod->strtab = (void *)sechdrs[strindex].sh_addr; | 2008 | /* Make sure we get permanent strtab: don't use info->strtab. */ |
2009 | mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr; | ||
2009 | 2010 | ||
2010 | /* Set types up while we still have access to sections. */ | 2011 | /* Set types up while we still have access to sections. */ |
2011 | for (i = 0; i < mod->num_symtab; i++) | 2012 | for (i = 0; i < mod->num_symtab; i++) |
2012 | mod->symtab[i].st_info | 2013 | mod->symtab[i].st_info = elf_type(&mod->symtab[i], info); |
2013 | = elf_type(&mod->symtab[i], sechdrs, secstrings, mod); | ||
2014 | 2014 | ||
2015 | mod->core_symtab = dst = mod->module_core + symoffs; | 2015 | mod->core_symtab = dst = mod->module_core + info->symoffs; |
2016 | src = mod->symtab; | 2016 | src = mod->symtab; |
2017 | *dst = *src; | 2017 | *dst = *src; |
2018 | for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) { | 2018 | for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) { |
2019 | if (!is_core_symbol(src, sechdrs, shnum)) | 2019 | if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) |
2020 | continue; | 2020 | continue; |
2021 | dst[ndst] = *src; | 2021 | dst[ndst] = *src; |
2022 | dst[ndst].st_name = bitmap_weight(strmap, dst[ndst].st_name); | 2022 | dst[ndst].st_name = bitmap_weight(info->strmap, |
2023 | dst[ndst].st_name); | ||
2023 | ++ndst; | 2024 | ++ndst; |
2024 | } | 2025 | } |
2025 | mod->core_num_syms = ndst; | 2026 | mod->core_num_syms = ndst; |
2026 | 2027 | ||
2027 | mod->core_strtab = s = mod->module_core + stroffs; | 2028 | mod->core_strtab = s = mod->module_core + info->stroffs; |
2028 | for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i) | 2029 | for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i) |
2029 | if (test_bit(i, strmap)) | 2030 | if (test_bit(i, info->strmap)) |
2030 | *++s = mod->strtab[i]; | 2031 | *++s = mod->strtab[i]; |
2031 | } | 2032 | } |
2032 | #else | 2033 | #else |
2033 | static inline unsigned long layout_symtab(struct module *mod, | 2034 | static inline void layout_symtab(struct module *mod, struct load_info *info) |
2034 | Elf_Shdr *sechdrs, | ||
2035 | unsigned int symindex, | ||
2036 | unsigned int strindex, | ||
2037 | const Elf_Ehdr *hdr, | ||
2038 | const char *secstrings, | ||
2039 | unsigned long *pstroffs, | ||
2040 | unsigned long *strmap) | ||
2041 | { | 2035 | { |
2042 | return 0; | ||
2043 | } | 2036 | } |
2044 | 2037 | ||
2045 | static inline void add_kallsyms(struct module *mod, | 2038 | static void add_kallsyms(struct module *mod, struct load_info *info) |
2046 | Elf_Shdr *sechdrs, | ||
2047 | unsigned int shnum, | ||
2048 | unsigned int symindex, | ||
2049 | unsigned int strindex, | ||
2050 | unsigned long symoffs, | ||
2051 | unsigned long stroffs, | ||
2052 | const char *secstrings, | ||
2053 | const unsigned long *strmap) | ||
2054 | { | 2039 | { |
2055 | } | 2040 | } |
2056 | #endif /* CONFIG_KALLSYMS */ | 2041 | #endif /* CONFIG_KALLSYMS */ |
2057 | 2042 | ||
2058 | static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) | 2043 | static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) |
2059 | { | 2044 | { |
2045 | if (!debug) | ||
2046 | return; | ||
2060 | #ifdef CONFIG_DYNAMIC_DEBUG | 2047 | #ifdef CONFIG_DYNAMIC_DEBUG |
2061 | if (ddebug_add_module(debug, num, debug->modname)) | 2048 | if (ddebug_add_module(debug, num, debug->modname)) |
2062 | printk(KERN_ERR "dynamic debug error adding module: %s\n", | 2049 | printk(KERN_ERR "dynamic debug error adding module: %s\n", |
@@ -2087,65 +2074,47 @@ static void *module_alloc_update_bounds(unsigned long size) | |||
2087 | } | 2074 | } |
2088 | 2075 | ||
2089 | #ifdef CONFIG_DEBUG_KMEMLEAK | 2076 | #ifdef CONFIG_DEBUG_KMEMLEAK |
2090 | static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr, | 2077 | static void kmemleak_load_module(const struct module *mod, |
2091 | Elf_Shdr *sechdrs, char *secstrings) | 2078 | const struct load_info *info) |
2092 | { | 2079 | { |
2093 | unsigned int i; | 2080 | unsigned int i; |
2094 | 2081 | ||
2095 | /* only scan the sections containing data */ | 2082 | /* only scan the sections containing data */ |
2096 | kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); | 2083 | kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); |
2097 | 2084 | ||
2098 | for (i = 1; i < hdr->e_shnum; i++) { | 2085 | for (i = 1; i < info->hdr->e_shnum; i++) { |
2099 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) | 2086 | const char *name = info->secstrings + info->sechdrs[i].sh_name; |
2087 | if (!(info->sechdrs[i].sh_flags & SHF_ALLOC)) | ||
2100 | continue; | 2088 | continue; |
2101 | if (strncmp(secstrings + sechdrs[i].sh_name, ".data", 5) != 0 | 2089 | if (!strstarts(name, ".data") && !strstarts(name, ".bss")) |
2102 | && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0) | ||
2103 | continue; | 2090 | continue; |
2104 | 2091 | ||
2105 | kmemleak_scan_area((void *)sechdrs[i].sh_addr, | 2092 | kmemleak_scan_area((void *)info->sechdrs[i].sh_addr, |
2106 | sechdrs[i].sh_size, GFP_KERNEL); | 2093 | info->sechdrs[i].sh_size, GFP_KERNEL); |
2107 | } | 2094 | } |
2108 | } | 2095 | } |
2109 | #else | 2096 | #else |
2110 | static inline void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr, | 2097 | static inline void kmemleak_load_module(const struct module *mod, |
2111 | Elf_Shdr *sechdrs, char *secstrings) | 2098 | const struct load_info *info) |
2112 | { | 2099 | { |
2113 | } | 2100 | } |
2114 | #endif | 2101 | #endif |
2115 | 2102 | ||
2116 | /* Allocate and load the module: note that size of section 0 is always | 2103 | /* Sets info->hdr and info->len. */ |
2117 | zero, and we rely on this for optional sections. */ | 2104 | static int copy_and_check(struct load_info *info, |
2118 | static noinline struct module *load_module(void __user *umod, | 2105 | const void __user *umod, unsigned long len, |
2119 | unsigned long len, | 2106 | const char __user *uargs) |
2120 | const char __user *uargs) | ||
2121 | { | 2107 | { |
2108 | int err; | ||
2122 | Elf_Ehdr *hdr; | 2109 | Elf_Ehdr *hdr; |
2123 | Elf_Shdr *sechdrs; | ||
2124 | char *secstrings, *args, *modmagic, *strtab = NULL; | ||
2125 | char *staging; | ||
2126 | unsigned int i; | ||
2127 | unsigned int symindex = 0; | ||
2128 | unsigned int strindex = 0; | ||
2129 | unsigned int modindex, versindex, infoindex, pcpuindex; | ||
2130 | struct module *mod; | ||
2131 | long err = 0; | ||
2132 | void *ptr = NULL; /* Stops spurious gcc warning */ | ||
2133 | unsigned long symoffs, stroffs, *strmap; | ||
2134 | void __percpu *percpu; | ||
2135 | struct _ddebug *debug = NULL; | ||
2136 | unsigned int num_debug = 0; | ||
2137 | 2110 | ||
2138 | mm_segment_t old_fs; | ||
2139 | |||
2140 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", | ||
2141 | umod, len, uargs); | ||
2142 | if (len < sizeof(*hdr)) | 2111 | if (len < sizeof(*hdr)) |
2143 | return ERR_PTR(-ENOEXEC); | 2112 | return -ENOEXEC; |
2144 | 2113 | ||
2145 | /* Suck in entire file: we'll want most of it. */ | 2114 | /* Suck in entire file: we'll want most of it. */ |
2146 | /* vmalloc barfs on "unusual" numbers. Check here */ | 2115 | /* vmalloc barfs on "unusual" numbers. Check here */ |
2147 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) | 2116 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) |
2148 | return ERR_PTR(-ENOMEM); | 2117 | return -ENOMEM; |
2149 | 2118 | ||
2150 | if (copy_from_user(hdr, umod, len) != 0) { | 2119 | if (copy_from_user(hdr, umod, len) != 0) { |
2151 | err = -EFAULT; | 2120 | err = -EFAULT; |
@@ -2153,135 +2122,225 @@ static noinline struct module *load_module(void __user *umod, | |||
2153 | } | 2122 | } |
2154 | 2123 | ||
2155 | /* Sanity checks against insmoding binaries or wrong arch, | 2124 | /* Sanity checks against insmoding binaries or wrong arch, |
2156 | weird elf version */ | 2125 | weird elf version */ |
2157 | if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0 | 2126 | if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0 |
2158 | || hdr->e_type != ET_REL | 2127 | || hdr->e_type != ET_REL |
2159 | || !elf_check_arch(hdr) | 2128 | || !elf_check_arch(hdr) |
2160 | || hdr->e_shentsize != sizeof(*sechdrs)) { | 2129 | || hdr->e_shentsize != sizeof(Elf_Shdr)) { |
2161 | err = -ENOEXEC; | 2130 | err = -ENOEXEC; |
2162 | goto free_hdr; | 2131 | goto free_hdr; |
2163 | } | 2132 | } |
2164 | 2133 | ||
2165 | if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) | 2134 | if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) { |
2166 | goto truncated; | 2135 | err = -ENOEXEC; |
2136 | goto free_hdr; | ||
2137 | } | ||
2167 | 2138 | ||
2168 | /* Convenience variables */ | 2139 | info->hdr = hdr; |
2169 | sechdrs = (void *)hdr + hdr->e_shoff; | 2140 | info->len = len; |
2170 | secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; | 2141 | return 0; |
2171 | sechdrs[0].sh_addr = 0; | ||
2172 | 2142 | ||
2173 | for (i = 1; i < hdr->e_shnum; i++) { | 2143 | free_hdr: |
2174 | if (sechdrs[i].sh_type != SHT_NOBITS | 2144 | vfree(hdr); |
2175 | && len < sechdrs[i].sh_offset + sechdrs[i].sh_size) | 2145 | return err; |
2176 | goto truncated; | 2146 | } |
2147 | |||
2148 | static void free_copy(struct load_info *info) | ||
2149 | { | ||
2150 | vfree(info->hdr); | ||
2151 | } | ||
2152 | |||
2153 | static int rewrite_section_headers(struct load_info *info) | ||
2154 | { | ||
2155 | unsigned int i; | ||
2156 | |||
2157 | /* This should always be true, but let's be sure. */ | ||
2158 | info->sechdrs[0].sh_addr = 0; | ||
2159 | |||
2160 | for (i = 1; i < info->hdr->e_shnum; i++) { | ||
2161 | Elf_Shdr *shdr = &info->sechdrs[i]; | ||
2162 | if (shdr->sh_type != SHT_NOBITS | ||
2163 | && info->len < shdr->sh_offset + shdr->sh_size) { | ||
2164 | printk(KERN_ERR "Module len %lu truncated\n", | ||
2165 | info->len); | ||
2166 | return -ENOEXEC; | ||
2167 | } | ||
2177 | 2168 | ||
2178 | /* Mark all sections sh_addr with their address in the | 2169 | /* Mark all sections sh_addr with their address in the |
2179 | temporary image. */ | 2170 | temporary image. */ |
2180 | sechdrs[i].sh_addr = (size_t)hdr + sechdrs[i].sh_offset; | 2171 | shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset; |
2181 | 2172 | ||
2182 | /* Internal symbols and strings. */ | ||
2183 | if (sechdrs[i].sh_type == SHT_SYMTAB) { | ||
2184 | symindex = i; | ||
2185 | strindex = sechdrs[i].sh_link; | ||
2186 | strtab = (char *)hdr + sechdrs[strindex].sh_offset; | ||
2187 | } | ||
2188 | #ifndef CONFIG_MODULE_UNLOAD | 2173 | #ifndef CONFIG_MODULE_UNLOAD |
2189 | /* Don't load .exit sections */ | 2174 | /* Don't load .exit sections */ |
2190 | if (strstarts(secstrings+sechdrs[i].sh_name, ".exit")) | 2175 | if (strstarts(info->secstrings+shdr->sh_name, ".exit")) |
2191 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; | 2176 | shdr->sh_flags &= ~(unsigned long)SHF_ALLOC; |
2192 | #endif | 2177 | #endif |
2193 | } | 2178 | } |
2194 | 2179 | ||
2195 | modindex = find_sec(hdr, sechdrs, secstrings, | 2180 | /* Track but don't keep modinfo and version sections. */ |
2196 | ".gnu.linkonce.this_module"); | 2181 | info->index.vers = find_sec(info, "__versions"); |
2197 | if (!modindex) { | 2182 | info->index.info = find_sec(info, ".modinfo"); |
2183 | info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
2184 | info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
2185 | return 0; | ||
2186 | } | ||
2187 | |||
2188 | /* | ||
2189 | * Set up our basic convenience variables (pointers to section headers, | ||
2190 | * search for module section index etc), and do some basic section | ||
2191 | * verification. | ||
2192 | * | ||
2193 | * Return the temporary module pointer (we'll replace it with the final | ||
2194 | * one when we move the module sections around). | ||
2195 | */ | ||
2196 | static struct module *setup_load_info(struct load_info *info) | ||
2197 | { | ||
2198 | unsigned int i; | ||
2199 | int err; | ||
2200 | struct module *mod; | ||
2201 | |||
2202 | /* Set up the convenience variables */ | ||
2203 | info->sechdrs = (void *)info->hdr + info->hdr->e_shoff; | ||
2204 | info->secstrings = (void *)info->hdr | ||
2205 | + info->sechdrs[info->hdr->e_shstrndx].sh_offset; | ||
2206 | |||
2207 | err = rewrite_section_headers(info); | ||
2208 | if (err) | ||
2209 | return ERR_PTR(err); | ||
2210 | |||
2211 | /* Find internal symbols and strings. */ | ||
2212 | for (i = 1; i < info->hdr->e_shnum; i++) { | ||
2213 | if (info->sechdrs[i].sh_type == SHT_SYMTAB) { | ||
2214 | info->index.sym = i; | ||
2215 | info->index.str = info->sechdrs[i].sh_link; | ||
2216 | info->strtab = (char *)info->hdr | ||
2217 | + info->sechdrs[info->index.str].sh_offset; | ||
2218 | break; | ||
2219 | } | ||
2220 | } | ||
2221 | |||
2222 | info->index.mod = find_sec(info, ".gnu.linkonce.this_module"); | ||
2223 | if (!info->index.mod) { | ||
2198 | printk(KERN_WARNING "No module found in object\n"); | 2224 | printk(KERN_WARNING "No module found in object\n"); |
2199 | err = -ENOEXEC; | 2225 | return ERR_PTR(-ENOEXEC); |
2200 | goto free_hdr; | ||
2201 | } | 2226 | } |
2202 | /* This is temporary: point mod into copy of data. */ | 2227 | /* This is temporary: point mod into copy of data. */ |
2203 | mod = (void *)sechdrs[modindex].sh_addr; | 2228 | mod = (void *)info->sechdrs[info->index.mod].sh_addr; |
2204 | 2229 | ||
2205 | if (symindex == 0) { | 2230 | if (info->index.sym == 0) { |
2206 | printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", | 2231 | printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", |
2207 | mod->name); | 2232 | mod->name); |
2208 | err = -ENOEXEC; | 2233 | return ERR_PTR(-ENOEXEC); |
2209 | goto free_hdr; | ||
2210 | } | 2234 | } |
2211 | 2235 | ||
2212 | versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); | 2236 | info->index.pcpu = find_pcpusec(info); |
2213 | infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); | ||
2214 | pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); | ||
2215 | |||
2216 | /* Don't keep modinfo and version sections. */ | ||
2217 | sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
2218 | sechdrs[versindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
2219 | 2237 | ||
2220 | /* Check module struct version now, before we try to use module. */ | 2238 | /* Check module struct version now, before we try to use module. */ |
2221 | if (!check_modstruct_version(sechdrs, versindex, mod)) { | 2239 | if (!check_modstruct_version(info->sechdrs, info->index.vers, mod)) |
2222 | err = -ENOEXEC; | 2240 | return ERR_PTR(-ENOEXEC); |
2223 | goto free_hdr; | 2241 | |
2224 | } | 2242 | return mod; |
2243 | } | ||
2244 | |||
2245 | static int check_modinfo(struct module *mod, struct load_info *info) | ||
2246 | { | ||
2247 | const char *modmagic = get_modinfo(info, "vermagic"); | ||
2248 | int err; | ||
2225 | 2249 | ||
2226 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); | ||
2227 | /* This is allowed: modprobe --force will invalidate it. */ | 2250 | /* This is allowed: modprobe --force will invalidate it. */ |
2228 | if (!modmagic) { | 2251 | if (!modmagic) { |
2229 | err = try_to_force_load(mod, "bad vermagic"); | 2252 | err = try_to_force_load(mod, "bad vermagic"); |
2230 | if (err) | 2253 | if (err) |
2231 | goto free_hdr; | 2254 | return err; |
2232 | } else if (!same_magic(modmagic, vermagic, versindex)) { | 2255 | } else if (!same_magic(modmagic, vermagic, info->index.vers)) { |
2233 | printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", | 2256 | printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", |
2234 | mod->name, modmagic, vermagic); | 2257 | mod->name, modmagic, vermagic); |
2235 | err = -ENOEXEC; | 2258 | return -ENOEXEC; |
2236 | goto free_hdr; | ||
2237 | } | 2259 | } |
2238 | 2260 | ||
2239 | staging = get_modinfo(sechdrs, infoindex, "staging"); | 2261 | if (get_modinfo(info, "staging")) { |
2240 | if (staging) { | ||
2241 | add_taint_module(mod, TAINT_CRAP); | 2262 | add_taint_module(mod, TAINT_CRAP); |
2242 | printk(KERN_WARNING "%s: module is from the staging directory," | 2263 | printk(KERN_WARNING "%s: module is from the staging directory," |
2243 | " the quality is unknown, you have been warned.\n", | 2264 | " the quality is unknown, you have been warned.\n", |
2244 | mod->name); | 2265 | mod->name); |
2245 | } | 2266 | } |
2246 | 2267 | ||
2247 | /* Now copy in args */ | 2268 | /* Set up license info based on the info section */ |
2248 | args = strndup_user(uargs, ~0UL >> 1); | 2269 | set_license(mod, get_modinfo(info, "license")); |
2249 | if (IS_ERR(args)) { | ||
2250 | err = PTR_ERR(args); | ||
2251 | goto free_hdr; | ||
2252 | } | ||
2253 | 2270 | ||
2254 | strmap = kzalloc(BITS_TO_LONGS(sechdrs[strindex].sh_size) | 2271 | return 0; |
2255 | * sizeof(long), GFP_KERNEL); | 2272 | } |
2256 | if (!strmap) { | ||
2257 | err = -ENOMEM; | ||
2258 | goto free_mod; | ||
2259 | } | ||
2260 | 2273 | ||
2261 | mod->state = MODULE_STATE_COMING; | 2274 | static void find_module_sections(struct module *mod, struct load_info *info) |
2275 | { | ||
2276 | mod->kp = section_objs(info, "__param", | ||
2277 | sizeof(*mod->kp), &mod->num_kp); | ||
2278 | mod->syms = section_objs(info, "__ksymtab", | ||
2279 | sizeof(*mod->syms), &mod->num_syms); | ||
2280 | mod->crcs = section_addr(info, "__kcrctab"); | ||
2281 | mod->gpl_syms = section_objs(info, "__ksymtab_gpl", | ||
2282 | sizeof(*mod->gpl_syms), | ||
2283 | &mod->num_gpl_syms); | ||
2284 | mod->gpl_crcs = section_addr(info, "__kcrctab_gpl"); | ||
2285 | mod->gpl_future_syms = section_objs(info, | ||
2286 | "__ksymtab_gpl_future", | ||
2287 | sizeof(*mod->gpl_future_syms), | ||
2288 | &mod->num_gpl_future_syms); | ||
2289 | mod->gpl_future_crcs = section_addr(info, "__kcrctab_gpl_future"); | ||
2262 | 2290 | ||
2263 | /* Allow arches to frob section contents and sizes. */ | 2291 | #ifdef CONFIG_UNUSED_SYMBOLS |
2264 | err = module_frob_arch_sections(hdr, sechdrs, secstrings, mod); | 2292 | mod->unused_syms = section_objs(info, "__ksymtab_unused", |
2265 | if (err < 0) | 2293 | sizeof(*mod->unused_syms), |
2266 | goto free_mod; | 2294 | &mod->num_unused_syms); |
2295 | mod->unused_crcs = section_addr(info, "__kcrctab_unused"); | ||
2296 | mod->unused_gpl_syms = section_objs(info, "__ksymtab_unused_gpl", | ||
2297 | sizeof(*mod->unused_gpl_syms), | ||
2298 | &mod->num_unused_gpl_syms); | ||
2299 | mod->unused_gpl_crcs = section_addr(info, "__kcrctab_unused_gpl"); | ||
2300 | #endif | ||
2301 | #ifdef CONFIG_CONSTRUCTORS | ||
2302 | mod->ctors = section_objs(info, ".ctors", | ||
2303 | sizeof(*mod->ctors), &mod->num_ctors); | ||
2304 | #endif | ||
2267 | 2305 | ||
2268 | if (pcpuindex) { | 2306 | #ifdef CONFIG_TRACEPOINTS |
2269 | /* We have a special allocation for this section. */ | 2307 | mod->tracepoints = section_objs(info, "__tracepoints", |
2270 | err = percpu_modalloc(mod, sechdrs[pcpuindex].sh_size, | 2308 | sizeof(*mod->tracepoints), |
2271 | sechdrs[pcpuindex].sh_addralign); | 2309 | &mod->num_tracepoints); |
2272 | if (err) | 2310 | #endif |
2273 | goto free_mod; | 2311 | #ifdef CONFIG_EVENT_TRACING |
2274 | sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | 2312 | mod->trace_events = section_objs(info, "_ftrace_events", |
2275 | } | 2313 | sizeof(*mod->trace_events), |
2276 | /* Keep this around for failure path. */ | 2314 | &mod->num_trace_events); |
2277 | percpu = mod_percpu(mod); | 2315 | /* |
2316 | * This section contains pointers to allocated objects in the trace | ||
2317 | * code and not scanning it leads to false positives. | ||
2318 | */ | ||
2319 | kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) * | ||
2320 | mod->num_trace_events, GFP_KERNEL); | ||
2321 | #endif | ||
2322 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD | ||
2323 | /* sechdrs[0].sh_size is always zero */ | ||
2324 | mod->ftrace_callsites = section_objs(info, "__mcount_loc", | ||
2325 | sizeof(*mod->ftrace_callsites), | ||
2326 | &mod->num_ftrace_callsites); | ||
2327 | #endif | ||
2278 | 2328 | ||
2279 | /* Determine total sizes, and put offsets in sh_entsize. For now | 2329 | mod->extable = section_objs(info, "__ex_table", |
2280 | this is done generically; there doesn't appear to be any | 2330 | sizeof(*mod->extable), &mod->num_exentries); |
2281 | special cases for the architectures. */ | 2331 | |
2282 | layout_sections(mod, hdr, sechdrs, secstrings); | 2332 | if (section_addr(info, "__obsparm")) |
2283 | symoffs = layout_symtab(mod, sechdrs, symindex, strindex, hdr, | 2333 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", |
2284 | secstrings, &stroffs, strmap); | 2334 | mod->name); |
2335 | |||
2336 | info->debug = section_objs(info, "__verbose", | ||
2337 | sizeof(*info->debug), &info->num_debug); | ||
2338 | } | ||
2339 | |||
2340 | static int move_module(struct module *mod, struct load_info *info) | ||
2341 | { | ||
2342 | int i; | ||
2343 | void *ptr; | ||
2285 | 2344 | ||
2286 | /* Do the allocs. */ | 2345 | /* Do the allocs. */ |
2287 | ptr = module_alloc_update_bounds(mod->core_size); | 2346 | ptr = module_alloc_update_bounds(mod->core_size); |
@@ -2291,10 +2350,9 @@ static noinline struct module *load_module(void __user *umod, | |||
2291 | * leak. | 2350 | * leak. |
2292 | */ | 2351 | */ |
2293 | kmemleak_not_leak(ptr); | 2352 | kmemleak_not_leak(ptr); |
2294 | if (!ptr) { | 2353 | if (!ptr) |
2295 | err = -ENOMEM; | 2354 | return -ENOMEM; |
2296 | goto free_percpu; | 2355 | |
2297 | } | ||
2298 | memset(ptr, 0, mod->core_size); | 2356 | memset(ptr, 0, mod->core_size); |
2299 | mod->module_core = ptr; | 2357 | mod->module_core = ptr; |
2300 | 2358 | ||
@@ -2307,50 +2365,40 @@ static noinline struct module *load_module(void __user *umod, | |||
2307 | */ | 2365 | */ |
2308 | kmemleak_ignore(ptr); | 2366 | kmemleak_ignore(ptr); |
2309 | if (!ptr && mod->init_size) { | 2367 | if (!ptr && mod->init_size) { |
2310 | err = -ENOMEM; | 2368 | module_free(mod, mod->module_core); |
2311 | goto free_core; | 2369 | return -ENOMEM; |
2312 | } | 2370 | } |
2313 | memset(ptr, 0, mod->init_size); | 2371 | memset(ptr, 0, mod->init_size); |
2314 | mod->module_init = ptr; | 2372 | mod->module_init = ptr; |
2315 | 2373 | ||
2316 | /* Transfer each section which specifies SHF_ALLOC */ | 2374 | /* Transfer each section which specifies SHF_ALLOC */ |
2317 | DEBUGP("final section addresses:\n"); | 2375 | DEBUGP("final section addresses:\n"); |
2318 | for (i = 0; i < hdr->e_shnum; i++) { | 2376 | for (i = 0; i < info->hdr->e_shnum; i++) { |
2319 | void *dest; | 2377 | void *dest; |
2378 | Elf_Shdr *shdr = &info->sechdrs[i]; | ||
2320 | 2379 | ||
2321 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) | 2380 | if (!(shdr->sh_flags & SHF_ALLOC)) |
2322 | continue; | 2381 | continue; |
2323 | 2382 | ||
2324 | if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) | 2383 | if (shdr->sh_entsize & INIT_OFFSET_MASK) |
2325 | dest = mod->module_init | 2384 | dest = mod->module_init |
2326 | + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK); | 2385 | + (shdr->sh_entsize & ~INIT_OFFSET_MASK); |
2327 | else | 2386 | else |
2328 | dest = mod->module_core + sechdrs[i].sh_entsize; | 2387 | dest = mod->module_core + shdr->sh_entsize; |
2329 | 2388 | ||
2330 | if (sechdrs[i].sh_type != SHT_NOBITS) | 2389 | if (shdr->sh_type != SHT_NOBITS) |
2331 | memcpy(dest, (void *)sechdrs[i].sh_addr, | 2390 | memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size); |
2332 | sechdrs[i].sh_size); | ||
2333 | /* Update sh_addr to point to copy in image. */ | 2391 | /* Update sh_addr to point to copy in image. */ |
2334 | sechdrs[i].sh_addr = (unsigned long)dest; | 2392 | shdr->sh_addr = (unsigned long)dest; |
2335 | DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name); | 2393 | DEBUGP("\t0x%lx %s\n", |
2336 | } | 2394 | shdr->sh_addr, info->secstrings + shdr->sh_name); |
2337 | /* Module has been moved. */ | ||
2338 | mod = (void *)sechdrs[modindex].sh_addr; | ||
2339 | kmemleak_load_module(mod, hdr, sechdrs, secstrings); | ||
2340 | |||
2341 | #if defined(CONFIG_MODULE_UNLOAD) | ||
2342 | mod->refptr = alloc_percpu(struct module_ref); | ||
2343 | if (!mod->refptr) { | ||
2344 | err = -ENOMEM; | ||
2345 | goto free_init; | ||
2346 | } | 2395 | } |
2347 | #endif | ||
2348 | /* Now we've moved module, initialize linked lists, etc. */ | ||
2349 | module_unload_init(mod); | ||
2350 | 2396 | ||
2351 | /* Set up license info based on the info section */ | 2397 | return 0; |
2352 | set_license(mod, get_modinfo(sechdrs, infoindex, "license")); | 2398 | } |
2353 | 2399 | ||
2400 | static int check_module_license_and_versions(struct module *mod) | ||
2401 | { | ||
2354 | /* | 2402 | /* |
2355 | * ndiswrapper is under GPL by itself, but loads proprietary modules. | 2403 | * ndiswrapper is under GPL by itself, but loads proprietary modules. |
2356 | * Don't use add_taint_module(), as it would prevent ndiswrapper from | 2404 | * Don't use add_taint_module(), as it would prevent ndiswrapper from |
@@ -2363,77 +2411,6 @@ static noinline struct module *load_module(void __user *umod, | |||
2363 | if (strcmp(mod->name, "driverloader") == 0) | 2411 | if (strcmp(mod->name, "driverloader") == 0) |
2364 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 2412 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); |
2365 | 2413 | ||
2366 | /* Set up MODINFO_ATTR fields */ | ||
2367 | setup_modinfo(mod, sechdrs, infoindex); | ||
2368 | |||
2369 | /* Fix up syms, so that st_value is a pointer to location. */ | ||
2370 | err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, | ||
2371 | mod); | ||
2372 | if (err < 0) | ||
2373 | goto cleanup; | ||
2374 | |||
2375 | /* Now we've got everything in the final locations, we can | ||
2376 | * find optional sections. */ | ||
2377 | mod->kp = section_objs(hdr, sechdrs, secstrings, "__param", | ||
2378 | sizeof(*mod->kp), &mod->num_kp); | ||
2379 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", | ||
2380 | sizeof(*mod->syms), &mod->num_syms); | ||
2381 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); | ||
2382 | mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl", | ||
2383 | sizeof(*mod->gpl_syms), | ||
2384 | &mod->num_gpl_syms); | ||
2385 | mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl"); | ||
2386 | mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings, | ||
2387 | "__ksymtab_gpl_future", | ||
2388 | sizeof(*mod->gpl_future_syms), | ||
2389 | &mod->num_gpl_future_syms); | ||
2390 | mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings, | ||
2391 | "__kcrctab_gpl_future"); | ||
2392 | |||
2393 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
2394 | mod->unused_syms = section_objs(hdr, sechdrs, secstrings, | ||
2395 | "__ksymtab_unused", | ||
2396 | sizeof(*mod->unused_syms), | ||
2397 | &mod->num_unused_syms); | ||
2398 | mod->unused_crcs = section_addr(hdr, sechdrs, secstrings, | ||
2399 | "__kcrctab_unused"); | ||
2400 | mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings, | ||
2401 | "__ksymtab_unused_gpl", | ||
2402 | sizeof(*mod->unused_gpl_syms), | ||
2403 | &mod->num_unused_gpl_syms); | ||
2404 | mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings, | ||
2405 | "__kcrctab_unused_gpl"); | ||
2406 | #endif | ||
2407 | #ifdef CONFIG_CONSTRUCTORS | ||
2408 | mod->ctors = section_objs(hdr, sechdrs, secstrings, ".ctors", | ||
2409 | sizeof(*mod->ctors), &mod->num_ctors); | ||
2410 | #endif | ||
2411 | |||
2412 | #ifdef CONFIG_TRACEPOINTS | ||
2413 | mod->tracepoints = section_objs(hdr, sechdrs, secstrings, | ||
2414 | "__tracepoints", | ||
2415 | sizeof(*mod->tracepoints), | ||
2416 | &mod->num_tracepoints); | ||
2417 | #endif | ||
2418 | #ifdef CONFIG_EVENT_TRACING | ||
2419 | mod->trace_events = section_objs(hdr, sechdrs, secstrings, | ||
2420 | "_ftrace_events", | ||
2421 | sizeof(*mod->trace_events), | ||
2422 | &mod->num_trace_events); | ||
2423 | /* | ||
2424 | * This section contains pointers to allocated objects in the trace | ||
2425 | * code and not scanning it leads to false positives. | ||
2426 | */ | ||
2427 | kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) * | ||
2428 | mod->num_trace_events, GFP_KERNEL); | ||
2429 | #endif | ||
2430 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD | ||
2431 | /* sechdrs[0].sh_size is always zero */ | ||
2432 | mod->ftrace_callsites = section_objs(hdr, sechdrs, secstrings, | ||
2433 | "__mcount_loc", | ||
2434 | sizeof(*mod->ftrace_callsites), | ||
2435 | &mod->num_ftrace_callsites); | ||
2436 | #endif | ||
2437 | #ifdef CONFIG_MODVERSIONS | 2414 | #ifdef CONFIG_MODVERSIONS |
2438 | if ((mod->num_syms && !mod->crcs) | 2415 | if ((mod->num_syms && !mod->crcs) |
2439 | || (mod->num_gpl_syms && !mod->gpl_crcs) | 2416 | || (mod->num_gpl_syms && !mod->gpl_crcs) |
@@ -2443,56 +2420,16 @@ static noinline struct module *load_module(void __user *umod, | |||
2443 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) | 2420 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) |
2444 | #endif | 2421 | #endif |
2445 | ) { | 2422 | ) { |
2446 | err = try_to_force_load(mod, | 2423 | return try_to_force_load(mod, |
2447 | "no versions for exported symbols"); | 2424 | "no versions for exported symbols"); |
2448 | if (err) | ||
2449 | goto cleanup; | ||
2450 | } | 2425 | } |
2451 | #endif | 2426 | #endif |
2427 | return 0; | ||
2428 | } | ||
2452 | 2429 | ||
2453 | /* Now do relocations. */ | 2430 | static void flush_module_icache(const struct module *mod) |
2454 | for (i = 1; i < hdr->e_shnum; i++) { | 2431 | { |
2455 | const char *strtab = (char *)sechdrs[strindex].sh_addr; | 2432 | mm_segment_t old_fs; |
2456 | unsigned int info = sechdrs[i].sh_info; | ||
2457 | |||
2458 | /* Not a valid relocation section? */ | ||
2459 | if (info >= hdr->e_shnum) | ||
2460 | continue; | ||
2461 | |||
2462 | /* Don't bother with non-allocated sections */ | ||
2463 | if (!(sechdrs[info].sh_flags & SHF_ALLOC)) | ||
2464 | continue; | ||
2465 | |||
2466 | if (sechdrs[i].sh_type == SHT_REL) | ||
2467 | err = apply_relocate(sechdrs, strtab, symindex, i,mod); | ||
2468 | else if (sechdrs[i].sh_type == SHT_RELA) | ||
2469 | err = apply_relocate_add(sechdrs, strtab, symindex, i, | ||
2470 | mod); | ||
2471 | if (err < 0) | ||
2472 | goto cleanup; | ||
2473 | } | ||
2474 | |||
2475 | /* Set up and sort exception table */ | ||
2476 | mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table", | ||
2477 | sizeof(*mod->extable), &mod->num_exentries); | ||
2478 | sort_extable(mod->extable, mod->extable + mod->num_exentries); | ||
2479 | |||
2480 | /* Finally, copy percpu area over. */ | ||
2481 | percpu_modcopy(mod, (void *)sechdrs[pcpuindex].sh_addr, | ||
2482 | sechdrs[pcpuindex].sh_size); | ||
2483 | |||
2484 | add_kallsyms(mod, sechdrs, hdr->e_shnum, symindex, strindex, | ||
2485 | symoffs, stroffs, secstrings, strmap); | ||
2486 | kfree(strmap); | ||
2487 | strmap = NULL; | ||
2488 | |||
2489 | if (!mod->taints) | ||
2490 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", | ||
2491 | sizeof(*debug), &num_debug); | ||
2492 | |||
2493 | err = module_finalize(hdr, sechdrs, mod); | ||
2494 | if (err < 0) | ||
2495 | goto cleanup; | ||
2496 | 2433 | ||
2497 | /* flush the icache in correct context */ | 2434 | /* flush the icache in correct context */ |
2498 | old_fs = get_fs(); | 2435 | old_fs = get_fs(); |
@@ -2511,11 +2448,160 @@ static noinline struct module *load_module(void __user *umod, | |||
2511 | (unsigned long)mod->module_core + mod->core_size); | 2448 | (unsigned long)mod->module_core + mod->core_size); |
2512 | 2449 | ||
2513 | set_fs(old_fs); | 2450 | set_fs(old_fs); |
2451 | } | ||
2514 | 2452 | ||
2515 | mod->args = args; | 2453 | static struct module *layout_and_allocate(struct load_info *info) |
2516 | if (section_addr(hdr, sechdrs, secstrings, "__obsparm")) | 2454 | { |
2517 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", | 2455 | /* Module within temporary copy. */ |
2518 | mod->name); | 2456 | struct module *mod; |
2457 | Elf_Shdr *pcpusec; | ||
2458 | int err; | ||
2459 | |||
2460 | mod = setup_load_info(info); | ||
2461 | if (IS_ERR(mod)) | ||
2462 | return mod; | ||
2463 | |||
2464 | err = check_modinfo(mod, info); | ||
2465 | if (err) | ||
2466 | return ERR_PTR(err); | ||
2467 | |||
2468 | /* Allow arches to frob section contents and sizes. */ | ||
2469 | err = module_frob_arch_sections(info->hdr, info->sechdrs, | ||
2470 | info->secstrings, mod); | ||
2471 | if (err < 0) | ||
2472 | goto out; | ||
2473 | |||
2474 | pcpusec = &info->sechdrs[info->index.pcpu]; | ||
2475 | if (pcpusec->sh_size) { | ||
2476 | /* We have a special allocation for this section. */ | ||
2477 | err = percpu_modalloc(mod, | ||
2478 | pcpusec->sh_size, pcpusec->sh_addralign); | ||
2479 | if (err) | ||
2480 | goto out; | ||
2481 | pcpusec->sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
2482 | } | ||
2483 | |||
2484 | /* Determine total sizes, and put offsets in sh_entsize. For now | ||
2485 | this is done generically; there doesn't appear to be any | ||
2486 | special cases for the architectures. */ | ||
2487 | layout_sections(mod, info); | ||
2488 | |||
2489 | info->strmap = kzalloc(BITS_TO_LONGS(info->sechdrs[info->index.str].sh_size) | ||
2490 | * sizeof(long), GFP_KERNEL); | ||
2491 | if (!info->strmap) { | ||
2492 | err = -ENOMEM; | ||
2493 | goto free_percpu; | ||
2494 | } | ||
2495 | layout_symtab(mod, info); | ||
2496 | |||
2497 | /* Allocate and move to the final place */ | ||
2498 | err = move_module(mod, info); | ||
2499 | if (err) | ||
2500 | goto free_strmap; | ||
2501 | |||
2502 | /* Module has been copied to its final place now: return it. */ | ||
2503 | mod = (void *)info->sechdrs[info->index.mod].sh_addr; | ||
2504 | kmemleak_load_module(mod, info); | ||
2505 | return mod; | ||
2506 | |||
2507 | free_strmap: | ||
2508 | kfree(info->strmap); | ||
2509 | free_percpu: | ||
2510 | percpu_modfree(mod); | ||
2511 | out: | ||
2512 | return ERR_PTR(err); | ||
2513 | } | ||
2514 | |||
2515 | /* mod is no longer valid after this! */ | ||
2516 | static void module_deallocate(struct module *mod, struct load_info *info) | ||
2517 | { | ||
2518 | kfree(info->strmap); | ||
2519 | percpu_modfree(mod); | ||
2520 | module_free(mod, mod->module_init); | ||
2521 | module_free(mod, mod->module_core); | ||
2522 | } | ||
2523 | |||
2524 | static int post_relocation(struct module *mod, const struct load_info *info) | ||
2525 | { | ||
2526 | /* Sort exception table now relocations are done. */ | ||
2527 | sort_extable(mod->extable, mod->extable + mod->num_exentries); | ||
2528 | |||
2529 | /* Copy relocated percpu area over. */ | ||
2530 | percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr, | ||
2531 | info->sechdrs[info->index.pcpu].sh_size); | ||
2532 | |||
2533 | /* Setup kallsyms-specific fields. */ | ||
2534 | add_kallsyms(mod, info); | ||
2535 | |||
2536 | /* Arch-specific module finalizing. */ | ||
2537 | return module_finalize(info->hdr, info->sechdrs, mod); | ||
2538 | } | ||
2539 | |||
2540 | /* Allocate and load the module: note that size of section 0 is always | ||
2541 | zero, and we rely on this for optional sections. */ | ||
2542 | static struct module *load_module(void __user *umod, | ||
2543 | unsigned long len, | ||
2544 | const char __user *uargs) | ||
2545 | { | ||
2546 | struct load_info info = { NULL, }; | ||
2547 | struct module *mod; | ||
2548 | long err; | ||
2549 | |||
2550 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", | ||
2551 | umod, len, uargs); | ||
2552 | |||
2553 | /* Copy in the blobs from userspace, check they are vaguely sane. */ | ||
2554 | err = copy_and_check(&info, umod, len, uargs); | ||
2555 | if (err) | ||
2556 | return ERR_PTR(err); | ||
2557 | |||
2558 | /* Figure out module layout, and allocate all the memory. */ | ||
2559 | mod = layout_and_allocate(&info); | ||
2560 | if (IS_ERR(mod)) { | ||
2561 | err = PTR_ERR(mod); | ||
2562 | goto free_copy; | ||
2563 | } | ||
2564 | |||
2565 | /* Now module is in final location, initialize linked lists, etc. */ | ||
2566 | err = module_unload_init(mod); | ||
2567 | if (err) | ||
2568 | goto free_module; | ||
2569 | |||
2570 | /* Now we've got everything in the final locations, we can | ||
2571 | * find optional sections. */ | ||
2572 | find_module_sections(mod, &info); | ||
2573 | |||
2574 | err = check_module_license_and_versions(mod); | ||
2575 | if (err) | ||
2576 | goto free_unload; | ||
2577 | |||
2578 | /* Set up MODINFO_ATTR fields */ | ||
2579 | setup_modinfo(mod, &info); | ||
2580 | |||
2581 | /* Fix up syms, so that st_value is a pointer to location. */ | ||
2582 | err = simplify_symbols(mod, &info); | ||
2583 | if (err < 0) | ||
2584 | goto free_modinfo; | ||
2585 | |||
2586 | err = apply_relocations(mod, &info); | ||
2587 | if (err < 0) | ||
2588 | goto free_modinfo; | ||
2589 | |||
2590 | err = post_relocation(mod, &info); | ||
2591 | if (err < 0) | ||
2592 | goto free_modinfo; | ||
2593 | |||
2594 | flush_module_icache(mod); | ||
2595 | |||
2596 | /* Now copy in args */ | ||
2597 | mod->args = strndup_user(uargs, ~0UL >> 1); | ||
2598 | if (IS_ERR(mod->args)) { | ||
2599 | err = PTR_ERR(mod->args); | ||
2600 | goto free_arch_cleanup; | ||
2601 | } | ||
2602 | |||
2603 | /* Mark state as coming so strong_try_module_get() ignores us. */ | ||
2604 | mod->state = MODULE_STATE_COMING; | ||
2519 | 2605 | ||
2520 | /* Now sew it into the lists so we can get lockdep and oops | 2606 | /* Now sew it into the lists so we can get lockdep and oops |
2521 | * info during argument parsing. Noone should access us, since | 2607 | * info during argument parsing. Noone should access us, since |
@@ -2530,8 +2616,9 @@ static noinline struct module *load_module(void __user *umod, | |||
2530 | goto unlock; | 2616 | goto unlock; |
2531 | } | 2617 | } |
2532 | 2618 | ||
2533 | if (debug) | 2619 | /* This has to be done once we're sure module name is unique. */ |
2534 | dynamic_debug_setup(debug, num_debug); | 2620 | if (!mod->taints) |
2621 | dynamic_debug_setup(info.debug, info.num_debug); | ||
2535 | 2622 | ||
2536 | /* Find duplicate symbols */ | 2623 | /* Find duplicate symbols */ |
2537 | err = verify_export_symbols(mod); | 2624 | err = verify_export_symbols(mod); |
@@ -2541,23 +2628,22 @@ static noinline struct module *load_module(void __user *umod, | |||
2541 | list_add_rcu(&mod->list, &modules); | 2628 | list_add_rcu(&mod->list, &modules); |
2542 | mutex_unlock(&module_mutex); | 2629 | mutex_unlock(&module_mutex); |
2543 | 2630 | ||
2631 | /* Module is ready to execute: parsing args may do that. */ | ||
2544 | err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); | 2632 | err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); |
2545 | if (err < 0) | 2633 | if (err < 0) |
2546 | goto unlink; | 2634 | goto unlink; |
2547 | 2635 | ||
2548 | err = mod_sysfs_setup(mod, mod->kp, mod->num_kp); | 2636 | /* Link in to syfs. */ |
2637 | err = mod_sysfs_setup(mod, &info, mod->kp, mod->num_kp); | ||
2549 | if (err < 0) | 2638 | if (err < 0) |
2550 | goto unlink; | 2639 | goto unlink; |
2551 | 2640 | ||
2552 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2641 | /* Get rid of temporary copy and strmap. */ |
2553 | add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2642 | kfree(info.strmap); |
2554 | 2643 | free_copy(&info); | |
2555 | /* Get rid of temporary copy */ | ||
2556 | vfree(hdr); | ||
2557 | |||
2558 | trace_module_load(mod); | ||
2559 | 2644 | ||
2560 | /* Done! */ | 2645 | /* Done! */ |
2646 | trace_module_load(mod); | ||
2561 | return mod; | 2647 | return mod; |
2562 | 2648 | ||
2563 | unlink: | 2649 | unlink: |
@@ -2565,35 +2651,23 @@ static noinline struct module *load_module(void __user *umod, | |||
2565 | /* Unlink carefully: kallsyms could be walking list. */ | 2651 | /* Unlink carefully: kallsyms could be walking list. */ |
2566 | list_del_rcu(&mod->list); | 2652 | list_del_rcu(&mod->list); |
2567 | ddebug: | 2653 | ddebug: |
2568 | dynamic_debug_remove(debug); | 2654 | if (!mod->taints) |
2655 | dynamic_debug_remove(info.debug); | ||
2569 | unlock: | 2656 | unlock: |
2570 | mutex_unlock(&module_mutex); | 2657 | mutex_unlock(&module_mutex); |
2571 | synchronize_sched(); | 2658 | synchronize_sched(); |
2659 | kfree(mod->args); | ||
2660 | free_arch_cleanup: | ||
2572 | module_arch_cleanup(mod); | 2661 | module_arch_cleanup(mod); |
2573 | cleanup: | 2662 | free_modinfo: |
2574 | free_modinfo(mod); | 2663 | free_modinfo(mod); |
2664 | free_unload: | ||
2575 | module_unload_free(mod); | 2665 | module_unload_free(mod); |
2576 | #if defined(CONFIG_MODULE_UNLOAD) | 2666 | free_module: |
2577 | free_percpu(mod->refptr); | 2667 | module_deallocate(mod, &info); |
2578 | free_init: | 2668 | free_copy: |
2579 | #endif | 2669 | free_copy(&info); |
2580 | module_free(mod, mod->module_init); | ||
2581 | free_core: | ||
2582 | module_free(mod, mod->module_core); | ||
2583 | /* mod will be freed with core. Don't access it beyond this line! */ | ||
2584 | free_percpu: | ||
2585 | free_percpu(percpu); | ||
2586 | free_mod: | ||
2587 | kfree(args); | ||
2588 | kfree(strmap); | ||
2589 | free_hdr: | ||
2590 | vfree(hdr); | ||
2591 | return ERR_PTR(err); | 2670 | return ERR_PTR(err); |
2592 | |||
2593 | truncated: | ||
2594 | printk(KERN_ERR "Module len %lu truncated\n", len); | ||
2595 | err = -ENOEXEC; | ||
2596 | goto free_hdr; | ||
2597 | } | 2671 | } |
2598 | 2672 | ||
2599 | /* Call module constructors. */ | 2673 | /* Call module constructors. */ |