19 #include <linux/export.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
29 #include <linux/elf.h>
33 #include <linux/fcntl.h>
35 #include <linux/capability.h>
38 #include <linux/errno.h>
42 #include <linux/sched.h>
44 #include <linux/device.h>
45 #include <linux/string.h>
48 #include <asm/uaccess.h>
49 #include <asm/cacheflush.h>
50 #include <asm/mmu_context.h>
52 #include <asm/sections.h>
64 #define CREATE_TRACE_POINTS
67 #ifndef ARCH_SHF_SMALL
68 #define ARCH_SHF_SMALL 0
76 #ifdef CONFIG_DEBUG_SET_MODULE_RONX
77 # define debug_align(X) ALIGN(X, PAGE_SIZE)
79 # define debug_align(X) (X)
86 #define MOD_NUMBER_OF_PAGES(BASE, SIZE) (((SIZE) > 0) ? \
87 (PFN_DOWN((unsigned long)(BASE) + (SIZE) - 1) - \
88 PFN_DOWN((unsigned long)BASE) + 1) \
92 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
103 #ifdef CONFIG_KGDB_KDB
104 struct list_head *kdb_modules = &modules;
107 #ifdef CONFIG_MODULE_SIG
108 #ifdef CONFIG_MODULE_SIG_FORCE
109 static bool sig_enforce =
true;
111 static bool sig_enforce =
false;
113 static int param_set_bool_enable_only(
const char *
val,
127 if (!test && sig_enforce)
136 .
set = param_set_bool_enable_only,
139 #define param_check_bool_enable_only param_check_bool
147 core_param(nomodule, modules_disabled, bint, 0);
156 static unsigned long module_addr_min = -1
UL, module_addr_max = 0;
186 static inline int strong_try_module_get(
struct module *
mod)
188 if (mod && mod->state == MODULE_STATE_COMING)
190 if (try_module_get(mod))
196 static inline void add_taint_module(
struct module *
mod,
unsigned flag)
199 mod->taints |= (1
U <<
flag);
218 for (i = 1; i < info->
hdr->e_shnum; i++) {
229 static void *section_addr(
const struct load_info *info,
const char *name)
232 return (
void *)info->
sechdrs[find_sec(info, name)].sh_addr;
236 static void *section_objs(
const struct load_info *info,
241 unsigned int sec = find_sec(info, name);
258 #ifdef CONFIG_UNUSED_SYMBOLS
259 extern const struct kernel_symbol __start___ksymtab_unused[];
261 extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
262 extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
263 extern const unsigned long __start___kcrctab_unused[];
264 extern const unsigned long __start___kcrctab_unused_gpl[];
267 #ifndef CONFIG_MODVERSIONS
268 #define symversion(base, idx) NULL
270 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
273 static bool each_symbol_in_section(
const struct symsearch *arr,
274 unsigned int arrsize,
276 bool (*
fn)(
const struct symsearch *syms,
283 for (j = 0; j < arrsize; j++) {
284 if (
fn(&arr[j], owner, data))
298 static const struct symsearch arr[] = {
300 NOT_GPL_ONLY,
false },
302 __start___kcrctab_gpl,
305 __start___kcrctab_gpl_future,
306 WILL_BE_GPL_ONLY,
false },
307 #ifdef CONFIG_UNUSED_SYMBOLS
308 { __start___ksymtab_unused, __stop___ksymtab_unused,
309 __start___kcrctab_unused,
310 NOT_GPL_ONLY,
true },
311 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl,
312 __start___kcrctab_unused_gpl,
320 list_for_each_entry_rcu(mod, &modules,
list) {
321 struct symsearch arr[] = {
322 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
323 NOT_GPL_ONLY,
false },
324 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
327 { mod->gpl_future_syms,
328 mod->gpl_future_syms + mod->num_gpl_future_syms,
329 mod->gpl_future_crcs,
330 WILL_BE_GPL_ONLY,
false },
331 #ifdef CONFIG_UNUSED_SYMBOLS
333 mod->unused_syms + mod->num_unused_syms,
335 NOT_GPL_ONLY,
true },
336 { mod->unused_gpl_syms,
337 mod->unused_gpl_syms + mod->num_unused_gpl_syms,
338 mod->unused_gpl_crcs,
343 if (each_symbol_in_section(arr,
ARRAY_SIZE(arr), mod,
fn, data))
362 static bool check_symbol(
const struct symsearch *syms,
364 unsigned int symnum,
void *
data)
369 if (syms->licence == GPL_ONLY)
371 if (syms->licence == WILL_BE_GPL_ONLY && fsa->
warn) {
373 "by a non-GPL module, which will not "
374 "be allowed in the future\n", fsa->
name);
376 "Documentation/feature-removal-schedule.txt "
377 "in the kernel source tree for more details.\n");
381 #ifdef CONFIG_UNUSED_SYMBOLS
382 if (syms->unused && fsa->
warn) {
384 "however this module is using it.\n", fsa->
name);
386 "This symbol will go away in the future.\n");
388 "Please evalute if this is the right api to use and if "
389 "it really is, submit a report the linux kernel "
390 "mailinglist together with submitting your code for "
397 fsa->
sym = &syms->start[symnum];
401 static int cmp_name(
const void *
va,
const void *vb)
409 static bool find_symbol_in_section(
const struct symsearch *syms,
416 sym =
bsearch(fsa->
name, syms->start, syms->stop - syms->start,
419 if (sym !=
NULL && check_symbol(syms, owner, sym - syms->start, data))
429 const unsigned long **
crc,
447 pr_debug(
"Failed to find symbol %s\n", name);
472 static int percpu_modalloc(
struct module *
mod,
484 "%s: Could not allocate %lu bytes percpu data\n",
488 mod->percpu_size =
size;
492 static void percpu_modfree(
struct module *mod)
497 static unsigned int find_pcpusec(
struct load_info *info)
499 return find_sec(info,
".data..percpu");
502 static void percpu_modcopy(
struct module *mod,
503 const void *
from,
unsigned long size)
527 list_for_each_entry_rcu(mod, &modules,
list) {
528 if (!mod->percpu_size)
533 if ((
void *)addr >= start &&
534 (
void *)addr < start + mod->percpu_size) {
551 static inline int percpu_modalloc(
struct module *mod,
552 unsigned long size,
unsigned long align)
556 static inline void percpu_modfree(
struct module *mod)
559 static unsigned int find_pcpusec(
struct load_info *info)
563 static inline void percpu_modcopy(
struct module *mod,
564 const void *from,
unsigned long size)
576 #define MODINFO_ATTR(field) \
577 static void setup_modinfo_##field(struct module *mod, const char *s) \
579 mod->field = kstrdup(s, GFP_KERNEL); \
581 static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
582 struct module_kobject *mk, char *buffer) \
584 return sprintf(buffer, "%s\n", mk->mod->field); \
586 static int modinfo_##field##_exists(struct module *mod) \
588 return mod->field != NULL; \
590 static void free_modinfo_##field(struct module *mod) \
595 static struct module_attribute modinfo_##field = { \
596 .attr = { .name = __stringify(field), .mode = 0444 }, \
597 .show = show_modinfo_##field, \
598 .setup = setup_modinfo_##field, \
599 .test = modinfo_##field##_exists, \
600 .free = free_modinfo_##field, \
608 #ifdef CONFIG_MODULE_UNLOAD
613 static int module_unload_init(
struct module *mod)
619 INIT_LIST_HEAD(&mod->source_list);
620 INIT_LIST_HEAD(&mod->target_list);
633 struct module_use *use;
636 if (use->source == a) {
652 static int add_module_usage(
struct module *a,
struct module *b)
654 struct module_use *use;
665 list_add(&use->source_list, &b->source_list);
666 list_add(&use->target_list, &a->target_list);
675 if (b ==
NULL || already_uses(a, b))
679 err = strong_try_module_get(b);
683 err = add_module_usage(a, b);
693 static void module_unload_free(
struct module *mod)
695 struct module_use *use, *
tmp;
699 struct module *i = use->target;
711 #ifdef CONFIG_MODULE_FORCE_UNLOAD
712 static inline int try_force_unload(
unsigned int flags)
720 static inline int try_force_unload(
unsigned int flags)
734 static int __try_stop_module(
void *_sref)
736 struct stopref *sref = _sref;
739 if (module_refcount(sref->mod) != 0) {
740 if (!(*sref->forced = try_force_unload(sref->flags)))
745 sref->mod->state = MODULE_STATE_GOING;
749 static int try_stop_module(
struct module *mod,
int flags,
int *forced)
752 struct stopref sref = {
mod,
flags, forced };
754 return stop_machine(__try_stop_module, &sref,
NULL);
757 mod->state = MODULE_STATE_GOING;
763 unsigned long module_refcount(
struct module *mod)
765 unsigned long incs = 0, decs = 0;
798 pr_debug(
"Looking at refcount...\n");
800 if (module_refcount(mod) == 0)
831 if (!list_empty(&mod->source_list)) {
838 if (mod->state != MODULE_STATE_LIVE) {
847 if (mod->init && !mod->exit) {
848 forced = try_force_unload(flags);
860 ret = try_stop_module(mod, flags, &forced);
865 if (!forced && module_refcount(mod) != 0)
866 wait_for_zero_refcount(mod);
870 if (mod->exit !=
NULL)
873 MODULE_STATE_GOING, mod);
877 strlcpy(last_unloaded_module, mod->
name,
sizeof(last_unloaded_module));
886 static inline void print_unload_info(
struct seq_file *
m,
struct module *mod)
888 struct module_use *use;
889 int printed_something = 0;
896 printed_something = 1;
900 if (mod->init !=
NULL && mod->exit ==
NULL) {
901 printed_something = 1;
905 if (!printed_something)
909 void __symbol_put(
const char *
symbol)
941 return sprintf(buffer,
"%lu\n", module_refcount(mk->
mod));
958 bool try_module_get(
struct module *module)
965 if (
likely(module_is_live(module))) {
977 void module_put(
struct module *module)
986 if (
unlikely(!module_is_live(module)))
994 static inline void print_unload_info(
struct seq_file *m,
struct module *mod)
1000 static inline void module_unload_free(
struct module *mod)
1006 return strong_try_module_get(b);
1010 static inline int module_unload_init(
struct module *mod)
1016 static size_t module_flags_taint(
struct module *mod,
char *
buf)
1039 const char *
state =
"unknown";
1041 switch (mk->
mod->state) {
1042 case MODULE_STATE_LIVE:
1045 case MODULE_STATE_COMING:
1048 case MODULE_STATE_GOING:
1052 return sprintf(buffer,
"%s\n", state);
1056 __ATTR(initstate, 0444, show_initstate,
NULL);
1060 const char *buffer,
size_t count)
1075 return sprintf(buffer,
"%u\n", mk->
mod->core_size);
1084 return sprintf(buffer,
"%u\n", mk->
mod->init_size);
1095 l = module_flags_taint(mk->
mod, buffer);
1106 &modinfo_srcversion,
1111 #ifdef CONFIG_MODULE_UNLOAD
1119 static int try_to_force_load(
struct module *mod,
const char *
reason)
1121 #ifdef CONFIG_MODULE_FORCE_LOAD
1132 #ifdef CONFIG_MODVERSIONS
1134 static unsigned long maybe_relocated(
unsigned long crc,
1135 const struct module *crc_owner)
1137 #ifdef ARCH_RELOCATES_KCRCTAB
1138 if (crc_owner ==
NULL)
1139 return crc - (
unsigned long)reloc_start;
1144 static int check_version(
Elf_Shdr *sechdrs,
1145 unsigned int versindex,
1146 const char *symname,
1148 const unsigned long *crc,
1149 const struct module *crc_owner)
1151 unsigned int i, num_versions;
1160 return try_to_force_load(mod, symname) == 0;
1162 versions = (
void *) sechdrs[versindex].sh_addr;
1163 num_versions = sechdrs[versindex].sh_size
1166 for (i = 0; i < num_versions; i++) {
1167 if (
strcmp(versions[i].name, symname) != 0)
1170 if (versions[i].crc == maybe_relocated(*crc, crc_owner))
1172 pr_debug(
"Found checksum %lX vs module %lX\n",
1173 maybe_relocated(*crc, crc_owner), versions[i].crc);
1178 mod->
name, symname);
1182 printk(
"%s: disagrees about version of symbol %s\n",
1183 mod->
name, symname);
1187 static inline int check_modstruct_version(
Elf_Shdr *sechdrs,
1188 unsigned int versindex,
1191 const unsigned long *
crc;
1198 return check_version(sechdrs, versindex,
"module_layout", mod, crc,
1203 static inline int same_magic(
const char *amagic,
const char *bmagic,
1207 amagic +=
strcspn(amagic,
" ");
1208 bmagic +=
strcspn(bmagic,
" ");
1210 return strcmp(amagic, bmagic) == 0;
1213 static inline int check_version(
Elf_Shdr *sechdrs,
1214 unsigned int versindex,
1215 const char *symname,
1217 const unsigned long *crc,
1218 const struct module *crc_owner)
1223 static inline int check_modstruct_version(
Elf_Shdr *sechdrs,
1224 unsigned int versindex,
1230 static inline int same_magic(
const char *amagic,
const char *bmagic,
1233 return strcmp(amagic, bmagic) == 0;
1238 static const struct kernel_symbol *resolve_symbol(
struct module *mod,
1243 struct module *
owner;
1245 const unsigned long *
crc;
1254 if (!check_version(info->
sechdrs, info->
index.vers, name, mod, crc,
1275 resolve_symbol_wait(
struct module *mod,
1283 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner))
1284 || PTR_ERR(ksym) != -
EBUSY,
1298 #ifdef CONFIG_KALLSYMS
1301 return !(sect->sh_flags &
SHF_ALLOC) || sect->sh_size == 0;
1304 struct module_sect_attr
1311 struct module_sect_attrs
1314 unsigned int nsections;
1315 struct module_sect_attr attrs[0];
1321 struct module_sect_attr *sattr =
1323 return sprintf(buf,
"0x%pK\n", (
void *)sattr->address);
1326 static void free_sect_attrs(
struct module_sect_attrs *sect_attrs)
1330 for (section = 0; section < sect_attrs->nsections; section++)
1331 kfree(sect_attrs->attrs[section].name);
1335 static void add_sect_attrs(
struct module *mod,
const struct load_info *info)
1337 unsigned int nloaded = 0,
i, size[2];
1338 struct module_sect_attrs *sect_attrs;
1339 struct module_sect_attr *sattr;
1343 for (i = 0; i < info->
hdr->e_shnum; i++)
1344 if (!sect_empty(&info->
sechdrs[i]))
1346 size[0] =
ALIGN(
sizeof(*sect_attrs)
1347 + nloaded *
sizeof(sect_attrs->attrs[0]),
1348 sizeof(sect_attrs->grp.attrs[0]));
1349 size[1] = (nloaded + 1) *
sizeof(sect_attrs->grp.attrs[0]);
1350 sect_attrs = kzalloc(size[0] + size[1],
GFP_KERNEL);
1351 if (sect_attrs ==
NULL)
1355 sect_attrs->grp.name =
"sections";
1356 sect_attrs->grp.attrs = (
void *)sect_attrs + size[0];
1358 sect_attrs->nsections = 0;
1359 sattr = §_attrs->attrs[0];
1360 gattr = §_attrs->grp.attrs[0];
1361 for (i = 0; i < info->
hdr->e_shnum; i++) {
1363 if (sect_empty(sec))
1365 sattr->address = sec->sh_addr;
1368 if (sattr->name ==
NULL)
1370 sect_attrs->nsections++;
1372 sattr->mattr.show = module_sect_show;
1373 sattr->mattr.store =
NULL;
1374 sattr->mattr.attr.name = sattr->name;
1375 sattr->mattr.attr.mode =
S_IRUGO;
1376 *(gattr++) = &(sattr++)->mattr.attr;
1383 mod->sect_attrs = sect_attrs;
1386 free_sect_attrs(sect_attrs);
1389 static void remove_sect_attrs(
struct module *mod)
1391 if (mod->sect_attrs) {
1393 &mod->sect_attrs->grp);
1396 free_sect_attrs(mod->sect_attrs);
1397 mod->sect_attrs =
NULL;
1405 struct module_notes_attrs {
1413 char *buf, loff_t
pos,
size_t count)
1422 static void free_notes_attrs(
struct module_notes_attrs *notes_attrs,
1425 if (notes_attrs->dir) {
1428 ¬es_attrs->attrs[i]);
1434 static void add_notes_attrs(
struct module *mod,
const struct load_info *info)
1436 unsigned int notes, loaded,
i;
1437 struct module_notes_attrs *notes_attrs;
1441 if (!mod->sect_attrs)
1446 for (i = 0; i < info->
hdr->e_shnum; i++)
1447 if (!sect_empty(&info->
sechdrs[i]) &&
1454 notes_attrs = kzalloc(
sizeof(*notes_attrs)
1455 + notes *
sizeof(notes_attrs->attrs[0]),
1457 if (notes_attrs ==
NULL)
1460 notes_attrs->notes = notes;
1461 nattr = ¬es_attrs->attrs[0];
1462 for (loaded = i = 0; i < info->
hdr->e_shnum; ++
i) {
1463 if (sect_empty(&info->
sechdrs[i]))
1467 nattr->
attr.name = mod->sect_attrs->attrs[loaded].
name;
1471 nattr->
read = module_notes_read;
1478 if (!notes_attrs->dir)
1481 for (i = 0; i < notes; ++
i)
1483 ¬es_attrs->attrs[i]))
1486 mod->notes_attrs = notes_attrs;
1490 free_notes_attrs(notes_attrs, i);
1493 static void remove_notes_attrs(
struct module *mod)
1495 if (mod->notes_attrs)
1496 free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes);
1501 static inline void add_sect_attrs(
struct module *mod,
1506 static inline void remove_sect_attrs(
struct module *mod)
1510 static inline void add_notes_attrs(
struct module *mod,
1515 static inline void remove_notes_attrs(
struct module *mod)
1520 static void add_usage_links(
struct module *mod)
1522 #ifdef CONFIG_MODULE_UNLOAD
1523 struct module_use *use;
1529 &mod->mkobj.kobj, mod->
name);
1535 static void del_usage_links(
struct module *mod)
1537 #ifdef CONFIG_MODULE_UNLOAD
1538 struct module_use *use;
1547 static int module_add_modinfo_attrs(
struct module *mod)
1557 if (!mod->modinfo_attrs)
1560 temp_attr = mod->modinfo_attrs;
1561 for (i = 0; (attr = modinfo_attrs[
i]) && !error; i++) {
1564 memcpy(temp_attr, attr,
sizeof(*temp_attr));
1573 static void module_remove_modinfo_attrs(
struct module *mod)
1578 for (i = 0; (attr = &mod->modinfo_attrs[
i]); i++) {
1580 if (!attr->
attr.name)
1586 kfree(mod->modinfo_attrs);
1589 static int mod_sysfs_init(
struct module *mod)
1594 if (!module_sysfs_initialized) {
1609 mod->mkobj.mod =
mod;
1611 memset(&mod->mkobj.kobj, 0,
sizeof(mod->mkobj.kobj));
1612 mod->mkobj.kobj.kset = module_kset;
1623 static int mod_sysfs_setup(
struct module *mod,
1626 unsigned int num_params)
1630 err = mod_sysfs_init(mod);
1635 if (!mod->holders_dir) {
1640 err = module_param_sysfs_setup(mod, kparam, num_params);
1642 goto out_unreg_holders;
1644 err = module_add_modinfo_attrs(mod);
1646 goto out_unreg_param;
1648 add_usage_links(mod);
1649 add_sect_attrs(mod, info);
1650 add_notes_attrs(mod, info);
1656 module_param_sysfs_remove(mod);
1665 static void mod_sysfs_fini(
struct module *mod)
1667 remove_notes_attrs(mod);
1668 remove_sect_attrs(mod);
1674 static int mod_sysfs_setup(
struct module *mod,
1677 unsigned int num_params)
1682 static void mod_sysfs_fini(
struct module *mod)
1686 static void module_remove_modinfo_attrs(
struct module *mod)
1690 static void del_usage_links(
struct module *mod)
1696 static void mod_sysfs_teardown(
struct module *mod)
1698 del_usage_links(mod);
1699 module_remove_modinfo_attrs(mod);
1700 module_param_sysfs_remove(mod);
1703 mod_sysfs_fini(mod);
1710 static int __unlink_module(
void *_mod)
1712 struct module *mod = _mod;
1714 module_bug_cleanup(mod);
1718 #ifdef CONFIG_DEBUG_SET_MODULE_RONX
1723 void set_page_attributes(
void *start,
void *
end,
int (*
set)(
unsigned long start,
int num_pages))
1725 unsigned long begin_pfn =
PFN_DOWN((
unsigned long)start);
1726 unsigned long end_pfn =
PFN_DOWN((
unsigned long)end);
1728 if (end_pfn > begin_pfn)
1729 set(begin_pfn <<
PAGE_SHIFT, end_pfn - begin_pfn);
1732 static void set_section_ro_nx(
void *base,
1733 unsigned long text_size,
1734 unsigned long ro_size,
1738 unsigned long begin_pfn;
1739 unsigned long end_pfn;
1754 if (total_size > text_size) {
1755 begin_pfn =
PFN_UP((
unsigned long)base + text_size);
1756 end_pfn =
PFN_UP((
unsigned long)base + total_size);
1757 if (end_pfn > begin_pfn)
1762 static void unset_module_core_ro_nx(
struct module *mod)
1764 set_page_attributes(mod->module_core + mod->core_text_size,
1765 mod->module_core + mod->core_size,
1767 set_page_attributes(mod->module_core,
1768 mod->module_core + mod->core_ro_size,
1772 static void unset_module_init_ro_nx(
struct module *mod)
1774 set_page_attributes(mod->module_init + mod->init_text_size,
1775 mod->module_init + mod->init_size,
1777 set_page_attributes(mod->module_init,
1778 mod->module_init + mod->init_ro_size,
1783 void set_all_modules_text_rw(
void)
1788 list_for_each_entry_rcu(mod, &modules,
list) {
1789 if ((mod->module_core) && (mod->core_text_size)) {
1790 set_page_attributes(mod->module_core,
1791 mod->module_core + mod->core_text_size,
1794 if ((mod->module_init) && (mod->init_text_size)) {
1795 set_page_attributes(mod->module_init,
1796 mod->module_init + mod->init_text_size,
1804 void set_all_modules_text_ro(
void)
1809 list_for_each_entry_rcu(mod, &modules,
list) {
1810 if ((mod->module_core) && (mod->core_text_size)) {
1811 set_page_attributes(mod->module_core,
1812 mod->module_core + mod->core_text_size,
1815 if ((mod->module_init) && (mod->init_text_size)) {
1816 set_page_attributes(mod->module_init,
1817 mod->module_init + mod->init_text_size,
1824 static inline void set_section_ro_nx(
void *base,
unsigned long text_size,
unsigned long ro_size,
unsigned long total_size) { }
1825 static void unset_module_core_ro_nx(
struct module *mod) { }
1826 static void unset_module_init_ro_nx(
struct module *mod) { }
1831 vfree(module_region);
1839 static void free_module(
struct module *mod)
1841 trace_module_free(mod);
1845 stop_machine(__unlink_module, mod,
NULL);
1847 mod_sysfs_teardown(mod);
1856 module_unload_free(mod);
1859 destroy_params(mod->kp, mod->num_kp);
1862 unset_module_init_ro_nx(mod);
1865 percpu_modfree(mod);
1871 unset_module_core_ro_nx(mod);
1875 update_protections(
current->mm);
1881 struct module *
owner;
1886 if (sym && strong_try_module_get(owner))
1900 static int verify_export_symbols(
struct module *mod)
1903 struct module *
owner;
1909 { mod->syms, mod->num_syms },
1910 { mod->gpl_syms, mod->num_gpl_syms },
1911 { mod->gpl_future_syms, mod->num_gpl_future_syms },
1912 #ifdef CONFIG_UNUSED_SYMBOLS
1913 { mod->unused_syms, mod->num_unused_syms },
1914 { mod->unused_gpl_syms, mod->num_unused_gpl_syms },
1919 for (s = arr[i].sym; s < arr[
i].sym + arr[
i].num; s++) {
1922 "%s: exports duplicate symbol %s"
1933 static int simplify_symbols(
struct module *mod,
const struct load_info *info)
1936 Elf_Sym *sym = (
void *)symsec->sh_addr;
1937 unsigned long secbase;
1942 for (i = 1; i < symsec->sh_size /
sizeof(
Elf_Sym); i++) {
1943 const char *name = info->
strtab + sym[
i].st_name;
1945 switch (sym[i].st_shndx) {
1949 pr_debug(
"Common symbol: %s\n", name);
1950 printk(
"%s: please compile with -fno-common\n",
1957 pr_debug(
"Absolute symbol: 0x%08lx\n",
1958 (
long)sym[i].st_value);
1962 ksym = resolve_symbol_wait(mod, info, name);
1964 if (ksym && !IS_ERR(ksym)) {
1965 sym[
i].st_value = ksym->
value;
1974 mod->
name, name, PTR_ERR(ksym));
1975 ret = PTR_ERR(ksym) ?: -
ENOENT;
1980 if (sym[i].st_shndx == info->
index.pcpu)
1981 secbase = (
unsigned long)mod_percpu(mod);
1983 secbase = info->
sechdrs[sym[
i].st_shndx].sh_addr;
1984 sym[
i].st_value += secbase;
1992 static int apply_relocations(
struct module *mod,
const struct load_info *info)
1998 for (i = 1; i < info->
hdr->e_shnum; i++) {
1999 unsigned int infosec = info->
sechdrs[
i].sh_info;
2002 if (infosec >= info->
hdr->e_shnum)
2011 info->
index.sym, i, mod);
2014 info->
index.sym, i, mod);
2023 unsigned int section)
2030 static long get_offset(
struct module *mod,
unsigned int *size,
2031 Elf_Shdr *sechdr,
unsigned int section)
2036 ret =
ALIGN(*size, sechdr->sh_addralign ?: 1);
2037 *size = ret + sechdr->sh_size;
2045 static void layout_sections(
struct module *mod,
struct load_info *info)
2047 static unsigned long const masks[][2] = {
2058 for (i = 0; i < info->
hdr->e_shnum; i++)
2061 pr_debug(
"Core section allocation order:\n");
2063 for (i = 0; i < info->
hdr->e_shnum; ++
i) {
2065 const char *sname = info->
secstrings + s->sh_name;
2067 if ((s->sh_flags & masks[m][0]) != masks[
m][0]
2068 || (s->sh_flags & masks[
m][1])
2069 || s->sh_entsize != ~0
UL
2072 s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
2078 mod->core_text_size = mod->core_size;
2082 mod->core_ro_size = mod->core_size;
2090 pr_debug(
"Init section allocation order:\n");
2092 for (i = 0; i < info->
hdr->e_shnum; ++
i) {
2094 const char *sname = info->
secstrings + s->sh_name;
2096 if ((s->sh_flags & masks[m][0]) != masks[
m][0]
2097 || (s->sh_flags & masks[
m][1])
2098 || s->sh_entsize != ~0
UL
2101 s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
2108 mod->init_text_size = mod->init_size;
2112 mod->init_ro_size = mod->init_size;
2121 static void set_license(
struct module *mod,
const char *license)
2124 license =
"unspecified";
2126 if (!license_is_gpl_compatible(license)) {
2129 "kernel.\n", mod->
name, license);
2135 static char *next_string(
char *
string,
unsigned long *secsize)
2140 if ((*secsize)-- <= 1)
2145 while (!
string[0]) {
2147 if ((*secsize)-- <= 1)
2153 static char *get_modinfo(
struct load_info *info,
const char *
tag)
2156 unsigned int taglen =
strlen(tag);
2158 unsigned long size = infosec->sh_size;
2160 for (p = (
char *)infosec->sh_addr; p; p = next_string(p, &size)) {
2161 if (
strncmp(p, tag, taglen) == 0 && p[taglen] ==
'=')
2162 return p + taglen + 1;
2167 static void setup_modinfo(
struct module *mod,
struct load_info *info)
2172 for (i = 0; (attr = modinfo_attrs[
i]); i++) {
2174 attr->
setup(mod, get_modinfo(info, attr->
attr.name));
2178 static void free_modinfo(
struct module *mod)
2183 for (i = 0; (attr = modinfo_attrs[
i]); i++) {
2189 #ifdef CONFIG_KALLSYMS
2192 static const struct kernel_symbol *lookup_symbol(
const char *name,
2196 return bsearch(name, start, stop - start,
2200 static int is_exported(
const char *name,
unsigned long value,
2201 const struct module *mod)
2205 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
2207 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
2230 if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC
2231 && sechdrs[sym->st_shndx].sh_type !=
SHT_NOBITS) {
2232 if (!(sechdrs[sym->st_shndx].sh_flags &
SHF_WRITE))
2239 if (sechdrs[sym->st_shndx].sh_type ==
SHT_NOBITS) {
2258 || src->st_shndx >= shnum
2262 sec = sechdrs + src->st_shndx;
2263 if (!(sec->sh_flags & SHF_ALLOC)
2264 #ifndef CONFIG_KALLSYMS_ALL
2265 || !(sec->sh_flags & SHF_EXECINSTR)
2280 static void layout_symtab(
struct module *mod,
struct load_info *info)
2285 unsigned int i, nsrc, ndst, strtab_size;
2289 symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
2293 src = (
void *)info->
hdr + symsect->sh_offset;
2294 nsrc = symsect->sh_size /
sizeof(*src);
2300 for (ndst = i = 0; i < nsrc; i++) {
2302 is_core_symbol(src+i, info->
sechdrs, info->
hdr->e_shnum)) {
2303 strtab_size +=
strlen(&info->
strtab[src[i].st_name])+1;
2309 info->
symoffs =
ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
2311 mod->core_size += strtab_size;
2315 strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
2320 static void add_kallsyms(
struct module *mod,
const struct load_info *info)
2322 unsigned int i, ndst;
2328 mod->symtab = (
void *)symsec->sh_addr;
2329 mod->num_symtab = symsec->sh_size /
sizeof(
Elf_Sym);
2331 mod->strtab = (
void *)info->
sechdrs[info->
index.str].sh_addr;
2334 for (i = 0; i < mod->num_symtab; i++)
2335 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
2337 mod->core_symtab = dst = mod->module_core + info->
symoffs;
2338 mod->core_strtab = s = mod->module_core + info->
stroffs;
2341 for (ndst = i = 0; i < mod->num_symtab; i++) {
2343 is_core_symbol(src+i, info->
sechdrs, info->
hdr->e_shnum)) {
2345 dst[ndst++].st_name = s - mod->core_strtab;
2346 s +=
strlcpy(s, &mod->strtab[src[i].st_name],
2350 mod->core_num_syms = ndst;
2353 static inline void layout_symtab(
struct module *mod,
struct load_info *info)
2357 static void add_kallsyms(
struct module *mod,
const struct load_info *info)
2362 static void dynamic_debug_setup(
struct _ddebug *
debug,
unsigned int num)
2366 #ifdef CONFIG_DYNAMIC_DEBUG
2373 static void dynamic_debug_remove(
struct _ddebug *debug)
2384 static void *module_alloc_update_bounds(
unsigned long size)
2391 if ((
unsigned long)ret < module_addr_min)
2392 module_addr_min = (
unsigned long)ret;
2393 if ((
unsigned long)ret + size > module_addr_max)
2394 module_addr_max = (
unsigned long)ret +
size;
2400 #ifdef CONFIG_DEBUG_KMEMLEAK
2401 static void kmemleak_load_module(
const struct module *mod,
2409 for (i = 1; i < info->
hdr->e_shnum; i++) {
2411 if (!(info->
sechdrs[i].sh_flags & SHF_ALLOC))
2421 static inline void kmemleak_load_module(
const struct module *mod,
2427 #ifdef CONFIG_MODULE_SIG
2428 static int module_sig_check(
struct load_info *info,
2429 const void *mod,
unsigned long *_len)
2433 unsigned long len = *_len;
2435 if (len > markerlen &&
2449 panic(
"Module verification failed with error %d in FIPS mode\n",
2451 if (err == -
ENOKEY && !sig_enforce)
2457 static int module_sig_check(
struct load_info *info,
2458 void *mod,
unsigned long *len)
2465 static int copy_and_check(
struct load_info *info,
2466 const void __user *umod,
unsigned long len,
2467 const char __user *uargs)
2472 if (len <
sizeof(*hdr))
2484 err = module_sig_check(info, hdr, &len);
2493 || hdr->e_shentsize !=
sizeof(
Elf_Shdr)) {
2498 if (hdr->e_shoff >= len ||
2499 hdr->e_shnum *
sizeof(
Elf_Shdr) > len - hdr->e_shoff) {
2513 static void free_copy(
struct load_info *info)
2518 static int rewrite_section_headers(
struct load_info *info)
2525 for (i = 1; i < info->
hdr->e_shnum; i++) {
2528 && info->
len < shdr->sh_offset + shdr->sh_size) {
2536 shdr->sh_addr = (
size_t)info->
hdr + shdr->sh_offset;
2538 #ifndef CONFIG_MODULE_UNLOAD
2541 shdr->sh_flags &= ~(
unsigned long)
SHF_ALLOC;
2546 info->
index.vers = find_sec(info,
"__versions");
2547 info->
index.info = find_sec(info,
".modinfo");
2561 static struct module *setup_load_info(
struct load_info *info)
2570 + info->
sechdrs[info->
hdr->e_shstrndx].sh_offset;
2572 err = rewrite_section_headers(info);
2574 return ERR_PTR(err);
2577 for (i = 1; i < info->
hdr->e_shnum; i++) {
2587 info->
index.mod = find_sec(info,
".gnu.linkonce.this_module");
2588 if (!info->
index.mod) {
2601 info->
index.pcpu = find_pcpusec(info);
2604 if (!check_modstruct_version(info->
sechdrs, info->
index.vers, mod))
2610 static int check_modinfo(
struct module *mod,
struct load_info *info)
2612 const char *modmagic = get_modinfo(info,
"vermagic");
2617 err = try_to_force_load(mod,
"bad vermagic");
2620 }
else if (!same_magic(modmagic, vermagic, info->
index.vers)) {
2622 mod->
name, modmagic, vermagic);
2626 if (!get_modinfo(info,
"intree"))
2629 if (get_modinfo(info,
"staging")) {
2632 " the quality is unknown, you have been warned.\n",
2637 set_license(mod, get_modinfo(info,
"license"));
2642 static void find_module_sections(
struct module *mod,
struct load_info *info)
2644 mod->kp = section_objs(info,
"__param",
2645 sizeof(*mod->kp), &mod->num_kp);
2646 mod->syms = section_objs(info,
"__ksymtab",
2647 sizeof(*mod->syms), &mod->num_syms);
2648 mod->crcs = section_addr(info,
"__kcrctab");
2649 mod->gpl_syms = section_objs(info,
"__ksymtab_gpl",
2650 sizeof(*mod->gpl_syms),
2651 &mod->num_gpl_syms);
2652 mod->gpl_crcs = section_addr(info,
"__kcrctab_gpl");
2653 mod->gpl_future_syms = section_objs(info,
2654 "__ksymtab_gpl_future",
2655 sizeof(*mod->gpl_future_syms),
2656 &mod->num_gpl_future_syms);
2657 mod->gpl_future_crcs = section_addr(info,
"__kcrctab_gpl_future");
2659 #ifdef CONFIG_UNUSED_SYMBOLS
2660 mod->unused_syms = section_objs(info,
"__ksymtab_unused",
2661 sizeof(*mod->unused_syms),
2662 &mod->num_unused_syms);
2663 mod->unused_crcs = section_addr(info,
"__kcrctab_unused");
2664 mod->unused_gpl_syms = section_objs(info,
"__ksymtab_unused_gpl",
2665 sizeof(*mod->unused_gpl_syms),
2666 &mod->num_unused_gpl_syms);
2667 mod->unused_gpl_crcs = section_addr(info,
"__kcrctab_unused_gpl");
2669 #ifdef CONFIG_CONSTRUCTORS
2670 mod->ctors = section_objs(info,
".ctors",
2671 sizeof(*mod->ctors), &mod->num_ctors);
2674 #ifdef CONFIG_TRACEPOINTS
2675 mod->tracepoints_ptrs = section_objs(info,
"__tracepoints_ptrs",
2676 sizeof(*mod->tracepoints_ptrs),
2677 &mod->num_tracepoints);
2679 #ifdef HAVE_JUMP_LABEL
2680 mod->jump_entries = section_objs(info,
"__jump_table",
2681 sizeof(*mod->jump_entries),
2682 &mod->num_jump_entries);
2684 #ifdef CONFIG_EVENT_TRACING
2685 mod->trace_events = section_objs(info,
"_ftrace_events",
2686 sizeof(*mod->trace_events),
2687 &mod->num_trace_events);
2695 #ifdef CONFIG_TRACING
2696 mod->trace_bprintk_fmt_start = section_objs(info,
"__trace_printk_fmt",
2697 sizeof(*mod->trace_bprintk_fmt_start),
2698 &mod->num_trace_bprintk_fmt);
2704 sizeof(*mod->trace_bprintk_fmt_start) *
2707 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
2709 mod->ftrace_callsites = section_objs(info,
"__mcount_loc",
2710 sizeof(*mod->ftrace_callsites),
2711 &mod->num_ftrace_callsites);
2714 mod->extable = section_objs(info,
"__ex_table",
2715 sizeof(*mod->extable), &mod->num_exentries);
2717 if (section_addr(info,
"__obsparm"))
2721 info->
debug = section_objs(info,
"__verbose",
2725 static int move_module(
struct module *mod,
struct load_info *info)
2731 ptr = module_alloc_update_bounds(mod->core_size);
2741 memset(ptr, 0, mod->core_size);
2742 mod->module_core =
ptr;
2744 ptr = module_alloc_update_bounds(mod->init_size);
2752 if (!ptr && mod->init_size) {
2756 memset(ptr, 0, mod->init_size);
2757 mod->module_init =
ptr;
2760 pr_debug(
"final section addresses:\n");
2761 for (i = 0; i < info->
hdr->e_shnum; i++) {
2765 if (!(shdr->sh_flags & SHF_ALLOC))
2769 dest = mod->module_init
2772 dest = mod->module_core + shdr->sh_entsize;
2775 memcpy(dest, (
void *)shdr->sh_addr, shdr->sh_size);
2777 shdr->sh_addr = (
unsigned long)dest;
2779 (
long)shdr->sh_addr, info->
secstrings + shdr->sh_name);
2785 static int check_module_license_and_versions(
struct module *mod)
2803 #ifdef CONFIG_MODVERSIONS
2804 if ((mod->num_syms && !mod->crcs)
2805 || (mod->num_gpl_syms && !mod->gpl_crcs)
2806 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs)
2807 #ifdef CONFIG_UNUSED_SYMBOLS
2808 || (mod->num_unused_syms && !mod->unused_crcs)
2809 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
2812 return try_to_force_load(mod,
2813 "no versions for exported symbols");
2819 static void flush_module_icache(
const struct module *mod)
2832 if (mod->module_init)
2834 (
unsigned long)mod->module_init
2837 (
unsigned long)mod->module_core + mod->core_size);
2850 static struct module *layout_and_allocate(
struct load_info *info)
2857 mod = setup_load_info(info);
2861 err = check_modinfo(mod, info);
2863 return ERR_PTR(err);
2872 if (pcpusec->sh_size) {
2874 err = percpu_modalloc(mod,
2875 pcpusec->sh_size, pcpusec->sh_addralign);
2878 pcpusec->sh_flags &= ~(
unsigned long)SHF_ALLOC;
2884 layout_sections(mod, info);
2885 layout_symtab(mod, info);
2888 err = move_module(mod, info);
2894 kmemleak_load_module(mod, info);
2898 percpu_modfree(mod);
2900 return ERR_PTR(err);
2904 static void module_deallocate(
struct module *mod,
struct load_info *info)
2906 percpu_modfree(mod);
2918 static int post_relocation(
struct module *mod,
const struct load_info *info)
2921 sort_extable(mod->extable, mod->extable + mod->num_exentries);
2924 percpu_modcopy(mod, (
void *)info->
sechdrs[info->
index.pcpu].sh_addr,
2928 add_kallsyms(mod, info);
2935 static bool finished_loading(
const char *name)
2942 ret = !mod || mod->state != MODULE_STATE_COMING;
2950 static struct module *load_module(
void __user *umod,
2952 const char __user *uargs)
2955 struct module *
mod, *old;
2958 pr_debug(
"load_module: umod=%p, len=%lu, uargs=%p\n",
2962 err = copy_and_check(&info, umod, len, uargs);
2964 return ERR_PTR(err);
2967 mod = layout_and_allocate(&info);
2973 #ifdef CONFIG_MODULE_SIG
2974 mod->sig_ok = info.
sig_ok;
2980 err = module_unload_init(mod);
2986 find_module_sections(mod, &info);
2988 err = check_module_license_and_versions(mod);
2993 setup_modinfo(mod, &info);
2996 err = simplify_symbols(mod, &info);
3000 err = apply_relocations(mod, &info);
3004 err = post_relocation(mod, &info);
3008 flush_module_icache(mod);
3012 if (IS_ERR(mod->args)) {
3013 err = PTR_ERR(mod->args);
3014 goto free_arch_cleanup;
3018 mod->state = MODULE_STATE_COMING;
3030 if (old->state == MODULE_STATE_COMING) {
3034 finished_loading(mod->
name));
3036 goto free_arch_cleanup;
3047 err = verify_export_symbols(mod);
3051 module_bug_finalize(info.
hdr, info.
sechdrs, mod);
3052 list_add_rcu(&mod->list, &modules);
3062 err = mod_sysfs_setup(mod, &info, mod->kp, mod->num_kp);
3070 trace_module_load(mod);
3076 list_del_rcu(&mod->list);
3077 module_bug_cleanup(mod);
3080 dynamic_debug_remove(info.
debug);
3090 module_unload_free(mod);
3092 module_deallocate(mod, &info);
3095 return ERR_PTR(err);
3099 static void do_mod_ctors(
struct module *mod)
3101 #ifdef CONFIG_CONSTRUCTORS
3104 for (i = 0; i < mod->num_ctors; i++)
3111 unsigned long, len,
const char __user *, uargs)
3121 mod = load_module(umod, len, uargs);
3123 return PTR_ERR(mod);
3126 MODULE_STATE_COMING, mod);
3129 set_section_ro_nx(mod->module_core,
3130 mod->core_text_size,
3135 set_section_ro_nx(mod->module_init,
3136 mod->init_text_size,
3142 if (mod->init !=
NULL)
3147 mod->state = MODULE_STATE_GOING;
3151 MODULE_STATE_GOING, mod);
3158 "%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n"
3159 "%s: loading module anyway...\n",
3160 __func__, mod->
name, ret,
3166 mod->state = MODULE_STATE_LIVE;
3168 MODULE_STATE_LIVE, mod);
3177 #ifdef CONFIG_KALLSYMS
3178 mod->num_symtab = mod->core_num_syms;
3179 mod->symtab = mod->core_symtab;
3180 mod->strtab = mod->core_strtab;
3182 unset_module_init_ro_nx(mod);
3184 mod->module_init =
NULL;
3186 mod->init_ro_size = 0;
3187 mod->init_text_size = 0;
3194 static inline int within(
unsigned long addr,
void *start,
unsigned long size)
3196 return ((
void *)addr >= start && (
void *)addr < start + size);
3199 #ifdef CONFIG_KALLSYMS
3204 static inline int is_arm_mapping_symbol(
const char *
str)
3206 return str[0] ==
'$' &&
strchr(
"atd", str[1])
3207 && (str[2] ==
'\0' || str[2] ==
'.');
3210 static const char *get_ksymbol(
struct module *mod,
3212 unsigned long *size,
3215 unsigned int i, best = 0;
3216 unsigned long nextval;
3219 if (within_module_init(addr, mod))
3220 nextval = (
unsigned long)mod->module_init+mod->init_text_size;
3222 nextval = (
unsigned long)mod->module_core+mod->core_text_size;
3226 for (i = 1; i < mod->num_symtab; i++) {
3227 if (mod->symtab[i].st_shndx ==
SHN_UNDEF)
3232 if (mod->symtab[i].st_value <= addr
3233 && mod->symtab[i].st_value > mod->symtab[best].st_value
3234 && *(mod->strtab + mod->symtab[i].st_name) !=
'\0'
3235 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3237 if (mod->symtab[i].st_value > addr
3238 && mod->symtab[i].st_value < nextval
3239 && *(mod->strtab + mod->symtab[i].st_name) !=
'\0'
3240 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3241 nextval = mod->symtab[i].st_value;
3248 *size = nextval - mod->symtab[best].st_value;
3250 *offset = addr - mod->symtab[best].st_value;
3251 return mod->strtab + mod->symtab[best].st_name;
3256 const char *module_address_lookup(
unsigned long addr,
3257 unsigned long *size,
3258 unsigned long *offset,
3263 const char *ret =
NULL;
3266 list_for_each_entry_rcu(mod, &modules,
list) {
3267 if (within_module_init(addr, mod) ||
3268 within_module_core(addr, mod)) {
3270 *modname = mod->
name;
3271 ret = get_ksymbol(mod, addr, size, offset);
3284 int lookup_module_symbol_name(
unsigned long addr,
char *symname)
3289 list_for_each_entry_rcu(mod, &modules,
list) {
3290 if (within_module_init(addr, mod) ||
3291 within_module_core(addr, mod)) {
3294 sym = get_ksymbol(mod, addr,
NULL,
NULL);
3307 int lookup_module_symbol_attrs(
unsigned long addr,
unsigned long *size,
3308 unsigned long *offset,
char *modname,
char *name)
3313 list_for_each_entry_rcu(mod, &modules,
list) {
3314 if (within_module_init(addr, mod) ||
3315 within_module_core(addr, mod)) {
3318 sym = get_ksymbol(mod, addr, size, offset);
3334 int module_get_kallsym(
unsigned int symnum,
unsigned long *value,
char *
type,
3340 list_for_each_entry_rcu(mod, &modules,
list) {
3341 if (symnum < mod->num_symtab) {
3342 *value = mod->symtab[symnum].st_value;
3343 *type = mod->symtab[symnum].st_info;
3344 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
3347 *exported = is_exported(name, *value, mod);
3351 symnum -= mod->num_symtab;
3357 static unsigned long mod_find_symname(
struct module *mod,
const char *name)
3361 for (i = 0; i < mod->num_symtab; i++)
3362 if (
strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 &&
3363 mod->symtab[i].st_info !=
'U')
3364 return mod->symtab[
i].st_value;
3369 unsigned long module_kallsyms_lookup_name(
const char *name)
3373 unsigned long ret = 0;
3380 ret = mod_find_symname(mod, colon+1);
3383 list_for_each_entry_rcu(mod, &modules,
list)
3384 if ((ret = mod_find_symname(mod, name)) != 0)
3391 int module_kallsyms_on_each_symbol(
int (*
fn)(
void *,
const char *,
3392 struct module *,
unsigned long),
3400 for (i = 0; i < mod->num_symtab; i++) {
3401 ret =
fn(data, mod->strtab + mod->symtab[i].st_name,
3402 mod, mod->symtab[i].st_value);
3411 static char *module_flags(
struct module *mod,
char *buf)
3416 mod->state == MODULE_STATE_GOING ||
3417 mod->state == MODULE_STATE_COMING) {
3419 bx += module_flags_taint(mod, buf + bx);
3421 if (mod->state == MODULE_STATE_GOING)
3424 if (mod->state == MODULE_STATE_COMING)
3433 #ifdef CONFIG_PROC_FS
3435 static void *m_start(
struct seq_file *m, loff_t *
pos)
3441 static void *m_next(
struct seq_file *m,
void *p, loff_t *
pos)
3446 static void m_stop(
struct seq_file *m,
void *p)
3451 static int m_show(
struct seq_file *m,
void *p)
3457 mod->
name, mod->init_size + mod->core_size);
3458 print_unload_info(m, mod);
3462 mod->state == MODULE_STATE_GOING ?
"Unloading":
3463 mod->state == MODULE_STATE_COMING ?
"Loading":
3470 seq_printf(m,
" %s", module_flags(mod, buf));
3490 return seq_open(file, &modules_op);
3494 .
open = modules_open,
3500 static int __init proc_modules_init(
void)
3502 proc_create(
"modules", 0,
NULL, &proc_modules_operations);
3515 list_for_each_entry_rcu(mod, &modules,
list) {
3516 if (mod->num_exentries == 0)
3520 mod->extable + mod->num_exentries - 1,
3561 if (addr < module_addr_min || addr > module_addr_max)
3564 list_for_each_entry_rcu(mod, &modules,
list)
3565 if (within_module_core(addr, mod)
3566 || within_module_init(addr, mod))
3603 if (!within(addr, mod->module_init, mod->init_text_size)
3604 && !within(addr, mod->module_core, mod->core_text_size))
3620 list_for_each_entry_rcu(mod, &modules,
list)
3621 printk(
" %s%s", mod->
name, module_flags(mod, buf));
3623 if (last_unloaded_module[0])
3624 printk(
" [last unloaded: %s]", last_unloaded_module);
3628 #ifdef CONFIG_MODVERSIONS
3631 void module_layout(
struct module *mod,