|
|
c4e390 |
From a0951a168054fa30a1c1d48b5edf066d8e08900d Mon Sep 17 00:00:00 2001
|
|
|
c4e390 |
From: Peter Jones <pjones@redhat.com>
|
|
|
c4e390 |
Date: Sat, 18 Jul 2020 18:28:14 -0400
|
|
|
c4e390 |
Subject: [PATCH 326/336] build-grub-module-verifier: make output more useful
|
|
|
c4e390 |
|
|
|
c4e390 |
- show the user which module has the error
|
|
|
c4e390 |
- show which section relocation errors are in
|
|
|
c4e390 |
- show which relocation is in error
|
|
|
c4e390 |
|
|
|
c4e390 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
c4e390 |
---
|
|
|
c4e390 |
util/grub-module-verifier.c | 4 +--
|
|
|
c4e390 |
util/grub-module-verifierXX.c | 61 ++++++++++++++++++----------------
|
|
|
c4e390 |
include/grub/module_verifier.h | 4 +--
|
|
|
c4e390 |
3 files changed, 36 insertions(+), 33 deletions(-)
|
|
|
c4e390 |
|
|
|
c4e390 |
diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c
|
|
|
c4e390 |
index 405c9117051..4acbad38421 100644
|
|
|
c4e390 |
--- a/util/grub-module-verifier.c
|
|
|
c4e390 |
+++ b/util/grub-module-verifier.c
|
|
|
c4e390 |
@@ -137,8 +137,8 @@ main (int argc, char **argv)
|
|
|
c4e390 |
module_size = grub_util_get_image_size (argv[1]);
|
|
|
c4e390 |
module_img = grub_util_read_image (argv[1]);
|
|
|
c4e390 |
if (archs[arch].voidp_sizeof == 8)
|
|
|
c4e390 |
- grub_module_verify64(module_img, module_size, &archs[arch]);
|
|
|
c4e390 |
+ grub_module_verify64(module_img, module_size, &archs[arch], argv[1]);
|
|
|
c4e390 |
else
|
|
|
c4e390 |
- grub_module_verify32(module_img, module_size, &archs[arch]);
|
|
|
c4e390 |
+ grub_module_verify32(module_img, module_size, &archs[arch], argv[1]);
|
|
|
c4e390 |
return 0;
|
|
|
c4e390 |
}
|
|
|
c4e390 |
diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c
|
|
|
c4e390 |
index 9c04caa63b4..aecb45e9c87 100644
|
|
|
c4e390 |
--- a/util/grub-module-verifierXX.c
|
|
|
c4e390 |
+++ b/util/grub-module-verifierXX.c
|
|
|
c4e390 |
@@ -151,14 +151,14 @@ find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const c
|
|
|
c4e390 |
}
|
|
|
c4e390 |
|
|
|
c4e390 |
static void
|
|
|
c4e390 |
-check_license (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
|
|
|
c4e390 |
+check_license (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char *filename)
|
|
|
c4e390 |
{
|
|
|
c4e390 |
Elf_Shdr *s = find_section (arch, e, ".module_license");
|
|
|
c4e390 |
if (s && (strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3") == 0
|
|
|
c4e390 |
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3+") == 0
|
|
|
c4e390 |
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv2+") == 0))
|
|
|
c4e390 |
return;
|
|
|
c4e390 |
- grub_util_error ("incompatible license");
|
|
|
c4e390 |
+ grub_util_error ("%s: incompatible license", filename);
|
|
|
c4e390 |
}
|
|
|
c4e390 |
|
|
|
c4e390 |
static Elf_Sym *
|
|
|
c4e390 |
@@ -185,7 +185,7 @@ get_symtab (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word
|
|
|
c4e390 |
}
|
|
|
c4e390 |
|
|
|
c4e390 |
static void
|
|
|
c4e390 |
-check_symbols (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
|
|
|
c4e390 |
+check_symbols (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char * filename)
|
|
|
c4e390 |
{
|
|
|
c4e390 |
Elf_Sym *sym;
|
|
|
c4e390 |
Elf_Word size, entsize;
|
|
|
c4e390 |
@@ -199,10 +199,10 @@ check_symbols (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
|
|
|
c4e390 |
Elf_Shdr *s = find_section (arch, e, ".moddeps");
|
|
|
c4e390 |
|
|
|
c4e390 |
if (!s)
|
|
|
c4e390 |
- grub_util_error ("no symbol table and no .moddeps section");
|
|
|
c4e390 |
+ grub_util_error ("%s: no symbol table and no .moddeps section", filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
if (!s->sh_size)
|
|
|
c4e390 |
- grub_util_error ("no symbol table and empty .moddeps section");
|
|
|
c4e390 |
+ grub_util_error ("%s: no symbol table and empty .moddeps section", filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
return;
|
|
|
c4e390 |
}
|
|
|
c4e390 |
@@ -223,7 +223,7 @@ check_symbols (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
|
|
|
c4e390 |
break;
|
|
|
c4e390 |
|
|
|
c4e390 |
default:
|
|
|
c4e390 |
- return grub_util_error ("unknown symbol type `%d'", (int) type);
|
|
|
c4e390 |
+ return grub_util_error ("%s: unknown symbol type `%d'", filename, (int) type);
|
|
|
c4e390 |
}
|
|
|
c4e390 |
}
|
|
|
c4e390 |
}
|
|
|
c4e390 |
@@ -250,26 +250,29 @@ is_symbol_local(Elf_Sym *sym)
|
|
|
c4e390 |
|
|
|
c4e390 |
static void
|
|
|
c4e390 |
section_check_relocations (const struct grub_module_verifier_arch *arch, void *ehdr,
|
|
|
c4e390 |
- Elf_Shdr *s, size_t target_seg_size)
|
|
|
c4e390 |
+ Elf_Shdr *s, size_t target_seg_size, const char * filename)
|
|
|
c4e390 |
{
|
|
|
c4e390 |
Elf_Rel *rel, *max;
|
|
|
c4e390 |
Elf_Sym *symtab;
|
|
|
c4e390 |
Elf_Word symtabsize, symtabentsize;
|
|
|
c4e390 |
+ unsigned int r;
|
|
|
c4e390 |
|
|
|
c4e390 |
symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize);
|
|
|
c4e390 |
if (!symtab)
|
|
|
c4e390 |
- grub_util_error ("relocation without symbol table");
|
|
|
c4e390 |
+ grub_util_error ("%s: relocation without symbol table", filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)),
|
|
|
c4e390 |
- max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size));
|
|
|
c4e390 |
+ max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size)),
|
|
|
c4e390 |
+ r = 0;
|
|
|
c4e390 |
rel < max;
|
|
|
c4e390 |
- rel = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_entsize)))
|
|
|
c4e390 |
+ rel = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_entsize)),
|
|
|
c4e390 |
+ r++)
|
|
|
c4e390 |
{
|
|
|
c4e390 |
Elf_Sym *sym;
|
|
|
c4e390 |
unsigned i;
|
|
|
c4e390 |
|
|
|
c4e390 |
if (target_seg_size < grub_target_to_host (rel->r_offset))
|
|
|
c4e390 |
- grub_util_error ("reloc offset is out of the segment");
|
|
|
c4e390 |
+ grub_util_error ("%s: reloc offset is out of the segment", filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
grub_uint32_t type = ELF_R_TYPE (grub_target_to_host (rel->r_info));
|
|
|
c4e390 |
|
|
|
c4e390 |
@@ -282,22 +285,22 @@ section_check_relocations (const struct grub_module_verifier_arch *arch, void *e
|
|
|
c4e390 |
if (arch->supported_relocations[i] != -1)
|
|
|
c4e390 |
continue;
|
|
|
c4e390 |
if (!arch->short_relocations)
|
|
|
c4e390 |
- grub_util_error ("unsupported relocation 0x%x", type);
|
|
|
c4e390 |
+ grub_util_error ("%s: relocation %u has unsupported type 0x%x", filename, r, type);
|
|
|
c4e390 |
for (i = 0; arch->short_relocations[i] != -1; i++)
|
|
|
c4e390 |
if (type == arch->short_relocations[i])
|
|
|
c4e390 |
break;
|
|
|
c4e390 |
if (arch->short_relocations[i] == -1)
|
|
|
c4e390 |
- grub_util_error ("unsupported relocation 0x%x", type);
|
|
|
c4e390 |
+ grub_util_error ("%s: relocation %u has unsupported type 0x%x", filename, r, type);
|
|
|
c4e390 |
sym = (Elf_Sym *) ((char *) symtab + symtabentsize * ELF_R_SYM (grub_target_to_host (rel->r_info)));
|
|
|
c4e390 |
|
|
|
c4e390 |
if (is_symbol_local (sym))
|
|
|
c4e390 |
continue;
|
|
|
c4e390 |
- grub_util_error ("relocation 0x%x is not module-local", type);
|
|
|
c4e390 |
+ grub_util_error ("%s: relocation %d with type 0x%x is not module-local", filename, r, type);
|
|
|
c4e390 |
}
|
|
|
c4e390 |
}
|
|
|
c4e390 |
|
|
|
c4e390 |
static void
|
|
|
c4e390 |
-check_relocations (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
|
|
|
c4e390 |
+check_relocations (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char * filename)
|
|
|
c4e390 |
{
|
|
|
c4e390 |
Elf_Shdr *s;
|
|
|
c4e390 |
unsigned i;
|
|
|
c4e390 |
@@ -310,27 +313,27 @@ check_relocations (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
|
|
|
c4e390 |
Elf_Shdr *ts;
|
|
|
c4e390 |
|
|
|
c4e390 |
if (grub_target_to_host32 (s->sh_type) == SHT_REL && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_REL))
|
|
|
c4e390 |
- grub_util_error ("unsupported SHT_REL");
|
|
|
c4e390 |
+ grub_util_error ("%s: section %d is unsupported SHT_REL", filename, i);
|
|
|
c4e390 |
if (grub_target_to_host32 (s->sh_type) == SHT_RELA && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_RELA))
|
|
|
c4e390 |
- grub_util_error ("unsupported SHT_RELA");
|
|
|
c4e390 |
+ grub_util_error ("%s: section %d is unsupported SHT_RELA", filename, i);
|
|
|
c4e390 |
|
|
|
c4e390 |
/* Find the target segment. */
|
|
|
c4e390 |
if (grub_target_to_host32 (s->sh_info) >= grub_target_to_host16 (e->e_shnum))
|
|
|
c4e390 |
- grub_util_error ("orphaned reloc section");
|
|
|
c4e390 |
+ grub_util_error ("%s: section %d is orphaned reloc", filename, i);
|
|
|
c4e390 |
ts = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host32 (s->sh_info) * grub_target_to_host16 (e->e_shentsize));
|
|
|
c4e390 |
|
|
|
c4e390 |
- section_check_relocations (arch, e, s, grub_target_to_host (ts->sh_size));
|
|
|
c4e390 |
+ section_check_relocations (arch, e, s, grub_target_to_host (ts->sh_size), filename);
|
|
|
c4e390 |
}
|
|
|
c4e390 |
}
|
|
|
c4e390 |
|
|
|
c4e390 |
void
|
|
|
c4e390 |
-SUFFIX(grub_module_verify) (void *module_img, size_t size, const struct grub_module_verifier_arch *arch)
|
|
|
c4e390 |
+SUFFIX(grub_module_verify) (void *module_img, size_t size, const struct grub_module_verifier_arch *arch, const char * filename)
|
|
|
c4e390 |
{
|
|
|
c4e390 |
Elf_Ehdr *e = module_img;
|
|
|
c4e390 |
|
|
|
c4e390 |
/* Check the header size. */
|
|
|
c4e390 |
if (size < sizeof (Elf_Ehdr))
|
|
|
c4e390 |
- grub_util_error ("ELF header smaller than expected");
|
|
|
c4e390 |
+ grub_util_error ("%s: ELF header smaller than expected", filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
/* Check the magic numbers. */
|
|
|
c4e390 |
if (e->e_ident[EI_MAG0] != ELFMAG0
|
|
|
c4e390 |
@@ -339,33 +342,33 @@ SUFFIX(grub_module_verify) (void *module_img, size_t size, const struct grub_mod
|
|
|
c4e390 |
|| e->e_ident[EI_MAG3] != ELFMAG3
|
|
|
c4e390 |
|| e->e_ident[EI_VERSION] != EV_CURRENT
|
|
|
c4e390 |
|| grub_target_to_host32 (e->e_version) != EV_CURRENT)
|
|
|
c4e390 |
- grub_util_error ("invalid arch-independent ELF magic");
|
|
|
c4e390 |
+ grub_util_error ("%s: invalid arch-independent ELF magic", filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
if (e->e_ident[EI_CLASS] != ELFCLASSXX
|
|
|
c4e390 |
|| e->e_ident[EI_DATA] != (arch->bigendian ? ELFDATA2MSB : ELFDATA2LSB)
|
|
|
c4e390 |
|| grub_target_to_host16 (e->e_machine) != arch->machine)
|
|
|
c4e390 |
- grub_util_error ("invalid arch-dependent ELF magic");
|
|
|
c4e390 |
+ grub_util_error ("%s: invalid arch-dependent ELF magic", filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
if (grub_target_to_host16 (e->e_type) != ET_REL)
|
|
|
c4e390 |
{
|
|
|
c4e390 |
- grub_util_error ("this ELF file is not of the right type");
|
|
|
c4e390 |
+ grub_util_error ("%s: this ELF file is not of the right type", filename);
|
|
|
c4e390 |
}
|
|
|
c4e390 |
|
|
|
c4e390 |
/* Make sure that every section is within the core. */
|
|
|
c4e390 |
if (size < grub_target_to_host (e->e_shoff)
|
|
|
c4e390 |
+ (grub_uint32_t) grub_target_to_host16 (e->e_shentsize) * grub_target_to_host16(e->e_shnum))
|
|
|
c4e390 |
{
|
|
|
c4e390 |
- grub_util_error ("ELF sections outside core");
|
|
|
c4e390 |
+ grub_util_error ("%s: ELF sections outside core", filename);
|
|
|
c4e390 |
}
|
|
|
c4e390 |
|
|
|
c4e390 |
- check_license (arch, e);
|
|
|
c4e390 |
+ check_license (arch, e, filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
Elf_Shdr *s;
|
|
|
c4e390 |
|
|
|
c4e390 |
s = find_section (arch, e, ".modname");
|
|
|
c4e390 |
if (!s)
|
|
|
c4e390 |
- grub_util_error ("no module name found");
|
|
|
c4e390 |
+ grub_util_error ("%s: no module name found", filename);
|
|
|
c4e390 |
|
|
|
c4e390 |
- check_symbols(arch, e);
|
|
|
c4e390 |
- check_relocations(arch, e);
|
|
|
c4e390 |
+ check_symbols(arch, e, filename);
|
|
|
c4e390 |
+ check_relocations(arch, e, filename);
|
|
|
c4e390 |
}
|
|
|
c4e390 |
diff --git a/include/grub/module_verifier.h b/include/grub/module_verifier.h
|
|
|
c4e390 |
index 6cddff30f2e..7dd0fa18ec8 100644
|
|
|
c4e390 |
--- a/include/grub/module_verifier.h
|
|
|
c4e390 |
+++ b/include/grub/module_verifier.h
|
|
|
c4e390 |
@@ -16,5 +16,5 @@ struct grub_module_verifier_arch {
|
|
|
c4e390 |
const int *short_relocations;
|
|
|
c4e390 |
};
|
|
|
c4e390 |
|
|
|
c4e390 |
-void grub_module_verify64(void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch);
|
|
|
c4e390 |
-void grub_module_verify32(void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch);
|
|
|
c4e390 |
+void grub_module_verify64(void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char * filename);
|
|
|
c4e390 |
+void grub_module_verify32(void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char * filename);
|
|
|
c4e390 |
--
|
|
|
c4e390 |
2.26.2
|
|
|
c4e390 |
|