hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/linux/module.h
....@@ -1,11 +1,14 @@
1
-#ifndef _LINUX_MODULE_H
2
-#define _LINUX_MODULE_H
1
+/* SPDX-License-Identifier: GPL-2.0-only */
32 /*
43 * Dynamic loading of modules into the kernel.
54 *
65 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
76 * Rewritten again by Rusty Russell, 2002
87 */
8
+
9
+#ifndef _LINUX_MODULE_H
10
+#define _LINUX_MODULE_H
11
+
912 #include <linux/list.h>
1013 #include <linux/stat.h>
1114 #include <linux/compiler.h>
....@@ -21,14 +24,13 @@
2124 #include <linux/rbtree_latch.h>
2225 #include <linux/error-injection.h>
2326 #include <linux/tracepoint-defs.h>
27
+#include <linux/srcu.h>
28
+#include <linux/static_call_types.h>
2429 #include <linux/cfi.h>
2530 #include <linux/android_kabi.h>
2631
2732 #include <linux/percpu.h>
2833 #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"
3234
3335 /* Not Yet Implemented */
3436 #define MODULE_SUPPORTED_DEVICE(name)
....@@ -126,19 +128,22 @@
126128 #define late_initcall_sync(fn) module_init(fn)
127129
128130 #define console_initcall(fn) module_init(fn)
129
-#define security_initcall(fn) module_init(fn)
130131
131132 /* Each module must use one module_init(). */
132133 #define module_init(initfn) \
133134 static inline initcall_t __maybe_unused __inittest(void) \
134135 { 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)
136139
137140 /* This is only required if you want to be unloadable. */
138141 #define module_exit(exitfn) \
139142 static inline exitcall_t __maybe_unused __exittest(void) \
140143 { 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)
142147
143148 #endif
144149
....@@ -172,10 +177,20 @@
172177 #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep)
173178
174179 /*
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
+/*
175190 * The following license idents are currently accepted as indicating free
176191 * software modules
177192 *
178
- * "GPL" [GNU Public License v2 or later]
193
+ * "GPL" [GNU Public License v2]
179194 * "GPL v2" [GNU Public License v2]
180195 * "GPL and additional rights" [GNU Public License v2 rights and more]
181196 * "Dual BSD/GPL" [GNU Public License v2
....@@ -189,6 +204,22 @@
189204 *
190205 * "Proprietary" [Non free products]
191206 *
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
+ *
192223 * There are dual licensed components, but when running with Linux it is the
193224 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
194225 * is a GPL combined work.
....@@ -199,7 +230,7 @@
199230 * 2. So the community can ignore bug reports including proprietary modules
200231 * 3. So vendors can do likewise based on their own policies
201232 */
202
-#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
233
+#define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license)
203234
204235 /*
205236 * Author(s), use "Name <email>" or just "Name", for multiple
....@@ -240,6 +271,7 @@
240271 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
241272 #else
242273 #define MODULE_VERSION(_version) \
274
+ MODULE_INFO(version, _version); \
243275 static struct module_version_attribute ___modver_attr = { \
244276 .mattr = { \
245277 .attr = { \
....@@ -252,7 +284,7 @@
252284 .version = _version, \
253285 }; \
254286 static const struct module_version_attribute \
255
- __used __attribute__ ((__section__ ("__modver"))) \
287
+ __used __section("__modver") \
256288 * __moduleparam_const __modver_attr = &___modver_attr
257289 #endif
258290
....@@ -260,6 +292,8 @@
260292 * format is simply firmware file name. Multiple firmware
261293 * files require multiple MODULE_FIRMWARE() specifiers */
262294 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
295
+
296
+#define MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, __stringify(ns))
263297
264298 struct notifier_block;
265299
....@@ -318,6 +352,7 @@
318352 Elf_Sym *symtab;
319353 unsigned int num_symtab;
320354 char *strtab;
355
+ char *typetab;
321356 };
322357
323358 #ifdef CONFIG_LIVEPATCH
....@@ -343,6 +378,7 @@
343378 struct module_attribute *modinfo_attrs;
344379 const char *version;
345380 const char *srcversion;
381
+ const char *scmversion;
346382 struct kobject *holders_dir;
347383
348384 /* Exported symbols */
....@@ -365,6 +401,7 @@
365401 unsigned int num_gpl_syms;
366402 const struct kernel_symbol *gpl_syms;
367403 const s32 *gpl_crcs;
404
+ bool using_gplonly_symbols;
368405
369406 #ifdef CONFIG_UNUSED_SYMBOLS
370407 /* unused exported symbols. */
....@@ -417,7 +454,7 @@
417454
418455 #ifdef CONFIG_KALLSYMS
419456 /* Protected by RCU and/or module_mutex: use rcu_dereference() */
420
- struct mod_kallsyms *kallsyms;
457
+ struct mod_kallsyms __rcu *kallsyms;
421458 struct mod_kallsyms core_kallsyms;
422459
423460 /* Section attributes */
....@@ -436,10 +473,20 @@
436473 void __percpu *percpu;
437474 unsigned int percpu_size;
438475 #endif
476
+ void *noinstr_text_start;
477
+ unsigned int noinstr_text_size;
439478
440479 #ifdef CONFIG_TRACEPOINTS
441480 unsigned int num_tracepoints;
442481 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;
443490 #endif
444491 #ifdef CONFIG_JUMP_LABEL
445492 struct jump_entry *jump_entries;
....@@ -458,6 +505,16 @@
458505 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
459506 unsigned int num_ftrace_callsites;
460507 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;
461518 #endif
462519
463520 #ifdef CONFIG_LIVEPATCH
....@@ -497,6 +554,13 @@
497554 } ____cacheline_aligned __randomize_layout;
498555 #ifndef MODULE_ARCH_INIT
499556 #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
+}
500564 #endif
501565
502566 extern struct mutex module_mutex;
....@@ -641,6 +705,7 @@
641705 #endif /* CONFIG_LIVEPATCH */
642706
643707 bool is_module_sig_enforced(void);
708
+void set_module_sig_enforced(void);
644709
645710 #else /* !CONFIG_MODULES... */
646711
....@@ -692,7 +757,7 @@
692757 }
693758
694759 /* 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); })
696761 #define symbol_put(x) do { } while (0)
697762 #define symbol_put_addr(x) do { } while (0)
698763
....@@ -778,6 +843,10 @@
778843 return false;
779844 }
780845
846
+static inline void set_module_sig_enforced(void)
847
+{
848
+}
849
+
781850 /* Dereference module function descriptor */
782851 static inline
783852 void *dereference_module_function_descriptor(struct module *mod, void *ptr)
....@@ -798,18 +867,6 @@
798867 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
799868
800869 #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
813870
814871 #ifdef CONFIG_GENERIC_BUG
815872 void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,