diff options
Diffstat (limited to 'kernel/module.c')
| -rw-r--r-- | kernel/module.c | 229 | 
1 files changed, 106 insertions, 123 deletions
diff --git a/kernel/module.c b/kernel/module.c index dc582749fa1..81e727cf6df 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -378,23 +378,21 @@ static bool check_symbol(const struct symsearch *syms,  		if (syms->licence == GPL_ONLY)  			return false;  		if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) { -			printk(KERN_WARNING "Symbol %s is being used " -			       "by a non-GPL module, which will not " -			       "be allowed in the future\n", fsa->name); +			pr_warn("Symbol %s is being used by a non-GPL module, " +				"which will not be allowed in the future\n", +				fsa->name);  		}  	}  #ifdef CONFIG_UNUSED_SYMBOLS  	if (syms->unused && fsa->warn) { -		printk(KERN_WARNING "Symbol %s is marked as UNUSED, " -		       "however this module is using it.\n", fsa->name); -		printk(KERN_WARNING -		       "This symbol will go away in the future.\n"); -		printk(KERN_WARNING -		       "Please evalute if this is the right api to use and if " -		       "it really is, submit a report the linux kernel " -		       "mailinglist together with submitting your code for " -		       "inclusion.\n"); +		pr_warn("Symbol %s is marked as UNUSED, however this module is " +			"using it.\n", fsa->name); +		pr_warn("This symbol will go away in the future.\n"); +		pr_warn("Please evalute if this is the right api to use and if " +			"it really is, submit a report the linux kernel " +			"mailinglist together with submitting your code for " +			"inclusion.\n");  	}  #endif @@ -492,16 +490,15 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)  		return 0;  	if (align > PAGE_SIZE) { -		printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", -		       mod->name, align, PAGE_SIZE); +		pr_warn("%s: per-cpu alignment %li > %li\n", +			mod->name, align, PAGE_SIZE);  		align = PAGE_SIZE;  	}  	mod->percpu = __alloc_reserved_percpu(pcpusec->sh_size, align);  	if (!mod->percpu) { -		printk(KERN_WARNING -		       "%s: Could not allocate %lu bytes percpu data\n", -		       mod->name, (unsigned long)pcpusec->sh_size); +		pr_warn("%s: Could not allocate %lu bytes percpu data\n", +			mod->name, (unsigned long)pcpusec->sh_size);  		return -ENOMEM;  	}  	mod->percpu_size = pcpusec->sh_size; @@ -643,9 +640,7 @@ static int module_unload_init(struct module *mod)  	INIT_LIST_HEAD(&mod->target_list);  	/* Hold reference count during initialization. */ -	__this_cpu_write(mod->refptr->incs, 1); -	/* Backwards compatibility macros put refcount during init. */ -	mod->waiter = current; +	raw_cpu_write(mod->refptr->incs, 1);  	return 0;  } @@ -679,7 +674,7 @@ static int add_module_usage(struct module *a, struct module *b)  	pr_debug("Allocating new usage for %s.\n", a->name);  	use = kmalloc(sizeof(*use), GFP_ATOMIC);  	if (!use) { -		printk(KERN_WARNING "%s: out of memory loading\n", a->name); +		pr_warn("%s: out of memory loading\n", a->name);  		return -ENOMEM;  	} @@ -771,16 +766,9 @@ static int __try_stop_module(void *_sref)  static int try_stop_module(struct module *mod, int flags, int *forced)  { -	if (flags & O_NONBLOCK) { -		struct stopref sref = { mod, flags, forced }; +	struct stopref sref = { mod, flags, forced }; -		return stop_machine(__try_stop_module, &sref, NULL); -	} else { -		/* We don't need to stop the machine for this. */ -		mod->state = MODULE_STATE_GOING; -		synchronize_sched(); -		return 0; -	} +	return stop_machine(__try_stop_module, &sref, NULL);  }  unsigned long module_refcount(struct module *mod) @@ -813,21 +801,6 @@ EXPORT_SYMBOL(module_refcount);  /* This exists whether we can unload or not */  static void free_module(struct module *mod); -static void wait_for_zero_refcount(struct module *mod) -{ -	/* Since we might sleep for some time, release the mutex first */ -	mutex_unlock(&module_mutex); -	for (;;) { -		pr_debug("Looking at refcount...\n"); -		set_current_state(TASK_UNINTERRUPTIBLE); -		if (module_refcount(mod) == 0) -			break; -		schedule(); -	} -	current->state = TASK_RUNNING; -	mutex_lock(&module_mutex); -} -  SYSCALL_DEFINE2(delete_module, const char __user *, name_user,  		unsigned int, flags)  { @@ -859,8 +832,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,  	/* Doing init or already dying? */  	if (mod->state != MODULE_STATE_LIVE) { -		/* FIXME: if (force), slam module count and wake up -                   waiter --RR */ +		/* FIXME: if (force), slam module count damn the torpedoes */  		pr_debug("%s already dying\n", mod->name);  		ret = -EBUSY;  		goto out; @@ -876,18 +848,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,  		}  	} -	/* Set this up before setting mod->state */ -	mod->waiter = current; -  	/* Stop the machine so refcounts can't move and disable module. */  	ret = try_stop_module(mod, flags, &forced);  	if (ret != 0)  		goto out; -	/* Never wait if forced. */ -	if (!forced && module_refcount(mod) != 0) -		wait_for_zero_refcount(mod); -  	mutex_unlock(&module_mutex);  	/* Final destruction now no one is using it. */  	if (mod->exit != NULL) @@ -1005,9 +970,6 @@ void module_put(struct module *module)  		__this_cpu_inc(module->refptr->decs);  		trace_module_put(module, _RET_IP_); -		/* Maybe they're waiting for us to drop reference? */ -		if (unlikely(!module_is_live(module))) -			wake_up_process(module->waiter);  		preempt_enable();  	}  } @@ -1048,9 +1010,11 @@ static size_t module_flags_taint(struct module *mod, char *buf)  		buf[l++] = 'F';  	if (mod->taints & (1 << TAINT_CRAP))  		buf[l++] = 'C'; +	if (mod->taints & (1 << TAINT_UNSIGNED_MODULE)) +		buf[l++] = 'E';  	/*  	 * TAINT_FORCED_RMMOD: could be added. -	 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't +	 * TAINT_CPU_OUT_OF_SPEC, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't  	 * apply to modules.  	 */  	return l; @@ -1145,8 +1109,7 @@ static int try_to_force_load(struct module *mod, const char *reason)  {  #ifdef CONFIG_MODULE_FORCE_LOAD  	if (!test_taint(TAINT_FORCED_MODULE)) -		printk(KERN_WARNING "%s: %s: kernel tainted.\n", -		       mod->name, reason); +		pr_warn("%s: %s: kernel tainted.\n", mod->name, reason);  	add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE);  	return 0;  #else @@ -1199,8 +1162,7 @@ static int check_version(Elf_Shdr *sechdrs,  		goto bad_version;  	} -	printk(KERN_WARNING "%s: no symbol version for %s\n", -	       mod->name, symname); +	pr_warn("%s: no symbol version for %s\n", mod->name, symname);  	return 0;  bad_version: @@ -1309,8 +1271,8 @@ resolve_symbol_wait(struct module *mod,  			!IS_ERR(ksym = resolve_symbol(mod, info, name, owner))  			|| PTR_ERR(ksym) != -EBUSY,  					     30 * HZ) <= 0) { -		printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", -		       mod->name, owner); +		pr_warn("%s: gave up waiting for init of module %s.\n", +			mod->name, owner);  	}  	return ksym;  } @@ -1626,15 +1588,14 @@ static int mod_sysfs_init(struct module *mod)  	struct kobject *kobj;  	if (!module_sysfs_initialized) { -		printk(KERN_ERR "%s: module sysfs not initialized\n", -		       mod->name); +		pr_err("%s: module sysfs not initialized\n", mod->name);  		err = -EINVAL;  		goto out;  	}  	kobj = kset_find_obj(module_kset, mod->name);  	if (kobj) { -		printk(KERN_ERR "%s: module is already loaded\n", mod->name); +		pr_err("%s: module is already loaded\n", mod->name);  		kobject_put(kobj);  		err = -EINVAL;  		goto out; @@ -1961,8 +1922,7 @@ static int verify_export_symbols(struct module *mod)  	for (i = 0; i < ARRAY_SIZE(arr); i++) {  		for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {  			if (find_symbol(s->name, &owner, NULL, true, false)) { -				printk(KERN_ERR -				       "%s: exports duplicate symbol %s" +				pr_err("%s: exports duplicate symbol %s"  				       " (owned by %s)\n",  				       mod->name, s->name, module_name(owner));  				return -ENOEXEC; @@ -1987,6 +1947,10 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)  		switch (sym[i].st_shndx) {  		case SHN_COMMON: +			/* Ignore common symbols */ +			if (!strncmp(name, "__gnu_lto", 9)) +				break; +  			/* We compiled with -fno-common.  These are not  			   supposed to happen.  */  			pr_debug("Common symbol: %s\n", name); @@ -2013,8 +1977,8 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)  			if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK)  				break; -			printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", -			       mod->name, name, PTR_ERR(ksym)); +			pr_warn("%s: Unknown symbol %s (err %li)\n", +				mod->name, name, PTR_ERR(ksym));  			ret = PTR_ERR(ksym) ?: -ENOENT;  			break; @@ -2168,8 +2132,8 @@ static void set_license(struct module *mod, const char *license)  	if (!license_is_gpl_compatible(license)) {  		if (!test_taint(TAINT_PROPRIETARY_MODULE)) -			printk(KERN_WARNING "%s: module license '%s' taints " -				"kernel.\n", mod->name, license); +			pr_warn("%s: module license '%s' taints kernel.\n", +				mod->name, license);  		add_taint_module(mod, TAINT_PROPRIETARY_MODULE,  				 LOCKDEP_NOW_UNRELIABLE);  	} @@ -2405,8 +2369,8 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)  		return;  #ifdef CONFIG_DYNAMIC_DEBUG  	if (ddebug_add_module(debug, num, debug->modname)) -		printk(KERN_ERR "dynamic debug error adding module: %s\n", -					debug->modname); +		pr_err("dynamic debug error adding module: %s\n", +			debug->modname);  #endif  } @@ -2619,8 +2583,7 @@ static int rewrite_section_headers(struct load_info *info, int flags)  		Elf_Shdr *shdr = &info->sechdrs[i];  		if (shdr->sh_type != SHT_NOBITS  		    && info->len < shdr->sh_offset + shdr->sh_size) { -			printk(KERN_ERR "Module len %lu truncated\n", -			       info->len); +			pr_err("Module len %lu truncated\n", info->len);  			return -ENOEXEC;  		} @@ -2682,15 +2645,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)  	info->index.mod = find_sec(info, ".gnu.linkonce.this_module");  	if (!info->index.mod) { -		printk(KERN_WARNING "No module found in object\n"); +		pr_warn("No module found in object\n");  		return ERR_PTR(-ENOEXEC);  	}  	/* This is temporary: point mod into copy of data. */  	mod = (void *)info->sechdrs[info->index.mod].sh_addr;  	if (info->index.sym == 0) { -		printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", -		       mod->name); +		pr_warn("%s: module has no symbols (stripped?)\n", mod->name);  		return ERR_PTR(-ENOEXEC);  	} @@ -2717,7 +2679,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)  		if (err)  			return err;  	} else if (!same_magic(modmagic, vermagic, info->index.vers)) { -		printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", +		pr_err("%s: version magic '%s' should be '%s'\n",  		       mod->name, modmagic, vermagic);  		return -ENOEXEC;  	} @@ -2727,9 +2689,8 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)  	if (get_modinfo(info, "staging")) {  		add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK); -		printk(KERN_WARNING "%s: module is from the staging directory," -		       " the quality is unknown, you have been warned.\n", -		       mod->name); +		pr_warn("%s: module is from the staging directory, the quality " +			"is unknown, you have been warned.\n", mod->name);  	}  	/* Set up license info based on the info section */ @@ -2738,7 +2699,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)  	return 0;  } -static void find_module_sections(struct module *mod, struct load_info *info) +static int find_module_sections(struct module *mod, struct load_info *info)  {  	mod->kp = section_objs(info, "__param",  			       sizeof(*mod->kp), &mod->num_kp); @@ -2768,6 +2729,18 @@ static void find_module_sections(struct module *mod, struct load_info *info)  #ifdef CONFIG_CONSTRUCTORS  	mod->ctors = section_objs(info, ".ctors",  				  sizeof(*mod->ctors), &mod->num_ctors); +	if (!mod->ctors) +		mod->ctors = section_objs(info, ".init_array", +				sizeof(*mod->ctors), &mod->num_ctors); +	else if (find_sec(info, ".init_array")) { +		/* +		 * This shouldn't happen with same compiler and binutils +		 * building all parts of the module. +		 */ +		printk(KERN_WARNING "%s: has both .ctors and .init_array.\n", +		       mod->name); +		return -EINVAL; +	}  #endif  #ifdef CONFIG_TRACEPOINTS @@ -2801,11 +2774,12 @@ static void find_module_sections(struct module *mod, struct load_info *info)  				    sizeof(*mod->extable), &mod->num_exentries);  	if (section_addr(info, "__obsparm")) -		printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", -		       mod->name); +		pr_warn("%s: Ignoring obsolete parameters\n", mod->name);  	info->debug = section_objs(info, "__verbose",  				   sizeof(*info->debug), &info->num_debug); + +	return 0;  }  static int move_module(struct module *mod, struct load_info *info) @@ -3046,21 +3020,6 @@ static int do_init_module(struct module *mod)  	 */  	current->flags &= ~PF_USED_ASYNC; -	blocking_notifier_call_chain(&module_notify_list, -			MODULE_STATE_COMING, mod); - -	/* Set RO and NX regions for core */ -	set_section_ro_nx(mod->module_core, -				mod->core_text_size, -				mod->core_ro_size, -				mod->core_size); - -	/* Set RO and NX regions for init */ -	set_section_ro_nx(mod->module_init, -				mod->init_text_size, -				mod->init_ro_size, -				mod->init_size); -  	do_mod_ctors(mod);  	/* Start the module */  	if (mod->init != NULL) @@ -3078,11 +3037,10 @@ static int do_init_module(struct module *mod)  		return ret;  	}  	if (ret > 0) { -		printk(KERN_WARNING -"%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n" -"%s: loading module anyway...\n", -		       __func__, mod->name, ret, -		       __func__); +		pr_warn("%s: '%s'->init suspiciously returned %d, it should " +			"follow 0/-E convention\n" +			"%s: loading module anyway...\n", +			__func__, mod->name, ret, __func__);  		dump_stack();  	} @@ -3192,9 +3150,26 @@ static int complete_formation(struct module *mod, struct load_info *info)  	/* This relies on module_mutex for list integrity. */  	module_bug_finalize(info->hdr, info->sechdrs, mod); +	/* Set RO and NX regions for core */ +	set_section_ro_nx(mod->module_core, +				mod->core_text_size, +				mod->core_ro_size, +				mod->core_size); + +	/* Set RO and NX regions for init */ +	set_section_ro_nx(mod->module_init, +				mod->init_text_size, +				mod->init_ro_size, +				mod->init_size); +  	/* Mark state as coming so strong_try_module_get() ignores us,  	 * but kallsyms etc. can see us. */  	mod->state = MODULE_STATE_COMING; +	mutex_unlock(&module_mutex); + +	blocking_notifier_call_chain(&module_notify_list, +				     MODULE_STATE_COMING, mod); +	return 0;  out:  	mutex_unlock(&module_mutex); @@ -3205,10 +3180,8 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname)  {  	/* Check for magic 'dyndbg' arg */   	int ret = ddebug_dyndbg_module_param_cb(param, val, modname); -	if (ret != 0) { -		printk(KERN_WARNING "%s: unknown parameter '%s' ignored\n", -		       modname, param); -	} +	if (ret != 0) +		pr_warn("%s: unknown parameter '%s' ignored\n", modname, param);  	return 0;  } @@ -3219,6 +3192,7 @@ static int load_module(struct load_info *info, const char __user *uargs,  {  	struct module *mod;  	long err; +	char *after_dashes;  	err = module_sig_check(info);  	if (err) @@ -3243,11 +3217,10 @@ static int load_module(struct load_info *info, const char __user *uargs,  #ifdef CONFIG_MODULE_SIG  	mod->sig_ok = info->sig_ok;  	if (!mod->sig_ok) { -		printk_once(KERN_NOTICE -			    "%s: module verification failed: signature and/or" -			    " required key missing - tainting kernel\n", -			    mod->name); -		add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK); +		pr_notice_once("%s: module verification failed: signature " +			       "and/or  required key missing - tainting " +			       "kernel\n", mod->name); +		add_taint_module(mod, TAINT_UNSIGNED_MODULE, LOCKDEP_STILL_OK);  	}  #endif @@ -3263,7 +3236,9 @@ static int load_module(struct load_info *info, const char __user *uargs,  	/* Now we've got everything in the final locations, we can  	 * find optional sections. */ -	find_module_sections(mod, info); +	err = find_module_sections(mod, info); +	if (err) +		goto free_unload;  	err = check_module_license_and_versions(mod);  	if (err) @@ -3296,16 +3271,24 @@ static int load_module(struct load_info *info, const char __user *uargs,  	dynamic_debug_setup(info->debug, info->num_debug); +	/* Ftrace init must be called in the MODULE_STATE_UNFORMED state */ +	ftrace_module_init(mod); +  	/* Finally it's fully formed, ready to start executing. */  	err = complete_formation(mod, info);  	if (err)  		goto ddebug_cleanup;  	/* Module is ready to execute: parsing args may do that. */ -	err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, -			 -32768, 32767, unknown_module_param_cb); -	if (err < 0) +	after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, +				  -32768, 32767, unknown_module_param_cb); +	if (IS_ERR(after_dashes)) { +		err = PTR_ERR(after_dashes);  		goto bug_cleanup; +	} else if (after_dashes) { +		pr_warn("%s: parameters '%s' after `--' ignored\n", +		       mod->name, after_dashes); +	}  	/* Link in to syfs. */  	err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp); @@ -3840,12 +3823,12 @@ void print_modules(void)  	list_for_each_entry_rcu(mod, &modules, list) {  		if (mod->state == MODULE_STATE_UNFORMED)  			continue; -		printk(" %s%s", mod->name, module_flags(mod, buf)); +		pr_cont(" %s%s", mod->name, module_flags(mod, buf));  	}  	preempt_enable();  	if (last_unloaded_module[0]) -		printk(" [last unloaded: %s]", last_unloaded_module); -	printk("\n"); +		pr_cont(" [last unloaded: %s]", last_unloaded_module); +	pr_cont("\n");  }  #ifdef CONFIG_MODVERSIONS  | 
