History

Merge tag 'modules-for-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux

Pull module updates from Jessica Yu: "Summary of modules changes for the 5.6 merge window: - Add "MS" (SHF_MERGE|SHF_STRINGS) section flags to __ksymtab_strings to indicate to the linker that it can perform string deduplication (i.e., duplicate strings are reduced to a single copy in the string table). This means any repeated namespace string would be merged to just one entry in __ksymtab_strings. - Various code cleanups and small fixes (fix small memleak in error path, improve moduleparam docs, silence rcu warnings, improve error logging)" * tag 'modules-for-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux: module.h: Annotate mod_kallsyms with __rcu module: avoid setting info->name early in case we can fall back to info->mod->name modsign: print module name along with error message kernel/module: Fix memleak in module_add_modinfo_attrs() export.h: reduce __ksymtab_strings string duplication by using "MS" section flags moduleparam: fix kerneldoc modules: lockdep: Suppress suspicious RCU usage warning

Linus Torvalds committed 6 years ago

Commit ddaefe82 parents c5951e7 6080d605 files · +119 −28Browse files

Unified · Split

5 files
  1. include/asm-generic/export.h +5 −3
  2. include/linux/export.h +23 −10
  3. include/linux/module.h +1 −1
  4. include/linux/moduleparam.h +77 −5
  5. kernel/module.c +13 −9
