]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/dl: Print module name on license check failure
authorRobbie Harwood <rharwood@redhat.com>
Mon, 25 Oct 2021 22:17:03 +0000 (18:17 -0400)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Nov 2021 15:13:34 +0000 (16:13 +0100)
Prior to this change, the GRUB would only indicate that the check had
been failed, but not by what module. This made it difficult to track
down either the problem module, or debug the false positive further.

Before performing the license check, resolve the module name so that
it can be printed if the license check fails.

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/dl.c

index 48f8a79073dd024190f3904338628742c2eef4d1..6a52de1686d83fdcc652aa647902bb8010398b1a 100644 (file)
@@ -457,14 +457,22 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name)
    Be sure to understand your license obligations.
 */
 static grub_err_t
-grub_dl_check_license (Elf_Ehdr *e)
+grub_dl_check_license (grub_dl_t mod, Elf_Ehdr *e)
 {
   Elf_Shdr *s = grub_dl_find_section (e, ".module_license");
-  if (s && (grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3") == 0
-           || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3+") == 0
-           || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv2+") == 0))
+
+  if (s == NULL)
+    return grub_error (GRUB_ERR_BAD_MODULE,
+                      "no license section in module %.63s", mod->name);
+
+  if (grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3") == 0
+      || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv3+") == 0
+      || grub_strcmp ((char *) e + s->sh_offset, "LICENSE=GPLv2+") == 0)
     return GRUB_ERR_NONE;
-  return grub_error (GRUB_ERR_BAD_MODULE, "incompatible license");
+
+  return grub_error (GRUB_ERR_BAD_MODULE,
+                    "incompatible license in module %.63s: %.63s", mod->name,
+                    (char *) e + s->sh_offset);
 }
 
 static grub_err_t
@@ -641,8 +649,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size)
      constitutes linking) and GRUB core being licensed under GPLv3+.
      Be sure to understand your license obligations.
   */
-  if (grub_dl_check_license (e)
-      || grub_dl_resolve_name (mod, e)
+  if (grub_dl_resolve_name (mod, e)
+      || grub_dl_check_license (mod, e)
       || grub_dl_resolve_dependencies (mod, e)
       || grub_dl_load_segments (mod, e)
       || grub_dl_resolve_symbols (mod, e)