Blame SOURCES/0348-dl-Add-support-for-persistent-modules.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Daniel Kiper <daniel.kiper@oracle.com>
80913e
Date: Tue, 2 Oct 2018 18:49:26 +0200
80913e
Subject: [PATCH] dl: Add support for persistent modules
80913e
80913e
This type of modules cannot be unloaded. This is useful if a given
80913e
functionality, e.g. UEFI secure boot shim signature verification, should
80913e
not be disabled if it was enabled at some point in time. Somebody may
80913e
say that we can use standalone GRUB2 here. That is true. However, the
80913e
code is not so big nor complicated hence it make sense to support
80913e
modularized configs too.
80913e
80913e
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
80913e
(cherry picked from commit ee7808e2197cbf5e8515d90ecbd81c9d0dd6fc15)
80913e
---
80913e
 grub-core/commands/minicmd.c |  3 +++
80913e
 include/grub/dl.h            | 13 +++++++++++++
80913e
 2 files changed, 16 insertions(+)
80913e
80913e
diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c
b32e65
index 46bf135e8..6d66b7c45 100644
80913e
--- a/grub-core/commands/minicmd.c
80913e
+++ b/grub-core/commands/minicmd.c
80913e
@@ -137,6 +137,9 @@ grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)),
80913e
   if (! mod)
80913e
     return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module");
80913e
 
80913e
+  if (grub_dl_is_persistent (mod))
80913e
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload persistent module");
80913e
+
80913e
   if (grub_dl_unref (mod) <= 0)
80913e
     grub_dl_unload (mod);
80913e
 
80913e
diff --git a/include/grub/dl.h b/include/grub/dl.h
b32e65
index 7b5bfb07c..f7cfe6482 100644
80913e
--- a/include/grub/dl.h
80913e
+++ b/include/grub/dl.h
80913e
@@ -177,6 +177,7 @@ struct grub_dl
80913e
 {
80913e
   char *name;
80913e
   int ref_count;
80913e
+  int persistent;
80913e
   grub_dl_dep_t dep;
80913e
   grub_dl_segment_t segment;
80913e
   Elf_Sym *symtab;
80913e
@@ -242,6 +243,18 @@ grub_dl_get (const char *name)
80913e
   return 0;
80913e
 }
80913e
 
80913e
+static inline void
80913e
+grub_dl_set_persistent (grub_dl_t mod)
80913e
+{
80913e
+  mod->persistent = 1;
80913e
+}
80913e
+
80913e
+static inline int
80913e
+grub_dl_is_persistent (grub_dl_t mod)
80913e
+{
80913e
+  return mod->persistent;
80913e
+}
80913e
+
80913e
 #endif
80913e
 
80913e
 void * EXPORT_FUNC(grub_resolve_symbol) (const char *name);