1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Module version support
5 * Copyright (C) 2008 Rusty Russell
8 #include <linux/module.h>
9 #include <linux/string.h>
10 #include <linux/printk.h>
13 int check_version(const struct load_info *info,
18 Elf_Shdr *sechdrs = info->sechdrs;
19 unsigned int versindex = info->index.vers;
20 unsigned int i, num_versions;
21 struct modversion_info *versions;
23 /* Exporting module didn't supply crcs? OK, we're already tainted. */
27 /* No versions at all? modprobe --force does this. */
29 return try_to_force_load(mod, symname) == 0;
31 versions = (void *)sechdrs[versindex].sh_addr;
32 num_versions = sechdrs[versindex].sh_size
33 / sizeof(struct modversion_info);
35 for (i = 0; i < num_versions; i++) {
38 if (strcmp(versions[i].name, symname) != 0)
42 if (versions[i].crc == crcval)
44 pr_debug("Found checksum %X vs module %lX\n",
45 crcval, versions[i].crc);
49 /* Broken toolchain. Warn once, then let it go.. */
50 pr_warn_once("%s: no symbol version for %s\n", info->name, symname);
54 pr_warn("%s: disagrees about version of symbol %s\n", info->name, symname);
58 int check_modstruct_version(const struct load_info *info,
61 struct find_symbol_arg fsa = {
62 .name = "module_layout",
67 * Since this should be found in kernel (which can't be removed), no
68 * locking is necessary -- use preempt_disable() to placate lockdep.
71 if (!find_symbol(&fsa)) {
76 return check_version(info, "module_layout", mod, fsa.crc);
79 /* First part is kernel version, which we ignore if module has crcs. */
80 int same_magic(const char *amagic, const char *bmagic,
84 amagic += strcspn(amagic, " ");
85 bmagic += strcspn(bmagic, " ");
87 return strcmp(amagic, bmagic) == 0;
91 * Generate the signature for all relevant module structures here.
92 * If these change, we don't want to try to parse the module.
94 void module_layout(struct module *mod,
95 struct modversion_info *ver,
96 struct kernel_param *kp,
97 struct kernel_symbol *ks,
98 struct tracepoint * const *tp)
101 EXPORT_SYMBOL(module_layout);