Skip to content

Commit edce10e

Browse files
prudo1hcahca
authored andcommitted
s390/kexec_file: print some more error messages
Be kind and give some more information on what went wrong. Signed-off-by: Philipp Rudo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Carstens <[email protected]>
1 parent 0fcfb00 commit edce10e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

arch/s390/kernel/machine_kexec_file.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Author(s): Philipp Rudo <[email protected]>
88
*/
99

10+
#define pr_fmt(fmt) "kexec: " fmt
11+
1012
#include <linux/elf.h>
1113
#include <linux/errno.h>
1214
#include <linux/kexec.h>
@@ -290,9 +292,16 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
290292
const Elf_Shdr *relsec,
291293
const Elf_Shdr *symtab)
292294
{
295+
const char *strtab, *name, *shstrtab;
296+
const Elf_Shdr *sechdrs;
293297
Elf_Rela *relas;
294298
int i, r_type;
295299

300+
/* String & section header string table */
301+
sechdrs = (void *)pi->ehdr + pi->ehdr->e_shoff;
302+
strtab = (char *)pi->ehdr + sechdrs[symtab->sh_link].sh_offset;
303+
shstrtab = (char *)pi->ehdr + sechdrs[pi->ehdr->e_shstrndx].sh_offset;
304+
296305
relas = (void *)pi->ehdr + relsec->sh_offset;
297306

298307
for (i = 0; i < relsec->sh_size / sizeof(*relas); i++) {
@@ -304,15 +313,27 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
304313
sym = (void *)pi->ehdr + symtab->sh_offset;
305314
sym += ELF64_R_SYM(relas[i].r_info);
306315

307-
if (sym->st_shndx == SHN_UNDEF)
316+
if (sym->st_name)
317+
name = strtab + sym->st_name;
318+
else
319+
name = shstrtab + sechdrs[sym->st_shndx].sh_name;
320+
321+
if (sym->st_shndx == SHN_UNDEF) {
322+
pr_err("Undefined symbol: %s\n", name);
308323
return -ENOEXEC;
324+
}
309325

310-
if (sym->st_shndx == SHN_COMMON)
326+
if (sym->st_shndx == SHN_COMMON) {
327+
pr_err("symbol '%s' in common section\n", name);
311328
return -ENOEXEC;
329+
}
312330

313331
if (sym->st_shndx >= pi->ehdr->e_shnum &&
314-
sym->st_shndx != SHN_ABS)
332+
sym->st_shndx != SHN_ABS) {
333+
pr_err("Invalid section %d for symbol %s\n",
334+
sym->st_shndx, name);
315335
return -ENOEXEC;
336+
}
316337

317338
loc = pi->purgatory_buf;
318339
loc += section->sh_offset;

0 commit comments

Comments
 (0)