Lines Matching refs:info
181 static unsigned int find_sec(const struct load_info *info, const char *name) in find_sec() argument
185 for (i = 1; i < info->hdr->e_shnum; i++) { in find_sec()
186 Elf_Shdr *shdr = &info->sechdrs[i]; in find_sec()
189 && strcmp(info->secstrings + shdr->sh_name, name) == 0) in find_sec()
196 static void *section_addr(const struct load_info *info, const char *name) in section_addr() argument
199 return (void *)info->sechdrs[find_sec(info, name)].sh_addr; in section_addr()
203 static void *section_objs(const struct load_info *info, in section_objs() argument
208 unsigned int sec = find_sec(info, name); in section_objs()
211 *num = info->sechdrs[sec].sh_size / object_size; in section_objs()
212 return (void *)info->sechdrs[sec].sh_addr; in section_objs()
216 static unsigned int find_any_sec(const struct load_info *info, const char *name) in find_any_sec() argument
220 for (i = 1; i < info->hdr->e_shnum; i++) { in find_any_sec()
221 Elf_Shdr *shdr = &info->sechdrs[i]; in find_any_sec()
222 if (strcmp(info->secstrings + shdr->sh_name, name) == 0) in find_any_sec()
232 static __maybe_unused void *any_section_objs(const struct load_info *info, in any_section_objs() argument
237 unsigned int sec = find_any_sec(info, name); in any_section_objs()
240 *num = info->sechdrs[sec].sh_size / object_size; in any_section_objs()
241 return (void *)info->sechdrs[sec].sh_addr; in any_section_objs()
374 static int percpu_modalloc(struct module *mod, struct load_info *info) in percpu_modalloc() argument
376 Elf_Shdr *pcpusec = &info->sechdrs[info->index.pcpu]; in percpu_modalloc()
403 static unsigned int find_pcpusec(struct load_info *info) in find_pcpusec() argument
405 return find_sec(info, ".data..percpu"); in find_pcpusec()
469 static int percpu_modalloc(struct module *mod, struct load_info *info) in percpu_modalloc() argument
472 if (info->sechdrs[info->index.pcpu].sh_size != 0) in percpu_modalloc()
479 static unsigned int find_pcpusec(struct load_info *info) in find_pcpusec() argument
1008 static char *get_modinfo(const struct load_info *info, const char *tag);
1009 static char *get_next_modinfo(const struct load_info *info, const char *tag,
1012 static int verify_namespace_is_imported(const struct load_info *info, in verify_namespace_is_imported() argument
1021 imported_namespace = get_modinfo(info, "import_ns"); in verify_namespace_is_imported()
1026 info, "import_ns", imported_namespace); in verify_namespace_is_imported()
1063 const struct load_info *info, in resolve_symbol() argument
1092 if (!check_version(info, name, mod, fsa.crc)) { in resolve_symbol()
1097 err = verify_namespace_is_imported(info, fsa.sym, mod); in resolve_symbol()
1134 const struct load_info *info, in resolve_symbol_wait() argument
1141 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner)) in resolve_symbol_wait()
1316 static int simplify_symbols(struct module *mod, const struct load_info *info) in simplify_symbols() argument
1318 Elf_Shdr *symsec = &info->sechdrs[info->index.sym]; in simplify_symbols()
1326 const char *name = info->strtab + sym[i].st_name; in simplify_symbols()
1355 ksym = resolve_symbol_wait(mod, info, name); in simplify_symbols()
1365 ignore_undef_symbol(info->hdr->e_machine, name))) in simplify_symbols()
1381 if (sym[i].st_shndx == info->index.pcpu) in simplify_symbols()
1384 secbase = info->sechdrs[sym[i].st_shndx].sh_addr; in simplify_symbols()
1393 static int apply_relocations(struct module *mod, const struct load_info *info) in apply_relocations() argument
1399 for (i = 1; i < info->hdr->e_shnum; i++) { in apply_relocations()
1400 unsigned int infosec = info->sechdrs[i].sh_info; in apply_relocations()
1403 if (infosec >= info->hdr->e_shnum) in apply_relocations()
1407 if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC)) in apply_relocations()
1410 if (info->sechdrs[i].sh_flags & SHF_RELA_LIVEPATCH) in apply_relocations()
1411 err = klp_apply_section_relocs(mod, info->sechdrs, in apply_relocations()
1412 info->secstrings, in apply_relocations()
1413 info->strtab, in apply_relocations()
1414 info->index.sym, i, in apply_relocations()
1416 else if (info->sechdrs[i].sh_type == SHT_REL) in apply_relocations()
1417 err = apply_relocate(info->sechdrs, info->strtab, in apply_relocations()
1418 info->index.sym, i, mod); in apply_relocations()
1419 else if (info->sechdrs[i].sh_type == SHT_RELA) in apply_relocations()
1420 err = apply_relocate_add(info->sechdrs, info->strtab, in apply_relocations()
1421 info->index.sym, i, mod); in apply_relocations()
1463 static void layout_sections(struct module *mod, struct load_info *info) in layout_sections() argument
1479 for (i = 0; i < info->hdr->e_shnum; i++) in layout_sections()
1480 info->sechdrs[i].sh_entsize = ~0UL; in layout_sections()
1484 for (i = 0; i < info->hdr->e_shnum; ++i) { in layout_sections()
1485 Elf_Shdr *s = &info->sechdrs[i]; in layout_sections()
1486 const char *sname = info->secstrings + s->sh_name; in layout_sections()
1519 for (i = 0; i < info->hdr->e_shnum; ++i) { in layout_sections()
1520 Elf_Shdr *s = &info->sechdrs[i]; in layout_sections()
1521 const char *sname = info->secstrings + s->sh_name; in layout_sections()
1588 static char *get_next_modinfo(const struct load_info *info, const char *tag, in get_next_modinfo() argument
1593 Elf_Shdr *infosec = &info->sechdrs[info->index.info]; in get_next_modinfo()
1600 char *modinfo = (char *)info->hdr + infosec->sh_offset; in get_next_modinfo()
1614 static char *get_modinfo(const struct load_info *info, const char *tag) in get_modinfo() argument
1616 return get_next_modinfo(info, tag, NULL); in get_modinfo()
1619 static void setup_modinfo(struct module *mod, struct load_info *info) in setup_modinfo() argument
1626 attr->setup(mod, get_modinfo(info, attr->attr.name)); in setup_modinfo()
1671 static int validate_section_offset(struct load_info *info, Elf_Shdr *shdr) in validate_section_offset() argument
1684 if (secend < shdr->sh_offset || secend > info->len) in validate_section_offset()
1696 static int elf_validity_check(struct load_info *info) in elf_validity_check() argument
1702 if (info->len < sizeof(*(info->hdr))) { in elf_validity_check()
1703 pr_err("Invalid ELF header len %lu\n", info->len); in elf_validity_check()
1707 if (memcmp(info->hdr->e_ident, ELFMAG, SELFMAG) != 0) { in elf_validity_check()
1711 if (info->hdr->e_type != ET_REL) { in elf_validity_check()
1713 info->hdr->e_type, ET_REL); in elf_validity_check()
1716 if (!elf_check_arch(info->hdr)) { in elf_validity_check()
1718 info->hdr->e_machine); in elf_validity_check()
1721 if (info->hdr->e_shentsize != sizeof(Elf_Shdr)) { in elf_validity_check()
1731 if (info->hdr->e_shoff >= info->len in elf_validity_check()
1732 || (info->hdr->e_shnum * sizeof(Elf_Shdr) > in elf_validity_check()
1733 info->len - info->hdr->e_shoff)) { in elf_validity_check()
1738 info->sechdrs = (void *)info->hdr + info->hdr->e_shoff; in elf_validity_check()
1743 if (info->hdr->e_shstrndx == SHN_UNDEF in elf_validity_check()
1744 || info->hdr->e_shstrndx >= info->hdr->e_shnum) { in elf_validity_check()
1746 info->hdr->e_shstrndx, info->hdr->e_shstrndx, in elf_validity_check()
1747 info->hdr->e_shnum); in elf_validity_check()
1751 strhdr = &info->sechdrs[info->hdr->e_shstrndx]; in elf_validity_check()
1752 err = validate_section_offset(info, strhdr); in elf_validity_check()
1763 info->secstrings = (void *)info->hdr + strhdr->sh_offset; in elf_validity_check()
1768 if (info->secstrings[strhdr->sh_size - 1] != '\0') { in elf_validity_check()
1777 if (info->sechdrs[0].sh_type != SHT_NULL in elf_validity_check()
1778 || info->sechdrs[0].sh_size != 0 in elf_validity_check()
1779 || info->sechdrs[0].sh_addr != 0) { in elf_validity_check()
1781 info->sechdrs[0].sh_type); in elf_validity_check()
1785 for (i = 1; i < info->hdr->e_shnum; i++) { in elf_validity_check()
1786 shdr = &info->sechdrs[i]; in elf_validity_check()
1793 || shdr->sh_link >= info->hdr->e_shnum) { in elf_validity_check()
1796 info->hdr->e_shnum); in elf_validity_check()
1801 err = validate_section_offset(info, shdr); in elf_validity_check()
1842 static int check_modinfo_livepatch(struct module *mod, struct load_info *info) in check_modinfo_livepatch() argument
1844 if (!get_modinfo(info, "livepatch")) in check_modinfo_livepatch()
1860 static void check_modinfo_retpoline(struct module *mod, struct load_info *info) in check_modinfo_retpoline() argument
1862 if (retpoline_module_ok(get_modinfo(info, "retpoline"))) in check_modinfo_retpoline()
1871 struct load_info *info) in copy_module_from_user() argument
1875 info->len = len; in copy_module_from_user()
1876 if (info->len < sizeof(*(info->hdr))) in copy_module_from_user()
1884 info->hdr = __vmalloc(info->len, GFP_KERNEL | __GFP_NOWARN); in copy_module_from_user()
1885 if (!info->hdr) in copy_module_from_user()
1888 if (copy_chunked_from_user(info->hdr, umod, info->len) != 0) { in copy_module_from_user()
1893 err = security_kernel_post_load_data((char *)info->hdr, info->len, in copy_module_from_user()
1897 vfree(info->hdr); in copy_module_from_user()
1902 static void free_copy(struct load_info *info, int flags) in free_copy() argument
1905 module_decompress_cleanup(info); in free_copy()
1907 vfree(info->hdr); in free_copy()
1910 static int rewrite_section_headers(struct load_info *info, int flags) in rewrite_section_headers() argument
1915 info->sechdrs[0].sh_addr = 0; in rewrite_section_headers()
1917 for (i = 1; i < info->hdr->e_shnum; i++) { in rewrite_section_headers()
1918 Elf_Shdr *shdr = &info->sechdrs[i]; in rewrite_section_headers()
1924 shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset; in rewrite_section_headers()
1929 info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC; in rewrite_section_headers()
1930 info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC; in rewrite_section_headers()
1943 static int setup_load_info(struct load_info *info, int flags) in setup_load_info() argument
1948 info->index.info = find_sec(info, ".modinfo"); in setup_load_info()
1949 if (info->index.info) in setup_load_info()
1950 info->name = get_modinfo(info, "name"); in setup_load_info()
1953 for (i = 1; i < info->hdr->e_shnum; i++) { in setup_load_info()
1954 if (info->sechdrs[i].sh_type == SHT_SYMTAB) { in setup_load_info()
1955 info->index.sym = i; in setup_load_info()
1956 info->index.str = info->sechdrs[i].sh_link; in setup_load_info()
1957 info->strtab = (char *)info->hdr in setup_load_info()
1958 + info->sechdrs[info->index.str].sh_offset; in setup_load_info()
1963 if (info->index.sym == 0) { in setup_load_info()
1965 info->name ?: "(missing .modinfo section or name field)"); in setup_load_info()
1969 info->index.mod = find_sec(info, ".gnu.linkonce.this_module"); in setup_load_info()
1970 if (!info->index.mod) { in setup_load_info()
1972 info->name ?: "(missing .modinfo section or name field)"); in setup_load_info()
1976 info->mod = (void *)info->hdr + info->sechdrs[info->index.mod].sh_offset; in setup_load_info()
1982 if (!info->name) in setup_load_info()
1983 info->name = info->mod->name; in setup_load_info()
1986 info->index.vers = 0; /* Pretend no __versions section! */ in setup_load_info()
1988 info->index.vers = find_sec(info, "__versions"); in setup_load_info()
1990 info->index.pcpu = find_pcpusec(info); in setup_load_info()
1995 static int check_modinfo(struct module *mod, struct load_info *info, int flags) in check_modinfo() argument
1997 const char *modmagic = get_modinfo(info, "vermagic"); in check_modinfo()
2008 } else if (!same_magic(modmagic, vermagic, info->index.vers)) { in check_modinfo()
2010 info->name, modmagic, vermagic); in check_modinfo()
2014 if (!get_modinfo(info, "intree")) { in check_modinfo()
2021 check_modinfo_retpoline(mod, info); in check_modinfo()
2023 if (get_modinfo(info, "staging")) { in check_modinfo()
2029 err = check_modinfo_livepatch(mod, info); in check_modinfo()
2034 set_license(mod, get_modinfo(info, "license")); in check_modinfo()
2036 if (get_modinfo(info, "test")) { in check_modinfo()
2046 static int find_module_sections(struct module *mod, struct load_info *info) in find_module_sections() argument
2048 mod->kp = section_objs(info, "__param", in find_module_sections()
2050 mod->syms = section_objs(info, "__ksymtab", in find_module_sections()
2052 mod->crcs = section_addr(info, "__kcrctab"); in find_module_sections()
2053 mod->gpl_syms = section_objs(info, "__ksymtab_gpl", in find_module_sections()
2056 mod->gpl_crcs = section_addr(info, "__kcrctab_gpl"); in find_module_sections()
2059 mod->ctors = section_objs(info, ".ctors", in find_module_sections()
2062 mod->ctors = section_objs(info, ".init_array", in find_module_sections()
2064 else if (find_sec(info, ".init_array")) { in find_module_sections()
2075 mod->noinstr_text_start = section_objs(info, ".noinstr.text", 1, in find_module_sections()
2079 mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs", in find_module_sections()
2084 mod->srcu_struct_ptrs = section_objs(info, "___srcu_struct_ptrs", in find_module_sections()
2089 mod->bpf_raw_events = section_objs(info, "__bpf_raw_tp_map", in find_module_sections()
2094 mod->btf_data = any_section_objs(info, ".BTF", 1, &mod->btf_data_size); in find_module_sections()
2097 mod->jump_entries = section_objs(info, "__jump_table", in find_module_sections()
2102 mod->trace_events = section_objs(info, "_ftrace_events", in find_module_sections()
2105 mod->trace_evals = section_objs(info, "_ftrace_eval_map", in find_module_sections()
2110 mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt", in find_module_sections()
2116 mod->ftrace_callsites = section_objs(info, FTRACE_CALLSITE_SECTION, in find_module_sections()
2121 mod->ei_funcs = section_objs(info, "_error_injection_whitelist", in find_module_sections()
2126 mod->kprobes_text_start = section_objs(info, ".kprobes.text", 1, in find_module_sections()
2128 mod->kprobe_blacklist = section_objs(info, "_kprobe_blacklist", in find_module_sections()
2133 mod->printk_index_start = section_objs(info, ".printk_index", in find_module_sections()
2138 mod->static_call_sites = section_objs(info, ".static_call_sites", in find_module_sections()
2143 mod->kunit_suites = section_objs(info, ".kunit_test_suites", in find_module_sections()
2148 mod->extable = section_objs(info, "__ex_table", in find_module_sections()
2151 if (section_addr(info, "__obsparm")) in find_module_sections()
2154 info->dyndbg.descs = section_objs(info, "__dyndbg", in find_module_sections()
2155 sizeof(*info->dyndbg.descs), &info->dyndbg.num_descs); in find_module_sections()
2156 info->dyndbg.classes = section_objs(info, "__dyndbg_classes", in find_module_sections()
2157 sizeof(*info->dyndbg.classes), &info->dyndbg.num_classes); in find_module_sections()
2162 static int move_module(struct module *mod, struct load_info *info) in move_module() argument
2218 for (i = 0; i < info->hdr->e_shnum; i++) { in move_module()
2220 Elf_Shdr *shdr = &info->sechdrs[i]; in move_module()
2238 (long)shdr->sh_addr, info->secstrings + shdr->sh_name); in move_module()
2323 static struct module *layout_and_allocate(struct load_info *info, int flags) in layout_and_allocate() argument
2329 err = check_modinfo(info->mod, info, flags); in layout_and_allocate()
2334 err = module_frob_arch_sections(info->hdr, info->sechdrs, in layout_and_allocate()
2335 info->secstrings, info->mod); in layout_and_allocate()
2339 err = module_enforce_rwx_sections(info->hdr, info->sechdrs, in layout_and_allocate()
2340 info->secstrings, info->mod); in layout_and_allocate()
2345 info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC; in layout_and_allocate()
2352 ndx = find_sec(info, ".data..ro_after_init"); in layout_and_allocate()
2354 info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT; in layout_and_allocate()
2361 ndx = find_sec(info, "__jump_table"); in layout_and_allocate()
2363 info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT; in layout_and_allocate()
2370 layout_sections(info->mod, info); in layout_and_allocate()
2371 layout_symtab(info->mod, info); in layout_and_allocate()
2374 err = move_module(info->mod, info); in layout_and_allocate()
2379 mod = (void *)info->sechdrs[info->index.mod].sh_addr; in layout_and_allocate()
2380 kmemleak_load_module(mod, info); in layout_and_allocate()
2385 static void module_deallocate(struct module *mod, struct load_info *info) in module_deallocate() argument
2405 static int post_relocation(struct module *mod, const struct load_info *info) in post_relocation() argument
2411 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr, in post_relocation()
2412 info->sechdrs[info->index.pcpu].sh_size); in post_relocation()
2415 add_kallsyms(mod, info); in post_relocation()
2418 return module_finalize(info->hdr, info->sechdrs, mod); in post_relocation()
2656 static int complete_formation(struct module *mod, struct load_info *info) in complete_formation() argument
2668 module_bug_finalize(info->hdr, info->sechdrs, mod); in complete_formation()
2669 module_cfi_finalize(info->hdr, info->sechdrs, mod); in complete_formation()
2736 static int load_module(struct load_info *info, const char __user *uargs, in load_module() argument
2755 err = module_sig_check(info, flags); in load_module()
2763 err = elf_validity_check(info); in load_module()
2771 err = setup_load_info(info, flags); in load_module()
2779 if (blacklisted(info->name)) { in load_module()
2781 pr_err("Module %s is blacklisted\n", info->name); in load_module()
2785 err = rewrite_section_headers(info, flags); in load_module()
2790 if (!check_modstruct_version(info, info->mod)) { in load_module()
2796 mod = layout_and_allocate(info, flags); in load_module()
2810 mod->sig_ok = info->sig_ok; in load_module()
2822 err = percpu_modalloc(mod, info); in load_module()
2837 err = find_module_sections(mod, info); in load_module()
2846 setup_modinfo(mod, info); in load_module()
2849 err = simplify_symbols(mod, info); in load_module()
2853 err = apply_relocations(mod, info); in load_module()
2857 err = post_relocation(mod, info); in load_module()
2870 init_build_id(mod, info); in load_module()
2871 dynamic_debug_setup(mod, &info->dyndbg); in load_module()
2877 err = complete_formation(mod, info); in load_module()
2900 err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp); in load_module()
2905 err = copy_module_elf(mod, info); in load_module()
2911 free_copy(info, flags); in load_module()
2935 dynamic_debug_remove(mod, &info->dyndbg); in load_module()
2957 module_deallocate(mod, info); in load_module()
2959 free_copy(info, flags); in load_module()
2967 struct load_info info = { }; in SYSCALL_DEFINE3() local
2976 err = copy_module_from_user(umod, len, &info); in SYSCALL_DEFINE3()
2980 return load_module(&info, uargs, 0); in SYSCALL_DEFINE3()
2985 struct load_info info = { }; in SYSCALL_DEFINE3() local
3007 err = module_decompress(&info, buf, len); in SYSCALL_DEFINE3()
3012 info.hdr = buf; in SYSCALL_DEFINE3()
3013 info.len = len; in SYSCALL_DEFINE3()
3016 return load_module(&info, uargs, flags); in SYSCALL_DEFINE3()