1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
| static int load_module(struct load_info *info, const char __user *uargs, int flags) { struct module *mod; bool module_allocated = false; long err = 0; char *after_dashes;
err = module_sig_check(info, flags); if (err) goto free_copy;
err = elf_validity_cache_copy(info, flags); if (err) goto free_copy;
err = early_mod_check(info, flags); if (err) goto free_copy;
mod = layout_and_allocate(info, flags); if (IS_ERR(mod)) { err = PTR_ERR(mod); goto free_copy; }
module_allocated = true;
audit_log_kern_module(info->name);
err = add_unformed_module(mod); if (err) goto free_module;
module_augment_kernel_taints(mod, info);
err = percpu_modalloc(mod, info); if (err) goto unlink_mod;
err = module_unload_init(mod); if (err) goto unlink_mod;
init_param_lock(mod);
err = find_module_sections(mod, info); if (err) goto free_unload;
err = check_export_symbol_versions(mod); if (err) goto free_unload;
setup_modinfo(mod, info);
err = simplify_symbols(mod, info); if (err < 0) goto free_modinfo;
err = apply_relocations(mod, info); if (err < 0) goto free_modinfo;
err = post_relocation(mod, info); if (err < 0) goto free_modinfo;
flush_module_icache(mod);
mod->args = strndup_user(uargs, ~0UL >> 1); if (IS_ERR(mod->args)) { err = PTR_ERR(mod->args); goto free_arch_cleanup; }
init_build_id(mod, info);
ftrace_module_init(mod);
err = complete_formation(mod, info); if (err) goto ddebug_cleanup;
err = prepare_coming_module(mod); if (err) goto bug_cleanup;
mod->async_probe_requested = async_probe;
after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, -32768, 32767, mod, unknown_module_param_cb); if (IS_ERR(after_dashes)) { err = PTR_ERR(after_dashes); goto coming_cleanup; } else if (after_dashes) { pr_warn("%s: parameters '%s' after `--' ignored\n", mod->name, after_dashes); }
err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp); if (err < 0) goto coming_cleanup;
if (is_livepatch_module(mod)) { err = copy_module_elf(mod, info); if (err < 0) goto sysfs_cleanup; }
free_copy(info, flags);
trace_module_load(mod);
return do_init_module(mod);
sysfs_cleanup: mod_sysfs_teardown(mod); coming_cleanup: mod->state = MODULE_STATE_GOING; destroy_params(mod->kp, mod->num_kp); blocking_notifier_call_chain(&module_notify_list, MODULE_STATE_GOING, mod); klp_module_going(mod); bug_cleanup: mod->state = MODULE_STATE_GOING; mutex_lock(&module_mutex); module_bug_cleanup(mod); mutex_unlock(&module_mutex);
ddebug_cleanup: ftrace_release_mod(mod); synchronize_rcu(); kfree(mod->args); free_arch_cleanup: module_arch_cleanup(mod); free_modinfo: free_modinfo(mod); free_unload: module_unload_free(mod); unlink_mod: mutex_lock(&module_mutex); list_del_rcu(&mod->list); mod_tree_remove(mod); wake_up_all(&module_wq); synchronize_rcu(); mutex_unlock(&module_mutex); free_module: mod_stat_bump_invalid(info, flags); for_class_mod_mem_type(type, core_data) { lockdep_free_key_range(mod->mem[type].base, mod->mem[type].size); }
module_deallocate(mod, info); free_copy:
if (!module_allocated) { audit_log_kern_module(info->name ? info->name : "?"); mod_stat_bump_becoming(info, flags); } free_copy(info, flags); return err; }
|