57
57
#include <linux/kmemleak.h>
58
58
#include <linux/jump_label.h>
59
59
#include <linux/pfn.h>
60
#include <trace/kernel.h>
61
62
#define CREATE_TRACE_POINTS
62
63
#include <trace/events/module.h>
99
100
* 1) List of modules (also safely readable with preempt_disable),
100
101
* 2) module_use links,
101
102
* 3) module_addr_min/module_addr_max.
102
* (delete uses stop_machine/add uses RCU list operations). */
103
* (delete uses stop_machine/add uses RCU list operations).
104
* Sorted by ascending list node address.
103
106
DEFINE_MUTEX(module_mutex);
104
107
EXPORT_SYMBOL_GPL(module_mutex);
105
108
static LIST_HEAD(modules);
120
123
* Protected by module_mutex. */
121
124
static unsigned long module_addr_min = -1UL, module_addr_max = 0;
126
DEFINE_TRACE(kernel_module_load);
127
DEFINE_TRACE(kernel_module_free);
123
129
int register_module_notifier(struct notifier_block * nb)
125
131
return blocking_notifier_chain_register(&module_notify_list, nb);
1675
1681
/* Free a module, remove from lists, etc. */
1676
1682
static void free_module(struct module *mod)
1684
trace_kernel_module_free(mod);
1678
1685
trace_module_free(mod);
1680
1687
/* Delete from various lists */
2459
2472
sizeof(*mod->ctors), &mod->num_ctors);
2475
#ifdef CONFIG_MARKERS
2476
mod->markers = section_objs(info, "__markers",
2477
sizeof(*mod->markers), &mod->num_markers);
2462
2479
#ifdef CONFIG_TRACEPOINTS
2463
2480
mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs",
2464
2481
sizeof(*mod->tracepoints_ptrs),
2717
2734
const char __user *uargs)
2719
2736
struct load_info info = { NULL, };
2737
struct module *mod, *iter;
2723
2740
DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
2801
2818
module_bug_finalize(info.hdr, info.sechdrs, mod);
2820
* We sort the modules by struct module pointer address to permit
2821
* correct iteration over modules of, at least, kallsyms for preemptible
2822
* operations, such as read(). Sorting by struct module pointer address
2823
* is equivalent to sort by list node address.
2825
list_for_each_entry_reverse(iter, &modules, list) {
2826
BUG_ON(iter == mod); /* Should never be in the list twice */
2828
/* We belong to the location right after iter. */
2829
list_add_rcu(&mod->list, &iter->list);
2833
/* We should be added at the head of the list */
2802
2834
list_add_rcu(&mod->list, &modules);
2803
2836
mutex_unlock(&module_mutex);
2805
2838
/* Module is ready to execute: parsing args may do that. */
3196
3230
static void *m_start(struct seq_file *m, loff_t *pos)
3198
3232
mutex_lock(&module_mutex);
3199
return seq_list_start(&modules, *pos);
3233
return seq_sorted_list_start(&modules, pos);
3202
3236
static void *m_next(struct seq_file *m, void *p, loff_t *pos)
3204
return seq_list_next(p, &modules, pos);
3238
return seq_sorted_list_next(p, &modules, pos);
3207
3241
static void m_stop(struct seq_file *m, void *p)
3266
3300
module_init(proc_modules_init);
3303
void list_modules(void *call_data)
3305
/* Enumerate loaded modules */
3306
struct list_head *i;
3308
unsigned long refcount = 0;
3310
mutex_lock(&module_mutex);
3311
list_for_each(i, &modules) {
3312
mod = list_entry(i, struct module, list);
3313
#ifdef CONFIG_MODULE_UNLOAD
3314
refcount = module_refcount(mod);
3316
__trace_mark(0, module_state, list_module, call_data,
3317
"name %s state %d refcount %lu",
3318
mod->name, mod->state, refcount);
3320
mutex_unlock(&module_mutex);
3322
EXPORT_SYMBOL_GPL(list_modules);
3269
3324
/* Given an address, look for it in the module exception tables. */
3270
3325
const struct exception_table_entry *search_module_extables(unsigned long addr)
3393
3448
struct modversion_info *ver,
3394
3449
struct kernel_param *kp,
3395
3450
struct kernel_symbol *ks,
3451
struct marker *marker,
3396
3452
struct tracepoint * const *tp)
3399
3455
EXPORT_SYMBOL(module_layout);
3458
#ifdef CONFIG_MARKERS
3459
void module_update_markers(void)
3463
mutex_lock(&module_mutex);
3464
list_for_each_entry(mod, &modules, list)
3465
if (!(mod->taints & TAINT_FORCED_MODULE))
3466
marker_update_probe_range(mod->markers,
3467
mod->markers + mod->num_markers);
3468
mutex_unlock(&module_mutex);
3472
* Returns 0 if current not found.
3473
* Returns 1 if current found.
3475
int module_get_iter_markers(struct marker_iter *iter)
3477
struct module *iter_mod;
3480
mutex_lock(&module_mutex);
3481
list_for_each_entry(iter_mod, &modules, list) {
3482
if (!(iter_mod->taints & TAINT_FORCED_MODULE)) {
3484
* Sorted module list
3486
if (iter_mod < iter->module)
3488
else if (iter_mod > iter->module)
3489
iter->marker = NULL;
3490
found = marker_get_iter_range(&iter->marker,
3492
iter_mod->markers + iter_mod->num_markers);
3494
iter->module = iter_mod;
3499
mutex_unlock(&module_mutex);
3402
3504
#ifdef CONFIG_TRACEPOINTS
3403
3505
void module_update_tracepoints(void)