--- zzzz-none-000/linux-4.1.52/kernel/module.c 2018-05-28 02:26:45.000000000 +0000 +++ bcm63-7530ax-731/linux-4.1.52/kernel/module.c 2022-03-02 11:37:13.000000000 +0000 @@ -61,6 +61,14 @@ #include #include #include "module-internal.h" +#if defined(CONFIG_AVM_FASTIRQ) +#include +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ +#if defined(CONFIG_BUG_EXTRA_INFO) +#include +#endif/*--- #if defined(CONFIG_BUG_EXTRA_INFO) ---*/ + +#include #define CREATE_TRACE_POINTS #include @@ -538,7 +546,11 @@ { struct module *mod; unsigned int cpu; - +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return false; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ preempt_disable(); list_for_each_entry_rcu(mod, &modules, list) { @@ -1868,7 +1880,7 @@ /* This may be NULL, but that's OK */ unset_module_init_ro_nx(mod); module_arch_freeing_init(mod); - module_memfree(mod->module_init); + avm_module_mem_free(mod->module_init); kfree(mod->args); percpu_modfree(mod); @@ -1877,7 +1889,7 @@ /* Finally, free the core (containing the module structure) */ unset_module_core_ro_nx(mod); - module_memfree(mod->module_core); + avm_module_mem_free(mod->module_core); #ifdef CONFIG_MPU update_protections(current->mm); @@ -2414,9 +2426,10 @@ return vmalloc_exec(size); } -static void *module_alloc_update_bounds(unsigned long size) +static void *module_alloc_update_bounds(struct module *mod, unsigned long size, + enum avm_module_mem_type type) { - void *ret = module_alloc(size); + void *ret = avm_module_mem_alloc(mod, size, type); if (ret) { mutex_lock(&module_mutex); @@ -2844,7 +2857,8 @@ void *ptr; /* Do the allocs. */ - ptr = module_alloc_update_bounds(mod->core_size); + ptr = module_alloc_update_bounds(mod, mod->core_size, + avm_module_mem_type_core); /* * The pointer to this block is stored in the module structure * which is inside the block. Just mark it as not being a @@ -2858,7 +2872,8 @@ mod->module_core = ptr; if (mod->init_size) { - ptr = module_alloc_update_bounds(mod->init_size); + ptr = module_alloc_update_bounds(mod, mod->init_size, + avm_module_mem_type_init); /* * The pointer to this block is stored in the module structure * which is inside the block. This block doesn't need to be @@ -2867,7 +2882,7 @@ */ kmemleak_ignore(ptr); if (!ptr) { - module_memfree(mod->module_core); + avm_module_mem_free(mod->module_core); return -ENOMEM; } memset(ptr, 0, mod->init_size); @@ -3018,8 +3033,8 @@ { percpu_modfree(mod); module_arch_freeing_init(mod); - module_memfree(mod->module_init); - module_memfree(mod->module_core); + avm_module_mem_free(mod->module_init); + avm_module_mem_free(mod->module_core); } int __weak module_finalize(const Elf_Ehdr *hdr, @@ -3086,7 +3101,7 @@ static void do_free_init(struct rcu_head *head) { struct mod_initfree *m = container_of(head, struct mod_initfree, rcu); - module_memfree(m->module_init); + avm_module_mem_free(m->module_init); kfree(m); } @@ -3569,14 +3584,20 @@ struct module *mod; const char *ret = NULL; +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return NULL; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ + preempt_disable(); list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; if (within_module(addr, mod)) { - if (modname) - *modname = mod->name; - ret = get_ksymbol(mod, addr, size, offset); + if (modname) + *modname = mod->name; + ret = get_ksymbol(mod, addr, size, offset); break; } } @@ -3593,6 +3614,12 @@ { struct module *mod; +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return -ERANGE; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ + preempt_disable(); list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) @@ -3617,6 +3644,11 @@ unsigned long *offset, char *modname, char *name) { struct module *mod; +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return -ERANGE; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ preempt_disable(); list_for_each_entry_rcu(mod, &modules, list) { @@ -3646,6 +3678,12 @@ { struct module *mod; +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return -ERANGE; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ + preempt_disable(); list_for_each_entry_rcu(mod, &modules, list) { struct mod_kallsyms *kallsyms; @@ -3687,6 +3725,11 @@ char *colon; unsigned long ret = 0; +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return ret; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ /* Don't lock: we're in enough trouble already. */ preempt_disable(); if ((colon = strchr(name, ':')) != NULL) { @@ -3791,6 +3834,7 @@ /* Used by oprofile and other similar tools. */ seq_printf(m, " 0x%pK", mod->module_core); + /* Taints info */ if (mod->taints) seq_printf(m, " %s", module_flags(mod, buf)); @@ -3836,6 +3880,11 @@ { const struct exception_table_entry *e = NULL; struct module *mod; +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return e; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ preempt_disable(); list_for_each_entry_rcu(mod, &modules, list) { @@ -3868,6 +3917,11 @@ { bool ret; +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return false; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ preempt_disable(); ret = __module_address(addr) != NULL; preempt_enable(); @@ -3893,7 +3947,7 @@ if (mod->state == MODULE_STATE_UNFORMED) continue; if (within_module(addr, mod)) - return mod; + return mod; } return NULL; } @@ -3910,7 +3964,11 @@ bool is_module_text_address(unsigned long addr) { bool ret; - +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return false; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ preempt_disable(); ret = __module_text_address(addr) != NULL; preempt_enable(); @@ -3944,6 +4002,12 @@ struct module *mod; char buf[8]; +#if defined(CONFIG_AVM_FASTIRQ) + if(firq_is_avm_rte_restricted_mem_access()) { + return; + } +#endif/*--- #if defined(CONFIG_AVM_FASTIRQ) ---*/ + printk(KERN_DEFAULT "Modules linked in:"); /* Most callers should already have preempt disabled, but make sure */ preempt_disable(); @@ -3951,6 +4015,15 @@ if (mod->state == MODULE_STATE_UNFORMED) continue; pr_cont(" %s%s", mod->name, module_flags(mod, buf)); +#if !defined(CONFIG_AVM_ENHANCED) && defined(CONFIG_BCM_KF_EXTRA_DEBUG) + { + printk(" init_addr(%p - %p), core_addr(%p - %p)\n", + mod->module_init, + mod->module_init+mod->init_text_size, + mod->module_core, + mod->module_core+mod->core_text_size); + } +#endif } preempt_enable(); if (last_unloaded_module[0])