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
Unified · Split
| @@ -27,9 +27,11 @@ · 26 unmodified lines | ||
| 27 | 27 | .endm |
| 28 | 28 | |
| 29 | 29 | /* |
| 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. | |
| 32 | 33 | */ |
| 34 | + | |
| 33 | 35 | .macro ___EXPORT_SYMBOL name,val,sec |
| 34 | 36 | #ifdef CONFIG_MODULES |
| 35 | 37 | .section ___ksymtab\sec+\name,"a" |
| @@ -37,7 +39,7 @@ · 1 unmodified line | ||
| 37 | 39 | __ksymtab_\name: |
| 38 | 40 | __put \val, __kstrtab_\name |
| 39 | 41 | .previous |
| 40 | − .section __ksymtab_strings,"a" | |
| 42 | + .section __ksymtab_strings,"aMS",%progbits,1 | |
| 41 | 43 | __kstrtab_\name: |
| 42 | 44 | .asciz "\name" |
| 43 | 45 | .previous |
| @@ -82,16 +82,29 @@ struct kernel_symbol { · 81 unmodified lines | ||
| 82 | 82 | |
| 83 | 83 | #else |
| 84 | 84 | |
| 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"); \ | |
| 95 | 108 | __KSYMTAB_ENTRY(sym, sec) |
| 96 | 109 | |
| 97 | 110 | #endif |
| @@ -429,7 +429,7 @@ struct module { · 428 unmodified lines | ||
| 429 | 429 | |
| 430 | 430 | #ifdef CONFIG_KALLSYMS |
| 431 | 431 | /* Protected by RCU and/or module_mutex: use rcu_dereference() */ |
| 432 | − struct mod_kallsyms *kallsyms; | |
| 432 | + struct mod_kallsyms __rcu *kallsyms; | |
| 433 | 433 | struct mod_kallsyms core_kallsyms; |
| 434 | 434 | |
| 435 | 435 | /* Section attributes */ |
| @@ -128,6 +128,9 @@ struct kparam_array · 127 unmodified lines | ||
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * 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. | |
| 131 | 134 | */ |
| 132 | 135 | #define module_param_unsafe(name, type, perm) \ |
| 133 | 136 | module_param_named_unsafe(name, name, type, perm) |
| @@ -150,6 +153,10 @@ struct kparam_array · 16 unmodified lines | ||
| 150 | 153 | |
| 151 | 154 | /** |
| 152 | 155 | * 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. | |
| 153 | 160 | */ |
| 154 | 161 | #define module_param_named_unsafe(name, value, type, perm) \ |
| 155 | 162 | param_check_##type(name, &(value)); \ |
| @@ -160,6 +167,7 @@ struct kparam_array · 4 unmodified lines | ||
| 160 | 167 | * module_param_cb - general callback for a module/cmdline parameter |
| 161 | 168 | * @name: a valid C identifier which is the parameter name. |
| 162 | 169 | * @ops: the set & get operations for this parameter. |
| 170 | + * @arg: args for @ops | |
| 163 | 171 | * @perm: visibility in sysfs. |
| 164 | 172 | * |
| 165 | 173 | * The ops can have NULL set or get functions. |
| @@ -171,36 +179,96 @@ struct kparam_array · 5 unmodified lines | ||
| 171 | 179 | __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \ |
| 172 | 180 | KERNEL_PARAM_FL_UNSAFE) |
| 173 | 181 | |
| 182 | +#define __level_param_cb(name, ops, arg, perm, level) \ | |
| 183 | + __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0) | |
| 174 | 184 | /** |
| 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 | |
| 177 | 187 | * @name: a valid C identifier which is the parameter name. |
| 178 | 188 | * @ops: the set & get operations for this parameter. |
| 189 | + * @arg: args for @ops | |
| 179 | 190 | * @perm: visibility in sysfs. |
| 180 | 191 | * |
| 181 | 192 | * The ops can have NULL set or get functions. |
| 182 | 193 | */ |
| 183 | −#define __level_param_cb(name, ops, arg, perm, level) \ | |
| 184 | − __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0) | |
| 185 | − | |
| 186 | 194 | #define core_param_cb(name, ops, arg, perm) \ |
| 187 | 195 | __level_param_cb(name, ops, arg, perm, 1) |
| 188 | 196 | |
| 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 | + */ | |
| 189 | 207 | #define postcore_param_cb(name, ops, arg, perm) \ |
| 190 | 208 | __level_param_cb(name, ops, arg, perm, 2) |
| 191 | 209 | |
| 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 | + */ | |
| 192 | 220 | #define arch_param_cb(name, ops, arg, perm) \ |
| 193 | 221 | __level_param_cb(name, ops, arg, perm, 3) |
| 194 | 222 | |
| 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 | + */ | |
| 195 | 233 | #define subsys_param_cb(name, ops, arg, perm) \ |
| 196 | 234 | __level_param_cb(name, ops, arg, perm, 4) |
| 197 | 235 | |
| 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 | + */ | |
| 198 | 246 | #define fs_param_cb(name, ops, arg, perm) \ |
| 199 | 247 | __level_param_cb(name, ops, arg, perm, 5) |
| 200 | 248 | |
| 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 | + */ | |
| 201 | 259 | #define device_param_cb(name, ops, arg, perm) \ |
| 202 | 260 | __level_param_cb(name, ops, arg, perm, 6) |
| 203 | 261 | |
| 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 | + */ | |
| 204 | 272 | #define late_param_cb(name, ops, arg, perm) \ |
| 205 | 273 | __level_param_cb(name, ops, arg, perm, 7) |
| 206 | 274 | |
| @@ -263,6 +331,10 @@ static inline void kernel_param_unlock(struct module *mod) · 56 unmodified lines | ||
| 263 | 331 | |
| 264 | 332 | /** |
| 265 | 333 | * 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 | |
| 266 | 338 | */ |
| 267 | 339 | #define core_param_unsafe(name, var, type, perm) \ |
| 268 | 340 | param_check_##type(name, &(var)); \ |
| @@ -214,7 +214,8 @@ static struct module *mod_find(unsigned long addr) · 213 unmodified lines | ||
| 214 | 214 | { |
| 215 | 215 | struct module *mod; |
| 216 | 216 | |
| 217 | − list_for_each_entry_rcu(mod, &modules, list) { | |
| 217 | + list_for_each_entry_rcu(mod, &modules, list, | |
| 218 | + lockdep_is_held(&module_mutex)) { | |
| 218 | 219 | if (within_module(addr, mod)) |
| 219 | 220 | return mod; |
| 220 | 221 | } |
| @@ -448,7 +449,8 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr, · 227 unmodified lines | ||
| 448 | 449 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) |
| 449 | 450 | return true; |
| 450 | 451 | |
| 451 | − list_for_each_entry_rcu(mod, &modules, list) { | |
| 452 | + list_for_each_entry_rcu(mod, &modules, list, | |
| 453 | + lockdep_is_held(&module_mutex)) { | |
| 452 | 454 | struct symsearch arr[] = { |
| 453 | 455 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, |
| 454 | 456 | NOT_GPL_ONLY, false }, |
| @@ -616,7 +618,8 @@ static struct module *find_module_all(const char *name, size_t len, · 161 unmodified lines | ||
| 616 | 618 | |
| 617 | 619 | module_assert_mutex_or_preempt(); |
| 618 | 620 | |
| 619 | − list_for_each_entry_rcu(mod, &modules, list) { | |
| 621 | + list_for_each_entry_rcu(mod, &modules, list, | |
| 622 | + lockdep_is_held(&module_mutex)) { | |
| 620 | 623 | if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) |
| 621 | 624 | continue; |
| 622 | 625 | 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 | ||
| 1781 | 1784 | error_out: |
| 1782 | 1785 | if (i > 0) |
| 1783 | 1786 | module_remove_modinfo_attrs(mod, --i); |
| 1787 | + else | |
| 1788 | + kfree(mod->modinfo_attrs); | |
| 1784 | 1789 | return error; |
| 1785 | 1790 | } |
| 1786 | 1791 | |
| @@ -2834,7 +2839,7 @@ static int module_sig_check(struct load_info *info, int flags) · 1047 unmodified lines | ||
| 2834 | 2839 | reason = "Loading of module with unavailable key"; |
| 2835 | 2840 | decide: |
| 2836 | 2841 | if (is_module_sig_enforced()) { |
| 2837 | − pr_notice("%s is rejected\n", reason); | |
| 2842 | + pr_notice("%s: %s is rejected\n", info->name, reason); | |
| 2838 | 2843 | return -EKEYREJECTED; |
| 2839 | 2844 | } |
| 2840 | 2845 | |
| @@ -3011,9 +3016,7 @@ static int setup_load_info(struct load_info *info, int flags) · 170 unmodified lines | ||
| 3011 | 3016 | |
| 3012 | 3017 | /* Try to find a name early so we can log errors with a module name */ |
| 3013 | 3018 | 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) | |
| 3017 | 3020 | info->name = get_modinfo(info, "name"); |
| 3018 | 3021 | |
| 3019 | 3022 | /* Find internal symbols and strings. */ |
| @@ -3028,14 +3031,15 @@ static int setup_load_info(struct load_info *info, int flags) · 8 unmodified lines | ||
| 3028 | 3031 | } |
| 3029 | 3032 | |
| 3030 | 3033 | 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)"); | |
| 3032 | 3036 | return -ENOEXEC; |
| 3033 | 3037 | } |
| 3034 | 3038 | |
| 3035 | 3039 | info->index.mod = find_sec(info, ".gnu.linkonce.this_module"); |
| 3036 | 3040 | if (!info->index.mod) { |
| 3037 | 3041 | 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)"); | |
| 3039 | 3043 | return -ENOEXEC; |
| 3040 | 3044 | } |
| 3041 | 3045 | /* This is temporary: point mod into copy of data. */ |