diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/kernel/module.c b/kernel/module.c index 1f4cc00e0c20..f47cce910f25 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -757,8 +757,16 @@ sys_delete_module(const char __user *name_user, unsigned int flags) | |||
757 | return -EFAULT; | 757 | return -EFAULT; |
758 | name[MODULE_NAME_LEN-1] = '\0'; | 758 | name[MODULE_NAME_LEN-1] = '\0'; |
759 | 759 | ||
760 | if (mutex_lock_interruptible(&module_mutex) != 0) | 760 | /* Create stop_machine threads since free_module relies on |
761 | return -EINTR; | 761 | * a non-failing stop_machine call. */ |
762 | ret = stop_machine_create(); | ||
763 | if (ret) | ||
764 | return ret; | ||
765 | |||
766 | if (mutex_lock_interruptible(&module_mutex) != 0) { | ||
767 | ret = -EINTR; | ||
768 | goto out_stop; | ||
769 | } | ||
762 | 770 | ||
763 | mod = find_module(name); | 771 | mod = find_module(name); |
764 | if (!mod) { | 772 | if (!mod) { |
@@ -817,10 +825,12 @@ sys_delete_module(const char __user *name_user, unsigned int flags) | |||
817 | 825 | ||
818 | out: | 826 | out: |
819 | mutex_unlock(&module_mutex); | 827 | mutex_unlock(&module_mutex); |
828 | out_stop: | ||
829 | stop_machine_destroy(); | ||
820 | return ret; | 830 | return ret; |
821 | } | 831 | } |
822 | 832 | ||
823 | static void print_unload_info(struct seq_file *m, struct module *mod) | 833 | static inline void print_unload_info(struct seq_file *m, struct module *mod) |
824 | { | 834 | { |
825 | struct module_use *use; | 835 | struct module_use *use; |
826 | int printed_something = 0; | 836 | int printed_something = 0; |
@@ -893,7 +903,7 @@ void module_put(struct module *module) | |||
893 | EXPORT_SYMBOL(module_put); | 903 | EXPORT_SYMBOL(module_put); |
894 | 904 | ||
895 | #else /* !CONFIG_MODULE_UNLOAD */ | 905 | #else /* !CONFIG_MODULE_UNLOAD */ |
896 | static void print_unload_info(struct seq_file *m, struct module *mod) | 906 | static inline void print_unload_info(struct seq_file *m, struct module *mod) |
897 | { | 907 | { |
898 | /* We don't know the usage count, or what modules are using. */ | 908 | /* We don't know the usage count, or what modules are using. */ |
899 | seq_printf(m, " - -"); | 909 | seq_printf(m, " - -"); |
@@ -1578,11 +1588,21 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
1578 | return ret; | 1588 | return ret; |
1579 | } | 1589 | } |
1580 | 1590 | ||
1591 | /* Additional bytes needed by arch in front of individual sections */ | ||
1592 | unsigned int __weak arch_mod_section_prepend(struct module *mod, | ||
1593 | unsigned int section) | ||
1594 | { | ||
1595 | /* default implementation just returns zero */ | ||
1596 | return 0; | ||
1597 | } | ||
1598 | |||
1581 | /* Update size with this section: return offset. */ | 1599 | /* Update size with this section: return offset. */ |
1582 | static long get_offset(unsigned int *size, Elf_Shdr *sechdr) | 1600 | static long get_offset(struct module *mod, unsigned int *size, |
1601 | Elf_Shdr *sechdr, unsigned int section) | ||
1583 | { | 1602 | { |
1584 | long ret; | 1603 | long ret; |
1585 | 1604 | ||
1605 | *size += arch_mod_section_prepend(mod, section); | ||
1586 | ret = ALIGN(*size, sechdr->sh_addralign ?: 1); | 1606 | ret = ALIGN(*size, sechdr->sh_addralign ?: 1); |
1587 | *size = ret + sechdr->sh_size; | 1607 | *size = ret + sechdr->sh_size; |
1588 | return ret; | 1608 | return ret; |
@@ -1622,7 +1642,7 @@ static void layout_sections(struct module *mod, | |||
1622 | || strncmp(secstrings + s->sh_name, | 1642 | || strncmp(secstrings + s->sh_name, |
1623 | ".init", 5) == 0) | 1643 | ".init", 5) == 0) |
1624 | continue; | 1644 | continue; |
1625 | s->sh_entsize = get_offset(&mod->core_size, s); | 1645 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); |
1626 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1646 | DEBUGP("\t%s\n", secstrings + s->sh_name); |
1627 | } | 1647 | } |
1628 | if (m == 0) | 1648 | if (m == 0) |
@@ -1640,7 +1660,7 @@ static void layout_sections(struct module *mod, | |||
1640 | || strncmp(secstrings + s->sh_name, | 1660 | || strncmp(secstrings + s->sh_name, |
1641 | ".init", 5) != 0) | 1661 | ".init", 5) != 0) |
1642 | continue; | 1662 | continue; |
1643 | s->sh_entsize = (get_offset(&mod->init_size, s) | 1663 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) |
1644 | | INIT_OFFSET_MASK); | 1664 | | INIT_OFFSET_MASK); |
1645 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1665 | DEBUGP("\t%s\n", secstrings + s->sh_name); |
1646 | } | 1666 | } |
@@ -1725,15 +1745,15 @@ static const struct kernel_symbol *lookup_symbol(const char *name, | |||
1725 | return NULL; | 1745 | return NULL; |
1726 | } | 1746 | } |
1727 | 1747 | ||
1728 | static int is_exported(const char *name, const struct module *mod) | 1748 | static int is_exported(const char *name, unsigned long value, |
1749 | const struct module *mod) | ||
1729 | { | 1750 | { |
1730 | if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab)) | 1751 | const struct kernel_symbol *ks; |
1731 | return 1; | 1752 | if (!mod) |
1753 | ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab); | ||
1732 | else | 1754 | else |
1733 | if (mod && lookup_symbol(name, mod->syms, mod->syms + mod->num_syms)) | 1755 | ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms); |
1734 | return 1; | 1756 | return ks != NULL && ks->value == value; |
1735 | else | ||
1736 | return 0; | ||
1737 | } | 1757 | } |
1738 | 1758 | ||
1739 | /* As per nm */ | 1759 | /* As per nm */ |
@@ -1865,6 +1885,13 @@ static noinline struct module *load_module(void __user *umod, | |||
1865 | /* vmalloc barfs on "unusual" numbers. Check here */ | 1885 | /* vmalloc barfs on "unusual" numbers. Check here */ |
1866 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) | 1886 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) |
1867 | return ERR_PTR(-ENOMEM); | 1887 | return ERR_PTR(-ENOMEM); |
1888 | |||
1889 | /* Create stop_machine threads since the error path relies on | ||
1890 | * a non-failing stop_machine call. */ | ||
1891 | err = stop_machine_create(); | ||
1892 | if (err) | ||
1893 | goto free_hdr; | ||
1894 | |||
1868 | if (copy_from_user(hdr, umod, len) != 0) { | 1895 | if (copy_from_user(hdr, umod, len) != 0) { |
1869 | err = -EFAULT; | 1896 | err = -EFAULT; |
1870 | goto free_hdr; | 1897 | goto free_hdr; |
@@ -2184,24 +2211,15 @@ static noinline struct module *load_module(void __user *umod, | |||
2184 | struct mod_debug *debug; | 2211 | struct mod_debug *debug; |
2185 | unsigned int num_debug; | 2212 | unsigned int num_debug; |
2186 | 2213 | ||
2187 | #ifdef CONFIG_MARKERS | ||
2188 | marker_update_probe_range(mod->markers, | ||
2189 | mod->markers + mod->num_markers); | ||
2190 | #endif | ||
2191 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", | 2214 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", |
2192 | sizeof(*debug), &num_debug); | 2215 | sizeof(*debug), &num_debug); |
2193 | dynamic_printk_setup(debug, num_debug); | 2216 | dynamic_printk_setup(debug, num_debug); |
2194 | |||
2195 | #ifdef CONFIG_TRACEPOINTS | ||
2196 | tracepoint_update_probe_range(mod->tracepoints, | ||
2197 | mod->tracepoints + mod->num_tracepoints); | ||
2198 | #endif | ||
2199 | } | 2217 | } |
2200 | 2218 | ||
2201 | /* sechdrs[0].sh_size is always zero */ | 2219 | /* sechdrs[0].sh_size is always zero */ |
2202 | mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc", | 2220 | mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc", |
2203 | sizeof(*mseg), &num_mcount); | 2221 | sizeof(*mseg), &num_mcount); |
2204 | ftrace_init_module(mseg, mseg + num_mcount); | 2222 | ftrace_init_module(mod, mseg, mseg + num_mcount); |
2205 | 2223 | ||
2206 | err = module_finalize(hdr, sechdrs, mod); | 2224 | err = module_finalize(hdr, sechdrs, mod); |
2207 | if (err < 0) | 2225 | if (err < 0) |
@@ -2257,6 +2275,7 @@ static noinline struct module *load_module(void __user *umod, | |||
2257 | /* Get rid of temporary copy */ | 2275 | /* Get rid of temporary copy */ |
2258 | vfree(hdr); | 2276 | vfree(hdr); |
2259 | 2277 | ||
2278 | stop_machine_destroy(); | ||
2260 | /* Done! */ | 2279 | /* Done! */ |
2261 | return mod; | 2280 | return mod; |
2262 | 2281 | ||
@@ -2279,6 +2298,7 @@ static noinline struct module *load_module(void __user *umod, | |||
2279 | kfree(args); | 2298 | kfree(args); |
2280 | free_hdr: | 2299 | free_hdr: |
2281 | vfree(hdr); | 2300 | vfree(hdr); |
2301 | stop_machine_destroy(); | ||
2282 | return ERR_PTR(err); | 2302 | return ERR_PTR(err); |
2283 | 2303 | ||
2284 | truncated: | 2304 | truncated: |
@@ -2513,7 +2533,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | |||
2513 | strlcpy(name, mod->strtab + mod->symtab[symnum].st_name, | 2533 | strlcpy(name, mod->strtab + mod->symtab[symnum].st_name, |
2514 | KSYM_NAME_LEN); | 2534 | KSYM_NAME_LEN); |
2515 | strlcpy(module_name, mod->name, MODULE_NAME_LEN); | 2535 | strlcpy(module_name, mod->name, MODULE_NAME_LEN); |
2516 | *exported = is_exported(name, mod); | 2536 | *exported = is_exported(name, *value, mod); |
2517 | preempt_enable(); | 2537 | preempt_enable(); |
2518 | return 0; | 2538 | return 0; |
2519 | } | 2539 | } |
@@ -2713,7 +2733,7 @@ int is_module_address(unsigned long addr) | |||
2713 | 2733 | ||
2714 | 2734 | ||
2715 | /* Is this a valid kernel address? */ | 2735 | /* Is this a valid kernel address? */ |
2716 | struct module *__module_text_address(unsigned long addr) | 2736 | __notrace_funcgraph struct module *__module_text_address(unsigned long addr) |
2717 | { | 2737 | { |
2718 | struct module *mod; | 2738 | struct module *mod; |
2719 | 2739 | ||