module: get symbol CRC back to unsigned
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 28 Dec 2024 15:45:28 +0000 (00:45 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Fri, 10 Jan 2025 14:01:22 +0000 (23:01 +0900)
Commit 71810db27c1c ("modversions: treat symbol CRCs as 32 bit
quantities") changed the CRC fields to s32 because the __kcrctab and
__kcrctab_gpl sections contained relative references to the actual
CRC values stored in the .rodata section when CONFIG_MODULE_REL_CRCS=y.

Commit 7b4537199a4a ("kbuild: link symbol CRCs at final link, removing
CONFIG_MODULE_REL_CRCS") removed this complexity. Now, the __kcrctab
and __kcrctab_gpl sections directly contain the CRC values in all cases.

The genksyms tool outputs unsigned 32-bit CRC values, so u32 is preferred
over s32.

No functional changes are intended.

Regardless of this change, the CRC value is assigned to the u32 variable
'crcval' before the comparison, as seen in kernel/module/version.c:

    crcval = *crc;

It was previously mandatory (but now optional) in order to avoid sign
extension because the following line previously compared 'unsigned long'
and 's32':

    if (versions[i].crc == crcval)
            return 1;

versions[i].crc is still 'unsigned long' for backward compatibility.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
include/linux/module.h
kernel/module/internal.h
kernel/module/main.c
kernel/module/version.c

index 94acbacdcdf189e27013088de2202bccac9717e0..903ef8fe4c04d006fedb6354b2f2fc0a3ebde898 100644 (file)
@@ -430,7 +430,7 @@ struct module {
 
        /* Exported symbols */
        const struct kernel_symbol *syms;
-       const s32 *crcs;
+       const u32 *crcs;
        unsigned int num_syms;
 
 #ifdef CONFIG_ARCH_USES_CFI_TRAPS
@@ -448,7 +448,7 @@ struct module {
        /* GPL-only exported symbols. */
        unsigned int num_gpl_syms;
        const struct kernel_symbol *gpl_syms;
-       const s32 *gpl_crcs;
+       const u32 *gpl_crcs;
        bool using_gplonly_symbols;
 
 #ifdef CONFIG_MODULE_SIG
index daef2be8390222c22220e2f168baa8d35ad531b9..f10dc3ea7ff883b1c91e036b427cdb90502933b8 100644 (file)
@@ -55,8 +55,8 @@ extern const struct kernel_symbol __start___ksymtab[];
 extern const struct kernel_symbol __stop___ksymtab[];
 extern const struct kernel_symbol __start___ksymtab_gpl[];
 extern const struct kernel_symbol __stop___ksymtab_gpl[];
-extern const s32 __start___kcrctab[];
-extern const s32 __start___kcrctab_gpl[];
+extern const u32 __start___kcrctab[];
+extern const u32 __start___kcrctab_gpl[];
 
 struct load_info {
        const char *name;
@@ -102,7 +102,7 @@ struct find_symbol_arg {
 
        /* Output */
        struct module *owner;
-       const s32 *crc;
+       const u32 *crc;
        const struct kernel_symbol *sym;
        enum mod_license license;
 };
@@ -384,7 +384,7 @@ static inline void init_param_lock(struct module *mod) { }
 
 #ifdef CONFIG_MODVERSIONS
 int check_version(const struct load_info *info,
-                 const char *symname, struct module *mod, const s32 *crc);
+                 const char *symname, struct module *mod, const u32 *crc);
 void module_layout(struct module *mod, struct modversion_info *ver, struct kernel_param *kp,
                   struct kernel_symbol *ks, struct tracepoint * const *tp);
 int check_modstruct_version(const struct load_info *info, struct module *mod);
@@ -393,7 +393,7 @@ int same_magic(const char *amagic, const char *bmagic, bool has_crcs);
 static inline int check_version(const struct load_info *info,
                                const char *symname,
                                struct module *mod,
-                               const s32 *crc)
+                               const u32 *crc)
 {
        return 1;
 }
index 5399c182b3cbed2dbeea0291f717f30358d8e7fc..e58bff88b8d6379787eebd87926a213f78b75877 100644 (file)
@@ -86,7 +86,7 @@ struct mod_tree_root mod_tree __cacheline_aligned = {
 
 struct symsearch {
        const struct kernel_symbol *start, *stop;
-       const s32 *crcs;
+       const u32 *crcs;
        enum mod_license license;
 };
 
index 53f43ac5a73e9d537a9e95ff97728a51fad0e797..4e5731d403af20251cb2e3d6dbff8bc59109732b 100644 (file)
@@ -13,7 +13,7 @@
 int check_version(const struct load_info *info,
                  const char *symname,
                         struct module *mod,
-                        const s32 *crc)
+                        const u32 *crc)
 {
        Elf_Shdr *sechdrs = info->sechdrs;
        unsigned int versindex = info->index.vers;