Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/module: Improve relocation error messages

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>

+11 -8
+9 -6
arch/x86/kernel/module.c
··· 97 97 DEBUGP("%s relocate section %u to %u\n", 98 98 apply ? "Applying" : "Clearing", 99 99 relsec, sechdrs[relsec].sh_info); 100 + 100 101 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { 101 102 size_t size; 102 103 ··· 163 162 164 163 if (apply) { 165 164 if (memcmp(loc, &zero, size)) { 166 - pr_err("x86/modules: Invalid relocation target, existing value is nonzero for type %d, loc %p, val %Lx\n", 167 - (int)ELF64_R_TYPE(rel[i].r_info), loc, val); 165 + pr_err("x86/modules: Invalid relocation target, existing value is nonzero for sec %u, idx %u, type %d, loc %lx, val %llx\n", 166 + relsec, i, (int)ELF64_R_TYPE(rel[i].r_info), 167 + (unsigned long)loc, val); 168 168 return -ENOEXEC; 169 169 } 170 170 write(loc, &val, size); 171 171 } else { 172 172 if (memcmp(loc, &val, size)) { 173 - pr_warn("x86/modules: Invalid relocation target, existing value does not match expected value for type %d, loc %p, val %Lx\n", 174 - (int)ELF64_R_TYPE(rel[i].r_info), loc, val); 173 + 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", 174 + relsec, i, (int)ELF64_R_TYPE(rel[i].r_info), 175 + (unsigned long)loc, val); 175 176 return -ENOEXEC; 176 177 } 177 178 write(loc, &zero, size); ··· 182 179 return 0; 183 180 184 181 overflow: 185 - pr_err("overflow in relocation type %d val %Lx\n", 186 - (int)ELF64_R_TYPE(rel[i].r_info), val); 182 + pr_err("overflow in relocation type %d val %llx sec %u idx %d\n", 183 + (int)ELF64_R_TYPE(rel[i].r_info), val, relsec, i); 187 184 pr_err("`%s' likely not compiled with -mcmodel=kernel\n", 188 185 me->name); 189 186 return -ENOEXEC;
+2 -2
kernel/livepatch/core.c
··· 217 217 for (i = 0; i < relasec->sh_size / sizeof(Elf_Rela); i++) { 218 218 sym = (Elf_Sym *)sechdrs[symndx].sh_addr + ELF_R_SYM(relas[i].r_info); 219 219 if (sym->st_shndx != SHN_LIVEPATCH) { 220 - pr_err("symbol %s is not marked as a livepatch symbol\n", 221 - strtab + sym->st_name); 220 + pr_err("symbol %s at rela sec %u idx %d is not marked as a livepatch symbol\n", 221 + strtab + sym->st_name, symndx, i); 222 222 return -EINVAL; 223 223 } 224 224