| .. | .. | 
|---|
| 1 |  | -#ifndef _LINUX_MODULE_H | 
|---|
| 2 |  | -#define _LINUX_MODULE_H | 
|---|
|  | 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ | 
|---|
| 3 | 2 | /* | 
|---|
| 4 | 3 | * Dynamic loading of modules into the kernel. | 
|---|
| 5 | 4 | * | 
|---|
| 6 | 5 | * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996 | 
|---|
| 7 | 6 | * Rewritten again by Rusty Russell, 2002 | 
|---|
| 8 | 7 | */ | 
|---|
|  | 8 | + | 
|---|
|  | 9 | +#ifndef _LINUX_MODULE_H | 
|---|
|  | 10 | +#define _LINUX_MODULE_H | 
|---|
|  | 11 | + | 
|---|
| 9 | 12 | #include <linux/list.h> | 
|---|
| 10 | 13 | #include <linux/stat.h> | 
|---|
| 11 | 14 | #include <linux/compiler.h> | 
|---|
| .. | .. | 
|---|
| 21 | 24 | #include <linux/rbtree_latch.h> | 
|---|
| 22 | 25 | #include <linux/error-injection.h> | 
|---|
| 23 | 26 | #include <linux/tracepoint-defs.h> | 
|---|
|  | 27 | +#include <linux/srcu.h> | 
|---|
|  | 28 | +#include <linux/static_call_types.h> | 
|---|
| 24 | 29 | #include <linux/cfi.h> | 
|---|
| 25 | 30 | #include <linux/android_kabi.h> | 
|---|
| 26 | 31 |  | 
|---|
| 27 | 32 | #include <linux/percpu.h> | 
|---|
| 28 | 33 | #include <asm/module.h> | 
|---|
| 29 |  | - | 
|---|
| 30 |  | -/* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */ | 
|---|
| 31 |  | -#define MODULE_SIG_STRING "~Module signature appended~\n" | 
|---|
| 32 | 34 |  | 
|---|
| 33 | 35 | /* Not Yet Implemented */ | 
|---|
| 34 | 36 | #define MODULE_SUPPORTED_DEVICE(name) | 
|---|
| .. | .. | 
|---|
| 126 | 128 | #define late_initcall_sync(fn)		module_init(fn) | 
|---|
| 127 | 129 |  | 
|---|
| 128 | 130 | #define console_initcall(fn)		module_init(fn) | 
|---|
| 129 |  | -#define security_initcall(fn)		module_init(fn) | 
|---|
| 130 | 131 |  | 
|---|
| 131 | 132 | /* Each module must use one module_init(). */ | 
|---|
| 132 | 133 | #define module_init(initfn)					\ | 
|---|
| 133 | 134 | static inline initcall_t __maybe_unused __inittest(void)		\ | 
|---|
| 134 | 135 | { return initfn; }					\ | 
|---|
| 135 |  | -	int init_module(void) __copy(initfn) __attribute__((alias(#initfn))); | 
|---|
|  | 136 | +	int init_module(void) __copy(initfn) 			\ | 
|---|
|  | 137 | +		__attribute__((alias(#initfn)));		\ | 
|---|
|  | 138 | +	__CFI_ADDRESSABLE(init_module) | 
|---|
| 136 | 139 |  | 
|---|
| 137 | 140 | /* This is only required if you want to be unloadable. */ | 
|---|
| 138 | 141 | #define module_exit(exitfn)					\ | 
|---|
| 139 | 142 | static inline exitcall_t __maybe_unused __exittest(void)		\ | 
|---|
| 140 | 143 | { return exitfn; }					\ | 
|---|
| 141 |  | -	void cleanup_module(void) __copy(exitfn) __attribute__((alias(#exitfn))); | 
|---|
|  | 144 | +	void cleanup_module(void) __copy(exitfn) 		\ | 
|---|
|  | 145 | +		__attribute__((alias(#exitfn))); 		\ | 
|---|
|  | 146 | +	__CFI_ADDRESSABLE(cleanup_module) | 
|---|
| 142 | 147 |  | 
|---|
| 143 | 148 | #endif | 
|---|
| 144 | 149 |  | 
|---|
| .. | .. | 
|---|
| 172 | 177 | #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep) | 
|---|
| 173 | 178 |  | 
|---|
| 174 | 179 | /* | 
|---|
|  | 180 | + * MODULE_FILE is used for generating modules.builtin | 
|---|
|  | 181 | + * So, make it no-op when this is being built as a module | 
|---|
|  | 182 | + */ | 
|---|
|  | 183 | +#ifdef MODULE | 
|---|
|  | 184 | +#define MODULE_FILE | 
|---|
|  | 185 | +#else | 
|---|
|  | 186 | +#define MODULE_FILE	MODULE_INFO(file, KBUILD_MODFILE); | 
|---|
|  | 187 | +#endif | 
|---|
|  | 188 | + | 
|---|
|  | 189 | +/* | 
|---|
| 175 | 190 | * The following license idents are currently accepted as indicating free | 
|---|
| 176 | 191 | * software modules | 
|---|
| 177 | 192 | * | 
|---|
| 178 |  | - *	"GPL"				[GNU Public License v2 or later] | 
|---|
|  | 193 | + *	"GPL"				[GNU Public License v2] | 
|---|
| 179 | 194 | *	"GPL v2"			[GNU Public License v2] | 
|---|
| 180 | 195 | *	"GPL and additional rights"	[GNU Public License v2 rights and more] | 
|---|
| 181 | 196 | *	"Dual BSD/GPL"			[GNU Public License v2 | 
|---|
| .. | .. | 
|---|
| 189 | 204 | * | 
|---|
| 190 | 205 | *	"Proprietary"			[Non free products] | 
|---|
| 191 | 206 | * | 
|---|
|  | 207 | + * Both "GPL v2" and "GPL" (the latter also in dual licensed strings) are | 
|---|
|  | 208 | + * merely stating that the module is licensed under the GPL v2, but are not | 
|---|
|  | 209 | + * telling whether "GPL v2 only" or "GPL v2 or later". The reason why there | 
|---|
|  | 210 | + * are two variants is a historic and failed attempt to convey more | 
|---|
|  | 211 | + * information in the MODULE_LICENSE string. For module loading the | 
|---|
|  | 212 | + * "only/or later" distinction is completely irrelevant and does neither | 
|---|
|  | 213 | + * replace the proper license identifiers in the corresponding source file | 
|---|
|  | 214 | + * nor amends them in any way. The sole purpose is to make the | 
|---|
|  | 215 | + * 'Proprietary' flagging work and to refuse to bind symbols which are | 
|---|
|  | 216 | + * exported with EXPORT_SYMBOL_GPL when a non free module is loaded. | 
|---|
|  | 217 | + * | 
|---|
|  | 218 | + * In the same way "BSD" is not a clear license information. It merely | 
|---|
|  | 219 | + * states, that the module is licensed under one of the compatible BSD | 
|---|
|  | 220 | + * license variants. The detailed and correct license information is again | 
|---|
|  | 221 | + * to be found in the corresponding source files. | 
|---|
|  | 222 | + * | 
|---|
| 192 | 223 | * There are dual licensed components, but when running with Linux it is the | 
|---|
| 193 | 224 | * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL | 
|---|
| 194 | 225 | * is a GPL combined work. | 
|---|
| .. | .. | 
|---|
| 199 | 230 | * 2.	So the community can ignore bug reports including proprietary modules | 
|---|
| 200 | 231 | * 3.	So vendors can do likewise based on their own policies | 
|---|
| 201 | 232 | */ | 
|---|
| 202 |  | -#define MODULE_LICENSE(_license) MODULE_INFO(license, _license) | 
|---|
|  | 233 | +#define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license) | 
|---|
| 203 | 234 |  | 
|---|
| 204 | 235 | /* | 
|---|
| 205 | 236 | * Author(s), use "Name <email>" or just "Name", for multiple | 
|---|
| .. | .. | 
|---|
| 240 | 271 | #define MODULE_VERSION(_version) MODULE_INFO(version, _version) | 
|---|
| 241 | 272 | #else | 
|---|
| 242 | 273 | #define MODULE_VERSION(_version)					\ | 
|---|
|  | 274 | +	MODULE_INFO(version, _version);					\ | 
|---|
| 243 | 275 | static struct module_version_attribute ___modver_attr = {	\ | 
|---|
| 244 | 276 | .mattr	= {						\ | 
|---|
| 245 | 277 | .attr	= {					\ | 
|---|
| .. | .. | 
|---|
| 252 | 284 | .version	= _version,				\ | 
|---|
| 253 | 285 | };								\ | 
|---|
| 254 | 286 | static const struct module_version_attribute			\ | 
|---|
| 255 |  | -	__used __attribute__ ((__section__ ("__modver")))		\ | 
|---|
|  | 287 | +	__used __section("__modver")					\ | 
|---|
| 256 | 288 | * __moduleparam_const __modver_attr = &___modver_attr | 
|---|
| 257 | 289 | #endif | 
|---|
| 258 | 290 |  | 
|---|
| .. | .. | 
|---|
| 260 | 292 | * format is simply firmware file name.  Multiple firmware | 
|---|
| 261 | 293 | * files require multiple MODULE_FIRMWARE() specifiers */ | 
|---|
| 262 | 294 | #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) | 
|---|
|  | 295 | + | 
|---|
|  | 296 | +#define MODULE_IMPORT_NS(ns)	MODULE_INFO(import_ns, __stringify(ns)) | 
|---|
| 263 | 297 |  | 
|---|
| 264 | 298 | struct notifier_block; | 
|---|
| 265 | 299 |  | 
|---|
| .. | .. | 
|---|
| 318 | 352 | Elf_Sym *symtab; | 
|---|
| 319 | 353 | unsigned int num_symtab; | 
|---|
| 320 | 354 | char *strtab; | 
|---|
|  | 355 | +	char *typetab; | 
|---|
| 321 | 356 | }; | 
|---|
| 322 | 357 |  | 
|---|
| 323 | 358 | #ifdef CONFIG_LIVEPATCH | 
|---|
| .. | .. | 
|---|
| 343 | 378 | struct module_attribute *modinfo_attrs; | 
|---|
| 344 | 379 | const char *version; | 
|---|
| 345 | 380 | const char *srcversion; | 
|---|
|  | 381 | +	const char *scmversion; | 
|---|
| 346 | 382 | struct kobject *holders_dir; | 
|---|
| 347 | 383 |  | 
|---|
| 348 | 384 | /* Exported symbols */ | 
|---|
| .. | .. | 
|---|
| 365 | 401 | unsigned int num_gpl_syms; | 
|---|
| 366 | 402 | const struct kernel_symbol *gpl_syms; | 
|---|
| 367 | 403 | const s32 *gpl_crcs; | 
|---|
|  | 404 | +	bool using_gplonly_symbols; | 
|---|
| 368 | 405 |  | 
|---|
| 369 | 406 | #ifdef CONFIG_UNUSED_SYMBOLS | 
|---|
| 370 | 407 | /* unused exported symbols. */ | 
|---|
| .. | .. | 
|---|
| 417 | 454 |  | 
|---|
| 418 | 455 | #ifdef CONFIG_KALLSYMS | 
|---|
| 419 | 456 | /* Protected by RCU and/or module_mutex: use rcu_dereference() */ | 
|---|
| 420 |  | -	struct mod_kallsyms *kallsyms; | 
|---|
|  | 457 | +	struct mod_kallsyms __rcu *kallsyms; | 
|---|
| 421 | 458 | struct mod_kallsyms core_kallsyms; | 
|---|
| 422 | 459 |  | 
|---|
| 423 | 460 | /* Section attributes */ | 
|---|
| .. | .. | 
|---|
| 436 | 473 | void __percpu *percpu; | 
|---|
| 437 | 474 | unsigned int percpu_size; | 
|---|
| 438 | 475 | #endif | 
|---|
|  | 476 | +	void *noinstr_text_start; | 
|---|
|  | 477 | +	unsigned int noinstr_text_size; | 
|---|
| 439 | 478 |  | 
|---|
| 440 | 479 | #ifdef CONFIG_TRACEPOINTS | 
|---|
| 441 | 480 | unsigned int num_tracepoints; | 
|---|
| 442 | 481 | tracepoint_ptr_t *tracepoints_ptrs; | 
|---|
|  | 482 | +#endif | 
|---|
|  | 483 | +#ifdef CONFIG_TREE_SRCU | 
|---|
|  | 484 | +	unsigned int num_srcu_structs; | 
|---|
|  | 485 | +	struct srcu_struct **srcu_struct_ptrs; | 
|---|
|  | 486 | +#endif | 
|---|
|  | 487 | +#ifdef CONFIG_BPF_EVENTS | 
|---|
|  | 488 | +	unsigned int num_bpf_raw_events; | 
|---|
|  | 489 | +	struct bpf_raw_event_map *bpf_raw_events; | 
|---|
| 443 | 490 | #endif | 
|---|
| 444 | 491 | #ifdef CONFIG_JUMP_LABEL | 
|---|
| 445 | 492 | struct jump_entry *jump_entries; | 
|---|
| .. | .. | 
|---|
| 458 | 505 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD | 
|---|
| 459 | 506 | unsigned int num_ftrace_callsites; | 
|---|
| 460 | 507 | unsigned long *ftrace_callsites; | 
|---|
|  | 508 | +#endif | 
|---|
|  | 509 | +#ifdef CONFIG_KPROBES | 
|---|
|  | 510 | +	void *kprobes_text_start; | 
|---|
|  | 511 | +	unsigned int kprobes_text_size; | 
|---|
|  | 512 | +	unsigned long *kprobe_blacklist; | 
|---|
|  | 513 | +	unsigned int num_kprobe_blacklist; | 
|---|
|  | 514 | +#endif | 
|---|
|  | 515 | +#ifdef CONFIG_HAVE_STATIC_CALL_INLINE | 
|---|
|  | 516 | +	int num_static_call_sites; | 
|---|
|  | 517 | +	struct static_call_site *static_call_sites; | 
|---|
| 461 | 518 | #endif | 
|---|
| 462 | 519 |  | 
|---|
| 463 | 520 | #ifdef CONFIG_LIVEPATCH | 
|---|
| .. | .. | 
|---|
| 497 | 554 | } ____cacheline_aligned __randomize_layout; | 
|---|
| 498 | 555 | #ifndef MODULE_ARCH_INIT | 
|---|
| 499 | 556 | #define MODULE_ARCH_INIT {} | 
|---|
|  | 557 | +#endif | 
|---|
|  | 558 | + | 
|---|
|  | 559 | +#ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE | 
|---|
|  | 560 | +static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym) | 
|---|
|  | 561 | +{ | 
|---|
|  | 562 | +	return sym->st_value; | 
|---|
|  | 563 | +} | 
|---|
| 500 | 564 | #endif | 
|---|
| 501 | 565 |  | 
|---|
| 502 | 566 | extern struct mutex module_mutex; | 
|---|
| .. | .. | 
|---|
| 641 | 705 | #endif /* CONFIG_LIVEPATCH */ | 
|---|
| 642 | 706 |  | 
|---|
| 643 | 707 | bool is_module_sig_enforced(void); | 
|---|
|  | 708 | +void set_module_sig_enforced(void); | 
|---|
| 644 | 709 |  | 
|---|
| 645 | 710 | #else /* !CONFIG_MODULES... */ | 
|---|
| 646 | 711 |  | 
|---|
| .. | .. | 
|---|
| 692 | 757 | } | 
|---|
| 693 | 758 |  | 
|---|
| 694 | 759 | /* Get/put a kernel symbol (calls should be symmetric) */ | 
|---|
| 695 |  | -#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) | 
|---|
|  | 760 | +#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); }) | 
|---|
| 696 | 761 | #define symbol_put(x) do { } while (0) | 
|---|
| 697 | 762 | #define symbol_put_addr(x) do { } while (0) | 
|---|
| 698 | 763 |  | 
|---|
| .. | .. | 
|---|
| 778 | 843 | return false; | 
|---|
| 779 | 844 | } | 
|---|
| 780 | 845 |  | 
|---|
|  | 846 | +static inline void set_module_sig_enforced(void) | 
|---|
|  | 847 | +{ | 
|---|
|  | 848 | +} | 
|---|
|  | 849 | + | 
|---|
| 781 | 850 | /* Dereference module function descriptor */ | 
|---|
| 782 | 851 | static inline | 
|---|
| 783 | 852 | void *dereference_module_function_descriptor(struct module *mod, void *ptr) | 
|---|
| .. | .. | 
|---|
| 798 | 867 | /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ | 
|---|
| 799 | 868 |  | 
|---|
| 800 | 869 | #define __MODULE_STRING(x) __stringify(x) | 
|---|
| 801 |  | - | 
|---|
| 802 |  | -#ifdef CONFIG_STRICT_MODULE_RWX | 
|---|
| 803 |  | -extern void set_all_modules_text_rw(void); | 
|---|
| 804 |  | -extern void set_all_modules_text_ro(void); | 
|---|
| 805 |  | -extern void module_enable_ro(const struct module *mod, bool after_init); | 
|---|
| 806 |  | -extern void module_disable_ro(const struct module *mod); | 
|---|
| 807 |  | -#else | 
|---|
| 808 |  | -static inline void set_all_modules_text_rw(void) { } | 
|---|
| 809 |  | -static inline void set_all_modules_text_ro(void) { } | 
|---|
| 810 |  | -static inline void module_enable_ro(const struct module *mod, bool after_init) { } | 
|---|
| 811 |  | -static inline void module_disable_ro(const struct module *mod) { } | 
|---|
| 812 |  | -#endif | 
|---|
| 813 | 870 |  | 
|---|
| 814 | 871 | #ifdef CONFIG_GENERIC_BUG | 
|---|
| 815 | 872 | void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *, | 
|---|