Lines Matching refs:mod

116 static void mod_update_bounds(struct module *mod)  in mod_update_bounds()  argument
119 struct module_memory *mod_mem = &mod->mem[type]; in mod_update_bounds()
152 static inline int strong_try_module_get(struct module *mod) in strong_try_module_get() argument
154 BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED); in strong_try_module_get()
155 if (mod && mod->state == MODULE_STATE_COMING) in strong_try_module_get()
157 if (try_module_get(mod)) in strong_try_module_get()
163 static inline void add_taint_module(struct module *mod, unsigned flag, in add_taint_module() argument
167 set_bit(flag, &mod->taints); in add_taint_module()
174 void __noreturn __module_put_and_kthread_exit(struct module *mod, long code) in __module_put_and_kthread_exit() argument
176 module_put(mod); in __module_put_and_kthread_exit()
311 struct module *mod; in find_symbol() local
320 list_for_each_entry_rcu(mod, &modules, list, in find_symbol()
323 { mod->syms, mod->syms + mod->num_syms, mod->crcs, in find_symbol()
325 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, in find_symbol()
326 mod->gpl_crcs, in find_symbol()
330 if (mod->state == MODULE_STATE_UNFORMED) in find_symbol()
334 if (find_exported_symbol_in_section(&arr[i], mod, fsa)) in find_symbol()
349 struct module *mod; in find_module_all() local
353 list_for_each_entry_rcu(mod, &modules, list, in find_module_all()
355 if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) in find_module_all()
357 if (strlen(mod->name) == len && !memcmp(mod->name, name, len)) in find_module_all()
358 return mod; in find_module_all()
370 static inline void __percpu *mod_percpu(struct module *mod) in mod_percpu() argument
372 return mod->percpu; in mod_percpu()
375 static int percpu_modalloc(struct module *mod, struct load_info *info) in percpu_modalloc() argument
385 mod->name, align, PAGE_SIZE); in percpu_modalloc()
389 mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align); in percpu_modalloc()
390 if (!mod->percpu) { in percpu_modalloc()
392 mod->name, (unsigned long)pcpusec->sh_size); in percpu_modalloc()
395 mod->percpu_size = pcpusec->sh_size; in percpu_modalloc()
399 static void percpu_modfree(struct module *mod) in percpu_modfree() argument
401 free_percpu(mod->percpu); in percpu_modfree()
409 static void percpu_modcopy(struct module *mod, in percpu_modcopy() argument
415 memcpy(per_cpu_ptr(mod->percpu, cpu), from, size); in percpu_modcopy()
420 struct module *mod; in __is_module_percpu_address() local
425 list_for_each_entry_rcu(mod, &modules, list) { in __is_module_percpu_address()
426 if (mod->state == MODULE_STATE_UNFORMED) in __is_module_percpu_address()
428 if (!mod->percpu_size) in __is_module_percpu_address()
431 void *start = per_cpu_ptr(mod->percpu, cpu); in __is_module_percpu_address()
434 if (va >= start && va < start + mod->percpu_size) { in __is_module_percpu_address()
438 per_cpu_ptr(mod->percpu, in __is_module_percpu_address()
466 static inline void __percpu *mod_percpu(struct module *mod) in mod_percpu() argument
470 static int percpu_modalloc(struct module *mod, struct load_info *info) in percpu_modalloc() argument
477 static inline void percpu_modfree(struct module *mod) in percpu_modfree() argument
484 static inline void percpu_modcopy(struct module *mod, in percpu_modcopy() argument
503 static void setup_modinfo_##field(struct module *mod, const char *s) \
505 mod->field = kstrdup(s, GFP_KERNEL); \
510 return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field); \
512 static int modinfo_##field##_exists(struct module *mod) \
514 return mod->field != NULL; \
516 static void free_modinfo_##field(struct module *mod) \
518 kfree(mod->field); \
519 mod->field = NULL; \
545 static int module_unload_init(struct module *mod) in module_unload_init() argument
551 atomic_set(&mod->refcnt, MODULE_REF_BASE); in module_unload_init()
553 INIT_LIST_HEAD(&mod->source_list); in module_unload_init()
554 INIT_LIST_HEAD(&mod->target_list); in module_unload_init()
557 atomic_inc(&mod->refcnt); in module_unload_init()
620 static void module_unload_free(struct module *mod) in module_unload_free() argument
625 list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) { in module_unload_free()
627 pr_debug("%s unusing %s\n", mod->name, i->name); in module_unload_free()
652 static int try_release_module_ref(struct module *mod) in try_release_module_ref() argument
657 ret = atomic_sub_return(MODULE_REF_BASE, &mod->refcnt); in try_release_module_ref()
661 ret = atomic_add_unless(&mod->refcnt, MODULE_REF_BASE, 0); in try_release_module_ref()
666 static int try_stop_module(struct module *mod, int flags, int *forced) in try_stop_module() argument
669 if (try_release_module_ref(mod) != 0) { in try_stop_module()
676 mod->state = MODULE_STATE_GOING; in try_stop_module()
689 int module_refcount(struct module *mod) in module_refcount() argument
691 return atomic_read(&mod->refcnt) - MODULE_REF_BASE; in module_refcount()
696 static void free_module(struct module *mod);
701 struct module *mod; in SYSCALL_DEFINE2() local
718 mod = find_module(name); in SYSCALL_DEFINE2()
719 if (!mod) { in SYSCALL_DEFINE2()
724 if (!list_empty(&mod->source_list)) { in SYSCALL_DEFINE2()
731 if (mod->state != MODULE_STATE_LIVE) { in SYSCALL_DEFINE2()
733 pr_debug("%s already dying\n", mod->name); in SYSCALL_DEFINE2()
739 if (mod->init && !mod->exit) { in SYSCALL_DEFINE2()
748 ret = try_stop_module(mod, flags, &forced); in SYSCALL_DEFINE2()
754 if (mod->exit != NULL) in SYSCALL_DEFINE2()
755 mod->exit(); in SYSCALL_DEFINE2()
757 MODULE_STATE_GOING, mod); in SYSCALL_DEFINE2()
758 klp_module_going(mod); in SYSCALL_DEFINE2()
759 ftrace_release_mod(mod); in SYSCALL_DEFINE2()
764 strscpy(last_unloaded_module.name, mod->name, sizeof(last_unloaded_module.name)); in SYSCALL_DEFINE2()
765 …strscpy(last_unloaded_module.taints, module_flags(mod, buf, false), sizeof(last_unloaded_module.ta… in SYSCALL_DEFINE2()
767 free_module(mod); in SYSCALL_DEFINE2()
814 return sprintf(buffer, "%i\n", module_refcount(mk->mod)); in show_refcnt()
858 static inline void module_unload_free(struct module *mod) in module_unload_free() argument
867 static inline int module_unload_init(struct module *mod) in module_unload_init() argument
891 switch (mk->mod->state) { in show_initstate()
926 unsigned int size = mk->mod->mem[MOD_TEXT].size; in show_coresize()
930 size += mk->mod->mem[type].size; in show_coresize()
945 size += mk->mod->mem[type].size; in show_datasize()
959 size += mk->mod->mem[type].size; in show_initsize()
971 l = module_flags_taint(mk->mod->taints, buffer); in show_taint()
1000 int try_to_force_load(struct module *mod, const char *reason) in try_to_force_load() argument
1004 pr_warn("%s: %s: kernel tainted.\n", mod->name, reason); in try_to_force_load()
1005 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE); in try_to_force_load()
1064 struct module *mod) in verify_namespace_is_imported() argument
1081 mod->name, kernel_symbol_name(sym), namespace); in verify_namespace_is_imported()
1089 static bool inherit_taint(struct module *mod, struct module *owner, const char *name) in inherit_taint() argument
1094 if (mod->using_gplonly_symbols) { in inherit_taint()
1096 mod->name, name, owner->name); in inherit_taint()
1100 if (!test_bit(TAINT_PROPRIETARY_MODULE, &mod->taints)) { in inherit_taint()
1102 mod->name, name, owner->name); in inherit_taint()
1103 set_bit(TAINT_PROPRIETARY_MODULE, &mod->taints); in inherit_taint()
1109 static const struct kernel_symbol *resolve_symbol(struct module *mod, in resolve_symbol() argument
1116 .gplok = !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), in resolve_symbol()
1132 mod->using_gplonly_symbols = true; in resolve_symbol()
1134 if (!inherit_taint(mod, fsa.owner, name)) { in resolve_symbol()
1139 if (!check_version(info, name, mod, fsa.crc)) { in resolve_symbol()
1144 err = verify_namespace_is_imported(info, fsa.sym, mod); in resolve_symbol()
1150 err = ref_module(mod, fsa.owner); in resolve_symbol()
1165 resolve_symbol_wait(struct module *mod, in resolve_symbol_wait() argument
1173 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner)) in resolve_symbol_wait()
1177 mod->name, owner); in resolve_symbol_wait()
1192 void __weak module_arch_cleanup(struct module *mod) in module_arch_cleanup() argument
1196 void __weak module_arch_freeing_init(struct module *mod) in module_arch_freeing_init() argument
1221 static void free_mod_mem(struct module *mod) in free_mod_mem() argument
1224 struct module_memory *mod_mem = &mod->mem[type]; in free_mod_mem()
1236 lockdep_free_key_range(mod->mem[MOD_DATA].base, mod->mem[MOD_DATA].size); in free_mod_mem()
1237 module_memory_free(mod->mem[MOD_DATA].base, MOD_DATA); in free_mod_mem()
1241 static void free_module(struct module *mod) in free_module() argument
1243 trace_module_free(mod); in free_module()
1245 mod_sysfs_teardown(mod); in free_module()
1252 mod->state = MODULE_STATE_UNFORMED; in free_module()
1256 module_arch_cleanup(mod); in free_module()
1259 module_unload_free(mod); in free_module()
1262 destroy_params(mod->kp, mod->num_kp); in free_module()
1264 if (is_livepatch_module(mod)) in free_module()
1265 free_module_elf(mod); in free_module()
1270 list_del_rcu(&mod->list); in free_module()
1271 mod_tree_remove(mod); in free_module()
1273 module_bug_cleanup(mod); in free_module()
1276 if (try_add_tainted_module(mod)) in free_module()
1278 mod->name); in free_module()
1282 module_arch_freeing_init(mod); in free_module()
1283 kfree(mod->args); in free_module()
1284 percpu_modfree(mod); in free_module()
1286 free_mod_mem(mod); in free_module()
1321 static int verify_exported_symbols(struct module *mod) in verify_exported_symbols() argument
1329 { mod->syms, mod->num_syms }, in verify_exported_symbols()
1330 { mod->gpl_syms, mod->num_gpl_syms }, in verify_exported_symbols()
1342 mod->name, kernel_symbol_name(s), in verify_exported_symbols()
1367 static int simplify_symbols(struct module *mod, const struct load_info *info) in simplify_symbols() argument
1391 mod->name); in simplify_symbols()
1406 ksym = resolve_symbol_wait(mod, info, name); in simplify_symbols()
1421 mod->name, name, ret); in simplify_symbols()
1427 secbase = (unsigned long)mod_percpu(mod); in simplify_symbols()
1438 static int apply_relocations(struct module *mod, const struct load_info *info) in apply_relocations() argument
1456 err = klp_apply_section_relocs(mod, info->sechdrs, in apply_relocations()
1463 info->index.sym, i, mod); in apply_relocations()
1466 info->index.sym, i, mod); in apply_relocations()
1474 unsigned int __weak arch_mod_section_prepend(struct module *mod, in arch_mod_section_prepend() argument
1481 long module_get_offset_and_type(struct module *mod, enum mod_mem_type type, in module_get_offset_and_type() argument
1487 mod->mem[type].size += arch_mod_section_prepend(mod, section); in module_get_offset_and_type()
1488 offset = ALIGN(mod->mem[type].size, sechdr->sh_addralign ?: 1); in module_get_offset_and_type()
1489 mod->mem[type].size = offset + sechdr->sh_size; in module_get_offset_and_type()
1504 static void __layout_sections(struct module *mod, struct load_info *info, bool is_init) in __layout_sections() argument
1551 s->sh_entsize = module_get_offset_and_type(mod, type, s, i); in __layout_sections()
1563 static void layout_sections(struct module *mod, struct load_info *info) in layout_sections() argument
1570 pr_debug("Core section allocation order for %s:\n", mod->name); in layout_sections()
1571 __layout_sections(mod, info, false); in layout_sections()
1573 pr_debug("Init section allocation order for %s:\n", mod->name); in layout_sections()
1574 __layout_sections(mod, info, true); in layout_sections()
1577 static void module_license_taint_check(struct module *mod, const char *license) in module_license_taint_check() argument
1585 mod->name, license); in module_license_taint_check()
1586 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, in module_license_taint_check()
1591 static void setup_modinfo(struct module *mod, struct load_info *info) in setup_modinfo() argument
1598 attr->setup(mod, get_modinfo(info, attr->attr.name)); in setup_modinfo()
1602 static void free_modinfo(struct module *mod) in free_modinfo() argument
1609 attr->free(mod); in free_modinfo()
1877 info->index.mod = mod_idx; in elf_validity_cache_copy()
1880 info->mod = (void *)info->hdr + shdr->sh_offset; in elf_validity_cache_copy()
1887 info->name = info->mod->name; in elf_validity_cache_copy()
1919 static int check_modinfo_livepatch(struct module *mod, struct load_info *info) in check_modinfo_livepatch() argument
1925 if (set_livepatch_module(mod)) in check_modinfo_livepatch()
1929 mod->name); in check_modinfo_livepatch()
1933 static void check_modinfo_retpoline(struct module *mod, struct load_info *info) in check_modinfo_retpoline() argument
1939 mod->name); in check_modinfo_retpoline()
2010 static void module_augment_kernel_taints(struct module *mod, struct load_info *info) in module_augment_kernel_taints() argument
2017 mod->name); in module_augment_kernel_taints()
2018 add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK); in module_augment_kernel_taints()
2021 check_modinfo_retpoline(mod, info); in module_augment_kernel_taints()
2024 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK); in module_augment_kernel_taints()
2026 "is unknown, you have been warned.\n", mod->name); in module_augment_kernel_taints()
2029 if (is_livepatch_module(mod)) { in module_augment_kernel_taints()
2030 add_taint_module(mod, TAINT_LIVEPATCH, LOCKDEP_STILL_OK); in module_augment_kernel_taints()
2032 mod->name); in module_augment_kernel_taints()
2035 module_license_taint_check(mod, get_modinfo(info, "license")); in module_augment_kernel_taints()
2040 mod->name); in module_augment_kernel_taints()
2041 add_taint_module(mod, TAINT_TEST, LOCKDEP_STILL_OK); in module_augment_kernel_taints()
2044 mod->sig_ok = info->sig_ok; in module_augment_kernel_taints()
2045 if (!mod->sig_ok) { in module_augment_kernel_taints()
2048 "kernel\n", mod->name); in module_augment_kernel_taints()
2049 add_taint_module(mod, TAINT_UNSIGNED_MODULE, LOCKDEP_STILL_OK); in module_augment_kernel_taints()
2058 if (strcmp(mod->name, "ndiswrapper") == 0) in module_augment_kernel_taints()
2062 if (strcmp(mod->name, "driverloader") == 0) in module_augment_kernel_taints()
2063 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, in module_augment_kernel_taints()
2067 if (strcmp(mod->name, "lve") == 0) in module_augment_kernel_taints()
2068 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, in module_augment_kernel_taints()
2072 pr_warn("%s: module license taints kernel.\n", mod->name); in module_augment_kernel_taints()
2076 static int check_modinfo(struct module *mod, struct load_info *info, int flags) in check_modinfo() argument
2086 err = try_to_force_load(mod, "bad vermagic"); in check_modinfo()
2095 err = check_modinfo_livepatch(mod, info); in check_modinfo()
2102 static int find_module_sections(struct module *mod, struct load_info *info) in find_module_sections() argument
2104 mod->kp = section_objs(info, "__param", in find_module_sections()
2105 sizeof(*mod->kp), &mod->num_kp); in find_module_sections()
2106 mod->syms = section_objs(info, "__ksymtab", in find_module_sections()
2107 sizeof(*mod->syms), &mod->num_syms); in find_module_sections()
2108 mod->crcs = section_addr(info, "__kcrctab"); in find_module_sections()
2109 mod->gpl_syms = section_objs(info, "__ksymtab_gpl", in find_module_sections()
2110 sizeof(*mod->gpl_syms), in find_module_sections()
2111 &mod->num_gpl_syms); in find_module_sections()
2112 mod->gpl_crcs = section_addr(info, "__kcrctab_gpl"); in find_module_sections()
2115 mod->ctors = section_objs(info, ".ctors", in find_module_sections()
2116 sizeof(*mod->ctors), &mod->num_ctors); in find_module_sections()
2117 if (!mod->ctors) in find_module_sections()
2118 mod->ctors = section_objs(info, ".init_array", in find_module_sections()
2119 sizeof(*mod->ctors), &mod->num_ctors); in find_module_sections()
2126 mod->name); in find_module_sections()
2131 mod->noinstr_text_start = section_objs(info, ".noinstr.text", 1, in find_module_sections()
2132 &mod->noinstr_text_size); in find_module_sections()
2135 mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs", in find_module_sections()
2136 sizeof(*mod->tracepoints_ptrs), in find_module_sections()
2137 &mod->num_tracepoints); in find_module_sections()
2140 mod->srcu_struct_ptrs = section_objs(info, "___srcu_struct_ptrs", in find_module_sections()
2141 sizeof(*mod->srcu_struct_ptrs), in find_module_sections()
2142 &mod->num_srcu_structs); in find_module_sections()
2145 mod->bpf_raw_events = section_objs(info, "__bpf_raw_tp_map", in find_module_sections()
2146 sizeof(*mod->bpf_raw_events), in find_module_sections()
2147 &mod->num_bpf_raw_events); in find_module_sections()
2150 mod->btf_data = any_section_objs(info, ".BTF", 1, &mod->btf_data_size); in find_module_sections()
2153 mod->jump_entries = section_objs(info, "__jump_table", in find_module_sections()
2154 sizeof(*mod->jump_entries), in find_module_sections()
2155 &mod->num_jump_entries); in find_module_sections()
2158 mod->trace_events = section_objs(info, "_ftrace_events", in find_module_sections()
2159 sizeof(*mod->trace_events), in find_module_sections()
2160 &mod->num_trace_events); in find_module_sections()
2161 mod->trace_evals = section_objs(info, "_ftrace_eval_map", in find_module_sections()
2162 sizeof(*mod->trace_evals), in find_module_sections()
2163 &mod->num_trace_evals); in find_module_sections()
2166 mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt", in find_module_sections()
2167 sizeof(*mod->trace_bprintk_fmt_start), in find_module_sections()
2168 &mod->num_trace_bprintk_fmt); in find_module_sections()
2172 mod->ftrace_callsites = section_objs(info, FTRACE_CALLSITE_SECTION, in find_module_sections()
2173 sizeof(*mod->ftrace_callsites), in find_module_sections()
2174 &mod->num_ftrace_callsites); in find_module_sections()
2177 mod->ei_funcs = section_objs(info, "_error_injection_whitelist", in find_module_sections()
2178 sizeof(*mod->ei_funcs), in find_module_sections()
2179 &mod->num_ei_funcs); in find_module_sections()
2182 mod->kprobes_text_start = section_objs(info, ".kprobes.text", 1, in find_module_sections()
2183 &mod->kprobes_text_size); in find_module_sections()
2184 mod->kprobe_blacklist = section_objs(info, "_kprobe_blacklist", in find_module_sections()
2186 &mod->num_kprobe_blacklist); in find_module_sections()
2189 mod->printk_index_start = section_objs(info, ".printk_index", in find_module_sections()
2190 sizeof(*mod->printk_index_start), in find_module_sections()
2191 &mod->printk_index_size); in find_module_sections()
2194 mod->static_call_sites = section_objs(info, ".static_call_sites", in find_module_sections()
2195 sizeof(*mod->static_call_sites), in find_module_sections()
2196 &mod->num_static_call_sites); in find_module_sections()
2199 mod->kunit_suites = section_objs(info, ".kunit_test_suites", in find_module_sections()
2200 sizeof(*mod->kunit_suites), in find_module_sections()
2201 &mod->num_kunit_suites); in find_module_sections()
2204 mod->extable = section_objs(info, "__ex_table", in find_module_sections()
2205 sizeof(*mod->extable), &mod->num_exentries); in find_module_sections()
2208 pr_warn("%s: Ignoring obsolete parameters\n", mod->name); in find_module_sections()
2211 mod->dyndbg_info.descs = section_objs(info, "__dyndbg", in find_module_sections()
2212 sizeof(*mod->dyndbg_info.descs), in find_module_sections()
2213 &mod->dyndbg_info.num_descs); in find_module_sections()
2214 mod->dyndbg_info.classes = section_objs(info, "__dyndbg_classes", in find_module_sections()
2215 sizeof(*mod->dyndbg_info.classes), in find_module_sections()
2216 &mod->dyndbg_info.num_classes); in find_module_sections()
2222 static int move_module(struct module *mod, struct load_info *info) in move_module() argument
2230 if (!mod->mem[type].size) { in move_module()
2231 mod->mem[type].base = NULL; in move_module()
2234 mod->mem[type].size = PAGE_ALIGN(mod->mem[type].size); in move_module()
2235 ptr = module_memory_alloc(mod->mem[type].size, type); in move_module()
2252 memset(ptr, 0, mod->mem[type].size); in move_module()
2253 mod->mem[type].base = ptr; in move_module()
2257 pr_debug("Final section addresses for %s:\n", mod->name); in move_module()
2266 dest = mod->mem[type].base + (shdr->sh_entsize & SH_ENTSIZE_OFFSET_MASK); in move_module()
2275 if (i == info->index.mod && in move_module()
2296 module_memory_free(mod->mem[t].base, t); in move_module()
2300 static int check_export_symbol_versions(struct module *mod) in check_export_symbol_versions() argument
2303 if ((mod->num_syms && !mod->crcs) || in check_export_symbol_versions()
2304 (mod->num_gpl_syms && !mod->gpl_crcs)) { in check_export_symbol_versions()
2305 return try_to_force_load(mod, in check_export_symbol_versions()
2312 static void flush_module_icache(const struct module *mod) in flush_module_icache() argument
2320 const struct module_memory *mod_mem = &mod->mem[type]; in flush_module_icache()
2337 struct module *mod) in module_frob_arch_sections() argument
2365 struct module *mod; in layout_and_allocate() local
2371 info->secstrings, info->mod); in layout_and_allocate()
2376 info->secstrings, info->mod); in layout_and_allocate()
2406 layout_sections(info->mod, info); in layout_and_allocate()
2407 layout_symtab(info->mod, info); in layout_and_allocate()
2410 err = move_module(info->mod, info); in layout_and_allocate()
2415 mod = (void *)info->sechdrs[info->index.mod].sh_addr; in layout_and_allocate()
2416 kmemleak_load_module(mod, info); in layout_and_allocate()
2417 return mod; in layout_and_allocate()
2421 static void module_deallocate(struct module *mod, struct load_info *info) in module_deallocate() argument
2423 percpu_modfree(mod); in module_deallocate()
2424 module_arch_freeing_init(mod); in module_deallocate()
2426 free_mod_mem(mod); in module_deallocate()
2436 static int post_relocation(struct module *mod, const struct load_info *info) in post_relocation() argument
2439 sort_extable(mod->extable, mod->extable + mod->num_exentries); in post_relocation()
2442 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr, in post_relocation()
2446 add_kallsyms(mod, info); in post_relocation()
2449 return module_finalize(info->hdr, info->sechdrs, mod); in post_relocation()
2453 static void do_mod_ctors(struct module *mod) in do_mod_ctors() argument
2458 for (i = 0; i < mod->num_ctors; i++) in do_mod_ctors()
2459 mod->ctors[i](); in do_mod_ctors()
2501 static noinline int do_init_module(struct module *mod) in do_init_module() argument
2509 const struct module_memory *mod_mem = &mod->mem[type]; in do_init_module()
2523 freeinit->init_text = mod->mem[MOD_INIT_TEXT].base; in do_init_module()
2524 freeinit->init_data = mod->mem[MOD_INIT_DATA].base; in do_init_module()
2525 freeinit->init_rodata = mod->mem[MOD_INIT_RODATA].base; in do_init_module()
2527 do_mod_ctors(mod); in do_init_module()
2529 if (mod->init != NULL) in do_init_module()
2530 ret = do_one_initcall(mod->init); in do_init_module()
2538 __func__, mod->name, ret, __func__); in do_init_module()
2543 mod->state = MODULE_STATE_LIVE; in do_init_module()
2545 MODULE_STATE_LIVE, mod); in do_init_module()
2548 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); in do_init_module()
2558 if (!mod->async_probe_requested) in do_init_module()
2561 ftrace_free_mem(mod, mod->mem[MOD_INIT_TEXT].base, in do_init_module()
2562 mod->mem[MOD_INIT_TEXT].base + mod->mem[MOD_INIT_TEXT].size); in do_init_module()
2565 module_put(mod); in do_init_module()
2566 trim_init_extable(mod); in do_init_module()
2569 rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms); in do_init_module()
2571 module_enable_ro(mod, true); in do_init_module()
2572 mod_tree_remove_init(mod); in do_init_module()
2573 module_arch_freeing_init(mod); in do_init_module()
2575 mod->mem[type].base = NULL; in do_init_module()
2576 mod->mem[type].size = 0; in do_init_module()
2581 mod->btf_data = NULL; in do_init_module()
2613 mod->state = MODULE_STATE_GOING; in do_init_module()
2615 module_put(mod); in do_init_module()
2617 MODULE_STATE_GOING, mod); in do_init_module()
2618 klp_module_going(mod); in do_init_module()
2619 ftrace_release_mod(mod); in do_init_module()
2620 free_module(mod); in do_init_module()
2637 struct module *mod; in finished_loading() local
2647 mod = find_module_all(name, strlen(name), true); in finished_loading()
2648 ret = !mod || mod->state == MODULE_STATE_LIVE in finished_loading()
2649 || mod->state == MODULE_STATE_GOING; in finished_loading()
2700 static int add_unformed_module(struct module *mod) in add_unformed_module() argument
2704 mod->state = MODULE_STATE_UNFORMED; in add_unformed_module()
2707 err = module_patient_check_exists(mod->name, FAIL_DUP_MOD_LOAD); in add_unformed_module()
2711 mod_update_bounds(mod); in add_unformed_module()
2712 list_add_rcu(&mod->list, &modules); in add_unformed_module()
2713 mod_tree_insert(mod); in add_unformed_module()
2721 static int complete_formation(struct module *mod, struct load_info *info) in complete_formation() argument
2728 err = verify_exported_symbols(mod); in complete_formation()
2733 module_bug_finalize(info->hdr, info->sechdrs, mod); in complete_formation()
2734 module_cfi_finalize(info->hdr, info->sechdrs, mod); in complete_formation()
2736 module_enable_ro(mod, false); in complete_formation()
2737 module_enable_nx(mod); in complete_formation()
2738 module_enable_x(mod); in complete_formation()
2744 mod->state = MODULE_STATE_COMING; in complete_formation()
2754 static int prepare_coming_module(struct module *mod) in prepare_coming_module() argument
2758 ftrace_module_enable(mod); in prepare_coming_module()
2759 err = klp_module_coming(mod); in prepare_coming_module()
2764 MODULE_STATE_COMING, MODULE_STATE_GOING, mod); in prepare_coming_module()
2767 klp_module_going(mod); in prepare_coming_module()
2775 struct module *mod = arg; in unknown_module_param_cb() local
2779 if (kstrtobool(val, &mod->async_probe_requested)) in unknown_module_param_cb()
2780 mod->async_probe_requested = true; in unknown_module_param_cb()
2810 if (!check_modstruct_version(info, info->mod)) in early_mod_check()
2813 err = check_modinfo(info->mod, info, flags); in early_mod_check()
2818 err = module_patient_check_exists(info->mod->name, FAIL_DUP_MOD_BECOMING); in early_mod_check()
2831 struct module *mod; in load_module() local
2866 mod = layout_and_allocate(info, flags); in load_module()
2867 if (IS_ERR(mod)) { in load_module()
2868 err = PTR_ERR(mod); in load_module()
2874 audit_log_kern_module(mod->name); in load_module()
2877 err = add_unformed_module(mod); in load_module()
2885 module_augment_kernel_taints(mod, info); in load_module()
2888 err = percpu_modalloc(mod, info); in load_module()
2893 err = module_unload_init(mod); in load_module()
2897 init_param_lock(mod); in load_module()
2903 err = find_module_sections(mod, info); in load_module()
2907 err = check_export_symbol_versions(mod); in load_module()
2912 setup_modinfo(mod, info); in load_module()
2915 err = simplify_symbols(mod, info); in load_module()
2919 err = apply_relocations(mod, info); in load_module()
2923 err = post_relocation(mod, info); in load_module()
2927 flush_module_icache(mod); in load_module()
2930 mod->args = strndup_user(uargs, ~0UL >> 1); in load_module()
2931 if (IS_ERR(mod->args)) { in load_module()
2932 err = PTR_ERR(mod->args); in load_module()
2936 init_build_id(mod, info); in load_module()
2939 ftrace_module_init(mod); in load_module()
2942 err = complete_formation(mod, info); in load_module()
2946 err = prepare_coming_module(mod); in load_module()
2950 mod->async_probe_requested = async_probe; in load_module()
2953 after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, in load_module()
2954 -32768, 32767, mod, in load_module()
2961 mod->name, after_dashes); in load_module()
2965 err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp); in load_module()
2969 if (is_livepatch_module(mod)) { in load_module()
2970 err = copy_module_elf(mod, info); in load_module()
2979 trace_module_load(mod); in load_module()
2981 return do_init_module(mod); in load_module()
2984 mod_sysfs_teardown(mod); in load_module()
2986 mod->state = MODULE_STATE_GOING; in load_module()
2987 destroy_params(mod->kp, mod->num_kp); in load_module()
2989 MODULE_STATE_GOING, mod); in load_module()
2990 klp_module_going(mod); in load_module()
2992 mod->state = MODULE_STATE_GOING; in load_module()
2995 module_bug_cleanup(mod); in load_module()
2999 ftrace_release_mod(mod); in load_module()
3001 kfree(mod->args); in load_module()
3003 module_arch_cleanup(mod); in load_module()
3005 free_modinfo(mod); in load_module()
3007 module_unload_free(mod); in load_module()
3011 list_del_rcu(&mod->list); in load_module()
3012 mod_tree_remove(mod); in load_module()
3021 lockdep_free_key_range(mod->mem[type].base, in load_module()
3022 mod->mem[type].size); in load_module()
3025 module_deallocate(mod, info); in load_module()
3192 char *module_flags(struct module *mod, char *buf, bool show_state) in module_flags() argument
3196 BUG_ON(mod->state == MODULE_STATE_UNFORMED); in module_flags()
3197 if (!mod->taints && !show_state) in module_flags()
3199 if (mod->taints || in module_flags()
3200 mod->state == MODULE_STATE_GOING || in module_flags()
3201 mod->state == MODULE_STATE_COMING) { in module_flags()
3203 bx += module_flags_taint(mod->taints, buf + bx); in module_flags()
3205 if (mod->state == MODULE_STATE_GOING && show_state) in module_flags()
3208 if (mod->state == MODULE_STATE_COMING && show_state) in module_flags()
3222 struct module *mod; in search_module_extables() local
3225 mod = __module_address(addr); in search_module_extables()
3226 if (!mod) in search_module_extables()
3229 if (!mod->num_exentries) in search_module_extables()
3232 e = search_extable(mod->extable, in search_module_extables()
3233 mod->num_exentries, in search_module_extables()
3272 struct module *mod; in __module_address() local
3287 mod = mod_find(addr, &mod_tree); in __module_address()
3288 if (mod) { in __module_address()
3289 BUG_ON(!within_module(addr, mod)); in __module_address()
3290 if (mod->state == MODULE_STATE_UNFORMED) in __module_address()
3291 mod = NULL; in __module_address()
3293 return mod; in __module_address()
3324 struct module *mod = __module_address(addr); in __module_text_address() local
3325 if (mod) { in __module_text_address()
3327 if (!within_module_mem_type(addr, mod, MOD_TEXT) && in __module_text_address()
3328 !within_module_mem_type(addr, mod, MOD_INIT_TEXT)) in __module_text_address()
3329 mod = NULL; in __module_text_address()
3331 return mod; in __module_text_address()
3337 struct module *mod; in print_modules() local
3343 list_for_each_entry_rcu(mod, &modules, list) { in print_modules()
3344 if (mod->state == MODULE_STATE_UNFORMED) in print_modules()
3346 pr_cont(" %s%s", mod->name, module_flags(mod, buf, true)); in print_modules()