module: Don't report discarded init pages as kernel text.
[linux-2.6-block.git] / kernel / module.c
CommitLineData
f71d20e9 1/*
1da177e4
LT
2 Copyright (C) 2002 Richard Henderson
3 Copyright (C) 2001 Rusty Russell, 2002 Rusty Russell IBM.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
1da177e4
LT
19#include <linux/module.h>
20#include <linux/moduleloader.h>
21#include <linux/init.h>
ae84e324 22#include <linux/kallsyms.h>
6d760133 23#include <linux/sysfs.h>
9f158333 24#include <linux/kernel.h>
1da177e4
LT
25#include <linux/slab.h>
26#include <linux/vmalloc.h>
27#include <linux/elf.h>
28#include <linux/seq_file.h>
29#include <linux/syscalls.h>
30#include <linux/fcntl.h>
31#include <linux/rcupdate.h>
c59ede7b 32#include <linux/capability.h>
1da177e4
LT
33#include <linux/cpu.h>
34#include <linux/moduleparam.h>
35#include <linux/errno.h>
36#include <linux/err.h>
37#include <linux/vermagic.h>
38#include <linux/notifier.h>
f6a57033 39#include <linux/sched.h>
1da177e4
LT
40#include <linux/stop_machine.h>
41#include <linux/device.h>
c988d2b2 42#include <linux/string.h>
97d1f15b 43#include <linux/mutex.h>
4552d5dc 44#include <linux/unwind.h>
1da177e4
LT
45#include <asm/uaccess.h>
46#include <asm/semaphore.h>
47#include <asm/cacheflush.h>
b817f6fe 48#include <linux/license.h>
1da177e4
LT
49
50#if 0
51#define DEBUGP printk
52#else
53#define DEBUGP(fmt , a...)
54#endif
55
56#ifndef ARCH_SHF_SMALL
57#define ARCH_SHF_SMALL 0
58#endif
59
60/* If this is set, the section belongs in the init part of the module */
61#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
62
24da1cbf
RR
63/* List of modules, protected by module_mutex or preempt_disable
64 * (add/delete uses stop_machine). */
6389a385 65static DEFINE_MUTEX(module_mutex);
1da177e4
LT
66static LIST_HEAD(modules);
67
e041c683 68static BLOCKING_NOTIFIER_HEAD(module_notify_list);
1da177e4
LT
69
70int register_module_notifier(struct notifier_block * nb)
71{
e041c683 72 return blocking_notifier_chain_register(&module_notify_list, nb);
1da177e4
LT
73}
74EXPORT_SYMBOL(register_module_notifier);
75
76int unregister_module_notifier(struct notifier_block * nb)
77{
e041c683 78 return blocking_notifier_chain_unregister(&module_notify_list, nb);
1da177e4
LT
79}
80EXPORT_SYMBOL(unregister_module_notifier);
81
9a4b9708
ML
82/* We require a truly strong try_module_get(): 0 means failure due to
83 ongoing or failed initialization etc. */
1da177e4
LT
84static inline int strong_try_module_get(struct module *mod)
85{
86 if (mod && mod->state == MODULE_STATE_COMING)
87 return 0;
88 return try_module_get(mod);
89}
90
fa3ba2e8
FM
91static inline void add_taint_module(struct module *mod, unsigned flag)
92{
93 add_taint(flag);
94 mod->taints |= flag;
95}
96
02a3e59a
RD
97/*
98 * A thread that wants to hold a reference to a module only while it
99 * is running can call this to safely exit. nfsd and lockd use this.
1da177e4
LT
100 */
101void __module_put_and_exit(struct module *mod, long code)
102{
103 module_put(mod);
104 do_exit(code);
105}
106EXPORT_SYMBOL(__module_put_and_exit);
22a8bdeb 107
1da177e4
LT
108/* Find a module section: 0 means not found. */
109static unsigned int find_sec(Elf_Ehdr *hdr,
110 Elf_Shdr *sechdrs,
111 const char *secstrings,
112 const char *name)
113{
114 unsigned int i;
115
116 for (i = 1; i < hdr->e_shnum; i++)
117 /* Alloc bit cleared means "ignore it." */
118 if ((sechdrs[i].sh_flags & SHF_ALLOC)
119 && strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
120 return i;
121 return 0;
122}
123
124/* Provided by the linker */
125extern const struct kernel_symbol __start___ksymtab[];
126extern const struct kernel_symbol __stop___ksymtab[];
127extern const struct kernel_symbol __start___ksymtab_gpl[];
128extern const struct kernel_symbol __stop___ksymtab_gpl[];
9f28bb7e
GKH
129extern const struct kernel_symbol __start___ksymtab_gpl_future[];
130extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
f71d20e9
AV
131extern const struct kernel_symbol __start___ksymtab_unused[];
132extern const struct kernel_symbol __stop___ksymtab_unused[];
133extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
134extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
135extern const struct kernel_symbol __start___ksymtab_gpl_future[];
136extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
1da177e4
LT
137extern const unsigned long __start___kcrctab[];
138extern const unsigned long __start___kcrctab_gpl[];
9f28bb7e 139extern const unsigned long __start___kcrctab_gpl_future[];
f71d20e9
AV
140extern const unsigned long __start___kcrctab_unused[];
141extern const unsigned long __start___kcrctab_unused_gpl[];
1da177e4
LT
142
143#ifndef CONFIG_MODVERSIONS
144#define symversion(base, idx) NULL
145#else
f83ca9fe 146#define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
1da177e4
LT
147#endif
148
3fd6805f
SR
149/* lookup symbol in given range of kernel_symbols */
150static const struct kernel_symbol *lookup_symbol(const char *name,
151 const struct kernel_symbol *start,
152 const struct kernel_symbol *stop)
153{
154 const struct kernel_symbol *ks = start;
155 for (; ks < stop; ks++)
156 if (strcmp(ks->name, name) == 0)
157 return ks;
158 return NULL;
159}
160
f71d20e9
AV
161static void printk_unused_warning(const char *name)
162{
163 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
164 "however this module is using it.\n", name);
165 printk(KERN_WARNING "This symbol will go away in the future.\n");
166 printk(KERN_WARNING "Please evalute if this is the right api to use, "
167 "and if it really is, submit a report the linux kernel "
168 "mailinglist together with submitting your code for "
169 "inclusion.\n");
170}
171
1da177e4
LT
172/* Find a symbol, return value, crc and module which owns it */
173static unsigned long __find_symbol(const char *name,
174 struct module **owner,
175 const unsigned long **crc,
176 int gplok)
177{
178 struct module *mod;
3fd6805f 179 const struct kernel_symbol *ks;
1da177e4 180
22a8bdeb 181 /* Core kernel first. */
1da177e4 182 *owner = NULL;
3fd6805f
SR
183 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
184 if (ks) {
185 *crc = symversion(__start___kcrctab, (ks - __start___ksymtab));
186 return ks->value;
1da177e4
LT
187 }
188 if (gplok) {
3fd6805f
SR
189 ks = lookup_symbol(name, __start___ksymtab_gpl,
190 __stop___ksymtab_gpl);
191 if (ks) {
192 *crc = symversion(__start___kcrctab_gpl,
193 (ks - __start___ksymtab_gpl));
194 return ks->value;
195 }
1da177e4 196 }
9f28bb7e
GKH
197 ks = lookup_symbol(name, __start___ksymtab_gpl_future,
198 __stop___ksymtab_gpl_future);
199 if (ks) {
200 if (!gplok) {
201 printk(KERN_WARNING "Symbol %s is being used "
202 "by a non-GPL module, which will not "
203 "be allowed in the future\n", name);
204 printk(KERN_WARNING "Please see the file "
205 "Documentation/feature-removal-schedule.txt "
206 "in the kernel source tree for more "
207 "details.\n");
208 }
209 *crc = symversion(__start___kcrctab_gpl_future,
210 (ks - __start___ksymtab_gpl_future));
211 return ks->value;
212 }
1da177e4 213
f71d20e9
AV
214 ks = lookup_symbol(name, __start___ksymtab_unused,
215 __stop___ksymtab_unused);
216 if (ks) {
217 printk_unused_warning(name);
218 *crc = symversion(__start___kcrctab_unused,
219 (ks - __start___ksymtab_unused));
220 return ks->value;
221 }
222
223 if (gplok)
224 ks = lookup_symbol(name, __start___ksymtab_unused_gpl,
225 __stop___ksymtab_unused_gpl);
226 if (ks) {
227 printk_unused_warning(name);
228 *crc = symversion(__start___kcrctab_unused_gpl,
229 (ks - __start___ksymtab_unused_gpl));
230 return ks->value;
231 }
232
22a8bdeb 233 /* Now try modules. */
1da177e4
LT
234 list_for_each_entry(mod, &modules, list) {
235 *owner = mod;
3fd6805f
SR
236 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
237 if (ks) {
238 *crc = symversion(mod->crcs, (ks - mod->syms));
239 return ks->value;
240 }
1da177e4
LT
241
242 if (gplok) {
3fd6805f
SR
243 ks = lookup_symbol(name, mod->gpl_syms,
244 mod->gpl_syms + mod->num_gpl_syms);
245 if (ks) {
246 *crc = symversion(mod->gpl_crcs,
247 (ks - mod->gpl_syms));
248 return ks->value;
1da177e4
LT
249 }
250 }
f71d20e9
AV
251 ks = lookup_symbol(name, mod->unused_syms, mod->unused_syms + mod->num_unused_syms);
252 if (ks) {
253 printk_unused_warning(name);
254 *crc = symversion(mod->unused_crcs, (ks - mod->unused_syms));
255 return ks->value;
256 }
257
258 if (gplok) {
259 ks = lookup_symbol(name, mod->unused_gpl_syms,
260 mod->unused_gpl_syms + mod->num_unused_gpl_syms);
261 if (ks) {
262 printk_unused_warning(name);
263 *crc = symversion(mod->unused_gpl_crcs,
264 (ks - mod->unused_gpl_syms));
265 return ks->value;
266 }
267 }
9f28bb7e
GKH
268 ks = lookup_symbol(name, mod->gpl_future_syms,
269 (mod->gpl_future_syms +
270 mod->num_gpl_future_syms));
271 if (ks) {
272 if (!gplok) {
273 printk(KERN_WARNING "Symbol %s is being used "
274 "by a non-GPL module, which will not "
275 "be allowed in the future\n", name);
276 printk(KERN_WARNING "Please see the file "
277 "Documentation/feature-removal-schedule.txt "
278 "in the kernel source tree for more "
279 "details.\n");
280 }
281 *crc = symversion(mod->gpl_future_crcs,
282 (ks - mod->gpl_future_syms));
283 return ks->value;
284 }
1da177e4
LT
285 }
286 DEBUGP("Failed to find symbol %s\n", name);
22a8bdeb 287 return 0;
1da177e4
LT
288}
289
1da177e4
LT
290/* Search for module by name: must hold module_mutex. */
291static struct module *find_module(const char *name)
292{
293 struct module *mod;
294
295 list_for_each_entry(mod, &modules, list) {
296 if (strcmp(mod->name, name) == 0)
297 return mod;
298 }
299 return NULL;
300}
301
302#ifdef CONFIG_SMP
303/* Number of blocks used and allocated. */
304static unsigned int pcpu_num_used, pcpu_num_allocated;
305/* Size of each block. -ve means used. */
306static int *pcpu_size;
307
308static int split_block(unsigned int i, unsigned short size)
309{
310 /* Reallocation required? */
311 if (pcpu_num_used + 1 > pcpu_num_allocated) {
6d4f9c55
PE
312 int *new;
313
314 new = krealloc(pcpu_size, sizeof(new[0])*pcpu_num_allocated*2,
315 GFP_KERNEL);
1da177e4
LT
316 if (!new)
317 return 0;
318
1da177e4 319 pcpu_num_allocated *= 2;
1da177e4
LT
320 pcpu_size = new;
321 }
322
323 /* Insert a new subblock */
324 memmove(&pcpu_size[i+1], &pcpu_size[i],
325 sizeof(pcpu_size[0]) * (pcpu_num_used - i));
326 pcpu_num_used++;
327
328 pcpu_size[i+1] -= size;
329 pcpu_size[i] = size;
330 return 1;
331}
332
333static inline unsigned int block_size(int val)
334{
335 if (val < 0)
336 return -val;
337 return val;
338}
339
340/* Created by linker magic */
341extern char __per_cpu_start[], __per_cpu_end[];
342
842bbaaa
RR
343static void *percpu_modalloc(unsigned long size, unsigned long align,
344 const char *name)
1da177e4
LT
345{
346 unsigned long extra;
347 unsigned int i;
348 void *ptr;
349
b6e3590f
JF
350 if (align > PAGE_SIZE) {
351 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
352 name, align, PAGE_SIZE);
353 align = PAGE_SIZE;
842bbaaa 354 }
1da177e4
LT
355
356 ptr = __per_cpu_start;
357 for (i = 0; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) {
358 /* Extra for alignment requirement. */
359 extra = ALIGN((unsigned long)ptr, align) - (unsigned long)ptr;
360 BUG_ON(i == 0 && extra != 0);
361
362 if (pcpu_size[i] < 0 || pcpu_size[i] < extra + size)
363 continue;
364
365 /* Transfer extra to previous block. */
366 if (pcpu_size[i-1] < 0)
367 pcpu_size[i-1] -= extra;
368 else
369 pcpu_size[i-1] += extra;
370 pcpu_size[i] -= extra;
371 ptr += extra;
372
373 /* Split block if warranted */
374 if (pcpu_size[i] - size > sizeof(unsigned long))
375 if (!split_block(i, size))
376 return NULL;
377
378 /* Mark allocated */
379 pcpu_size[i] = -pcpu_size[i];
380 return ptr;
381 }
382
383 printk(KERN_WARNING "Could not allocate %lu bytes percpu data\n",
384 size);
385 return NULL;
386}
387
388static void percpu_modfree(void *freeme)
389{
390 unsigned int i;
391 void *ptr = __per_cpu_start + block_size(pcpu_size[0]);
392
393 /* First entry is core kernel percpu data. */
394 for (i = 1; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) {
395 if (ptr == freeme) {
396 pcpu_size[i] = -pcpu_size[i];
397 goto free;
398 }
399 }
400 BUG();
401
402 free:
403 /* Merge with previous? */
404 if (pcpu_size[i-1] >= 0) {
405 pcpu_size[i-1] += pcpu_size[i];
406 pcpu_num_used--;
407 memmove(&pcpu_size[i], &pcpu_size[i+1],
408 (pcpu_num_used - i) * sizeof(pcpu_size[0]));
409 i--;
410 }
411 /* Merge with next? */
412 if (i+1 < pcpu_num_used && pcpu_size[i+1] >= 0) {
413 pcpu_size[i] += pcpu_size[i+1];
414 pcpu_num_used--;
415 memmove(&pcpu_size[i+1], &pcpu_size[i+2],
416 (pcpu_num_used - (i+1)) * sizeof(pcpu_size[0]));
417 }
418}
419
420static unsigned int find_pcpusec(Elf_Ehdr *hdr,
421 Elf_Shdr *sechdrs,
422 const char *secstrings)
423{
424 return find_sec(hdr, sechdrs, secstrings, ".data.percpu");
425}
426
427static int percpu_modinit(void)
428{
429 pcpu_num_used = 2;
430 pcpu_num_allocated = 2;
431 pcpu_size = kmalloc(sizeof(pcpu_size[0]) * pcpu_num_allocated,
432 GFP_KERNEL);
433 /* Static in-kernel percpu data (used). */
b00742d3 434 pcpu_size[0] = -(__per_cpu_end-__per_cpu_start);
1da177e4
LT
435 /* Free room. */
436 pcpu_size[1] = PERCPU_ENOUGH_ROOM + pcpu_size[0];
437 if (pcpu_size[1] < 0) {
438 printk(KERN_ERR "No per-cpu room for modules.\n");
439 pcpu_num_used = 1;
440 }
441
442 return 0;
22a8bdeb 443}
1da177e4
LT
444__initcall(percpu_modinit);
445#else /* ... !CONFIG_SMP */
842bbaaa
RR
446static inline void *percpu_modalloc(unsigned long size, unsigned long align,
447 const char *name)
1da177e4
LT
448{
449 return NULL;
450}
451static inline void percpu_modfree(void *pcpuptr)
452{
453 BUG();
454}
455static inline unsigned int find_pcpusec(Elf_Ehdr *hdr,
456 Elf_Shdr *sechdrs,
457 const char *secstrings)
458{
459 return 0;
460}
461static inline void percpu_modcopy(void *pcpudst, const void *src,
462 unsigned long size)
463{
464 /* pcpusec should be 0, and size of that section should be 0. */
465 BUG_ON(size != 0);
466}
467#endif /* CONFIG_SMP */
468
c988d2b2
MD
469#define MODINFO_ATTR(field) \
470static void setup_modinfo_##field(struct module *mod, const char *s) \
471{ \
472 mod->field = kstrdup(s, GFP_KERNEL); \
473} \
474static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
475 struct module *mod, char *buffer) \
476{ \
477 return sprintf(buffer, "%s\n", mod->field); \
478} \
479static int modinfo_##field##_exists(struct module *mod) \
480{ \
481 return mod->field != NULL; \
482} \
483static void free_modinfo_##field(struct module *mod) \
484{ \
22a8bdeb
DW
485 kfree(mod->field); \
486 mod->field = NULL; \
c988d2b2
MD
487} \
488static struct module_attribute modinfo_##field = { \
7b595756 489 .attr = { .name = __stringify(field), .mode = 0444 }, \
c988d2b2
MD
490 .show = show_modinfo_##field, \
491 .setup = setup_modinfo_##field, \
492 .test = modinfo_##field##_exists, \
493 .free = free_modinfo_##field, \
494};
495
496MODINFO_ATTR(version);
497MODINFO_ATTR(srcversion);
498
e14af7ee
AV
499static char last_unloaded_module[MODULE_NAME_LEN+1];
500
03e88ae1 501#ifdef CONFIG_MODULE_UNLOAD
1da177e4
LT
502/* Init the unload section of the module. */
503static void module_unload_init(struct module *mod)
504{
505 unsigned int i;
506
507 INIT_LIST_HEAD(&mod->modules_which_use_me);
508 for (i = 0; i < NR_CPUS; i++)
509 local_set(&mod->ref[i].count, 0);
510 /* Hold reference count during initialization. */
39c715b7 511 local_set(&mod->ref[raw_smp_processor_id()].count, 1);
1da177e4
LT
512 /* Backwards compatibility macros put refcount during init. */
513 mod->waiter = current;
514}
515
516/* modules using other modules */
517struct module_use
518{
519 struct list_head list;
520 struct module *module_which_uses;
521};
522
523/* Does a already use b? */
524static int already_uses(struct module *a, struct module *b)
525{
526 struct module_use *use;
527
528 list_for_each_entry(use, &b->modules_which_use_me, list) {
529 if (use->module_which_uses == a) {
530 DEBUGP("%s uses %s!\n", a->name, b->name);
531 return 1;
532 }
533 }
534 DEBUGP("%s does not use %s!\n", a->name, b->name);
535 return 0;
536}
537
538/* Module a uses b */
539static int use_module(struct module *a, struct module *b)
540{
541 struct module_use *use;
270a6c4c
KS
542 int no_warn;
543
1da177e4
LT
544 if (b == NULL || already_uses(a, b)) return 1;
545
546 if (!strong_try_module_get(b))
547 return 0;
548
549 DEBUGP("Allocating new usage for %s.\n", a->name);
550 use = kmalloc(sizeof(*use), GFP_ATOMIC);
551 if (!use) {
552 printk("%s: out of memory loading\n", a->name);
553 module_put(b);
554 return 0;
555 }
556
557 use->module_which_uses = a;
558 list_add(&use->list, &b->modules_which_use_me);
270a6c4c 559 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
1da177e4
LT
560 return 1;
561}
562
563/* Clear the unload stuff of the module. */
564static void module_unload_free(struct module *mod)
565{
566 struct module *i;
567
568 list_for_each_entry(i, &modules, list) {
569 struct module_use *use;
570
571 list_for_each_entry(use, &i->modules_which_use_me, list) {
572 if (use->module_which_uses == mod) {
573 DEBUGP("%s unusing %s\n", mod->name, i->name);
574 module_put(i);
575 list_del(&use->list);
576 kfree(use);
270a6c4c 577 sysfs_remove_link(i->holders_dir, mod->name);
1da177e4
LT
578 /* There can be at most one match. */
579 break;
580 }
581 }
582 }
583}
584
585#ifdef CONFIG_MODULE_FORCE_UNLOAD
fb169793 586static inline int try_force_unload(unsigned int flags)
1da177e4
LT
587{
588 int ret = (flags & O_TRUNC);
589 if (ret)
fb169793 590 add_taint(TAINT_FORCED_RMMOD);
1da177e4
LT
591 return ret;
592}
593#else
fb169793 594static inline int try_force_unload(unsigned int flags)
1da177e4
LT
595{
596 return 0;
597}
598#endif /* CONFIG_MODULE_FORCE_UNLOAD */
599
600struct stopref
601{
602 struct module *mod;
603 int flags;
604 int *forced;
605};
606
607/* Whole machine is stopped with interrupts off when this runs. */
608static int __try_stop_module(void *_sref)
609{
610 struct stopref *sref = _sref;
611
612 /* If it's not unused, quit unless we are told to block. */
613 if ((sref->flags & O_NONBLOCK) && module_refcount(sref->mod) != 0) {
fb169793 614 if (!(*sref->forced = try_force_unload(sref->flags)))
1da177e4
LT
615 return -EWOULDBLOCK;
616 }
617
618 /* Mark it as dying. */
619 sref->mod->state = MODULE_STATE_GOING;
620 return 0;
621}
622
623static int try_stop_module(struct module *mod, int flags, int *forced)
624{
625 struct stopref sref = { mod, flags, forced };
626
627 return stop_machine_run(__try_stop_module, &sref, NR_CPUS);
628}
629
630unsigned int module_refcount(struct module *mod)
631{
632 unsigned int i, total = 0;
633
634 for (i = 0; i < NR_CPUS; i++)
635 total += local_read(&mod->ref[i].count);
636 return total;
637}
638EXPORT_SYMBOL(module_refcount);
639
640/* This exists whether we can unload or not */
641static void free_module(struct module *mod);
642
643static void wait_for_zero_refcount(struct module *mod)
644{
645 /* Since we might sleep for some time, drop the semaphore first */
6389a385 646 mutex_unlock(&module_mutex);
1da177e4
LT
647 for (;;) {
648 DEBUGP("Looking at refcount...\n");
649 set_current_state(TASK_UNINTERRUPTIBLE);
650 if (module_refcount(mod) == 0)
651 break;
652 schedule();
653 }
654 current->state = TASK_RUNNING;
6389a385 655 mutex_lock(&module_mutex);
1da177e4
LT
656}
657
dfff0a06
GKH
658asmlinkage long
659sys_delete_module(const char __user *name_user, unsigned int flags)
1da177e4
LT
660{
661 struct module *mod;
dfff0a06 662 char name[MODULE_NAME_LEN];
1da177e4
LT
663 int ret, forced = 0;
664
dfff0a06
GKH
665 if (!capable(CAP_SYS_MODULE))
666 return -EPERM;
667
668 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
669 return -EFAULT;
670 name[MODULE_NAME_LEN-1] = '\0';
671
6389a385 672 if (mutex_lock_interruptible(&module_mutex) != 0)
1da177e4
LT
673 return -EINTR;
674
675 mod = find_module(name);
676 if (!mod) {
677 ret = -ENOENT;
678 goto out;
679 }
680
681 if (!list_empty(&mod->modules_which_use_me)) {
682 /* Other modules depend on us: get rid of them first. */
683 ret = -EWOULDBLOCK;
684 goto out;
685 }
686
687 /* Doing init or already dying? */
688 if (mod->state != MODULE_STATE_LIVE) {
689 /* FIXME: if (force), slam module count and wake up
690 waiter --RR */
691 DEBUGP("%s already dying\n", mod->name);
692 ret = -EBUSY;
693 goto out;
694 }
695
696 /* If it has an init func, it must have an exit func to unload */
af49d924 697 if (mod->init && !mod->exit) {
fb169793 698 forced = try_force_unload(flags);
1da177e4
LT
699 if (!forced) {
700 /* This module can't be removed */
701 ret = -EBUSY;
702 goto out;
703 }
704 }
705
706 /* Set this up before setting mod->state */
707 mod->waiter = current;
708
709 /* Stop the machine so refcounts can't move and disable module. */
710 ret = try_stop_module(mod, flags, &forced);
711 if (ret != 0)
712 goto out;
713
714 /* Never wait if forced. */
715 if (!forced && module_refcount(mod) != 0)
716 wait_for_zero_refcount(mod);
717
718 /* Final destruction now noone is using it. */
719 if (mod->exit != NULL) {
6389a385 720 mutex_unlock(&module_mutex);
1da177e4 721 mod->exit();
6389a385 722 mutex_lock(&module_mutex);
1da177e4 723 }
e14af7ee
AV
724 /* Store the name of the last unloaded module for diagnostic purposes */
725 sprintf(last_unloaded_module, mod->name);
1da177e4
LT
726 free_module(mod);
727
728 out:
6389a385 729 mutex_unlock(&module_mutex);
1da177e4
LT
730 return ret;
731}
732
733static void print_unload_info(struct seq_file *m, struct module *mod)
734{
735 struct module_use *use;
736 int printed_something = 0;
737
738 seq_printf(m, " %u ", module_refcount(mod));
739
740 /* Always include a trailing , so userspace can differentiate
741 between this and the old multi-field proc format. */
742 list_for_each_entry(use, &mod->modules_which_use_me, list) {
743 printed_something = 1;
744 seq_printf(m, "%s,", use->module_which_uses->name);
745 }
746
1da177e4
LT
747 if (mod->init != NULL && mod->exit == NULL) {
748 printed_something = 1;
749 seq_printf(m, "[permanent],");
750 }
751
752 if (!printed_something)
753 seq_printf(m, "-");
754}
755
756void __symbol_put(const char *symbol)
757{
758 struct module *owner;
1da177e4
LT
759 const unsigned long *crc;
760
24da1cbf 761 preempt_disable();
1da177e4
LT
762 if (!__find_symbol(symbol, &owner, &crc, 1))
763 BUG();
764 module_put(owner);
24da1cbf 765 preempt_enable();
1da177e4
LT
766}
767EXPORT_SYMBOL(__symbol_put);
768
769void symbol_put_addr(void *addr)
770{
5e376613 771 struct module *modaddr;
1da177e4 772
5e376613
TP
773 if (core_kernel_text((unsigned long)addr))
774 return;
1da177e4 775
5e376613
TP
776 if (!(modaddr = module_text_address((unsigned long)addr)))
777 BUG();
778 module_put(modaddr);
1da177e4
LT
779}
780EXPORT_SYMBOL_GPL(symbol_put_addr);
781
782static ssize_t show_refcnt(struct module_attribute *mattr,
783 struct module *mod, char *buffer)
784{
256e2fdf 785 return sprintf(buffer, "%u\n", module_refcount(mod));
1da177e4
LT
786}
787
788static struct module_attribute refcnt = {
7b595756 789 .attr = { .name = "refcnt", .mode = 0444 },
1da177e4
LT
790 .show = show_refcnt,
791};
792
f6a57033
AV
793void module_put(struct module *module)
794{
795 if (module) {
796 unsigned int cpu = get_cpu();
797 local_dec(&module->ref[cpu].count);
798 /* Maybe they're waiting for us to drop reference? */
799 if (unlikely(!module_is_live(module)))
800 wake_up_process(module->waiter);
801 put_cpu();
802 }
803}
804EXPORT_SYMBOL(module_put);
805
1da177e4
LT
806#else /* !CONFIG_MODULE_UNLOAD */
807static void print_unload_info(struct seq_file *m, struct module *mod)
808{
809 /* We don't know the usage count, or what modules are using. */
810 seq_printf(m, " - -");
811}
812
813static inline void module_unload_free(struct module *mod)
814{
815}
816
817static inline int use_module(struct module *a, struct module *b)
818{
819 return strong_try_module_get(b);
820}
821
822static inline void module_unload_init(struct module *mod)
823{
824}
825#endif /* CONFIG_MODULE_UNLOAD */
826
1f71740a
KS
827static ssize_t show_initstate(struct module_attribute *mattr,
828 struct module *mod, char *buffer)
829{
830 const char *state = "unknown";
831
832 switch (mod->state) {
833 case MODULE_STATE_LIVE:
834 state = "live";
835 break;
836 case MODULE_STATE_COMING:
837 state = "coming";
838 break;
839 case MODULE_STATE_GOING:
840 state = "going";
841 break;
842 }
843 return sprintf(buffer, "%s\n", state);
844}
845
846static struct module_attribute initstate = {
7b595756 847 .attr = { .name = "initstate", .mode = 0444 },
1f71740a
KS
848 .show = show_initstate,
849};
850
03e88ae1
GKH
851static struct module_attribute *modinfo_attrs[] = {
852 &modinfo_version,
853 &modinfo_srcversion,
1f71740a 854 &initstate,
03e88ae1
GKH
855#ifdef CONFIG_MODULE_UNLOAD
856 &refcnt,
857#endif
858 NULL,
859};
860
1da177e4
LT
861static const char vermagic[] = VERMAGIC_STRING;
862
863#ifdef CONFIG_MODVERSIONS
864static int check_version(Elf_Shdr *sechdrs,
865 unsigned int versindex,
866 const char *symname,
867 struct module *mod,
868 const unsigned long *crc)
869{
870 unsigned int i, num_versions;
871 struct modversion_info *versions;
872
873 /* Exporting module didn't supply crcs? OK, we're already tainted. */
874 if (!crc)
875 return 1;
876
877 versions = (void *) sechdrs[versindex].sh_addr;
878 num_versions = sechdrs[versindex].sh_size
879 / sizeof(struct modversion_info);
880
881 for (i = 0; i < num_versions; i++) {
882 if (strcmp(versions[i].name, symname) != 0)
883 continue;
884
885 if (versions[i].crc == *crc)
886 return 1;
887 printk("%s: disagrees about version of symbol %s\n",
888 mod->name, symname);
889 DEBUGP("Found checksum %lX vs module %lX\n",
890 *crc, versions[i].crc);
891 return 0;
892 }
893 /* Not in module's version table. OK, but that taints the kernel. */
fa3ba2e8 894 if (!(tainted & TAINT_FORCED_MODULE))
1da177e4
LT
895 printk("%s: no version for \"%s\" found: kernel tainted.\n",
896 mod->name, symname);
fa3ba2e8 897 add_taint_module(mod, TAINT_FORCED_MODULE);
1da177e4
LT
898 return 1;
899}
900
901static inline int check_modstruct_version(Elf_Shdr *sechdrs,
902 unsigned int versindex,
903 struct module *mod)
904{
905 const unsigned long *crc;
906 struct module *owner;
907
908 if (!__find_symbol("struct_module", &owner, &crc, 1))
909 BUG();
910 return check_version(sechdrs, versindex, "struct_module", mod,
911 crc);
912}
913
914/* First part is kernel version, which we ignore. */
915static inline int same_magic(const char *amagic, const char *bmagic)
916{
917 amagic += strcspn(amagic, " ");
918 bmagic += strcspn(bmagic, " ");
919 return strcmp(amagic, bmagic) == 0;
920}
921#else
922static inline int check_version(Elf_Shdr *sechdrs,
923 unsigned int versindex,
924 const char *symname,
925 struct module *mod,
926 const unsigned long *crc)
927{
928 return 1;
929}
930
931static inline int check_modstruct_version(Elf_Shdr *sechdrs,
932 unsigned int versindex,
933 struct module *mod)
934{
935 return 1;
936}
937
938static inline int same_magic(const char *amagic, const char *bmagic)
939{
940 return strcmp(amagic, bmagic) == 0;
941}
942#endif /* CONFIG_MODVERSIONS */
943
944/* Resolve a symbol for this module. I.e. if we find one, record usage.
945 Must be holding module_mutex. */
946static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
947 unsigned int versindex,
948 const char *name,
949 struct module *mod)
950{
951 struct module *owner;
952 unsigned long ret;
953 const unsigned long *crc;
954
fa3ba2e8
FM
955 ret = __find_symbol(name, &owner, &crc,
956 !(mod->taints & TAINT_PROPRIETARY_MODULE));
1da177e4 957 if (ret) {
9a4b9708
ML
958 /* use_module can fail due to OOM,
959 or module initialization or unloading */
1da177e4
LT
960 if (!check_version(sechdrs, versindex, name, mod, crc) ||
961 !use_module(mod, owner))
962 ret = 0;
963 }
1da177e4
LT
964 return ret;
965}
966
967
968/*
969 * /sys/module/foo/sections stuff
970 * J. Corbet <corbet@lwn.net>
971 */
972#ifdef CONFIG_KALLSYMS
973static ssize_t module_sect_show(struct module_attribute *mattr,
974 struct module *mod, char *buf)
975{
976 struct module_sect_attr *sattr =
977 container_of(mattr, struct module_sect_attr, mattr);
978 return sprintf(buf, "0x%lx\n", sattr->address);
979}
980
04b1db9f
IN
981static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
982{
983 int section;
984
985 for (section = 0; section < sect_attrs->nsections; section++)
986 kfree(sect_attrs->attrs[section].name);
987 kfree(sect_attrs);
988}
989
1da177e4
LT
990static void add_sect_attrs(struct module *mod, unsigned int nsect,
991 char *secstrings, Elf_Shdr *sechdrs)
992{
993 unsigned int nloaded = 0, i, size[2];
994 struct module_sect_attrs *sect_attrs;
995 struct module_sect_attr *sattr;
996 struct attribute **gattr;
22a8bdeb 997
1da177e4
LT
998 /* Count loaded sections and allocate structures */
999 for (i = 0; i < nsect; i++)
1000 if (sechdrs[i].sh_flags & SHF_ALLOC)
1001 nloaded++;
1002 size[0] = ALIGN(sizeof(*sect_attrs)
1003 + nloaded * sizeof(sect_attrs->attrs[0]),
1004 sizeof(sect_attrs->grp.attrs[0]));
1005 size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]);
04b1db9f
IN
1006 sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL);
1007 if (sect_attrs == NULL)
1da177e4
LT
1008 return;
1009
1010 /* Setup section attributes. */
1011 sect_attrs->grp.name = "sections";
1012 sect_attrs->grp.attrs = (void *)sect_attrs + size[0];
1013
04b1db9f 1014 sect_attrs->nsections = 0;
1da177e4
LT
1015 sattr = &sect_attrs->attrs[0];
1016 gattr = &sect_attrs->grp.attrs[0];
1017 for (i = 0; i < nsect; i++) {
1018 if (! (sechdrs[i].sh_flags & SHF_ALLOC))
1019 continue;
1020 sattr->address = sechdrs[i].sh_addr;
04b1db9f
IN
1021 sattr->name = kstrdup(secstrings + sechdrs[i].sh_name,
1022 GFP_KERNEL);
1023 if (sattr->name == NULL)
1024 goto out;
1025 sect_attrs->nsections++;
1da177e4
LT
1026 sattr->mattr.show = module_sect_show;
1027 sattr->mattr.store = NULL;
1028 sattr->mattr.attr.name = sattr->name;
1da177e4
LT
1029 sattr->mattr.attr.mode = S_IRUGO;
1030 *(gattr++) = &(sattr++)->mattr.attr;
1031 }
1032 *gattr = NULL;
1033
1034 if (sysfs_create_group(&mod->mkobj.kobj, &sect_attrs->grp))
1035 goto out;
1036
1037 mod->sect_attrs = sect_attrs;
1038 return;
1039 out:
04b1db9f 1040 free_sect_attrs(sect_attrs);
1da177e4
LT
1041}
1042
1043static void remove_sect_attrs(struct module *mod)
1044{
1045 if (mod->sect_attrs) {
1046 sysfs_remove_group(&mod->mkobj.kobj,
1047 &mod->sect_attrs->grp);
1048 /* We are positive that no one is using any sect attrs
1049 * at this point. Deallocate immediately. */
04b1db9f 1050 free_sect_attrs(mod->sect_attrs);
1da177e4
LT
1051 mod->sect_attrs = NULL;
1052 }
1053}
1054
6d760133
RM
1055/*
1056 * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections.
1057 */
1058
1059struct module_notes_attrs {
1060 struct kobject *dir;
1061 unsigned int notes;
1062 struct bin_attribute attrs[0];
1063};
1064
1065static ssize_t module_notes_read(struct kobject *kobj,
1066 struct bin_attribute *bin_attr,
1067 char *buf, loff_t pos, size_t count)
1068{
1069 /*
1070 * The caller checked the pos and count against our size.
1071 */
1072 memcpy(buf, bin_attr->private + pos, count);
1073 return count;
1074}
1075
1076static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
1077 unsigned int i)
1078{
1079 if (notes_attrs->dir) {
1080 while (i-- > 0)
1081 sysfs_remove_bin_file(notes_attrs->dir,
1082 &notes_attrs->attrs[i]);
1083 kobject_del(notes_attrs->dir);
1084 }
1085 kfree(notes_attrs);
1086}
1087
1088static void add_notes_attrs(struct module *mod, unsigned int nsect,
1089 char *secstrings, Elf_Shdr *sechdrs)
1090{
1091 unsigned int notes, loaded, i;
1092 struct module_notes_attrs *notes_attrs;
1093 struct bin_attribute *nattr;
1094
1095 /* Count notes sections and allocate structures. */
1096 notes = 0;
1097 for (i = 0; i < nsect; i++)
1098 if ((sechdrs[i].sh_flags & SHF_ALLOC) &&
1099 (sechdrs[i].sh_type == SHT_NOTE))
1100 ++notes;
1101
1102 if (notes == 0)
1103 return;
1104
1105 notes_attrs = kzalloc(sizeof(*notes_attrs)
1106 + notes * sizeof(notes_attrs->attrs[0]),
1107 GFP_KERNEL);
1108 if (notes_attrs == NULL)
1109 return;
1110
1111 notes_attrs->notes = notes;
1112 nattr = &notes_attrs->attrs[0];
1113 for (loaded = i = 0; i < nsect; ++i) {
1114 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
1115 continue;
1116 if (sechdrs[i].sh_type == SHT_NOTE) {
1117 nattr->attr.name = mod->sect_attrs->attrs[loaded].name;
1118 nattr->attr.mode = S_IRUGO;
1119 nattr->size = sechdrs[i].sh_size;
1120 nattr->private = (void *) sechdrs[i].sh_addr;
1121 nattr->read = module_notes_read;
1122 ++nattr;
1123 }
1124 ++loaded;
1125 }
1126
4ff6abff 1127 notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj);
6d760133
RM
1128 if (!notes_attrs->dir)
1129 goto out;
1130
1131 for (i = 0; i < notes; ++i)
1132 if (sysfs_create_bin_file(notes_attrs->dir,
1133 &notes_attrs->attrs[i]))
1134 goto out;
1135
1136 mod->notes_attrs = notes_attrs;
1137 return;
1138
1139 out:
1140 free_notes_attrs(notes_attrs, i);
1141}
1142
1143static void remove_notes_attrs(struct module *mod)
1144{
1145 if (mod->notes_attrs)
1146 free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes);
1147}
1148
1da177e4 1149#else
04b1db9f 1150
1da177e4
LT
1151static inline void add_sect_attrs(struct module *mod, unsigned int nsect,
1152 char *sectstrings, Elf_Shdr *sechdrs)
1153{
1154}
1155
1156static inline void remove_sect_attrs(struct module *mod)
1157{
1158}
6d760133
RM
1159
1160static inline void add_notes_attrs(struct module *mod, unsigned int nsect,
1161 char *sectstrings, Elf_Shdr *sechdrs)
1162{
1163}
1164
1165static inline void remove_notes_attrs(struct module *mod)
1166{
1167}
1da177e4
LT
1168#endif /* CONFIG_KALLSYMS */
1169
ef665c1a
RD
1170#ifdef CONFIG_SYSFS
1171int module_add_modinfo_attrs(struct module *mod)
c988d2b2
MD
1172{
1173 struct module_attribute *attr;
03e88ae1 1174 struct module_attribute *temp_attr;
c988d2b2
MD
1175 int error = 0;
1176 int i;
1177
03e88ae1
GKH
1178 mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) *
1179 (ARRAY_SIZE(modinfo_attrs) + 1)),
1180 GFP_KERNEL);
1181 if (!mod->modinfo_attrs)
1182 return -ENOMEM;
1183
1184 temp_attr = mod->modinfo_attrs;
c988d2b2
MD
1185 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) {
1186 if (!attr->test ||
03e88ae1
GKH
1187 (attr->test && attr->test(mod))) {
1188 memcpy(temp_attr, attr, sizeof(*temp_attr));
03e88ae1
GKH
1189 error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr);
1190 ++temp_attr;
1191 }
c988d2b2
MD
1192 }
1193 return error;
1194}
1195
ef665c1a 1196void module_remove_modinfo_attrs(struct module *mod)
c988d2b2
MD
1197{
1198 struct module_attribute *attr;
1199 int i;
1200
03e88ae1
GKH
1201 for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) {
1202 /* pick a field to test for end of list */
1203 if (!attr->attr.name)
1204 break;
c988d2b2 1205 sysfs_remove_file(&mod->mkobj.kobj,&attr->attr);
03e88ae1
GKH
1206 if (attr->free)
1207 attr->free(mod);
c988d2b2 1208 }
03e88ae1 1209 kfree(mod->modinfo_attrs);
c988d2b2 1210}
ef665c1a 1211#endif
1da177e4 1212
ef665c1a
RD
1213#ifdef CONFIG_SYSFS
1214int mod_sysfs_init(struct module *mod)
1da177e4
LT
1215{
1216 int err;
1217
823bccfc
GKH
1218 if (!module_sysfs_initialized) {
1219 printk(KERN_ERR "%s: module sysfs not initialized\n",
1cc5f714
ES
1220 mod->name);
1221 err = -EINVAL;
1222 goto out;
1223 }
1da177e4 1224 mod->mkobj.mod = mod;
e17e0f51 1225
ac3c8141
GKH
1226 memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
1227 mod->mkobj.kobj.kset = module_kset;
1228 err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL,
1229 "%s", mod->name);
1230 if (err)
1231 kobject_put(&mod->mkobj.kobj);
270a6c4c 1232
97c146ef 1233 /* delay uevent until full sysfs population */
270a6c4c
KS
1234out:
1235 return err;
1236}
1237
ef665c1a 1238int mod_sysfs_setup(struct module *mod,
270a6c4c
KS
1239 struct kernel_param *kparam,
1240 unsigned int num_params)
1241{
1242 int err;
1243
4ff6abff 1244 mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj);
240936e1
AM
1245 if (!mod->holders_dir) {
1246 err = -ENOMEM;
270a6c4c 1247 goto out_unreg;
240936e1 1248 }
270a6c4c 1249
1da177e4
LT
1250 err = module_param_sysfs_setup(mod, kparam, num_params);
1251 if (err)
270a6c4c 1252 goto out_unreg_holders;
1da177e4 1253
c988d2b2
MD
1254 err = module_add_modinfo_attrs(mod);
1255 if (err)
e17e0f51 1256 goto out_unreg_param;
c988d2b2 1257
e17e0f51 1258 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
1da177e4
LT
1259 return 0;
1260
e17e0f51
KS
1261out_unreg_param:
1262 module_param_sysfs_remove(mod);
270a6c4c 1263out_unreg_holders:
78a2d906 1264 kobject_put(mod->holders_dir);
270a6c4c 1265out_unreg:
e17e0f51 1266 kobject_put(&mod->mkobj.kobj);
1da177e4
LT
1267 return err;
1268}
ef665c1a 1269#endif
1da177e4
LT
1270
1271static void mod_kobject_remove(struct module *mod)
1272{
c988d2b2 1273 module_remove_modinfo_attrs(mod);
1da177e4 1274 module_param_sysfs_remove(mod);
78a2d906
GKH
1275 kobject_put(mod->mkobj.drivers_dir);
1276 kobject_put(mod->holders_dir);
1277 kobject_put(&mod->mkobj.kobj);
1da177e4
LT
1278}
1279
1280/*
1281 * unlink the module with the whole machine is stopped with interrupts off
1282 * - this defends against kallsyms not taking locks
1283 */
1284static int __unlink_module(void *_mod)
1285{
1286 struct module *mod = _mod;
1287 list_del(&mod->list);
1288 return 0;
1289}
1290
02a3e59a 1291/* Free a module, remove from lists, etc (must hold module_mutex). */
1da177e4
LT
1292static void free_module(struct module *mod)
1293{
1294 /* Delete from various lists */
1295 stop_machine_run(__unlink_module, mod, NR_CPUS);
6d760133 1296 remove_notes_attrs(mod);
1da177e4
LT
1297 remove_sect_attrs(mod);
1298 mod_kobject_remove(mod);
1299
4552d5dc
JB
1300 unwind_remove_table(mod->unwind_info, 0);
1301
1da177e4
LT
1302 /* Arch-specific cleanup. */
1303 module_arch_cleanup(mod);
1304
1305 /* Module unload stuff */
1306 module_unload_free(mod);
1307
1308 /* This may be NULL, but that's OK */
1309 module_free(mod, mod->module_init);
1310 kfree(mod->args);
1311 if (mod->percpu)
1312 percpu_modfree(mod->percpu);
1313
fbb9ce95
IM
1314 /* Free lock-classes: */
1315 lockdep_free_key_range(mod->module_core, mod->core_size);
1316
1da177e4
LT
1317 /* Finally, free the core (containing the module structure) */
1318 module_free(mod, mod->module_core);
1319}
1320
1321void *__symbol_get(const char *symbol)
1322{
1323 struct module *owner;
24da1cbf 1324 unsigned long value;
1da177e4
LT
1325 const unsigned long *crc;
1326
24da1cbf 1327 preempt_disable();
1da177e4
LT
1328 value = __find_symbol(symbol, &owner, &crc, 1);
1329 if (value && !strong_try_module_get(owner))
1330 value = 0;
24da1cbf 1331 preempt_enable();
1da177e4
LT
1332
1333 return (void *)value;
1334}
1335EXPORT_SYMBOL_GPL(__symbol_get);
1336
eea8b54d
AN
1337/*
1338 * Ensure that an exported symbol [global namespace] does not already exist
02a3e59a 1339 * in the kernel or in some other module's exported symbol table.
eea8b54d
AN
1340 */
1341static int verify_export_symbols(struct module *mod)
1342{
1343 const char *name = NULL;
1344 unsigned long i, ret = 0;
1345 struct module *owner;
1346 const unsigned long *crc;
1347
1348 for (i = 0; i < mod->num_syms; i++)
22a8bdeb 1349 if (__find_symbol(mod->syms[i].name, &owner, &crc, 1)) {
eea8b54d
AN
1350 name = mod->syms[i].name;
1351 ret = -ENOEXEC;
1352 goto dup;
1353 }
1354
1355 for (i = 0; i < mod->num_gpl_syms; i++)
22a8bdeb 1356 if (__find_symbol(mod->gpl_syms[i].name, &owner, &crc, 1)) {
eea8b54d
AN
1357 name = mod->gpl_syms[i].name;
1358 ret = -ENOEXEC;
1359 goto dup;
1360 }
1361
1362dup:
1363 if (ret)
1364 printk(KERN_ERR "%s: exports duplicate symbol %s (owned by %s)\n",
1365 mod->name, name, module_name(owner));
1366
1367 return ret;
1368}
1369
9a4b9708 1370/* Change all symbols so that st_value encodes the pointer directly. */
1da177e4
LT
1371static int simplify_symbols(Elf_Shdr *sechdrs,
1372 unsigned int symindex,
1373 const char *strtab,
1374 unsigned int versindex,
1375 unsigned int pcpuindex,
1376 struct module *mod)
1377{
1378 Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr;
1379 unsigned long secbase;
1380 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
1381 int ret = 0;
1382
1383 for (i = 1; i < n; i++) {
1384 switch (sym[i].st_shndx) {
1385 case SHN_COMMON:
1386 /* We compiled with -fno-common. These are not
1387 supposed to happen. */
1388 DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name);
1389 printk("%s: please compile with -fno-common\n",
1390 mod->name);
1391 ret = -ENOEXEC;
1392 break;
1393
1394 case SHN_ABS:
1395 /* Don't need to do anything */
1396 DEBUGP("Absolute symbol: 0x%08lx\n",
1397 (long)sym[i].st_value);
1398 break;
1399
1400 case SHN_UNDEF:
1401 sym[i].st_value
1402 = resolve_symbol(sechdrs, versindex,
1403 strtab + sym[i].st_name, mod);
1404
1405 /* Ok if resolved. */
1406 if (sym[i].st_value != 0)
1407 break;
1408 /* Ok if weak. */
1409 if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
1410 break;
1411
1412 printk(KERN_WARNING "%s: Unknown symbol %s\n",
1413 mod->name, strtab + sym[i].st_name);
1414 ret = -ENOENT;
1415 break;
1416
1417 default:
1418 /* Divert to percpu allocation if a percpu var. */
1419 if (sym[i].st_shndx == pcpuindex)
1420 secbase = (unsigned long)mod->percpu;
1421 else
1422 secbase = sechdrs[sym[i].st_shndx].sh_addr;
1423 sym[i].st_value += secbase;
1424 break;
1425 }
1426 }
1427
1428 return ret;
1429}
1430
1431/* Update size with this section: return offset. */
1432static long get_offset(unsigned long *size, Elf_Shdr *sechdr)
1433{
1434 long ret;
1435
1436 ret = ALIGN(*size, sechdr->sh_addralign ?: 1);
1437 *size = ret + sechdr->sh_size;
1438 return ret;
1439}
1440
1441/* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld
1442 might -- code, read-only data, read-write data, small data. Tally
1443 sizes, and place the offsets into sh_entsize fields: high bit means it
1444 belongs in init. */
1445static void layout_sections(struct module *mod,
1446 const Elf_Ehdr *hdr,
1447 Elf_Shdr *sechdrs,
1448 const char *secstrings)
1449{
1450 static unsigned long const masks[][2] = {
1451 /* NOTE: all executable code must be the first section
1452 * in this array; otherwise modify the text_size
1453 * finder in the two loops below */
1454 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL },
1455 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL },
1456 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL },
1457 { ARCH_SHF_SMALL | SHF_ALLOC, 0 }
1458 };
1459 unsigned int m, i;
1460
1461 for (i = 0; i < hdr->e_shnum; i++)
1462 sechdrs[i].sh_entsize = ~0UL;
1463
1464 DEBUGP("Core section allocation order:\n");
1465 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
1466 for (i = 0; i < hdr->e_shnum; ++i) {
1467 Elf_Shdr *s = &sechdrs[i];
1468
1469 if ((s->sh_flags & masks[m][0]) != masks[m][0]
1470 || (s->sh_flags & masks[m][1])
1471 || s->sh_entsize != ~0UL
1472 || strncmp(secstrings + s->sh_name,
1473 ".init", 5) == 0)
1474 continue;
1475 s->sh_entsize = get_offset(&mod->core_size, s);
1476 DEBUGP("\t%s\n", secstrings + s->sh_name);
1477 }
1478 if (m == 0)
1479 mod->core_text_size = mod->core_size;
1480 }
1481
1482 DEBUGP("Init section allocation order:\n");
1483 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
1484 for (i = 0; i < hdr->e_shnum; ++i) {
1485 Elf_Shdr *s = &sechdrs[i];
1486
1487 if ((s->sh_flags & masks[m][0]) != masks[m][0]
1488 || (s->sh_flags & masks[m][1])
1489 || s->sh_entsize != ~0UL
1490 || strncmp(secstrings + s->sh_name,
1491 ".init", 5) != 0)
1492 continue;
1493 s->sh_entsize = (get_offset(&mod->init_size, s)
1494 | INIT_OFFSET_MASK);
1495 DEBUGP("\t%s\n", secstrings + s->sh_name);
1496 }
1497 if (m == 0)
1498 mod->init_text_size = mod->init_size;
1499 }
1500}
1501
1da177e4
LT
1502static void set_license(struct module *mod, const char *license)
1503{
1504 if (!license)
1505 license = "unspecified";
1506
fa3ba2e8
FM
1507 if (!license_is_gpl_compatible(license)) {
1508 if (!(tainted & TAINT_PROPRIETARY_MODULE))
1d4d2627 1509 printk(KERN_WARNING "%s: module license '%s' taints "
fa3ba2e8
FM
1510 "kernel.\n", mod->name, license);
1511 add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
1da177e4
LT
1512 }
1513}
1514
1515/* Parse tag=value strings from .modinfo section */
1516static char *next_string(char *string, unsigned long *secsize)
1517{
1518 /* Skip non-zero chars */
1519 while (string[0]) {
1520 string++;
1521 if ((*secsize)-- <= 1)
1522 return NULL;
1523 }
1524
1525 /* Skip any zero padding. */
1526 while (!string[0]) {
1527 string++;
1528 if ((*secsize)-- <= 1)
1529 return NULL;
1530 }
1531 return string;
1532}
1533
1534static char *get_modinfo(Elf_Shdr *sechdrs,
1535 unsigned int info,
1536 const char *tag)
1537{
1538 char *p;
1539 unsigned int taglen = strlen(tag);
1540 unsigned long size = sechdrs[info].sh_size;
1541
1542 for (p = (char *)sechdrs[info].sh_addr; p; p = next_string(p, &size)) {
1543 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
1544 return p + taglen + 1;
1545 }
1546 return NULL;
1547}
1548
c988d2b2
MD
1549static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs,
1550 unsigned int infoindex)
1551{
1552 struct module_attribute *attr;
1553 int i;
1554
1555 for (i = 0; (attr = modinfo_attrs[i]); i++) {
1556 if (attr->setup)
1557 attr->setup(mod,
1558 get_modinfo(sechdrs,
1559 infoindex,
1560 attr->attr.name));
1561 }
1562}
c988d2b2 1563
1da177e4 1564#ifdef CONFIG_KALLSYMS
ea07890a 1565static int is_exported(const char *name, const struct module *mod)
1da177e4 1566{
3fd6805f
SR
1567 if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab))
1568 return 1;
1569 else
f867d2a2 1570 if (mod && lookup_symbol(name, mod->syms, mod->syms + mod->num_syms))
1da177e4 1571 return 1;
3fd6805f
SR
1572 else
1573 return 0;
1da177e4
LT
1574}
1575
1576/* As per nm */
1577static char elf_type(const Elf_Sym *sym,
1578 Elf_Shdr *sechdrs,
1579 const char *secstrings,
1580 struct module *mod)
1581{
1582 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
1583 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
1584 return 'v';
1585 else
1586 return 'w';
1587 }
1588 if (sym->st_shndx == SHN_UNDEF)
1589 return 'U';
1590 if (sym->st_shndx == SHN_ABS)
1591 return 'a';
1592 if (sym->st_shndx >= SHN_LORESERVE)
1593 return '?';
1594 if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR)
1595 return 't';
1596 if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC
1597 && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) {
1598 if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE))
1599 return 'r';
1600 else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
1601 return 'g';
1602 else
1603 return 'd';
1604 }
1605 if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) {
1606 if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
1607 return 's';
1608 else
1609 return 'b';
1610 }
1611 if (strncmp(secstrings + sechdrs[sym->st_shndx].sh_name,
1612 ".debug", strlen(".debug")) == 0)
1613 return 'n';
1614 return '?';
1615}
1616
1617static void add_kallsyms(struct module *mod,
1618 Elf_Shdr *sechdrs,
1619 unsigned int symindex,
1620 unsigned int strindex,
1621 const char *secstrings)
1622{
1623 unsigned int i;
1624
1625 mod->symtab = (void *)sechdrs[symindex].sh_addr;
1626 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
1627 mod->strtab = (void *)sechdrs[strindex].sh_addr;
1628
1629 /* Set types up while we still have access to sections. */
1630 for (i = 0; i < mod->num_symtab; i++)
1631 mod->symtab[i].st_info
1632 = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
1633}
1634#else
1635static inline void add_kallsyms(struct module *mod,
1636 Elf_Shdr *sechdrs,
1637 unsigned int symindex,
1638 unsigned int strindex,
1639 const char *secstrings)
1640{
1641}
1642#endif /* CONFIG_KALLSYMS */
1643
1644/* Allocate and load the module: note that size of section 0 is always
1645 zero, and we rely on this for optional sections. */
1646static struct module *load_module(void __user *umod,
1647 unsigned long len,
1648 const char __user *uargs)
1649{
1650 Elf_Ehdr *hdr;
1651 Elf_Shdr *sechdrs;
1652 char *secstrings, *args, *modmagic, *strtab = NULL;
84860f99
AM
1653 unsigned int i;
1654 unsigned int symindex = 0;
1655 unsigned int strindex = 0;
1656 unsigned int setupindex;
1657 unsigned int exindex;
1658 unsigned int exportindex;
1659 unsigned int modindex;
1660 unsigned int obsparmindex;
1661 unsigned int infoindex;
1662 unsigned int gplindex;
1663 unsigned int crcindex;
1664 unsigned int gplcrcindex;
1665 unsigned int versindex;
1666 unsigned int pcpuindex;
1667 unsigned int gplfutureindex;
1668 unsigned int gplfuturecrcindex;
1669 unsigned int unwindex = 0;
1670 unsigned int unusedindex;
1671 unsigned int unusedcrcindex;
1672 unsigned int unusedgplindex;
1673 unsigned int unusedgplcrcindex;
8256e47c
MD
1674 unsigned int markersindex;
1675 unsigned int markersstringsindex;
1da177e4
LT
1676 struct module *mod;
1677 long err = 0;
1678 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
1679 struct exception_table_entry *extable;
378bac82 1680 mm_segment_t old_fs;
1da177e4
LT
1681
1682 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
1683 umod, len, uargs);
1684 if (len < sizeof(*hdr))
1685 return ERR_PTR(-ENOEXEC);
1686
1687 /* Suck in entire file: we'll want most of it. */
1688 /* vmalloc barfs on "unusual" numbers. Check here */
1689 if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
1690 return ERR_PTR(-ENOMEM);
1691 if (copy_from_user(hdr, umod, len) != 0) {
1692 err = -EFAULT;
1693 goto free_hdr;
1694 }
1695
1696 /* Sanity checks against insmoding binaries or wrong arch,
1697 weird elf version */
1698 if (memcmp(hdr->e_ident, ELFMAG, 4) != 0
1699 || hdr->e_type != ET_REL
1700 || !elf_check_arch(hdr)
1701 || hdr->e_shentsize != sizeof(*sechdrs)) {
1702 err = -ENOEXEC;
1703 goto free_hdr;
1704 }
1705
1706 if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr))
1707 goto truncated;
1708
1709 /* Convenience variables */
1710 sechdrs = (void *)hdr + hdr->e_shoff;
1711 secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
1712 sechdrs[0].sh_addr = 0;
1713
1714 for (i = 1; i < hdr->e_shnum; i++) {
1715 if (sechdrs[i].sh_type != SHT_NOBITS
1716 && len < sechdrs[i].sh_offset + sechdrs[i].sh_size)
1717 goto truncated;
1718
1719 /* Mark all sections sh_addr with their address in the
1720 temporary image. */
1721 sechdrs[i].sh_addr = (size_t)hdr + sechdrs[i].sh_offset;
1722
1723 /* Internal symbols and strings. */
1724 if (sechdrs[i].sh_type == SHT_SYMTAB) {
1725 symindex = i;
1726 strindex = sechdrs[i].sh_link;
1727 strtab = (char *)hdr + sechdrs[strindex].sh_offset;
1728 }
1729#ifndef CONFIG_MODULE_UNLOAD
1730 /* Don't load .exit sections */
1731 if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) == 0)
1732 sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC;
1733#endif
1734 }
1735
1736 modindex = find_sec(hdr, sechdrs, secstrings,
1737 ".gnu.linkonce.this_module");
1738 if (!modindex) {
1739 printk(KERN_WARNING "No module found in object\n");
1740 err = -ENOEXEC;
1741 goto free_hdr;
1742 }
1743 mod = (void *)sechdrs[modindex].sh_addr;
1744
1745 if (symindex == 0) {
1746 printk(KERN_WARNING "%s: module has no symbols (stripped?)\n",
1747 mod->name);
1748 err = -ENOEXEC;
1749 goto free_hdr;
1750 }
1751
1752 /* Optional sections */
1753 exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab");
1754 gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl");
9f28bb7e 1755 gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future");
f71d20e9
AV
1756 unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused");
1757 unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl");
1da177e4
LT
1758 crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab");
1759 gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl");
9f28bb7e 1760 gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future");
f71d20e9
AV
1761 unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused");
1762 unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl");
1da177e4
LT
1763 setupindex = find_sec(hdr, sechdrs, secstrings, "__param");
1764 exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table");
1765 obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm");
1766 versindex = find_sec(hdr, sechdrs, secstrings, "__versions");
1767 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo");
1768 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings);
4552d5dc
JB
1769#ifdef ARCH_UNWIND_SECTION_NAME
1770 unwindex = find_sec(hdr, sechdrs, secstrings, ARCH_UNWIND_SECTION_NAME);
1771#endif
1da177e4
LT
1772
1773 /* Don't keep modinfo section */
1774 sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
1775#ifdef CONFIG_KALLSYMS
1776 /* Keep symbol and string tables for decoding later. */
1777 sechdrs[symindex].sh_flags |= SHF_ALLOC;
1778 sechdrs[strindex].sh_flags |= SHF_ALLOC;
1779#endif
4552d5dc
JB
1780 if (unwindex)
1781 sechdrs[unwindex].sh_flags |= SHF_ALLOC;
1da177e4
LT
1782
1783 /* Check module struct version now, before we try to use module. */
1784 if (!check_modstruct_version(sechdrs, versindex, mod)) {
1785 err = -ENOEXEC;
1786 goto free_hdr;
1787 }
1788
1789 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
1790 /* This is allowed: modprobe --force will invalidate it. */
1791 if (!modmagic) {
fa3ba2e8 1792 add_taint_module(mod, TAINT_FORCED_MODULE);
1da177e4
LT
1793 printk(KERN_WARNING "%s: no version magic, tainting kernel.\n",
1794 mod->name);
1795 } else if (!same_magic(modmagic, vermagic)) {
1796 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n",
1797 mod->name, modmagic, vermagic);
1798 err = -ENOEXEC;
1799 goto free_hdr;
1800 }
1801
1802 /* Now copy in args */
24277dda
DA
1803 args = strndup_user(uargs, ~0UL >> 1);
1804 if (IS_ERR(args)) {
1805 err = PTR_ERR(args);
1da177e4
LT
1806 goto free_hdr;
1807 }
8e08b756 1808
1da177e4
LT
1809 if (find_module(mod->name)) {
1810 err = -EEXIST;
1811 goto free_mod;
1812 }
1813
1814 mod->state = MODULE_STATE_COMING;
1815
1816 /* Allow arches to frob section contents and sizes. */
1817 err = module_frob_arch_sections(hdr, sechdrs, secstrings, mod);
1818 if (err < 0)
1819 goto free_mod;
1820
1821 if (pcpuindex) {
1822 /* We have a special allocation for this section. */
1823 percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size,
842bbaaa
RR
1824 sechdrs[pcpuindex].sh_addralign,
1825 mod->name);
1da177e4
LT
1826 if (!percpu) {
1827 err = -ENOMEM;
1828 goto free_mod;
1829 }
1830 sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
1831 mod->percpu = percpu;
1832 }
1833
1834 /* Determine total sizes, and put offsets in sh_entsize. For now
1835 this is done generically; there doesn't appear to be any
1836 special cases for the architectures. */
1837 layout_sections(mod, hdr, sechdrs, secstrings);
1838
1839 /* Do the allocs. */
1840 ptr = module_alloc(mod->core_size);
1841 if (!ptr) {
1842 err = -ENOMEM;
1843 goto free_percpu;
1844 }
1845 memset(ptr, 0, mod->core_size);
1846 mod->module_core = ptr;
1847
1848 ptr = module_alloc(mod->init_size);
1849 if (!ptr && mod->init_size) {
1850 err = -ENOMEM;
1851 goto free_core;
1852 }
1853 memset(ptr, 0, mod->init_size);
1854 mod->module_init = ptr;
1855
1856 /* Transfer each section which specifies SHF_ALLOC */
1857 DEBUGP("final section addresses:\n");
1858 for (i = 0; i < hdr->e_shnum; i++) {
1859 void *dest;
1860
1861 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
1862 continue;
1863
1864 if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
1865 dest = mod->module_init
1866 + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
1867 else
1868 dest = mod->module_core + sechdrs[i].sh_entsize;
1869
1870 if (sechdrs[i].sh_type != SHT_NOBITS)
1871 memcpy(dest, (void *)sechdrs[i].sh_addr,
1872 sechdrs[i].sh_size);
1873 /* Update sh_addr to point to copy in image. */
1874 sechdrs[i].sh_addr = (unsigned long)dest;
1875 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
1876 }
1877 /* Module has been moved. */
1878 mod = (void *)sechdrs[modindex].sh_addr;
1879
1880 /* Now we've moved module, initialize linked lists, etc. */
1881 module_unload_init(mod);
1882
97c146ef 1883 /* add kobject, so we can reference it. */
d58ae678
AM
1884 err = mod_sysfs_init(mod);
1885 if (err)
97c146ef 1886 goto free_unload;
270a6c4c 1887
1da177e4
LT
1888 /* Set up license info based on the info section */
1889 set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
1890
fa3ba2e8 1891 if (strcmp(mod->name, "ndiswrapper") == 0)
0e2d57fc 1892 add_taint(TAINT_PROPRIETARY_MODULE);
fa3ba2e8
FM
1893 if (strcmp(mod->name, "driverloader") == 0)
1894 add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
9841d61d 1895
c988d2b2
MD
1896 /* Set up MODINFO_ATTR fields */
1897 setup_modinfo(mod, sechdrs, infoindex);
c988d2b2 1898
1da177e4
LT
1899 /* Fix up syms, so that st_value is a pointer to location. */
1900 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
1901 mod);
1902 if (err < 0)
1903 goto cleanup;
1904
1905 /* Set up EXPORTed & EXPORT_GPLed symbols (section 0 is 0 length) */
1906 mod->num_syms = sechdrs[exportindex].sh_size / sizeof(*mod->syms);
1907 mod->syms = (void *)sechdrs[exportindex].sh_addr;
1908 if (crcindex)
1909 mod->crcs = (void *)sechdrs[crcindex].sh_addr;
1910 mod->num_gpl_syms = sechdrs[gplindex].sh_size / sizeof(*mod->gpl_syms);
1911 mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr;
1912 if (gplcrcindex)
1913 mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr;
9f28bb7e
GKH
1914 mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size /
1915 sizeof(*mod->gpl_future_syms);
f71d20e9
AV
1916 mod->num_unused_syms = sechdrs[unusedindex].sh_size /
1917 sizeof(*mod->unused_syms);
1918 mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size /
1919 sizeof(*mod->unused_gpl_syms);
9f28bb7e
GKH
1920 mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr;
1921 if (gplfuturecrcindex)
1922 mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr;
1da177e4 1923
f71d20e9
AV
1924 mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr;
1925 if (unusedcrcindex)
1926 mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr;
1927 mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr;
1928 if (unusedgplcrcindex)
1929 mod->unused_crcs = (void *)sechdrs[unusedgplcrcindex].sh_addr;
1930
1da177e4 1931#ifdef CONFIG_MODVERSIONS
22a8bdeb 1932 if ((mod->num_syms && !crcindex) ||
9f28bb7e 1933 (mod->num_gpl_syms && !gplcrcindex) ||
f71d20e9
AV
1934 (mod->num_gpl_future_syms && !gplfuturecrcindex) ||
1935 (mod->num_unused_syms && !unusedcrcindex) ||
1936 (mod->num_unused_gpl_syms && !unusedgplcrcindex)) {
1da177e4
LT
1937 printk(KERN_WARNING "%s: No versions for exported symbols."
1938 " Tainting kernel.\n", mod->name);
fa3ba2e8 1939 add_taint_module(mod, TAINT_FORCED_MODULE);
1da177e4
LT
1940 }
1941#endif
8256e47c
MD
1942 markersindex = find_sec(hdr, sechdrs, secstrings, "__markers");
1943 markersstringsindex = find_sec(hdr, sechdrs, secstrings,
1944 "__markers_strings");
1da177e4
LT
1945
1946 /* Now do relocations. */
1947 for (i = 1; i < hdr->e_shnum; i++) {
1948 const char *strtab = (char *)sechdrs[strindex].sh_addr;
1949 unsigned int info = sechdrs[i].sh_info;
1950
1951 /* Not a valid relocation section? */
1952 if (info >= hdr->e_shnum)
1953 continue;
1954
1955 /* Don't bother with non-allocated sections */
1956 if (!(sechdrs[info].sh_flags & SHF_ALLOC))
1957 continue;
1958
1959 if (sechdrs[i].sh_type == SHT_REL)
1960 err = apply_relocate(sechdrs, strtab, symindex, i,mod);
1961 else if (sechdrs[i].sh_type == SHT_RELA)
1962 err = apply_relocate_add(sechdrs, strtab, symindex, i,
1963 mod);
1964 if (err < 0)
1965 goto cleanup;
1966 }
8256e47c
MD
1967#ifdef CONFIG_MARKERS
1968 mod->markers = (void *)sechdrs[markersindex].sh_addr;
1969 mod->num_markers =
1970 sechdrs[markersindex].sh_size / sizeof(*mod->markers);
1971#endif
1da177e4 1972
eea8b54d
AN
1973 /* Find duplicate symbols */
1974 err = verify_export_symbols(mod);
1975
1976 if (err < 0)
1977 goto cleanup;
1978
1da177e4
LT
1979 /* Set up and sort exception table */
1980 mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable);
1981 mod->extable = extable = (void *)sechdrs[exindex].sh_addr;
1982 sort_extable(extable, extable + mod->num_exentries);
1983
1984 /* Finally, copy percpu area over. */
1985 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr,
1986 sechdrs[pcpuindex].sh_size);
1987
1988 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
1989
8256e47c
MD
1990#ifdef CONFIG_MARKERS
1991 if (!mod->taints)
1992 marker_update_probe_range(mod->markers,
1993 mod->markers + mod->num_markers, NULL, NULL);
1994#endif
1da177e4
LT
1995 err = module_finalize(hdr, sechdrs, mod);
1996 if (err < 0)
1997 goto cleanup;
1998
378bac82
TK
1999 /* flush the icache in correct context */
2000 old_fs = get_fs();
2001 set_fs(KERNEL_DS);
2002
2003 /*
2004 * Flush the instruction cache, since we've played with text.
2005 * Do it before processing of module parameters, so the module
2006 * can provide parameter accessor functions of its own.
2007 */
2008 if (mod->module_init)
2009 flush_icache_range((unsigned long)mod->module_init,
2010 (unsigned long)mod->module_init
2011 + mod->init_size);
2012 flush_icache_range((unsigned long)mod->module_core,
2013 (unsigned long)mod->module_core + mod->core_size);
2014
2015 set_fs(old_fs);
2016
1da177e4 2017 mod->args = args;
8d3b33f6
RR
2018 if (obsparmindex)
2019 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
2020 mod->name);
2021
2022 /* Size of section 0 is 0, so this works well if no params */
2023 err = parse_args(mod->name, mod->args,
2024 (struct kernel_param *)
2025 sechdrs[setupindex].sh_addr,
2026 sechdrs[setupindex].sh_size
2027 / sizeof(struct kernel_param),
2028 NULL);
1da177e4
LT
2029 if (err < 0)
2030 goto arch_cleanup;
2031
22a8bdeb 2032 err = mod_sysfs_setup(mod,
1da177e4
LT
2033 (struct kernel_param *)
2034 sechdrs[setupindex].sh_addr,
2035 sechdrs[setupindex].sh_size
2036 / sizeof(struct kernel_param));
2037 if (err < 0)
2038 goto arch_cleanup;
2039 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
6d760133 2040 add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
1da177e4 2041
4552d5dc
JB
2042 /* Size of section 0 is 0, so this works well if no unwind info. */
2043 mod->unwind_info = unwind_add_table(mod,
22a8bdeb
DW
2044 (void *)sechdrs[unwindex].sh_addr,
2045 sechdrs[unwindex].sh_size);
4552d5dc 2046
1da177e4
LT
2047 /* Get rid of temporary copy */
2048 vfree(hdr);
2049
2050 /* Done! */
2051 return mod;
2052
2053 arch_cleanup:
2054 module_arch_cleanup(mod);
2055 cleanup:
97c146ef
KS
2056 kobject_del(&mod->mkobj.kobj);
2057 kobject_put(&mod->mkobj.kobj);
2058 free_unload:
1da177e4
LT
2059 module_unload_free(mod);
2060 module_free(mod, mod->module_init);
2061 free_core:
2062 module_free(mod, mod->module_core);
2063 free_percpu:
2064 if (percpu)
2065 percpu_modfree(percpu);
2066 free_mod:
2067 kfree(args);
2068 free_hdr:
2069 vfree(hdr);
6fe2e70b 2070 return ERR_PTR(err);
1da177e4
LT
2071
2072 truncated:
2073 printk(KERN_ERR "Module len %lu truncated\n", len);
2074 err = -ENOEXEC;
2075 goto free_hdr;
2076}
2077
2078/*
2079 * link the module with the whole machine is stopped with interrupts off
2080 * - this defends against kallsyms not taking locks
2081 */
2082static int __link_module(void *_mod)
2083{
2084 struct module *mod = _mod;
2085 list_add(&mod->list, &modules);
2086 return 0;
2087}
2088
2089/* This is where the real work happens */
2090asmlinkage long
2091sys_init_module(void __user *umod,
2092 unsigned long len,
2093 const char __user *uargs)
2094{
2095 struct module *mod;
2096 int ret = 0;
2097
2098 /* Must have permission */
2099 if (!capable(CAP_SYS_MODULE))
2100 return -EPERM;
2101
2102 /* Only one module load at a time, please */
6389a385 2103 if (mutex_lock_interruptible(&module_mutex) != 0)
1da177e4
LT
2104 return -EINTR;
2105
2106 /* Do all the hard work */
2107 mod = load_module(umod, len, uargs);
2108 if (IS_ERR(mod)) {
6389a385 2109 mutex_unlock(&module_mutex);
1da177e4
LT
2110 return PTR_ERR(mod);
2111 }
2112
1da177e4
LT
2113 /* Now sew it into the lists. They won't access us, since
2114 strong_try_module_get() will fail. */
2115 stop_machine_run(__link_module, mod, NR_CPUS);
2116
2117 /* Drop lock so they can recurse */
6389a385 2118 mutex_unlock(&module_mutex);
1da177e4 2119
e041c683
AS
2120 blocking_notifier_call_chain(&module_notify_list,
2121 MODULE_STATE_COMING, mod);
1da177e4
LT
2122
2123 /* Start the module */
2124 if (mod->init != NULL)
2125 ret = mod->init();
2126 if (ret < 0) {
2127 /* Init routine failed: abort. Try to protect us from
2128 buggy refcounters. */
2129 mod->state = MODULE_STATE_GOING;
fbd568a3 2130 synchronize_sched();
af49d924
RR
2131 module_put(mod);
2132 mutex_lock(&module_mutex);
2133 free_module(mod);
2134 mutex_unlock(&module_mutex);
1da177e4
LT
2135 return ret;
2136 }
2137
2138 /* Now it's a first class citizen! */
6389a385 2139 mutex_lock(&module_mutex);
1da177e4
LT
2140 mod->state = MODULE_STATE_LIVE;
2141 /* Drop initial reference. */
2142 module_put(mod);
4552d5dc 2143 unwind_remove_table(mod->unwind_info, 1);
1da177e4
LT
2144 module_free(mod, mod->module_init);
2145 mod->module_init = NULL;
2146 mod->init_size = 0;
2147 mod->init_text_size = 0;
6389a385 2148 mutex_unlock(&module_mutex);
1da177e4
LT
2149
2150 return 0;
2151}
2152
2153static inline int within(unsigned long addr, void *start, unsigned long size)
2154{
2155 return ((void *)addr >= start && (void *)addr < start + size);
2156}
2157
2158#ifdef CONFIG_KALLSYMS
2159/*
2160 * This ignores the intensely annoying "mapping symbols" found
2161 * in ARM ELF files: $a, $t and $d.
2162 */
2163static inline int is_arm_mapping_symbol(const char *str)
2164{
22a8bdeb 2165 return str[0] == '$' && strchr("atd", str[1])
1da177e4
LT
2166 && (str[2] == '\0' || str[2] == '.');
2167}
2168
2169static const char *get_ksymbol(struct module *mod,
2170 unsigned long addr,
2171 unsigned long *size,
2172 unsigned long *offset)
2173{
2174 unsigned int i, best = 0;
2175 unsigned long nextval;
2176
2177 /* At worse, next value is at end of module */
2178 if (within(addr, mod->module_init, mod->init_size))
2179 nextval = (unsigned long)mod->module_init+mod->init_text_size;
22a8bdeb 2180 else
1da177e4
LT
2181 nextval = (unsigned long)mod->module_core+mod->core_text_size;
2182
2183 /* Scan for closest preceeding symbol, and next symbol. (ELF
22a8bdeb 2184 starts real symbols at 1). */
1da177e4
LT
2185 for (i = 1; i < mod->num_symtab; i++) {
2186 if (mod->symtab[i].st_shndx == SHN_UNDEF)
2187 continue;
2188
2189 /* We ignore unnamed symbols: they're uninformative
2190 * and inserted at a whim. */
2191 if (mod->symtab[i].st_value <= addr
2192 && mod->symtab[i].st_value > mod->symtab[best].st_value
2193 && *(mod->strtab + mod->symtab[i].st_name) != '\0'
2194 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
2195 best = i;
2196 if (mod->symtab[i].st_value > addr
2197 && mod->symtab[i].st_value < nextval
2198 && *(mod->strtab + mod->symtab[i].st_name) != '\0'
2199 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
2200 nextval = mod->symtab[i].st_value;
2201 }
2202
2203 if (!best)
2204 return NULL;
2205
ffb45122
AD
2206 if (size)
2207 *size = nextval - mod->symtab[best].st_value;
2208 if (offset)
2209 *offset = addr - mod->symtab[best].st_value;
1da177e4
LT
2210 return mod->strtab + mod->symtab[best].st_name;
2211}
2212
2213/* For kallsyms to ask for address resolution. NULL means not found.
2214 We don't lock, as this is used for oops resolution and races are a
2215 lesser concern. */
cb2a5205 2216/* FIXME: Risky: returns a pointer into a module w/o lock */
1da177e4
LT
2217const char *module_address_lookup(unsigned long addr,
2218 unsigned long *size,
2219 unsigned long *offset,
2220 char **modname)
2221{
2222 struct module *mod;
cb2a5205 2223 const char *ret = NULL;
1da177e4 2224
cb2a5205 2225 preempt_disable();
1da177e4
LT
2226 list_for_each_entry(mod, &modules, list) {
2227 if (within(addr, mod->module_init, mod->init_size)
2228 || within(addr, mod->module_core, mod->core_size)) {
ffc50891
FBH
2229 if (modname)
2230 *modname = mod->name;
cb2a5205
RR
2231 ret = get_ksymbol(mod, addr, size, offset);
2232 break;
1da177e4
LT
2233 }
2234 }
cb2a5205
RR
2235 preempt_enable();
2236 return ret;
1da177e4
LT
2237}
2238
9d65cb4a
AD
2239int lookup_module_symbol_name(unsigned long addr, char *symname)
2240{
2241 struct module *mod;
2242
cb2a5205 2243 preempt_disable();
9d65cb4a
AD
2244 list_for_each_entry(mod, &modules, list) {
2245 if (within(addr, mod->module_init, mod->init_size) ||
2246 within(addr, mod->module_core, mod->core_size)) {
2247 const char *sym;
2248
2249 sym = get_ksymbol(mod, addr, NULL, NULL);
2250 if (!sym)
2251 goto out;
9281acea 2252 strlcpy(symname, sym, KSYM_NAME_LEN);
cb2a5205 2253 preempt_enable();
9d65cb4a
AD
2254 return 0;
2255 }
2256 }
2257out:
cb2a5205 2258 preempt_enable();
9d65cb4a
AD
2259 return -ERANGE;
2260}
2261
a5c43dae
AD
2262int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
2263 unsigned long *offset, char *modname, char *name)
2264{
2265 struct module *mod;
2266
cb2a5205 2267 preempt_disable();
a5c43dae
AD
2268 list_for_each_entry(mod, &modules, list) {
2269 if (within(addr, mod->module_init, mod->init_size) ||
2270 within(addr, mod->module_core, mod->core_size)) {
2271 const char *sym;
2272
2273 sym = get_ksymbol(mod, addr, size, offset);
2274 if (!sym)
2275 goto out;
2276 if (modname)
9281acea 2277 strlcpy(modname, mod->name, MODULE_NAME_LEN);
a5c43dae 2278 if (name)
9281acea 2279 strlcpy(name, sym, KSYM_NAME_LEN);
cb2a5205 2280 preempt_enable();
a5c43dae
AD
2281 return 0;
2282 }
2283 }
2284out:
cb2a5205 2285 preempt_enable();
a5c43dae
AD
2286 return -ERANGE;
2287}
2288
ea07890a
AD
2289int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
2290 char *name, char *module_name, int *exported)
1da177e4
LT
2291{
2292 struct module *mod;
2293
cb2a5205 2294 preempt_disable();
1da177e4
LT
2295 list_for_each_entry(mod, &modules, list) {
2296 if (symnum < mod->num_symtab) {
2297 *value = mod->symtab[symnum].st_value;
2298 *type = mod->symtab[symnum].st_info;
098c5eea 2299 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
9281acea
TH
2300 KSYM_NAME_LEN);
2301 strlcpy(module_name, mod->name, MODULE_NAME_LEN);
ea07890a 2302 *exported = is_exported(name, mod);
cb2a5205 2303 preempt_enable();
ea07890a 2304 return 0;
1da177e4
LT
2305 }
2306 symnum -= mod->num_symtab;
2307 }
cb2a5205 2308 preempt_enable();
ea07890a 2309 return -ERANGE;
1da177e4
LT
2310}
2311
2312static unsigned long mod_find_symname(struct module *mod, const char *name)
2313{
2314 unsigned int i;
2315
2316 for (i = 0; i < mod->num_symtab; i++)
54e8ce46
KO
2317 if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 &&
2318 mod->symtab[i].st_info != 'U')
1da177e4
LT
2319 return mod->symtab[i].st_value;
2320 return 0;
2321}
2322
2323/* Look for this name: can be of form module:name. */
2324unsigned long module_kallsyms_lookup_name(const char *name)
2325{
2326 struct module *mod;
2327 char *colon;
2328 unsigned long ret = 0;
2329
2330 /* Don't lock: we're in enough trouble already. */
cb2a5205 2331 preempt_disable();
1da177e4
LT
2332 if ((colon = strchr(name, ':')) != NULL) {
2333 *colon = '\0';
2334 if ((mod = find_module(name)) != NULL)
2335 ret = mod_find_symname(mod, colon+1);
2336 *colon = ':';
2337 } else {
2338 list_for_each_entry(mod, &modules, list)
2339 if ((ret = mod_find_symname(mod, name)) != 0)
2340 break;
2341 }
cb2a5205 2342 preempt_enable();
1da177e4
LT
2343 return ret;
2344}
2345#endif /* CONFIG_KALLSYMS */
2346
2347/* Called by the /proc file system to return a list of modules. */
2348static void *m_start(struct seq_file *m, loff_t *pos)
2349{
6389a385 2350 mutex_lock(&module_mutex);
708f4b52 2351 return seq_list_start(&modules, *pos);
1da177e4
LT
2352}
2353
2354static void *m_next(struct seq_file *m, void *p, loff_t *pos)
2355{
708f4b52 2356 return seq_list_next(p, &modules, pos);
1da177e4
LT
2357}
2358
2359static void m_stop(struct seq_file *m, void *p)
2360{
6389a385 2361 mutex_unlock(&module_mutex);
1da177e4
LT
2362}
2363
21aa9280 2364static char *module_flags(struct module *mod, char *buf)
fa3ba2e8
FM
2365{
2366 int bx = 0;
2367
21aa9280
AV
2368 if (mod->taints ||
2369 mod->state == MODULE_STATE_GOING ||
2370 mod->state == MODULE_STATE_COMING) {
fa3ba2e8 2371 buf[bx++] = '(';
21aa9280 2372 if (mod->taints & TAINT_PROPRIETARY_MODULE)
fa3ba2e8 2373 buf[bx++] = 'P';
21aa9280 2374 if (mod->taints & TAINT_FORCED_MODULE)
fa3ba2e8
FM
2375 buf[bx++] = 'F';
2376 /*
2377 * TAINT_FORCED_RMMOD: could be added.
2378 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
2379 * apply to modules.
2380 */
21aa9280
AV
2381
2382 /* Show a - for module-is-being-unloaded */
2383 if (mod->state == MODULE_STATE_GOING)
2384 buf[bx++] = '-';
2385 /* Show a + for module-is-being-loaded */
2386 if (mod->state == MODULE_STATE_COMING)
2387 buf[bx++] = '+';
fa3ba2e8
FM
2388 buf[bx++] = ')';
2389 }
2390 buf[bx] = '\0';
2391
2392 return buf;
2393}
2394
1da177e4
LT
2395static int m_show(struct seq_file *m, void *p)
2396{
2397 struct module *mod = list_entry(p, struct module, list);
fa3ba2e8
FM
2398 char buf[8];
2399
1da177e4
LT
2400 seq_printf(m, "%s %lu",
2401 mod->name, mod->init_size + mod->core_size);
2402 print_unload_info(m, mod);
2403
2404 /* Informative for users. */
2405 seq_printf(m, " %s",
2406 mod->state == MODULE_STATE_GOING ? "Unloading":
2407 mod->state == MODULE_STATE_COMING ? "Loading":
2408 "Live");
2409 /* Used by oprofile and other similar tools. */
2410 seq_printf(m, " 0x%p", mod->module_core);
2411
fa3ba2e8
FM
2412 /* Taints info */
2413 if (mod->taints)
21aa9280 2414 seq_printf(m, " %s", module_flags(mod, buf));
fa3ba2e8 2415
1da177e4
LT
2416 seq_printf(m, "\n");
2417 return 0;
2418}
2419
2420/* Format: modulename size refcount deps address
2421
2422 Where refcount is a number or -, and deps is a comma-separated list
2423 of depends or -.
2424*/
15ad7cdc 2425const struct seq_operations modules_op = {
1da177e4
LT
2426 .start = m_start,
2427 .next = m_next,
2428 .stop = m_stop,
2429 .show = m_show
2430};
2431
2432/* Given an address, look for it in the module exception tables. */
2433const struct exception_table_entry *search_module_extables(unsigned long addr)
2434{
1da177e4
LT
2435 const struct exception_table_entry *e = NULL;
2436 struct module *mod;
2437
24da1cbf 2438 preempt_disable();
1da177e4
LT
2439 list_for_each_entry(mod, &modules, list) {
2440 if (mod->num_exentries == 0)
2441 continue;
22a8bdeb 2442
1da177e4
LT
2443 e = search_extable(mod->extable,
2444 mod->extable + mod->num_exentries - 1,
2445 addr);
2446 if (e)
2447 break;
2448 }
24da1cbf 2449 preempt_enable();
1da177e4
LT
2450
2451 /* Now, if we found one, we are running inside it now, hence
22a8bdeb 2452 we cannot unload the module, hence no refcnt needed. */
1da177e4
LT
2453 return e;
2454}
2455
4d435f9d
IM
2456/*
2457 * Is this a valid module address?
2458 */
2459int is_module_address(unsigned long addr)
2460{
4d435f9d
IM
2461 struct module *mod;
2462
24da1cbf 2463 preempt_disable();
4d435f9d
IM
2464
2465 list_for_each_entry(mod, &modules, list) {
2466 if (within(addr, mod->module_core, mod->core_size)) {
24da1cbf 2467 preempt_enable();
4d435f9d
IM
2468 return 1;
2469 }
2470 }
2471
24da1cbf 2472 preempt_enable();
4d435f9d
IM
2473
2474 return 0;
2475}
2476
2477
24da1cbf 2478/* Is this a valid kernel address? */
1da177e4
LT
2479struct module *__module_text_address(unsigned long addr)
2480{
2481 struct module *mod;
2482
2483 list_for_each_entry(mod, &modules, list)
2484 if (within(addr, mod->module_init, mod->init_text_size)
2485 || within(addr, mod->module_core, mod->core_text_size))
2486 return mod;
2487 return NULL;
2488}
2489
2490struct module *module_text_address(unsigned long addr)
2491{
2492 struct module *mod;
1da177e4 2493
24da1cbf 2494 preempt_disable();
1da177e4 2495 mod = __module_text_address(addr);
24da1cbf 2496 preempt_enable();
1da177e4
LT
2497
2498 return mod;
2499}
2500
2501/* Don't grab lock, we're oopsing. */
2502void print_modules(void)
2503{
2504 struct module *mod;
2bc2d61a 2505 char buf[8];
1da177e4
LT
2506
2507 printk("Modules linked in:");
2508 list_for_each_entry(mod, &modules, list)
21aa9280 2509 printk(" %s%s", mod->name, module_flags(mod, buf));
e14af7ee
AV
2510 if (last_unloaded_module[0])
2511 printk(" [last unloaded: %s]", last_unloaded_module);
1da177e4
LT
2512 printk("\n");
2513}
2514
1da177e4
LT
2515#ifdef CONFIG_MODVERSIONS
2516/* Generate the signature for struct module here, too, for modversions. */
2517void struct_module(struct module *mod) { return; }
2518EXPORT_SYMBOL(struct_module);
2519#endif
8256e47c
MD
2520
2521#ifdef CONFIG_MARKERS
2522void module_update_markers(struct module *probe_module, int *refcount)
2523{
2524 struct module *mod;
2525
2526 mutex_lock(&module_mutex);
2527 list_for_each_entry(mod, &modules, list)
2528 if (!mod->taints)
2529 marker_update_probe_range(mod->markers,
2530 mod->markers + mod->num_markers,
2531 probe_module, refcount);
2532 mutex_unlock(&module_mutex);
2533}
2534#endif