nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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