]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/module: Improve relocation error messages
authorJosh Poimboeuf <jpoimboe@kernel.org>
Wed, 17 Sep 2025 16:03:11 +0000 (09:03 -0700)
committerJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 14 Oct 2025 21:45:21 +0000 (14:45 -0700)
Add the section number and reloc index to relocation error messages to
help find the faulty relocation.

Acked-by: Petr Mladek <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
arch/x86/kernel/module.c
kernel/livepatch/core.c

index 0ffbae902e2fe5a9b273d8ff527e4ee4f3877d6a..11c45ce42694cb7213094ab48da8518698ac5b31 100644 (file)
@@ -97,6 +97,7 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs,
        DEBUGP("%s relocate section %u to %u\n",
               apply ? "Applying" : "Clearing",
               relsec, sechdrs[relsec].sh_info);
+
        for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
                size_t size;
 
@@ -162,15 +163,17 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs,
 
                if (apply) {
                        if (memcmp(loc, &zero, size)) {
-                               pr_err("x86/modules: Invalid relocation target, existing value is nonzero for type %d, loc %p, val %Lx\n",
-                                      (int)ELF64_R_TYPE(rel[i].r_info), loc, val);
+                               pr_err("x86/modules: Invalid relocation target, existing value is nonzero for sec %u, idx %u, type %d, loc %lx, val %llx\n",
+                                      relsec, i, (int)ELF64_R_TYPE(rel[i].r_info),
+                                      (unsigned long)loc, val);
                                return -ENOEXEC;
                        }
                        write(loc, &val, size);
                } else {
                        if (memcmp(loc, &val, size)) {
-                               pr_warn("x86/modules: Invalid relocation target, existing value does not match expected value for type %d, loc %p, val %Lx\n",
-                                       (int)ELF64_R_TYPE(rel[i].r_info), loc, val);
+                               pr_warn("x86/modules: Invalid relocation target, existing value does not match expected value for sec %u, idx %u, type %d, loc %lx, val %llx\n",
+                                       relsec, i, (int)ELF64_R_TYPE(rel[i].r_info),
+                                       (unsigned long)loc, val);
                                return -ENOEXEC;
                        }
                        write(loc, &zero, size);
@@ -179,8 +182,8 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs,
        return 0;
 
 overflow:
-       pr_err("overflow in relocation type %d val %Lx\n",
-              (int)ELF64_R_TYPE(rel[i].r_info), val);
+       pr_err("overflow in relocation type %d val %llx sec %u idx %d\n",
+              (int)ELF64_R_TYPE(rel[i].r_info), val, relsec, i);
        pr_err("`%s' likely not compiled with -mcmodel=kernel\n",
               me->name);
        return -ENOEXEC;
index 0e73fac55f8ebe45629ab19a395975ec9efff96b..7e443c2cf7d489374a2f2ec6d91a85d9d2560d97 100644 (file)
@@ -217,8 +217,8 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
        for (i = 0; i < relasec->sh_size / sizeof(Elf_Rela); i++) {
                sym = (Elf_Sym *)sechdrs[symndx].sh_addr + ELF_R_SYM(relas[i].r_info);
                if (sym->st_shndx != SHN_LIVEPATCH) {
-                       pr_err("symbol %s is not marked as a livepatch symbol\n",
-                              strtab + sym->st_name);
+                       pr_err("symbol %s at rela sec %u idx %d is not marked as a livepatch symbol\n",
+                              strtab + sym->st_name, symndx, i);
                        return -EINVAL;
                }