Lines Matching +full:foo +full:- +full:queue

1 // SPDX-License-Identifier: GPL-2.0-or-later
79 /* Work queue for freeing init sections in success case */
85 .addr_min = -1UL,
106 if (min < tree->data_addr_min) in __mod_update_bounds()
107 tree->data_addr_min = min; in __mod_update_bounds()
108 if (max > tree->data_addr_max) in __mod_update_bounds()
109 tree->data_addr_max = max; in __mod_update_bounds()
113 if (min < tree->addr_min) in __mod_update_bounds()
114 tree->addr_min = min; in __mod_update_bounds()
115 if (max > tree->addr_max) in __mod_update_bounds()
116 tree->addr_max = max; in __mod_update_bounds()
122 struct module_memory *mod_mem = &mod->mem[type]; in mod_update_bounds()
124 if (mod_mem->size) in mod_update_bounds()
125 __mod_update_bounds(type, mod_mem->base, mod_mem->size, &mod_tree); in mod_update_bounds()
185 BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED); in strong_try_module_get()
186 if (mod && mod->state == MODULE_STATE_COMING) in strong_try_module_get()
187 return -EBUSY; in strong_try_module_get()
191 return -ENOENT; in strong_try_module_get()
198 set_bit(flag, &mod->taints); in add_taint_module()
202 * Like strncmp(), except s/-/_/g as per scripts/Makefile.lib:name-fix-token rule.
211 if (a == '-') a = '_'; in mod_strncmp()
212 if (b == '-') b = '_'; in mod_strncmp()
214 d = a - b; in mod_strncmp()
241 for (i = 1; i < info->hdr->e_shnum; i++) { in find_sec()
242 Elf_Shdr *shdr = &info->sechdrs[i]; in find_sec()
244 if ((shdr->sh_flags & SHF_ALLOC) in find_sec()
245 && strcmp(info->secstrings + shdr->sh_name, name) == 0) in find_sec()
252 * find_any_unique_sec() - Find a unique section index by name
267 for (i = 1; i < info->hdr->e_shnum; i++) { in find_any_unique_sec()
268 if (strcmp(info->secstrings + info->sechdrs[i].sh_name, in find_any_unique_sec()
279 return -count; in find_any_unique_sec()
287 return (void *)info->sechdrs[find_sec(info, name)].sh_addr; in section_addr()
299 *num = info->sechdrs[sec].sh_size / object_size; in section_objs()
300 return (void *)info->sechdrs[sec].sh_addr; in section_objs()
308 for (i = 1; i < info->hdr->e_shnum; i++) { in find_any_sec()
309 Elf_Shdr *shdr = &info->sechdrs[i]; in find_any_sec()
310 if (strcmp(info->secstrings + shdr->sh_name, name) == 0) in find_any_sec()
328 *num = info->sechdrs[sec].sh_size / object_size; in any_section_objs()
329 return (void *)info->sechdrs[sec].sh_addr; in any_section_objs()
341 return offset_to_ptr(&sym->name_offset); in kernel_symbol_name()
343 return sym->name; in kernel_symbol_name()
350 if (!sym->namespace_offset) in kernel_symbol_namespace()
352 return offset_to_ptr(&sym->namespace_offset); in kernel_symbol_namespace()
354 return sym->namespace; in kernel_symbol_namespace()
370 sym = bsearch(fsa->name, syms->start, syms->stop - syms->start, in find_exported_symbol_in_section()
375 sym_flags = *(syms->flagstab + (sym - syms->start)); in find_exported_symbol_in_section()
376 if (!fsa->gplok && (sym_flags & KSYM_FLAG_GPL_ONLY)) in find_exported_symbol_in_section()
379 fsa->owner = owner; in find_exported_symbol_in_section()
380 fsa->crc = symversion(syms->crcs, sym - syms->start); in find_exported_symbol_in_section()
381 fsa->sym = sym; in find_exported_symbol_in_section()
382 fsa->license = (sym_flags & KSYM_FLAG_GPL_ONLY) ? GPL_ONLY : NOT_GPL_ONLY; in find_exported_symbol_in_section()
407 .start = mod->syms, in find_symbol()
408 .stop = mod->syms + mod->num_syms, in find_symbol()
409 .crcs = mod->crcs, in find_symbol()
410 .flagstab = mod->flagstab, in find_symbol()
413 if (mod->state == MODULE_STATE_UNFORMED) in find_symbol()
420 pr_debug("Failed to find symbol %s\n", fsa->name); in find_symbol()
425 * Search for module by name: must hold module_mutex (or RCU for read-only
435 if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) in find_module_all()
437 if (strlen(mod->name) == len && !memcmp(mod->name, name, len)) in find_module_all()
452 return mod->percpu; in mod_percpu()
457 Elf_Shdr *pcpusec = &info->sechdrs[info->index.pcpu]; in percpu_modalloc()
458 unsigned long align = pcpusec->sh_addralign; in percpu_modalloc()
460 if (!pcpusec->sh_size) in percpu_modalloc()
464 pr_warn("%s: per-cpu alignment %li > %li\n", in percpu_modalloc()
465 mod->name, align, PAGE_SIZE); in percpu_modalloc()
469 mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align); in percpu_modalloc()
470 if (!mod->percpu) { in percpu_modalloc()
472 mod->name, (unsigned long)pcpusec->sh_size); in percpu_modalloc()
473 return -ENOMEM; in percpu_modalloc()
475 mod->percpu_size = pcpusec->sh_size; in percpu_modalloc()
481 free_percpu(mod->percpu); in percpu_modfree()
495 memcpy(per_cpu_ptr(mod->percpu, cpu), from, size); in percpu_modcopy()
505 if (mod->state == MODULE_STATE_UNFORMED) in __is_module_percpu_address()
507 if (!mod->percpu_size) in __is_module_percpu_address()
510 void *start = per_cpu_ptr(mod->percpu, cpu); in __is_module_percpu_address()
513 if (va >= start && va < start + mod->percpu_size) { in __is_module_percpu_address()
515 *can_addr = (unsigned long) (va - start); in __is_module_percpu_address()
517 per_cpu_ptr(mod->percpu, in __is_module_percpu_address()
528 * is_module_percpu_address() - test whether address is from module static percpu
549 if (info->sechdrs[info->index.pcpu].sh_size != 0) in percpu_modalloc()
550 return -ENOMEM; in percpu_modalloc()
581 mod->field = kstrdup(s, GFP_KERNEL); \
586 return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field); \
590 return mod->field != NULL; \
594 kfree(mod->field); \
595 mod->field = NULL; \
610 mod->imported_namespaces = NULL; in setup_modinfo_import_ns()
616 return sysfs_emit(buffer, "%s\n", mk->mod->imported_namespaces); in show_modinfo_import_ns()
621 return mod->imported_namespaces != NULL; in modinfo_import_ns_exists()
626 kfree(mod->imported_namespaces); in free_modinfo_import_ns()
627 mod->imported_namespaces = NULL; in free_modinfo_import_ns()
657 atomic_set(&mod->refcnt, MODULE_REF_BASE); in module_unload_init()
659 INIT_LIST_HEAD(&mod->source_list); in module_unload_init()
660 INIT_LIST_HEAD(&mod->target_list); in module_unload_init()
663 atomic_inc(&mod->refcnt); in module_unload_init()
673 list_for_each_entry(use, &b->source_list, source_list) { in already_uses()
674 if (use->source == a) in already_uses()
677 pr_debug("%s does not use %s!\n", a->name, b->name); in already_uses()
683 * - we add 'a' as a "source", 'b' as a "target" of module use
684 * - the module_use is added to the list of 'b' sources (so
692 pr_debug("Allocating new usage for %s.\n", a->name); in add_module_usage()
695 return -ENOMEM; in add_module_usage()
697 use->source = a; in add_module_usage()
698 use->target = b; in add_module_usage()
699 list_add(&use->source_list, &b->source_list); in add_module_usage()
700 list_add(&use->target_list, &a->target_list); in add_module_usage()
731 list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) { in module_unload_free()
732 struct module *i = use->target; in module_unload_free()
733 pr_debug("%s unusing %s\n", mod->name, i->name); in module_unload_free()
735 list_del(&use->source_list); in module_unload_free()
736 list_del(&use->target_list); in module_unload_free()
763 ret = atomic_sub_return(MODULE_REF_BASE, &mod->refcnt); in try_release_module_ref()
767 ret = atomic_add_unless(&mod->refcnt, MODULE_REF_BASE, 0); in try_release_module_ref()
778 return -EWOULDBLOCK; in try_stop_module()
782 mod->state = MODULE_STATE_GOING; in try_stop_module()
788 * module_refcount() - return the refcount or -1 if unloading
792 * -1 if the module is in the process of unloading
797 return atomic_read(&mod->refcnt) - MODULE_REF_BASE; in module_refcount()
813 return -EPERM; in SYSCALL_DEFINE2()
817 return -ENOENT; in SYSCALL_DEFINE2()
824 return -EINTR; in SYSCALL_DEFINE2()
828 ret = -ENOENT; in SYSCALL_DEFINE2()
832 if (!list_empty(&mod->source_list)) { in SYSCALL_DEFINE2()
834 ret = -EWOULDBLOCK; in SYSCALL_DEFINE2()
839 if (mod->state != MODULE_STATE_LIVE) { in SYSCALL_DEFINE2()
841 pr_debug("%s already dying\n", mod->name); in SYSCALL_DEFINE2()
842 ret = -EBUSY; in SYSCALL_DEFINE2()
847 if (mod->init && !mod->exit) { in SYSCALL_DEFINE2()
851 ret = -EBUSY; in SYSCALL_DEFINE2()
862 if (mod->exit != NULL) in SYSCALL_DEFINE2()
863 mod->exit(); in SYSCALL_DEFINE2()
872 strscpy(last_unloaded_module.name, mod->name); in SYSCALL_DEFINE2()
920 return sprintf(buffer, "%i\n", module_refcount(mk->mod)); in show_refcnt()
929 atomic_inc(&module->refcnt); in __module_get()
942 atomic_inc_not_zero(&module->refcnt) != 0)) in try_module_get()
956 ret = atomic_dec_if_positive(&module->refcnt); in module_put()
997 switch (mk->mod->state) { in show_initstate()
1022 rc = kobject_synth_uevent(&mk->kobj, buffer, count); in store_uevent()
1032 unsigned int size = mk->mod->mem[MOD_TEXT].size; in show_coresize()
1036 size += mk->mod->mem[type].size; in show_coresize()
1051 size += mk->mod->mem[type].size; in show_datasize()
1065 size += mk->mod->mem[type].size; in show_initsize()
1077 l = module_flags_taint(mk->mod->taints, buffer); in show_taint()
1111 pr_warn("%s: %s: kernel tainted.\n", mod->name, reason); in try_to_force_load()
1115 return -ENOEXEC; in try_to_force_load()
1122 /* Skip non-zero chars */ in module_next_tag_pair()
1125 if ((*secsize)-- <= 1) in module_next_tag_pair()
1132 if ((*secsize)-- <= 1) in module_next_tag_pair()
1143 Elf_Shdr *infosec = &info->sechdrs[info->index.info]; in get_next_modinfo()
1144 unsigned long size = infosec->sh_size; in get_next_modinfo()
1150 char *modinfo = (char *)info->hdr + infosec->sh_offset; in get_next_modinfo()
1153 size -= prev - modinfo; in get_next_modinfo()
1170 * verify_module_namespace() - does @modname have access to this symbol's @namespace
1177 * The patterns only support tail-glob.
1191 len = sep - namespace; in verify_module_namespace()
1194 if (sep[-1] == '*') { in verify_module_namespace()
1195 len--; in verify_module_namespace()
1219 if (verify_module_namespace(namespace, mod->name)) in verify_namespace_is_imported()
1232 mod->name, kernel_symbol_name(sym), namespace); in verify_namespace_is_imported()
1234 return -EINVAL; in verify_namespace_is_imported()
1242 if (!owner || !test_bit(TAINT_PROPRIETARY_MODULE, &owner->taints)) in inherit_taint()
1245 if (mod->using_gplonly_symbols) { in inherit_taint()
1246 pr_err("%s: module using GPL-only symbols uses symbols %s from proprietary module %s.\n", in inherit_taint()
1247 mod->name, name, owner->name); in inherit_taint()
1251 if (!test_bit(TAINT_PROPRIETARY_MODULE, &mod->taints)) { in inherit_taint()
1253 mod->name, name, owner->name); in inherit_taint()
1254 set_bit(TAINT_PROPRIETARY_MODULE, &mod->taints); in inherit_taint()
1267 .gplok = !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), in resolve_symbol()
1283 mod->using_gplonly_symbols = true; in resolve_symbol()
1291 fsa.sym = ERR_PTR(-EINVAL); in resolve_symbol()
1325 || PTR_ERR(ksym) != -EBUSY, in resolve_symbol_wait()
1328 mod->name, owner); in resolve_symbol_wait()
1343 unsigned int size = PAGE_ALIGN(mod->mem[type].size); in module_memory_alloc()
1347 mod->mem[type].size = size; in module_memory_alloc()
1356 return -ENOMEM; in module_memory_alloc()
1358 mod->mem[type].is_rox = execmem_is_rox(execmem_type); in module_memory_alloc()
1371 if (!mod->mem[type].is_rox) in module_memory_alloc()
1375 mod->mem[type].base = ptr; in module_memory_alloc()
1383 struct module_memory *mem = &mod->mem[type]; in module_memory_restore_rox()
1385 if (mem->is_rox) in module_memory_restore_rox()
1386 execmem_restore_rox(mem->base, mem->size); in module_memory_restore_rox()
1392 struct module_memory *mem = &mod->mem[type]; in module_memory_free()
1394 execmem_free(mem->base); in module_memory_free()
1400 struct module_memory *mod_mem = &mod->mem[type]; in free_mod_mem()
1405 /* Free lock-classes; relies on the preceding sync_rcu(). */ in free_mod_mem()
1406 lockdep_free_key_range(mod_mem->base, mod_mem->size); in free_mod_mem()
1407 if (mod_mem->size) in free_mod_mem()
1412 lockdep_free_key_range(mod->mem[MOD_DATA].base, mod->mem[MOD_DATA].size); in free_mod_mem()
1430 mod->state = MODULE_STATE_UNFORMED; in free_module()
1433 /* Arch-specific cleanup. */ in free_module()
1440 module_destroy_params(mod->kp, mod->num_kp); in free_module()
1448 list_del_rcu(&mod->list); in free_module()
1452 /* Wait for RCU synchronizing before releasing mod->list and buglist. */ in free_module()
1456 mod->name); in free_module()
1461 kfree(mod->args); in free_module()
1479 pr_warn("failing symbol_get of non-GPLONLY symbol %s.\n", in __symbol_get()
1499 for (s = mod->syms; s < mod->syms + mod->num_syms; s++) { in verify_exported_symbols()
1506 mod->name, kernel_symbol_name(s), in verify_exported_symbols()
1508 return -ENOEXEC; in verify_exported_symbols()
1517 * On x86, PIC code and Clang non-PIC code may have call foo@PLT. GNU as in ignore_undef_symbol()
1518 * before 2.37 produces an unreferenced _GLOBAL_OFFSET_TABLE_ on x86-64. in ignore_undef_symbol()
1532 Elf_Shdr *symsec = &info->sechdrs[info->index.sym]; in simplify_symbols()
1533 Elf_Sym *sym = (void *)symsec->sh_addr; in simplify_symbols()
1539 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) { in simplify_symbols()
1540 const char *name = info->strtab + sym[i].st_name; in simplify_symbols()
1549 * We compiled with -fno-common. These are not in simplify_symbols()
1553 pr_warn("%s: please compile with -fno-common\n", in simplify_symbols()
1554 mod->name); in simplify_symbols()
1555 ret = -ENOEXEC; in simplify_symbols()
1579 ignore_undef_symbol(info->hdr->e_machine, name))) in simplify_symbols()
1582 ret = PTR_ERR(ksym) ?: -ENOENT; in simplify_symbols()
1584 mod->name, name, ret); in simplify_symbols()
1588 if (sym[i].st_shndx >= info->hdr->e_shnum) { in simplify_symbols()
1590 mod->name, name, sym[i].st_shndx, info->hdr->e_shnum - 1); in simplify_symbols()
1591 ret = -ENOEXEC; in simplify_symbols()
1596 if (sym[i].st_shndx == info->index.pcpu) in simplify_symbols()
1599 secbase = info->sechdrs[sym[i].st_shndx].sh_addr; in simplify_symbols()
1614 for (i = 1; i < info->hdr->e_shnum; i++) { in apply_relocations()
1615 unsigned int infosec = info->sechdrs[i].sh_info; in apply_relocations()
1618 if (infosec >= info->hdr->e_shnum) in apply_relocations()
1622 * Don't bother with non-allocated sections. in apply_relocations()
1625 * ELF template and subsequently copy it to the per-CPU destinations. in apply_relocations()
1627 if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC) && in apply_relocations()
1628 (!infosec || infosec != info->index.pcpu)) in apply_relocations()
1631 if (info->sechdrs[i].sh_flags & SHF_RELA_LIVEPATCH) in apply_relocations()
1632 err = klp_apply_section_relocs(mod, info->sechdrs, in apply_relocations()
1633 info->secstrings, in apply_relocations()
1634 info->strtab, in apply_relocations()
1635 info->index.sym, i, in apply_relocations()
1637 else if (info->sechdrs[i].sh_type == SHT_REL) in apply_relocations()
1638 err = apply_relocate(info->sechdrs, info->strtab, in apply_relocations()
1639 info->index.sym, i, mod); in apply_relocations()
1640 else if (info->sechdrs[i].sh_type == SHT_RELA) in apply_relocations()
1641 err = apply_relocate_add(info->sechdrs, info->strtab, in apply_relocations()
1642 info->index.sym, i, mod); in apply_relocations()
1663 mod->mem[type].size += arch_mod_section_prepend(mod, section); in module_get_offset_and_type()
1664 offset = ALIGN(mod->mem[type].size, sechdr->sh_addralign ?: 1); in module_get_offset_and_type()
1665 mod->mem[type].size = offset + sechdr->sh_size; in module_get_offset_and_type()
1713 for (i = 0; i < info->hdr->e_shnum; ++i) { in __layout_sections()
1714 Elf_Shdr *s = &info->sechdrs[i]; in __layout_sections()
1715 const char *sname = info->secstrings + s->sh_name; in __layout_sections()
1717 if ((s->sh_flags & masks[m][0]) != masks[m][0] in __layout_sections()
1718 || (s->sh_flags & masks[m][1]) in __layout_sections()
1719 || s->sh_entsize != ~0UL in __layout_sections()
1730 if (codetag_needs_module_section(mod, sname, s->sh_size)) { in __layout_sections()
1732 * s->sh_entsize won't be used but populate the in __layout_sections()
1735 s->sh_entsize = ((unsigned long)(type) & SH_ENTSIZE_TYPE_MASK) in __layout_sections()
1740 s->sh_entsize = module_get_offset_and_type(mod, type, s, i); in __layout_sections()
1748 * might -- code, read-only data, read-write data, small data. Tally
1756 for (i = 0; i < info->hdr->e_shnum; i++) in layout_sections()
1757 info->sechdrs[i].sh_entsize = ~0UL; in layout_sections()
1759 pr_debug("Core section allocation order for %s:\n", mod->name); in layout_sections()
1762 pr_debug("Init section allocation order for %s:\n", mod->name); in layout_sections()
1774 mod->name, license); in module_license_taint_check()
1790 mod->imported_namespaces = NULL; in copy_modinfo_import_ns()
1796 return -ENOMEM; in copy_modinfo_import_ns()
1806 *(p - 1) = '\0'; in copy_modinfo_import_ns()
1808 mod->imported_namespaces = buf; in copy_modinfo_import_ns()
1819 if (attr->setup) in setup_modinfo()
1820 attr->setup(mod, get_modinfo(info, attr->attr.name)); in setup_modinfo()
1830 mod->name, imported_namespace); in setup_modinfo()
1831 return -EPERM; in setup_modinfo()
1848 if (attr->free) in free_modinfo()
1849 attr->free(mod); in free_modinfo()
1875 secend = shdr->sh_offset + shdr->sh_size; in validate_section_offset()
1876 if (secend < shdr->sh_offset || secend > info->len) in validate_section_offset()
1877 return -ENOEXEC; in validate_section_offset()
1883 * elf_validity_ehdr() - Checks an ELF header for module validity
1892 * * Optional arch-specific hook for other properties
1893 * - module_elf_check_arch() is currently only used by PPC to check
1896 * Return: %0 if valid, %-ENOEXEC on failure.
1900 if (info->len < sizeof(*(info->hdr))) { in elf_validity_ehdr()
1901 pr_err("Invalid ELF header len %lu\n", info->len); in elf_validity_ehdr()
1902 return -ENOEXEC; in elf_validity_ehdr()
1904 if (memcmp(info->hdr->e_ident, ELFMAG, SELFMAG) != 0) { in elf_validity_ehdr()
1906 return -ENOEXEC; in elf_validity_ehdr()
1908 if (info->hdr->e_type != ET_REL) { in elf_validity_ehdr()
1910 info->hdr->e_type, ET_REL); in elf_validity_ehdr()
1911 return -ENOEXEC; in elf_validity_ehdr()
1913 if (!elf_check_arch(info->hdr)) { in elf_validity_ehdr()
1915 info->hdr->e_machine); in elf_validity_ehdr()
1916 return -ENOEXEC; in elf_validity_ehdr()
1918 if (!module_elf_check_arch(info->hdr)) { in elf_validity_ehdr()
1920 info->hdr->e_machine); in elf_validity_ehdr()
1921 return -ENOEXEC; in elf_validity_ehdr()
1927 * elf_validity_cache_sechdrs() - Cache section headers if valid
1938 * Then updates @info with a &load_info->sechdrs pointer if valid.
1953 if (info->hdr->e_shentsize != sizeof(Elf_Shdr)) { in elf_validity_cache_sechdrs()
1955 return -ENOEXEC; in elf_validity_cache_sechdrs()
1963 if (info->hdr->e_shoff >= info->len in elf_validity_cache_sechdrs()
1964 || (info->hdr->e_shnum * sizeof(Elf_Shdr) > in elf_validity_cache_sechdrs()
1965 info->len - info->hdr->e_shoff)) { in elf_validity_cache_sechdrs()
1967 return -ENOEXEC; in elf_validity_cache_sechdrs()
1970 sechdrs = (void *)info->hdr + info->hdr->e_shoff; in elf_validity_cache_sechdrs()
1979 pr_err("ELF Spec violation: section 0 type(%d)!=SH_NULL or non-zero len or addr\n", in elf_validity_cache_sechdrs()
1981 return -ENOEXEC; in elf_validity_cache_sechdrs()
1985 for (i = 1; i < info->hdr->e_shnum; i++) { in elf_validity_cache_sechdrs()
1987 switch (shdr->sh_type) { in elf_validity_cache_sechdrs()
1996 i, shdr->sh_type); in elf_validity_cache_sechdrs()
2002 info->sechdrs = sechdrs; in elf_validity_cache_sechdrs()
2008 * elf_validity_cache_secstrings() - Caches section names if valid
2018 * Then updates @info with a &load_info->secstrings pointer if valid.
2031 if (info->hdr->e_shstrndx == SHN_UNDEF in elf_validity_cache_secstrings()
2032 || info->hdr->e_shstrndx >= info->hdr->e_shnum) { in elf_validity_cache_secstrings()
2034 info->hdr->e_shstrndx, info->hdr->e_shstrndx, in elf_validity_cache_secstrings()
2035 info->hdr->e_shnum); in elf_validity_cache_secstrings()
2036 return -ENOEXEC; in elf_validity_cache_secstrings()
2039 strhdr = &info->sechdrs[info->hdr->e_shstrndx]; in elf_validity_cache_secstrings()
2042 * The section name table must be NUL-terminated, as required in elf_validity_cache_secstrings()
2046 secstrings = (void *)info->hdr + strhdr->sh_offset; in elf_validity_cache_secstrings()
2047 if (strhdr->sh_size == 0) { in elf_validity_cache_secstrings()
2049 return -ENOEXEC; in elf_validity_cache_secstrings()
2051 if (secstrings[strhdr->sh_size - 1] != '\0') { in elf_validity_cache_secstrings()
2053 return -ENOEXEC; in elf_validity_cache_secstrings()
2056 for (i = 0; i < info->hdr->e_shnum; i++) { in elf_validity_cache_secstrings()
2057 shdr = &info->sechdrs[i]; in elf_validity_cache_secstrings()
2059 if (shdr->sh_type == SHT_NULL) in elf_validity_cache_secstrings()
2061 if (shdr->sh_name >= strhdr->sh_size) { in elf_validity_cache_secstrings()
2063 i, shdr->sh_type); in elf_validity_cache_secstrings()
2064 return -ENOEXEC; in elf_validity_cache_secstrings()
2068 info->secstrings = secstrings; in elf_validity_cache_secstrings()
2073 * elf_validity_cache_index_info() - Validate and cache modinfo section
2075 * Must have &load_info->sechdrs and &load_info->secstrings populated
2078 * Then, it caches its index in &load_info->index.info.
2081 * Return: %0 if valid, %-ENOEXEC if multiple modinfo sections were found.
2095 return -ENOEXEC; in elf_validity_cache_index_info()
2098 info->index.info = info_idx; in elf_validity_cache_index_info()
2100 info->name = get_modinfo(info, "name"); in elf_validity_cache_index_info()
2106 * elf_validity_cache_index_mod() - Validates and caches this_module section
2108 * Must have &load_info->sechdrs and &load_info->secstrings populated
2125 * If all checks pass, the index will be cached in &load_info->index.mod
2127 * Return: %0 on validation success, %-ENOEXEC on failure
2137 info->name ?: "(missing .modinfo section or name field)"); in elf_validity_cache_index_mod()
2138 return -ENOEXEC; in elf_validity_cache_index_mod()
2141 shdr = &info->sechdrs[mod_idx]; in elf_validity_cache_index_mod()
2143 if (shdr->sh_type == SHT_NOBITS) { in elf_validity_cache_index_mod()
2145 info->name ?: "(missing .modinfo section or name field)"); in elf_validity_cache_index_mod()
2146 return -ENOEXEC; in elf_validity_cache_index_mod()
2149 if (!(shdr->sh_flags & SHF_ALLOC)) { in elf_validity_cache_index_mod()
2151 info->name ?: "(missing .modinfo section or name field)"); in elf_validity_cache_index_mod()
2152 return -ENOEXEC; in elf_validity_cache_index_mod()
2155 if (shdr->sh_size != sizeof(struct module)) { in elf_validity_cache_index_mod()
2157 info->name ?: "(missing .modinfo section or name field)"); in elf_validity_cache_index_mod()
2158 return -ENOEXEC; in elf_validity_cache_index_mod()
2161 info->index.mod = mod_idx; in elf_validity_cache_index_mod()
2167 * elf_validity_cache_index_sym() - Validate and cache symtab index
2169 * Must have &load_info->sechdrs and &load_info->secstrings populated.
2172 * &load_info->index.sym.
2174 * Return: %0 if valid, %-ENOEXEC on failure.
2182 for (i = 1; i < info->hdr->e_shnum; i++) { in elf_validity_cache_index_sym()
2183 if (info->sechdrs[i].sh_type == SHT_SYMTAB) { in elf_validity_cache_index_sym()
2191 info->name ?: "(missing .modinfo section or name field)"); in elf_validity_cache_index_sym()
2192 return -ENOEXEC; in elf_validity_cache_index_sym()
2195 info->index.sym = sym_idx; in elf_validity_cache_index_sym()
2201 * elf_validity_cache_index_str() - Validate and cache strtab index
2203 * Must have &load_info->sechdrs and &load_info->secstrings populated.
2204 * Must have &load_info->index.sym populated.
2207 * in-bounds, and caches it.
2209 * Return: %0 if valid, %-ENOEXEC on failure.
2213 unsigned int str_idx = info->sechdrs[info->index.sym].sh_link; in elf_validity_cache_index_str()
2215 if (str_idx == SHN_UNDEF || str_idx >= info->hdr->e_shnum) { in elf_validity_cache_index_str()
2216 pr_err("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n", in elf_validity_cache_index_str()
2217 str_idx, str_idx, info->hdr->e_shnum); in elf_validity_cache_index_str()
2218 return -ENOEXEC; in elf_validity_cache_index_str()
2221 info->index.str = str_idx; in elf_validity_cache_index_str()
2226 * elf_validity_cache_index_versions() - Validate and cache version indices
2228 * Must have &load_info->sechdrs and &load_info->secstrings populated.
2240 * * &load_info->index.vers
2241 * * &load_info->index.vers_ext_crc
2242 * * &load_info->index.vers_ext_names
2246 * Return: %0 if valid, %-ENOEXEC on failure.
2259 info->index.vers = 0; in elf_validity_cache_index_versions()
2260 info->index.vers_ext_crc = 0; in elf_validity_cache_index_versions()
2261 info->index.vers_ext_name = 0; in elf_validity_cache_index_versions()
2271 return -ENOEXEC; in elf_validity_cache_index_versions()
2279 crc_count = info->sechdrs[vers_ext_crc].sh_size / sizeof(u32); in elf_validity_cache_index_versions()
2280 name = (void *)info->hdr + in elf_validity_cache_index_versions()
2281 info->sechdrs[vers_ext_name].sh_offset; in elf_validity_cache_index_versions()
2282 remaining_len = info->sechdrs[vers_ext_name].sh_size; in elf_validity_cache_index_versions()
2284 while (crc_count--) { in elf_validity_cache_index_versions()
2288 return -ENOEXEC; in elf_validity_cache_index_versions()
2290 remaining_len -= name_size; in elf_validity_cache_index_versions()
2295 info->index.vers = find_sec(info, "__versions"); in elf_validity_cache_index_versions()
2296 info->index.vers_ext_crc = vers_ext_crc; in elf_validity_cache_index_versions()
2297 info->index.vers_ext_name = vers_ext_name; in elf_validity_cache_index_versions()
2302 * elf_validity_cache_index() - Resolve, validate, cache section indices
2304 * &load_info->sechdrs and &load_info->secstrings must be populated.
2308 * Populates &load_info->index, validating as it goes.
2309 * See child functions for per-field validation:
2342 info->index.pcpu = find_pcpusec(info); in elf_validity_cache_index()
2348 * elf_validity_cache_strtab() - Validate and cache symbol string table
2350 * Must have &load_info->sechdrs and &load_info->secstrings populated.
2351 * Must have &load_info->index populated.
2357 * * Every &Elf_Sym->st_name offset in the symbol table is inbounds of the
2360 * And caches the pointer as &load_info->strtab in @info.
2366 Elf_Shdr *str_shdr = &info->sechdrs[info->index.str]; in elf_validity_cache_strtab()
2367 Elf_Shdr *sym_shdr = &info->sechdrs[info->index.sym]; in elf_validity_cache_strtab()
2368 char *strtab = (char *)info->hdr + str_shdr->sh_offset; in elf_validity_cache_strtab()
2369 Elf_Sym *syms = (void *)info->hdr + sym_shdr->sh_offset; in elf_validity_cache_strtab()
2372 if (str_shdr->sh_size == 0) { in elf_validity_cache_strtab()
2374 return -ENOEXEC; in elf_validity_cache_strtab()
2378 return -ENOEXEC; in elf_validity_cache_strtab()
2380 if (strtab[str_shdr->sh_size - 1] != '\0') { in elf_validity_cache_strtab()
2382 return -ENOEXEC; in elf_validity_cache_strtab()
2389 for (i = 0; i < sym_shdr->sh_size / sizeof(*syms); i++) { in elf_validity_cache_strtab()
2390 if (syms[i].st_name >= str_shdr->sh_size) { in elf_validity_cache_strtab()
2392 return -ENOEXEC; in elf_validity_cache_strtab()
2396 info->strtab = strtab; in elf_validity_cache_strtab()
2415 * As a last step we set info->mod to the temporary copy of the module in
2416 * info->hdr. The final one will be allocated in move_module(). Any
2438 info->mod = (void *)info->hdr + info->sechdrs[info->index.mod].sh_offset; in elf_validity_cache_copy()
2442 * on-disk struct mod 'name' field. in elf_validity_cache_copy()
2444 if (!info->name) in elf_validity_cache_copy()
2445 info->name = info->mod->name; in elf_validity_cache_copy()
2458 return -EFAULT; in copy_chunked_from_user()
2462 len -= n; in copy_chunked_from_user()
2477 mod->name); in check_modinfo_livepatch()
2478 return -ENOEXEC; in check_modinfo_livepatch()
2487 mod->name); in check_modinfo_retpoline()
2490 /* Sets info->hdr and info->len. */
2496 info->len = len; in copy_module_from_user()
2497 if (info->len < sizeof(*(info->hdr))) in copy_module_from_user()
2498 return -ENOEXEC; in copy_module_from_user()
2505 info->hdr = __vmalloc(info->len, GFP_KERNEL | __GFP_NOWARN); in copy_module_from_user()
2506 if (!info->hdr) in copy_module_from_user()
2507 return -ENOMEM; in copy_module_from_user()
2509 if (copy_chunked_from_user(info->hdr, umod, info->len) != 0) { in copy_module_from_user()
2510 err = -EFAULT; in copy_module_from_user()
2514 err = security_kernel_post_load_data((char *)info->hdr, info->len, in copy_module_from_user()
2518 vfree(info->hdr); in copy_module_from_user()
2528 vfree(info->hdr); in free_copy()
2536 info->sechdrs[0].sh_addr = 0; in rewrite_section_headers()
2538 for (i = 1; i < info->hdr->e_shnum; i++) { in rewrite_section_headers()
2539 Elf_Shdr *shdr = &info->sechdrs[i]; in rewrite_section_headers()
2545 shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset; in rewrite_section_headers()
2550 info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC; in rewrite_section_headers()
2551 info->sechdrs[info->index.vers_ext_crc].sh_flags &= in rewrite_section_headers()
2553 info->sechdrs[info->index.vers_ext_name].sh_flags &= in rewrite_section_headers()
2555 info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC; in rewrite_section_headers()
2577 pr_warn("%s: loading out-of-tree module taints kernel.\n", in module_augment_kernel_taints()
2578 mod->name); in module_augment_kernel_taints()
2587 "is unknown, you have been warned.\n", mod->name); in module_augment_kernel_taints()
2593 mod->name); in module_augment_kernel_taints()
2601 mod->name); in module_augment_kernel_taints()
2605 mod->sig_ok = info->sig_ok; in module_augment_kernel_taints()
2606 if (!mod->sig_ok) { in module_augment_kernel_taints()
2608 "and/or required key missing - tainting " in module_augment_kernel_taints()
2609 "kernel\n", mod->name); in module_augment_kernel_taints()
2617 * using GPL-only symbols it needs. in module_augment_kernel_taints()
2619 if (strcmp(mod->name, "ndiswrapper") == 0) in module_augment_kernel_taints()
2623 if (strcmp(mod->name, module_license_offenders[i]) == 0) in module_augment_kernel_taints()
2629 pr_warn("%s: module license taints kernel.\n", mod->name); in module_augment_kernel_taints()
2641 /* This is allowed: modprobe --force will invalidate it. */ in check_modinfo()
2646 } else if (!same_magic(modmagic, vermagic, info->index.vers)) { in check_modinfo()
2648 info->name, modmagic, vermagic); in check_modinfo()
2649 return -ENOEXEC; in check_modinfo()
2661 mod->kp = section_objs(info, "__param", in find_module_sections()
2662 sizeof(*mod->kp), &mod->num_kp); in find_module_sections()
2663 mod->syms = section_objs(info, "__ksymtab", in find_module_sections()
2664 sizeof(*mod->syms), &mod->num_syms); in find_module_sections()
2665 mod->crcs = section_addr(info, "__kcrctab"); in find_module_sections()
2666 mod->flagstab = section_addr(info, "__kflagstab"); in find_module_sections()
2670 mod->name); in find_module_sections()
2673 mod->name); in find_module_sections()
2676 mod->ctors = section_objs(info, ".ctors", in find_module_sections()
2677 sizeof(*mod->ctors), &mod->num_ctors); in find_module_sections()
2678 if (!mod->ctors) in find_module_sections()
2679 mod->ctors = section_objs(info, ".init_array", in find_module_sections()
2680 sizeof(*mod->ctors), &mod->num_ctors); in find_module_sections()
2687 mod->name); in find_module_sections()
2688 return -EINVAL; in find_module_sections()
2692 mod->noinstr_text_start = section_objs(info, ".noinstr.text", 1, in find_module_sections()
2693 &mod->noinstr_text_size); in find_module_sections()
2696 mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs", in find_module_sections()
2697 sizeof(*mod->tracepoints_ptrs), in find_module_sections()
2698 &mod->num_tracepoints); in find_module_sections()
2701 mod->srcu_struct_ptrs = section_objs(info, "___srcu_struct_ptrs", in find_module_sections()
2702 sizeof(*mod->srcu_struct_ptrs), in find_module_sections()
2703 &mod->num_srcu_structs); in find_module_sections()
2706 mod->bpf_raw_events = section_objs(info, "__bpf_raw_tp_map", in find_module_sections()
2707 sizeof(*mod->bpf_raw_events), in find_module_sections()
2708 &mod->num_bpf_raw_events); in find_module_sections()
2711 mod->btf_data = any_section_objs(info, ".BTF", 1, &mod->btf_data_size); in find_module_sections()
2712 mod->btf_base_data = any_section_objs(info, ".BTF.base", 1, in find_module_sections()
2713 &mod->btf_base_data_size); in find_module_sections()
2716 mod->jump_entries = section_objs(info, "__jump_table", in find_module_sections()
2717 sizeof(*mod->jump_entries), in find_module_sections()
2718 &mod->num_jump_entries); in find_module_sections()
2721 mod->trace_events = section_objs(info, "_ftrace_events", in find_module_sections()
2722 sizeof(*mod->trace_events), in find_module_sections()
2723 &mod->num_trace_events); in find_module_sections()
2724 mod->trace_evals = section_objs(info, "_ftrace_eval_map", in find_module_sections()
2725 sizeof(*mod->trace_evals), in find_module_sections()
2726 &mod->num_trace_evals); in find_module_sections()
2729 mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt", in find_module_sections()
2730 sizeof(*mod->trace_bprintk_fmt_start), in find_module_sections()
2731 &mod->num_trace_bprintk_fmt); in find_module_sections()
2735 mod->ftrace_callsites = section_objs(info, FTRACE_CALLSITE_SECTION, in find_module_sections()
2736 sizeof(*mod->ftrace_callsites), in find_module_sections()
2737 &mod->num_ftrace_callsites); in find_module_sections()
2740 mod->ei_funcs = section_objs(info, "_error_injection_whitelist", in find_module_sections()
2741 sizeof(*mod->ei_funcs), in find_module_sections()
2742 &mod->num_ei_funcs); in find_module_sections()
2745 mod->kprobes_text_start = section_objs(info, ".kprobes.text", 1, in find_module_sections()
2746 &mod->kprobes_text_size); in find_module_sections()
2747 mod->kprobe_blacklist = section_objs(info, "_kprobe_blacklist", in find_module_sections()
2749 &mod->num_kprobe_blacklist); in find_module_sections()
2752 mod->printk_index_start = section_objs(info, ".printk_index", in find_module_sections()
2753 sizeof(*mod->printk_index_start), in find_module_sections()
2754 &mod->printk_index_size); in find_module_sections()
2757 mod->static_call_sites = section_objs(info, ".static_call_sites", in find_module_sections()
2758 sizeof(*mod->static_call_sites), in find_module_sections()
2759 &mod->num_static_call_sites); in find_module_sections()
2762 mod->kunit_suites = section_objs(info, ".kunit_test_suites", in find_module_sections()
2763 sizeof(*mod->kunit_suites), in find_module_sections()
2764 &mod->num_kunit_suites); in find_module_sections()
2765 mod->kunit_init_suites = section_objs(info, ".kunit_init_test_suites", in find_module_sections()
2766 sizeof(*mod->kunit_init_suites), in find_module_sections()
2767 &mod->num_kunit_init_suites); in find_module_sections()
2770 mod->extable = section_objs(info, "__ex_table", in find_module_sections()
2771 sizeof(*mod->extable), &mod->num_exentries); in find_module_sections()
2774 pr_warn("%s: Ignoring obsolete parameters\n", mod->name); in find_module_sections()
2777 mod->dyndbg_info.descs = section_objs(info, "__dyndbg", in find_module_sections()
2778 sizeof(*mod->dyndbg_info.descs), in find_module_sections()
2779 &mod->dyndbg_info.num_descs); in find_module_sections()
2780 mod->dyndbg_info.classes = section_objs(info, "__dyndbg_classes", in find_module_sections()
2781 sizeof(*mod->dyndbg_info.classes), in find_module_sections()
2782 &mod->dyndbg_info.num_classes); in find_module_sections()
2795 if (!mod->mem[type].size) { in move_module()
2796 mod->mem[type].base = NULL; in move_module()
2808 pr_debug("Final section addresses for %s:\n", mod->name); in move_module()
2809 for (i = 0; i < info->hdr->e_shnum; i++) { in move_module()
2811 Elf_Shdr *shdr = &info->sechdrs[i]; in move_module()
2814 if (!(shdr->sh_flags & SHF_ALLOC)) in move_module()
2817 sname = info->secstrings + shdr->sh_name; in move_module()
2822 if (codetag_needs_module_section(mod, sname, shdr->sh_size)) { in move_module()
2823 dest = codetag_alloc_module_section(mod, sname, shdr->sh_size, in move_module()
2824 arch_mod_section_prepend(mod, i), shdr->sh_addralign); in move_module()
2826 ret = -EINVAL; in move_module()
2835 enum mod_mem_type type = shdr->sh_entsize >> SH_ENTSIZE_TYPE_SHIFT; in move_module()
2836 unsigned long offset = shdr->sh_entsize & SH_ENTSIZE_OFFSET_MASK; in move_module()
2838 dest = mod->mem[type].base + offset; in move_module()
2841 if (shdr->sh_type != SHT_NOBITS) { in move_module()
2848 if (i == info->index.mod && in move_module()
2849 (WARN_ON_ONCE(shdr->sh_size != sizeof(struct module)))) { in move_module()
2850 ret = -ENOEXEC; in move_module()
2853 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size); in move_module()
2861 shdr->sh_addr = (unsigned long)dest; in move_module()
2862 pr_debug("\t0x%lx 0x%.8lx %s\n", (long)shdr->sh_addr, in move_module()
2863 (long)shdr->sh_size, info->secstrings + shdr->sh_name); in move_module()
2869 while (t--) in move_module()
2879 if (mod->num_syms && !mod->flagstab) { in check_export_symbol_sections()
2880 pr_err("%s: no flags for exported symbols\n", mod->name); in check_export_symbol_sections()
2881 return -ENOEXEC; in check_export_symbol_sections()
2884 if (mod->num_syms && !mod->crcs) { in check_export_symbol_sections()
2900 const struct module_memory *mod_mem = &mod->mem[type]; in flush_module_icache()
2902 if (mod_mem->size) { in flush_module_icache()
2903 flush_icache_range((unsigned long)mod_mem->base, in flush_module_icache()
2904 (unsigned long)mod_mem->base + mod_mem->size); in flush_module_icache()
2922 /* module_blacklist is a comma-separated list of module names */
2949 err = module_frob_arch_sections(info->hdr, info->sechdrs, in layout_and_allocate()
2950 info->secstrings, info->mod); in layout_and_allocate()
2954 err = module_enforce_rwx_sections(info->hdr, info->sechdrs, in layout_and_allocate()
2955 info->secstrings, info->mod); in layout_and_allocate()
2959 /* We will do a special allocation for per-cpu sections later. */ in layout_and_allocate()
2960 info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC; in layout_and_allocate()
2967 module_mark_ro_after_init(info->hdr, info->sechdrs, info->secstrings); in layout_and_allocate()
2974 layout_sections(info->mod, info); in layout_and_allocate()
2975 layout_symtab(info->mod, info); in layout_and_allocate()
2978 err = move_module(info->mod, info); in layout_and_allocate()
2983 mod = (void *)info->sechdrs[info->index.mod].sh_addr; in layout_and_allocate()
2985 codetag_module_replaced(info->mod, mod); in layout_and_allocate()
3010 sort_extable(mod->extable, mod->extable + mod->num_exentries); in post_relocation()
3013 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr, in post_relocation()
3014 info->sechdrs[info->index.pcpu].sh_size); in post_relocation()
3016 /* Setup kallsyms-specific fields. */ in post_relocation()
3019 /* Arch-specific module finalizing. */ in post_relocation()
3020 return module_finalize(info->hdr, info->sechdrs, mod); in post_relocation()
3029 for (i = 0; i < mod->num_ctors; i++) in do_mod_ctors()
3030 mod->ctors[i](); in do_mod_ctors()
3053 execmem_free(initfree->init_text); in do_free_init()
3054 execmem_free(initfree->init_data); in do_free_init()
3055 execmem_free(initfree->init_rodata); in do_free_init()
3067 /* Default value for module->async_probe_requested */
3075 * helper command 'lx-symbols'.
3085 const struct module_memory *mod_mem = &mod->mem[type]; in do_init_module()
3086 if (mod_mem->size) { in do_init_module()
3087 total_size += mod_mem->size; in do_init_module()
3089 text_size += mod_mem->size; in do_init_module()
3096 ret = -ENOMEM; in do_init_module()
3099 freeinit->init_text = mod->mem[MOD_INIT_TEXT].base; in do_init_module()
3100 freeinit->init_data = mod->mem[MOD_INIT_DATA].base; in do_init_module()
3101 freeinit->init_rodata = mod->mem[MOD_INIT_RODATA].base; in do_init_module()
3105 if (mod->init != NULL) in do_init_module()
3106 ret = do_one_initcall(mod->init); in do_init_module()
3109 * -EEXIST is reserved by [f]init_module() to signal to userspace that in do_init_module()
3113 if (ret == -EEXIST) in do_init_module()
3114 ret = -EBUSY; in do_init_module()
3119 pr_warn("%s: init suspiciously returned %d, it should follow 0/-E convention\n", in do_init_module()
3120 mod->name, ret); in do_init_module()
3123 mod->state = MODULE_STATE_LIVE; in do_init_module()
3128 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); in do_init_module()
3138 if (!mod->async_probe_requested) in do_init_module()
3141 ftrace_free_mem(mod, mod->mem[MOD_INIT_TEXT].base, in do_init_module()
3142 mod->mem[MOD_INIT_TEXT].base + mod->mem[MOD_INIT_TEXT].size); in do_init_module()
3149 rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms); in do_init_module()
3155 mod->name, ret); in do_init_module()
3160 mod->mem[type].base = NULL; in do_init_module()
3161 mod->mem[type].size = 0; in do_init_module()
3166 mod->btf_data = NULL; in do_init_module()
3167 mod->btf_base_data = NULL; in do_init_module()
3174 * work and call synchronize_rcu() in a work queue. in do_init_module()
3182 if (llist_add(&freeinit->node, &init_free_list)) in do_init_module()
3199 mod->state = MODULE_STATE_GOING; in do_init_module()
3215 return -EPERM; in may_init_module()
3234 ret = !mod || mod->state == MODULE_STATE_LIVE in finished_loading()
3235 || mod->state == MODULE_STATE_GOING; in finished_loading()
3252 if (old->state == MODULE_STATE_COMING || in module_patient_check_exists()
3253 old->state == MODULE_STATE_UNFORMED) { in module_patient_check_exists()
3267 pr_warn("Could not add fail-tracking for module: %s\n", name); in module_patient_check_exists()
3276 if (old && old->state == MODULE_STATE_LIVE) in module_patient_check_exists()
3277 return -EEXIST; in module_patient_check_exists()
3278 return -EBUSY; in module_patient_check_exists()
3290 mod->state = MODULE_STATE_UNFORMED; in add_unformed_module()
3293 err = module_patient_check_exists(mod->name, FAIL_DUP_MOD_LOAD); in add_unformed_module()
3298 list_add_rcu(&mod->list, &modules); in add_unformed_module()
3319 module_bug_finalize(info->hdr, info->sechdrs, mod); in complete_formation()
3320 module_cfi_finalize(info->hdr, info->sechdrs, mod); in complete_formation()
3336 mod->state = MODULE_STATE_COMING; in complete_formation()
3373 if (kstrtobool(val, &mod->async_probe_requested)) in unknown_module_param_cb()
3374 mod->async_probe_requested = true; in unknown_module_param_cb()
3394 if (blacklisted(info->name)) { in early_mod_check()
3395 pr_err("Module %s is blacklisted\n", info->name); in early_mod_check()
3396 return -EPERM; in early_mod_check()
3404 if (!check_modstruct_version(info, info->mod)) in early_mod_check()
3405 return -ENOEXEC; in early_mod_check()
3407 err = check_modinfo(info->mod, info, flags); in early_mod_check()
3412 err = module_patient_check_exists(info->mod->name, FAIL_DUP_MOD_BECOMING); in early_mod_check()
3432 * the signature check needs is info->len, it does in load_module()
3438 * The check will also adjust info->len by stripping in load_module()
3440 * checks against info->len more correct. in load_module()
3449 * info->mod to the userspace passed struct module. in load_module()
3468 audit_log_kern_module(info->name); in load_module()
3526 mod->args = strndup_user(uargs, ~0UL >> 1); in load_module()
3527 if (IS_ERR(mod->args)) { in load_module()
3528 err = PTR_ERR(mod->args); in load_module()
3546 mod->async_probe_requested = async_probe; in load_module()
3549 after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, in load_module()
3550 -32768, 32767, mod, in load_module()
3556 pr_warn("%s: parameters '%s' after `--' ignored\n", in load_module()
3557 mod->name, after_dashes); in load_module()
3561 err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp); in load_module()
3585 mod->state = MODULE_STATE_GOING; in load_module()
3586 module_destroy_params(mod->kp, mod->num_kp); in load_module()
3591 mod->state = MODULE_STATE_GOING; in load_module()
3600 kfree(mod->args); in load_module()
3610 list_del_rcu(&mod->list); in load_module()
3613 /* Wait for RCU-sched synchronizing before releasing mod->list. */ in load_module()
3622 * The info->len is always set. We distinguish between in load_module()
3627 audit_log_kern_module(info->name ? info->name : "?"); in load_module()
3675 u->ret = -EINTR; in idempotent()
3676 u->cookie = cookie; in idempotent()
3677 init_completion(&u->complete); in idempotent()
3682 if (existing->cookie != cookie) in idempotent()
3687 hlist_add_head(&u->entry, idem_hash + hash); in idempotent()
3696 * remove everybody - which includes ourselves - fill in the return
3701 const void *cookie = u->cookie; in idempotent_complete()
3709 if (pos->cookie != cookie) in idempotent_complete()
3711 hlist_del_init(&pos->entry); in idempotent_complete()
3712 pos->ret = ret; in idempotent_complete()
3713 complete(&pos->complete); in idempotent_complete()
3726 * initialized to -EINTR and is thus always the right return
3732 if (wait_for_completion_interruptible(&u->complete)) { in idempotent_wait_for_completion()
3734 if (!hlist_unhashed(&u->entry)) in idempotent_wait_for_completion()
3735 hlist_del(&u->entry); in idempotent_wait_for_completion()
3738 return u->ret; in idempotent_wait_for_completion()
3784 if (!(f->f_mode & FMODE_READ)) in idempotent_init_module()
3785 return -EBADF; in idempotent_init_module()
3810 return -EINVAL; in SYSCALL_DEFINE3()
3814 return -EBADF; in SYSCALL_DEFINE3()
3823 BUG_ON(mod->state == MODULE_STATE_UNFORMED); in module_flags()
3824 if (!mod->taints && !show_state) in module_flags()
3826 if (mod->taints || in module_flags()
3827 mod->state == MODULE_STATE_GOING || in module_flags()
3828 mod->state == MODULE_STATE_COMING) { in module_flags()
3830 bx += module_flags_taint(mod->taints, buf + bx); in module_flags()
3831 /* Show a - for module-is-being-unloaded */ in module_flags()
3832 if (mod->state == MODULE_STATE_GOING && show_state) in module_flags()
3833 buf[bx++] = '-'; in module_flags()
3834 /* Show a + for module-is-being-loaded */ in module_flags()
3835 if (mod->state == MODULE_STATE_COMING && show_state) in module_flags()
3855 if (!mod->num_exentries) in search_module_extables()
3864 return search_extable(mod->extable, mod->num_exentries, addr); in search_module_extables()
3868 * is_module_address() - is this address inside a module?
3881 * __module_address() - get the module which contains an address.
3905 if (mod->state == MODULE_STATE_UNFORMED) in __module_address()
3912 * is_module_text_address() - is this address inside module code?
3931 if (mod->state == MODULE_STATE_UNFORMED) in module_for_each_mod()
3939 * __module_text_address() - get the module whose code contains an address.
3967 if (mod->state == MODULE_STATE_UNFORMED) in print_modules()
3969 pr_cont(" %s%s", mod->name, module_flags(mod, buf, true)); in print_modules()