1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Dynamic loading of modules into the kernel.
4 *
5 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
6 * Rewritten again by Rusty Russell, 2002
7 */
8
9 #ifndef _LINUX_MODULE_H
10 #define _LINUX_MODULE_H
11
12 #include <linux/list.h>
13 #include <linux/stat.h>
14 #include <linux/compiler.h>
15 #include <linux/cache.h>
16 #include <linux/kmod.h>
17 #include <linux/init.h>
18 #include <linux/elf.h>
19 #include <linux/stringify.h>
20 #include <linux/kobject.h>
21 #include <linux/moduleparam.h>
22 #include <linux/jump_label.h>
23 #include <linux/export.h>
24 #include <linux/rbtree_latch.h>
25 #include <linux/error-injection.h>
26 #include <linux/tracepoint-defs.h>
27 #include <linux/srcu.h>
28 #include <linux/static_call_types.h>
29 #include <linux/cfi.h>
30
31 #include <linux/percpu.h>
32 #include <asm/module.h>
33
34 /* Not Yet Implemented */
35 #define MODULE_SUPPORTED_DEVICE(name)
36
37 #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
38
39 struct modversion_info {
40 unsigned long crc;
41 char name[MODULE_NAME_LEN];
42 };
43
44 struct module;
45 struct exception_table_entry;
46
47 struct module_kobject {
48 struct kobject kobj;
49 struct module *mod;
50 struct kobject *drivers_dir;
51 struct module_param_attrs *mp;
52 struct completion *kobj_completion;
53 } __randomize_layout;
54
55 struct module_attribute {
56 struct attribute attr;
57 ssize_t (*show)(struct module_attribute *, struct module_kobject *,
58 char *);
59 ssize_t (*store)(struct module_attribute *, struct module_kobject *,
60 const char *, size_t count);
61 void (*setup)(struct module *, const char *);
62 int (*test)(struct module *);
63 void (*free)(struct module *);
64 };
65
66 struct module_version_attribute {
67 struct module_attribute mattr;
68 const char *module_name;
69 const char *version;
70 } __attribute__ ((__aligned__(sizeof(void *))));
71
72 extern ssize_t __modver_version_show(struct module_attribute *,
73 struct module_kobject *, char *);
74
75 extern struct module_attribute module_uevent;
76
77 /* These are either module local, or the kernel's dummy ones. */
78 extern int init_module(void);
79 extern void cleanup_module(void);
80
81 #ifndef MODULE
82 /**
83 * module_init() - driver initialization entry point
84 * @x: function to be run at kernel boot time or module insertion
85 *
86 * module_init() will either be called during do_initcalls() (if
87 * builtin) or at module insertion time (if a module). There can only
88 * be one per module.
89 */
90 #define module_init(x) __initcall(x);
91
92 /**
93 * module_exit() - driver exit entry point
94 * @x: function to be run when driver is removed
95 *
96 * module_exit() will wrap the driver clean-up code
97 * with cleanup_module() when used with rmmod when
98 * the driver is a module. If the driver is statically
99 * compiled into the kernel, module_exit() has no effect.
100 * There can only be one per module.
101 */
102 #define module_exit(x) __exitcall(x);
103
104 #else /* MODULE */
105
106 /*
107 * In most cases loadable modules do not need custom
108 * initcall levels. There are still some valid cases where
109 * a driver may be needed early if built in, and does not
110 * matter when built as a loadable module. Like bus
111 * snooping debug drivers.
112 */
113 #define early_initcall(fn) module_init(fn)
114 #define core_initcall(fn) module_init(fn)
115 #define core_initcall_sync(fn) module_init(fn)
116 #define postcore_initcall(fn) module_init(fn)
117 #define postcore_initcall_sync(fn) module_init(fn)
118 #define arch_initcall(fn) module_init(fn)
119 #define subsys_initcall(fn) module_init(fn)
120 #define subsys_initcall_sync(fn) module_init(fn)
121 #define fs_initcall(fn) module_init(fn)
122 #define fs_initcall_sync(fn) module_init(fn)
123 #define rootfs_initcall(fn) module_init(fn)
124 #define device_initcall(fn) module_init(fn)
125 #define device_initcall_sync(fn) module_init(fn)
126 #define late_initcall(fn) module_init(fn)
127 #define late_initcall_sync(fn) module_init(fn)
128
129 #define console_initcall(fn) module_init(fn)
130
131 /* Each module must use one module_init(). */
132 #define module_init(initfn) \
133 static inline initcall_t __maybe_unused __inittest(void) \
134 { return initfn; } \
135 int init_module(void) __copy(initfn) \
136 __attribute__((alias(#initfn))); \
137 __CFI_ADDRESSABLE(init_module, __initdata);
138
139 /* This is only required if you want to be unloadable. */
140 #define module_exit(exitfn) \
141 static inline exitcall_t __maybe_unused __exittest(void) \
142 { return exitfn; } \
143 void cleanup_module(void) __copy(exitfn) \
144 __attribute__((alias(#exitfn))); \
145 __CFI_ADDRESSABLE(cleanup_module, __exitdata);
146
147 #endif
148
149 /* This means "can be init if no module support, otherwise module load
150 may call it." */
151 #ifdef CONFIG_MODULES
152 #define __init_or_module
153 #define __initdata_or_module
154 #define __initconst_or_module
155 #define __INIT_OR_MODULE .text
156 #define __INITDATA_OR_MODULE .data
157 #define __INITRODATA_OR_MODULE .section ".rodata","a",%progbits
158 #else
159 #define __init_or_module __init
160 #define __initdata_or_module __initdata
161 #define __initconst_or_module __initconst
162 #define __INIT_OR_MODULE __INIT
163 #define __INITDATA_OR_MODULE __INITDATA
164 #define __INITRODATA_OR_MODULE __INITRODATA
165 #endif /*CONFIG_MODULES*/
166
167 /* Generic info of form tag = "info" */
168 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
169
170 /* For userspace: you can also call me... */
171 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
172
173 /* Soft module dependencies. See man modprobe.d for details.
174 * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz")
175 */
176 #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
177
178 /*
179 * MODULE_FILE is used for generating modules.builtin
180 * So, make it no-op when this is being built as a module
181 */
182 #ifdef MODULE
183 #define MODULE_FILE
184 #else
185 #define MODULE_FILE MODULE_INFO(file, KBUILD_MODFILE);
186 #endif
187
188 /*
189 * The following license idents are currently accepted as indicating free
190 * software modules
191 *
192 * "GPL" [GNU Public License v2]
193 * "GPL v2" [GNU Public License v2]
194 * "GPL and additional rights" [GNU Public License v2 rights and more]
195 * "Dual BSD/GPL" [GNU Public License v2
196 * or BSD license choice]
197 * "Dual MIT/GPL" [GNU Public License v2
198 * or MIT license choice]
199 * "Dual MPL/GPL" [GNU Public License v2
200 * or Mozilla license choice]
201 *
202 * The following other idents are available
203 *
204 * "Proprietary" [Non free products]
205 *
206 * Both "GPL v2" and "GPL" (the latter also in dual licensed strings) are
207 * merely stating that the module is licensed under the GPL v2, but are not
208 * telling whether "GPL v2 only" or "GPL v2 or later". The reason why there
209 * are two variants is a historic and failed attempt to convey more
210 * information in the MODULE_LICENSE string. For module loading the
211 * "only/or later" distinction is completely irrelevant and does neither
212 * replace the proper license identifiers in the corresponding source file
213 * nor amends them in any way. The sole purpose is to make the
214 * 'Proprietary' flagging work and to refuse to bind symbols which are
215 * exported with EXPORT_SYMBOL_GPL when a non free module is loaded.
216 *
217 * In the same way "BSD" is not a clear license information. It merely
218 * states, that the module is licensed under one of the compatible BSD
219 * license variants. The detailed and correct license information is again
220 * to be found in the corresponding source files.
221 *
222 * There are dual licensed components, but when running with Linux it is the
223 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
224 * is a GPL combined work.
225 *
226 * This exists for several reasons
227 * 1. So modinfo can show license info for users wanting to vet their setup
228 * is free
229 * 2. So the community can ignore bug reports including proprietary modules
230 * 3. So vendors can do likewise based on their own policies
231 */
232 #define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license)
233
234 /*
235 * Author(s), use "Name <email>" or just "Name", for multiple
236 * authors use multiple MODULE_AUTHOR() statements/lines.
237 */
238 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
239
240 /* What your module does. */
241 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
242
243 #ifdef MODULE
244 /* Creates an alias so file2alias.c can find device table. */
245 #define MODULE_DEVICE_TABLE(type, name) \
246 extern typeof(name) __mod_##type##__##name##_device_table \
247 __attribute__ ((unused, alias(__stringify(name))))
248 #else /* !MODULE */
249 #define MODULE_DEVICE_TABLE(type, name)
250 #endif
251
252 /* Version of form [<epoch>:]<version>[-<extra-version>].
253 * Or for CVS/RCS ID version, everything but the number is stripped.
254 * <epoch>: A (small) unsigned integer which allows you to start versions
255 * anew. If not mentioned, it's zero. eg. "2:1.0" is after
256 * "1:2.0".
257
258 * <version>: The <version> may contain only alphanumerics and the
259 * character `.'. Ordered by numeric sort for numeric parts,
260 * ascii sort for ascii parts (as per RPM or DEB algorithm).
261
262 * <extraversion>: Like <version>, but inserted for local
263 * customizations, eg "rh3" or "rusty1".
264
265 * Using this automatically adds a checksum of the .c files and the
266 * local headers in "srcversion".
267 */
268
269 #if defined(MODULE) || !defined(CONFIG_SYSFS)
270 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
271 #else
272 #define MODULE_VERSION(_version) \
273 MODULE_INFO(version, _version); \
274 static struct module_version_attribute ___modver_attr = { \
275 .mattr = { \
276 .attr = { \
277 .name = "version", \
278 .mode = S_IRUGO, \
279 }, \
280 .show = __modver_version_show, \
281 }, \
282 .module_name = KBUILD_MODNAME, \
283 .version = _version, \
284 }; \
285 static const struct module_version_attribute \
286 __used __section("__modver") \
287 * __moduleparam_const __modver_attr = &___modver_attr
288 #endif
289
290 /* Optional firmware file (or files) needed by the module
291 * format is simply firmware file name. Multiple firmware
292 * files require multiple MODULE_FIRMWARE() specifiers */
293 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
294
295 #define MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, #ns)
296
297 struct notifier_block;
298
299 #ifdef CONFIG_MODULES
300
301 extern int modules_disabled; /* for sysctl */
302 /* Get/put a kernel symbol (calls must be symmetric) */
303 void *__symbol_get(const char *symbol);
304 void *__symbol_get_gpl(const char *symbol);
305 #define symbol_get(x) ((typeof(&x))(__symbol_get(__stringify(x))))
306
307 /* modules using other modules: kdb wants to see this. */
308 struct module_use {
309 struct list_head source_list;
310 struct list_head target_list;
311 struct module *source, *target;
312 };
313
314 enum module_state {
315 MODULE_STATE_LIVE, /* Normal state. */
316 MODULE_STATE_COMING, /* Full formed, running module_init. */
317 MODULE_STATE_GOING, /* Going away. */
318 MODULE_STATE_UNFORMED, /* Still setting it up. */
319 };
320
321 struct mod_tree_node {
322 struct module *mod;
323 struct latch_tree_node node;
324 };
325
326 struct module_layout {
327 /* The actual code + data. */
328 void *base;
329 /* Total size. */
330 unsigned int size;
331 /* The size of the executable code. */
332 unsigned int text_size;
333 /* Size of RO section of the module (text+rodata) */
334 unsigned int ro_size;
335 /* Size of RO after init section */
336 unsigned int ro_after_init_size;
337
338 #ifdef CONFIG_MODULES_TREE_LOOKUP
339 struct mod_tree_node mtn;
340 #endif
341 };
342
343 #ifdef CONFIG_MODULES_TREE_LOOKUP
344 /* Only touch one cacheline for common rbtree-for-core-layout case. */
345 #define __module_layout_align ____cacheline_aligned
346 #else
347 #define __module_layout_align
348 #endif
349
350 struct mod_kallsyms {
351 Elf_Sym *symtab;
352 unsigned int num_symtab;
353 char *strtab;
354 char *typetab;
355 };
356
357 #ifdef CONFIG_LIVEPATCH
358 struct klp_modinfo {
359 Elf_Ehdr hdr;
360 Elf_Shdr *sechdrs;
361 char *secstrings;
362 unsigned int symndx;
363 };
364 #endif
365
366 struct module {
367 enum module_state state;
368
369 /* Member of list of modules */
370 struct list_head list;
371
372 /* Unique handle for this module */
373 char name[MODULE_NAME_LEN];
374
375 /* Sysfs stuff. */
376 struct module_kobject mkobj;
377 struct module_attribute *modinfo_attrs;
378 const char *version;
379 const char *srcversion;
380 struct kobject *holders_dir;
381
382 /* Exported symbols */
383 const struct kernel_symbol *syms;
384 const s32 *crcs;
385 unsigned int num_syms;
386
387 #ifdef CONFIG_CFI_CLANG
388 cfi_check_fn cfi_check;
389 #endif
390
391 /* Kernel parameters. */
392 #ifdef CONFIG_SYSFS
393 struct mutex param_lock;
394 #endif
395 struct kernel_param *kp;
396 unsigned int num_kp;
397
398 /* GPL-only exported symbols. */
399 unsigned int num_gpl_syms;
400 const struct kernel_symbol *gpl_syms;
401 const s32 *gpl_crcs;
402 bool using_gplonly_symbols;
403
404 #ifdef CONFIG_UNUSED_SYMBOLS
405 /* unused exported symbols. */
406 const struct kernel_symbol *unused_syms;
407 const s32 *unused_crcs;
408 unsigned int num_unused_syms;
409
410 /* GPL-only, unused exported symbols. */
411 unsigned int num_unused_gpl_syms;
412 const struct kernel_symbol *unused_gpl_syms;
413 const s32 *unused_gpl_crcs;
414 #endif
415
416 #ifdef CONFIG_MODULE_SIG
417 /* Signature was verified. */
418 bool sig_ok;
419 #endif
420
421 bool async_probe_requested;
422
423 /* symbols that will be GPL-only in the near future. */
424 const struct kernel_symbol *gpl_future_syms;
425 const s32 *gpl_future_crcs;
426 unsigned int num_gpl_future_syms;
427
428 /* Exception table */
429 unsigned int num_exentries;
430 struct exception_table_entry *extable;
431
432 /* Startup function. */
433 int (*init)(void);
434
435 /* Core layout: rbtree is accessed frequently, so keep together. */
436 struct module_layout core_layout __module_layout_align;
437 struct module_layout init_layout;
438
439 /* Arch-specific module values */
440 struct mod_arch_specific arch;
441
442 unsigned long taints; /* same bits as kernel:taint_flags */
443
444 #ifdef CONFIG_GENERIC_BUG
445 /* Support for BUG */
446 unsigned num_bugs;
447 struct list_head bug_list;
448 struct bug_entry *bug_table;
449 #endif
450
451 #ifdef CONFIG_KALLSYMS
452 /* Protected by RCU and/or module_mutex: use rcu_dereference() */
453 struct mod_kallsyms __rcu *kallsyms;
454 struct mod_kallsyms core_kallsyms;
455
456 /* Section attributes */
457 struct module_sect_attrs *sect_attrs;
458
459 /* Notes attributes */
460 struct module_notes_attrs *notes_attrs;
461 #endif
462
463 /* The command line arguments (may be mangled). People like
464 keeping pointers to this stuff */
465 char *args;
466
467 #ifdef CONFIG_SMP
468 /* Per-cpu data. */
469 void __percpu *percpu;
470 unsigned int percpu_size;
471 #endif
472 void *noinstr_text_start;
473 unsigned int noinstr_text_size;
474
475 #ifdef CONFIG_TRACEPOINTS
476 unsigned int num_tracepoints;
477 tracepoint_ptr_t *tracepoints_ptrs;
478 #endif
479 #ifdef CONFIG_TREE_SRCU
480 unsigned int num_srcu_structs;
481 struct srcu_struct **srcu_struct_ptrs;
482 #endif
483 #ifdef CONFIG_BPF_EVENTS
484 unsigned int num_bpf_raw_events;
485 struct bpf_raw_event_map *bpf_raw_events;
486 #endif
487 #ifdef CONFIG_JUMP_LABEL
488 struct jump_entry *jump_entries;
489 unsigned int num_jump_entries;
490 #endif
491 #ifdef CONFIG_TRACING
492 unsigned int num_trace_bprintk_fmt;
493 const char **trace_bprintk_fmt_start;
494 #endif
495 #ifdef CONFIG_EVENT_TRACING
496 struct trace_event_call **trace_events;
497 unsigned int num_trace_events;
498 struct trace_eval_map **trace_evals;
499 unsigned int num_trace_evals;
500 #endif
501 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
502 unsigned int num_ftrace_callsites;
503 unsigned long *ftrace_callsites;
504 #endif
505 #ifdef CONFIG_KPROBES
506 void *kprobes_text_start;
507 unsigned int kprobes_text_size;
508 unsigned long *kprobe_blacklist;
509 unsigned int num_kprobe_blacklist;
510 #endif
511 #ifdef CONFIG_HAVE_STATIC_CALL_INLINE
512 int num_static_call_sites;
513 struct static_call_site *static_call_sites;
514 #endif
515
516 #ifdef CONFIG_LIVEPATCH
517 bool klp; /* Is this a livepatch module? */
518 bool klp_alive;
519
520 /* Elf information */
521 struct klp_modinfo *klp_info;
522 #endif
523
524 #ifdef CONFIG_MODULE_UNLOAD
525 /* What modules depend on me? */
526 struct list_head source_list;
527 /* What modules do I depend on? */
528 struct list_head target_list;
529
530 /* Destruction function. */
531 void (*exit)(void);
532
533 atomic_t refcnt;
534 #endif
535
536 #ifdef CONFIG_CONSTRUCTORS
537 /* Constructor functions. */
538 ctor_fn_t *ctors;
539 unsigned int num_ctors;
540 #endif
541
542 #ifdef CONFIG_FUNCTION_ERROR_INJECTION
543 struct error_injection_entry *ei_funcs;
544 unsigned int num_ei_funcs;
545 #endif
546 } ____cacheline_aligned __randomize_layout;
547 #ifndef MODULE_ARCH_INIT
548 #define MODULE_ARCH_INIT {}
549 #endif
550
551 #ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE
kallsyms_symbol_value(const Elf_Sym * sym)552 static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym)
553 {
554 return sym->st_value;
555 }
556 #endif
557
558 extern struct mutex module_mutex;
559
560 /* FIXME: It'd be nice to isolate modules during init, too, so they
561 aren't used before they (may) fail. But presently too much code
562 (IDE & SCSI) require entry into the module during init.*/
module_is_live(struct module * mod)563 static inline bool module_is_live(struct module *mod)
564 {
565 return mod->state != MODULE_STATE_GOING;
566 }
567
568 struct module *__module_text_address(unsigned long addr);
569 struct module *__module_address(unsigned long addr);
570 bool is_module_address(unsigned long addr);
571 bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr);
572 bool is_module_percpu_address(unsigned long addr);
573 bool is_module_text_address(unsigned long addr);
574
within_module_core(unsigned long addr,const struct module * mod)575 static inline bool within_module_core(unsigned long addr,
576 const struct module *mod)
577 {
578 return (unsigned long)mod->core_layout.base <= addr &&
579 addr < (unsigned long)mod->core_layout.base + mod->core_layout.size;
580 }
581
within_module_init(unsigned long addr,const struct module * mod)582 static inline bool within_module_init(unsigned long addr,
583 const struct module *mod)
584 {
585 return (unsigned long)mod->init_layout.base <= addr &&
586 addr < (unsigned long)mod->init_layout.base + mod->init_layout.size;
587 }
588
within_module(unsigned long addr,const struct module * mod)589 static inline bool within_module(unsigned long addr, const struct module *mod)
590 {
591 return within_module_init(addr, mod) || within_module_core(addr, mod);
592 }
593
594 /* Search for module by name: must hold module_mutex. */
595 struct module *find_module(const char *name);
596
597 struct symsearch {
598 const struct kernel_symbol *start, *stop;
599 const s32 *crcs;
600 enum mod_license {
601 NOT_GPL_ONLY,
602 GPL_ONLY,
603 WILL_BE_GPL_ONLY,
604 } license;
605 bool unused;
606 };
607
608 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
609 symnum out of range. */
610 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
611 char *name, char *module_name, int *exported);
612
613 /* Look for this name: can be of form module:name. */
614 unsigned long module_kallsyms_lookup_name(const char *name);
615
616 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
617 struct module *, unsigned long),
618 void *data);
619
620 extern void __noreturn __module_put_and_exit(struct module *mod,
621 long code);
622 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code)
623
624 #ifdef CONFIG_MODULE_UNLOAD
625 int module_refcount(struct module *mod);
626 void __symbol_put(const char *symbol);
627 #define symbol_put(x) __symbol_put(__stringify(x))
628 void symbol_put_addr(void *addr);
629
630 /* Sometimes we know we already have a refcount, and it's easier not
631 to handle the error case (which only happens with rmmod --wait). */
632 extern void __module_get(struct module *module);
633
634 /* This is the Right Way to get a module: if it fails, it's being removed,
635 * so pretend it's not there. */
636 extern bool try_module_get(struct module *module);
637
638 extern void module_put(struct module *module);
639
640 #else /*!CONFIG_MODULE_UNLOAD*/
try_module_get(struct module * module)641 static inline bool try_module_get(struct module *module)
642 {
643 return !module || module_is_live(module);
644 }
module_put(struct module * module)645 static inline void module_put(struct module *module)
646 {
647 }
__module_get(struct module * module)648 static inline void __module_get(struct module *module)
649 {
650 }
651 #define symbol_put(x) do { } while (0)
652 #define symbol_put_addr(p) do { } while (0)
653
654 #endif /* CONFIG_MODULE_UNLOAD */
655
656 /* This is a #define so the string doesn't get put in every .o file */
657 #define module_name(mod) \
658 ({ \
659 struct module *__mod = (mod); \
660 __mod ? __mod->name : "kernel"; \
661 })
662
663 /* Dereference module function descriptor */
664 void *dereference_module_function_descriptor(struct module *mod, void *ptr);
665
666 /* For kallsyms to ask for address resolution. namebuf should be at
667 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
668 * found, otherwise NULL. */
669 const char *module_address_lookup(unsigned long addr,
670 unsigned long *symbolsize,
671 unsigned long *offset,
672 char **modname,
673 char *namebuf);
674 int lookup_module_symbol_name(unsigned long addr, char *symname);
675 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
676
677 int register_module_notifier(struct notifier_block *nb);
678 int unregister_module_notifier(struct notifier_block *nb);
679
680 extern void print_modules(void);
681
module_requested_async_probing(struct module * module)682 static inline bool module_requested_async_probing(struct module *module)
683 {
684 return module && module->async_probe_requested;
685 }
686
687 #ifdef CONFIG_LIVEPATCH
is_livepatch_module(struct module * mod)688 static inline bool is_livepatch_module(struct module *mod)
689 {
690 return mod->klp;
691 }
692 #else /* !CONFIG_LIVEPATCH */
is_livepatch_module(struct module * mod)693 static inline bool is_livepatch_module(struct module *mod)
694 {
695 return false;
696 }
697 #endif /* CONFIG_LIVEPATCH */
698
699 bool is_module_sig_enforced(void);
700 void set_module_sig_enforced(void);
701
702 #else /* !CONFIG_MODULES... */
703
__module_address(unsigned long addr)704 static inline struct module *__module_address(unsigned long addr)
705 {
706 return NULL;
707 }
708
__module_text_address(unsigned long addr)709 static inline struct module *__module_text_address(unsigned long addr)
710 {
711 return NULL;
712 }
713
is_module_address(unsigned long addr)714 static inline bool is_module_address(unsigned long addr)
715 {
716 return false;
717 }
718
is_module_percpu_address(unsigned long addr)719 static inline bool is_module_percpu_address(unsigned long addr)
720 {
721 return false;
722 }
723
__is_module_percpu_address(unsigned long addr,unsigned long * can_addr)724 static inline bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
725 {
726 return false;
727 }
728
is_module_text_address(unsigned long addr)729 static inline bool is_module_text_address(unsigned long addr)
730 {
731 return false;
732 }
733
within_module_core(unsigned long addr,const struct module * mod)734 static inline bool within_module_core(unsigned long addr,
735 const struct module *mod)
736 {
737 return false;
738 }
739
within_module_init(unsigned long addr,const struct module * mod)740 static inline bool within_module_init(unsigned long addr,
741 const struct module *mod)
742 {
743 return false;
744 }
745
within_module(unsigned long addr,const struct module * mod)746 static inline bool within_module(unsigned long addr, const struct module *mod)
747 {
748 return false;
749 }
750
751 /* Get/put a kernel symbol (calls should be symmetric) */
752 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); })
753 #define symbol_put(x) do { } while (0)
754 #define symbol_put_addr(x) do { } while (0)
755
__module_get(struct module * module)756 static inline void __module_get(struct module *module)
757 {
758 }
759
try_module_get(struct module * module)760 static inline bool try_module_get(struct module *module)
761 {
762 return true;
763 }
764
module_put(struct module * module)765 static inline void module_put(struct module *module)
766 {
767 }
768
769 #define module_name(mod) "kernel"
770
771 /* For kallsyms to ask for address resolution. NULL means not found. */
module_address_lookup(unsigned long addr,unsigned long * symbolsize,unsigned long * offset,char ** modname,char * namebuf)772 static inline const char *module_address_lookup(unsigned long addr,
773 unsigned long *symbolsize,
774 unsigned long *offset,
775 char **modname,
776 char *namebuf)
777 {
778 return NULL;
779 }
780
lookup_module_symbol_name(unsigned long addr,char * symname)781 static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
782 {
783 return -ERANGE;
784 }
785
lookup_module_symbol_attrs(unsigned long addr,unsigned long * size,unsigned long * offset,char * modname,char * name)786 static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
787 {
788 return -ERANGE;
789 }
790
module_get_kallsym(unsigned int symnum,unsigned long * value,char * type,char * name,char * module_name,int * exported)791 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
792 char *type, char *name,
793 char *module_name, int *exported)
794 {
795 return -ERANGE;
796 }
797
module_kallsyms_lookup_name(const char * name)798 static inline unsigned long module_kallsyms_lookup_name(const char *name)
799 {
800 return 0;
801 }
802
module_kallsyms_on_each_symbol(int (* fn)(void *,const char *,struct module *,unsigned long),void * data)803 static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
804 struct module *,
805 unsigned long),
806 void *data)
807 {
808 return 0;
809 }
810
register_module_notifier(struct notifier_block * nb)811 static inline int register_module_notifier(struct notifier_block *nb)
812 {
813 /* no events will happen anyway, so this can always succeed */
814 return 0;
815 }
816
unregister_module_notifier(struct notifier_block * nb)817 static inline int unregister_module_notifier(struct notifier_block *nb)
818 {
819 return 0;
820 }
821
822 #define module_put_and_exit(code) do_exit(code)
823
print_modules(void)824 static inline void print_modules(void)
825 {
826 }
827
module_requested_async_probing(struct module * module)828 static inline bool module_requested_async_probing(struct module *module)
829 {
830 return false;
831 }
832
is_module_sig_enforced(void)833 static inline bool is_module_sig_enforced(void)
834 {
835 return false;
836 }
837
set_module_sig_enforced(void)838 static inline void set_module_sig_enforced(void)
839 {
840 }
841
842 /* Dereference module function descriptor */
843 static inline
dereference_module_function_descriptor(struct module * mod,void * ptr)844 void *dereference_module_function_descriptor(struct module *mod, void *ptr)
845 {
846 return ptr;
847 }
848
849 #endif /* CONFIG_MODULES */
850
851 #ifdef CONFIG_SYSFS
852 extern struct kset *module_kset;
853 extern struct kobj_type module_ktype;
854 extern int module_sysfs_initialized;
855 #endif /* CONFIG_SYSFS */
856
857 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
858
859 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
860
861 #define __MODULE_STRING(x) __stringify(x)
862
863 #ifdef CONFIG_GENERIC_BUG
864 void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
865 struct module *);
866 void module_bug_cleanup(struct module *);
867
868 #else /* !CONFIG_GENERIC_BUG */
869
module_bug_finalize(const Elf_Ehdr * hdr,const Elf_Shdr * sechdrs,struct module * mod)870 static inline void module_bug_finalize(const Elf_Ehdr *hdr,
871 const Elf_Shdr *sechdrs,
872 struct module *mod)
873 {
874 }
module_bug_cleanup(struct module * mod)875 static inline void module_bug_cleanup(struct module *mod) {}
876 #endif /* CONFIG_GENERIC_BUG */
877
878 #ifdef CONFIG_RETPOLINE
879 extern bool retpoline_module_ok(bool has_retpoline);
880 #else
retpoline_module_ok(bool has_retpoline)881 static inline bool retpoline_module_ok(bool has_retpoline)
882 {
883 return true;
884 }
885 #endif
886
887 #ifdef CONFIG_MODULE_SIG
module_sig_ok(struct module * module)888 static inline bool module_sig_ok(struct module *module)
889 {
890 return module->sig_ok;
891 }
892 #else /* !CONFIG_MODULE_SIG */
module_sig_ok(struct module * module)893 static inline bool module_sig_ok(struct module *module)
894 {
895 return true;
896 }
897 #endif /* CONFIG_MODULE_SIG */
898
899 #endif /* _LINUX_MODULE_H */
900