include/asm-generic/export.h+5−3
@@ -27,9 +27,11 @@ · 26 unmodified lines
2727 .endm
2828
2929 /*
30− * note on .section use: @progbits vs %progbits nastiness doesn't matter,
31− * since we immediately emit into those sections anyway.
30+ * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
31+ * section flag requires it. Use '%progbits' instead of '@progbits' since the
32+ * former apparently works on all arches according to the binutils source.
3233 */
34+
3335 .macro ___EXPORT_SYMBOL name,val,sec
3436 #ifdef CONFIG_MODULES
3537 .section ___ksymtab\sec+\name,"a"
@@ -37,7 +39,7 @@ · 1 unmodified line
3739 __ksymtab_\name:
3840 __put \val, __kstrtab_\name
3941 .previous
40− .section __ksymtab_strings,"a"
42+ .section __ksymtab_strings,"aMS",%progbits,1
4143 __kstrtab_\name:
4244 .asciz "\name"
4345 .previous
include/linux/export.h+23−10
@@ -82,16 +82,29 @@ struct kernel_symbol { · 81 unmodified lines
8282
8383 #else
8484
85−/* For every exported symbol, place a struct in the __ksymtab section */
86−#define ___EXPORT_SYMBOL(sym, sec, ns) \
87− extern typeof(sym) sym; \
88− __CRC_SYMBOL(sym, sec); \
89− static const char __kstrtab_##sym[] \
90− __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
91− = #sym; \
92− static const char __kstrtabns_##sym[] \
93− __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
94− = ns; \
85+/*
86+ * For every exported symbol, do the following:
87+ *
88+ * - If applicable, place a CRC entry in the __kcrctab section.
89+ * - Put the name of the symbol and namespace (empty string "" for none) in
90+ * __ksymtab_strings.
91+ * - Place a struct kernel_symbol entry in the __ksymtab section.
92+ *
93+ * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE)
94+ * section flag requires it. Use '%progbits' instead of '@progbits' since the
95+ * former apparently works on all arches according to the binutils source.
96+ */
97+#define ___EXPORT_SYMBOL(sym, sec, ns) \
98+ extern typeof(sym) sym; \
99+ extern const char __kstrtab_##sym[]; \
100+ extern const char __kstrtabns_##sym[]; \
101+ __CRC_SYMBOL(sym, sec); \
102+ asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1 \n" \
103+ "__kstrtab_" #sym ": \n" \
104+ " .asciz \"" #sym "\" \n" \
105+ "__kstrtabns_" #sym ": \n" \
106+ " .asciz \"" ns "\" \n" \
107+ " .previous \n"); \
95108 __KSYMTAB_ENTRY(sym, sec)
96109
97110 #endif
include/linux/module.h+1−1
@@ -429,7 +429,7 @@ struct module { · 428 unmodified lines
429429
430430 #ifdef CONFIG_KALLSYMS
431431 /* Protected by RCU and/or module_mutex: use rcu_dereference() */
432− struct mod_kallsyms *kallsyms;
432+ struct mod_kallsyms __rcu *kallsyms;
433433 struct mod_kallsyms core_kallsyms;
434434
435435 /* Section attributes */
include/linux/moduleparam.h+77−5
@@ -128,6 +128,9 @@ struct kparam_array · 127 unmodified lines
128128
129129 /**
130130 * module_param_unsafe - same as module_param but taints kernel
131+ * @name: the variable to alter, and exposed parameter name.
132+ * @type: the type of the parameter
133+ * @perm: visibility in sysfs.
131134 */
132135 #define module_param_unsafe(name, type, perm) \
133136 module_param_named_unsafe(name, name, type, perm)
@@ -150,6 +153,10 @@ struct kparam_array · 16 unmodified lines
150153
151154 /**
152155 * module_param_named_unsafe - same as module_param_named but taints kernel
156+ * @name: a valid C identifier which is the parameter name.
157+ * @value: the actual lvalue to alter.
158+ * @type: the type of the parameter
159+ * @perm: visibility in sysfs.
153160 */
154161 #define module_param_named_unsafe(name, value, type, perm) \
155162 param_check_##type(name, &(value)); \
@@ -160,6 +167,7 @@ struct kparam_array · 4 unmodified lines
160167 * module_param_cb - general callback for a module/cmdline parameter
161168 * @name: a valid C identifier which is the parameter name.
162169 * @ops: the set & get operations for this parameter.
170+ * @arg: args for @ops
163171 * @perm: visibility in sysfs.
164172 *
165173 * The ops can have NULL set or get functions.
@@ -171,36 +179,96 @@ struct kparam_array · 5 unmodified lines
171179 __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \
172180 KERNEL_PARAM_FL_UNSAFE)
173181
182+#define __level_param_cb(name, ops, arg, perm, level) \
183+ __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
174184 /**
175− * <level>_param_cb - general callback for a module/cmdline parameter
176− * to be evaluated before certain initcall level
185+ * core_param_cb - general callback for a module/cmdline parameter
186+ * to be evaluated before core initcall level
177187 * @name: a valid C identifier which is the parameter name.
178188 * @ops: the set & get operations for this parameter.
189+ * @arg: args for @ops
179190 * @perm: visibility in sysfs.
180191 *
181192 * The ops can have NULL set or get functions.
182193 */
183−#define __level_param_cb(name, ops, arg, perm, level) \
184− __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
185−
186194 #define core_param_cb(name, ops, arg, perm) \
187195 __level_param_cb(name, ops, arg, perm, 1)
188196
197+/**
198+ * postcore_param_cb - general callback for a module/cmdline parameter
199+ * to be evaluated before postcore initcall level
200+ * @name: a valid C identifier which is the parameter name.
201+ * @ops: the set & get operations for this parameter.
202+ * @arg: args for @ops
203+ * @perm: visibility in sysfs.
204+ *
205+ * The ops can have NULL set or get functions.
206+ */
189207 #define postcore_param_cb(name, ops, arg, perm) \
190208 __level_param_cb(name, ops, arg, perm, 2)
191209
210+/**
211+ * arch_param_cb - general callback for a module/cmdline parameter
212+ * to be evaluated before arch initcall level
213+ * @name: a valid C identifier which is the parameter name.
214+ * @ops: the set & get operations for this parameter.
215+ * @arg: args for @ops
216+ * @perm: visibility in sysfs.
217+ *
218+ * The ops can have NULL set or get functions.
219+ */
192220 #define arch_param_cb(name, ops, arg, perm) \
193221 __level_param_cb(name, ops, arg, perm, 3)
194222
223+/**
224+ * subsys_param_cb - general callback for a module/cmdline parameter
225+ * to be evaluated before subsys initcall level
226+ * @name: a valid C identifier which is the parameter name.
227+ * @ops: the set & get operations for this parameter.
228+ * @arg: args for @ops
229+ * @perm: visibility in sysfs.
230+ *
231+ * The ops can have NULL set or get functions.
232+ */
195233 #define subsys_param_cb(name, ops, arg, perm) \
196234 __level_param_cb(name, ops, arg, perm, 4)
197235
236+/**
237+ * fs_param_cb - general callback for a module/cmdline parameter
238+ * to be evaluated before fs initcall level
239+ * @name: a valid C identifier which is the parameter name.
240+ * @ops: the set & get operations for this parameter.
241+ * @arg: args for @ops
242+ * @perm: visibility in sysfs.
243+ *
244+ * The ops can have NULL set or get functions.
245+ */
198246 #define fs_param_cb(name, ops, arg, perm) \
199247 __level_param_cb(name, ops, arg, perm, 5)
200248
249+/**
250+ * device_param_cb - general callback for a module/cmdline parameter
251+ * to be evaluated before device initcall level
252+ * @name: a valid C identifier which is the parameter name.
253+ * @ops: the set & get operations for this parameter.
254+ * @arg: args for @ops
255+ * @perm: visibility in sysfs.
256+ *
257+ * The ops can have NULL set or get functions.
258+ */
201259 #define device_param_cb(name, ops, arg, perm) \
202260 __level_param_cb(name, ops, arg, perm, 6)
203261
262+/**
263+ * late_param_cb - general callback for a module/cmdline parameter
264+ * to be evaluated before late initcall level
265+ * @name: a valid C identifier which is the parameter name.
266+ * @ops: the set & get operations for this parameter.
267+ * @arg: args for @ops
268+ * @perm: visibility in sysfs.
269+ *
270+ * The ops can have NULL set or get functions.
271+ */
204272 #define late_param_cb(name, ops, arg, perm) \
205273 __level_param_cb(name, ops, arg, perm, 7)
206274
@@ -263,6 +331,10 @@ static inline void kernel_param_unlock(struct module *mod) · 56 unmodified lines
263331
264332 /**
265333 * core_param_unsafe - same as core_param but taints kernel
334+ * @name: the name of the cmdline and sysfs parameter (often the same as var)
335+ * @var: the variable
336+ * @type: the type of the parameter
337+ * @perm: visibility in sysfs
266338 */
267339 #define core_param_unsafe(name, var, type, perm) \
268340 param_check_##type(name, &(var)); \
kernel/module.c+13−9
@@ -214,7 +214,8 @@ static struct module *mod_find(unsigned long addr) · 213 unmodified lines
214214 {
215215 struct module *mod;
216216
217− list_for_each_entry_rcu(mod, &modules, list) {
217+ list_for_each_entry_rcu(mod, &modules, list,
218+ lockdep_is_held(&module_mutex)) {
218219 if (within_module(addr, mod))
219220 return mod;
220221 }
@@ -448,7 +449,8 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr, · 227 unmodified lines
448449 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
449450 return true;
450451
451− list_for_each_entry_rcu(mod, &modules, list) {
452+ list_for_each_entry_rcu(mod, &modules, list,
453+ lockdep_is_held(&module_mutex)) {
452454 struct symsearch arr[] = {
453455 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
454456 NOT_GPL_ONLY, false },
@@ -616,7 +618,8 @@ static struct module *find_module_all(const char *name, size_t len, · 161 unmodified lines
616618
617619 module_assert_mutex_or_preempt();
618620
619− list_for_each_entry_rcu(mod, &modules, list) {
621+ list_for_each_entry_rcu(mod, &modules, list,
622+ lockdep_is_held(&module_mutex)) {
620623 if (!even_unformed && mod->state == MODULE_STATE_UNFORMED)
621624 continue;
622625 if (strlen(mod->name) == len && !memcmp(mod->name, name, len))
@@ -1781,6 +1784,8 @@ static int module_add_modinfo_attrs(struct module *mod) · 1158 unmodified lines
17811784 error_out:
17821785 if (i > 0)
17831786 module_remove_modinfo_attrs(mod, --i);
1787+ else
1788+ kfree(mod->modinfo_attrs);
17841789 return error;
17851790 }
17861791
@@ -2834,7 +2839,7 @@ static int module_sig_check(struct load_info *info, int flags) · 1047 unmodified lines
28342839 reason = "Loading of module with unavailable key";
28352840 decide:
28362841 if (is_module_sig_enforced()) {
2837− pr_notice("%s is rejected\n", reason);
2842+ pr_notice("%s: %s is rejected\n", info->name, reason);
28382843 return -EKEYREJECTED;
28392844 }
28402845
@@ -3011,9 +3016,7 @@ static int setup_load_info(struct load_info *info, int flags) · 170 unmodified lines
30113016
30123017 /* Try to find a name early so we can log errors with a module name */
30133018 info->index.info = find_sec(info, ".modinfo");
3014− if (!info->index.info)
3015− info->name = "(missing .modinfo section)";
3016− else
3019+ if (info->index.info)
30173020 info->name = get_modinfo(info, "name");
30183021
30193022 /* Find internal symbols and strings. */
@@ -3028,14 +3031,15 @@ static int setup_load_info(struct load_info *info, int flags) · 8 unmodified lines
30283031 }
30293032
30303033 if (info->index.sym == 0) {
3031− pr_warn("%s: module has no symbols (stripped?)\n", info->name);
3034+ pr_warn("%s: module has no symbols (stripped?)\n",
3035+ info->name ?: "(missing .modinfo section or name field)");
30323036 return -ENOEXEC;
30333037 }
30343038
30353039 info->index.mod = find_sec(info, ".gnu.linkonce.this_module");
30363040 if (!info->index.mod) {
30373041 pr_warn("%s: No module found in object\n",
3038− info->name ?: "(missing .modinfo name field)");
3042+ info->name ?: "(missing .modinfo section or name field)");
30393043 return -ENOEXEC;
30403044 }
30413045 /* This is temporary: point mod into copy of data. */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t