]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
dl: Add support for persistent modules
authorDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Oct 2018 16:49:26 +0000 (18:49 +0200)
committerDaniel Kiper <daniel.kiper@oracle.com>
Fri, 9 Nov 2018 12:25:31 +0000 (13:25 +0100)
This type of modules cannot be unloaded. This is useful if a given
functionality, e.g. UEFI secure boot shim signature verification, should
not be disabled if it was enabled at some point in time. Somebody may
say that we can use standalone GRUB2 here. That is true. However, the
code is not so big nor complicated hence it make sense to support
modularized configs too.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
grub-core/commands/minicmd.c
include/grub/dl.h

index fc20c65631d7139ce7f065c6354109c8327c3ce6..6bbce3128cf100ae7910163a7622ce3ac650c246 100644 (file)
@@ -137,6 +137,9 @@ grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)),
   if (! mod)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module");
 
+  if (grub_dl_is_persistent (mod))
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload persistent module");
+
   if (grub_dl_unref (mod) <= 0)
     grub_dl_unload (mod);
 
index 2bca56ce0e89f1ac507dd305e9fb8a01603af994..fee27a14c1a88c30ae2374e41746158f8fcf141b 100644 (file)
@@ -175,6 +175,7 @@ struct grub_dl
 {
   char *name;
   int ref_count;
+  int persistent;
   grub_dl_dep_t dep;
   grub_dl_segment_t segment;
   Elf_Sym *symtab;
@@ -240,6 +241,18 @@ grub_dl_get (const char *name)
   return 0;
 }
 
+static inline void
+grub_dl_set_persistent (grub_dl_t mod)
+{
+  mod->persistent = 1;
+}
+
+static inline int
+grub_dl_is_persistent (grub_dl_t mod)
+{
+  return mod->persistent;
+}
+
 #endif
 
 grub_err_t grub_dl_register_symbol (const char *name, void *addr,