Blame SOURCES/0376-efi-Use-grub_is_lockdown-instead-of-hardcoding-a-dis.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Javier Martinez Canillas <javierm@redhat.com>
468bd4
Date: Mon, 28 Sep 2020 20:08:33 +0200
468bd4
Subject: [PATCH] efi: Use grub_is_lockdown() instead of hardcoding a disabled
468bd4
 modules list
468bd4
468bd4
Now the GRUB can check if it has been locked down and this can be used to
468bd4
prevent executing commands that can be utilized to circumvent the UEFI
468bd4
Secure Boot mechanisms. So, instead of hardcoding a list of modules that
468bd4
have to be disabled, prevent the usage of commands that can be dangerous.
468bd4
468bd4
This not only allows the commands to be disabled on other platforms, but
468bd4
also properly separate the concerns. Since the shim_lock verifier logic
468bd4
should be only about preventing to run untrusted binaries and not about
468bd4
defining these kind of policies.
468bd4
468bd4
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 grub-core/commands/iorw.c  | 26 ++++++++++----------------
468bd4
 grub-core/commands/memrw.c | 26 ++++++++++----------------
468bd4
 2 files changed, 20 insertions(+), 32 deletions(-)
468bd4
468bd4
diff --git a/grub-core/commands/iorw.c b/grub-core/commands/iorw.c
030dc3
index 41a7f3f0466..584baec8f91 100644
468bd4
--- a/grub-core/commands/iorw.c
468bd4
+++ b/grub-core/commands/iorw.c
468bd4
@@ -23,7 +23,7 @@
468bd4
 #include <grub/env.h>
468bd4
 #include <grub/cpu/io.h>
468bd4
 #include <grub/i18n.h>
468bd4
-#include <grub/efi/sb.h>
468bd4
+#include <grub/lockdown.h>
468bd4
 
468bd4
 GRUB_MOD_LICENSE ("GPLv3+");
468bd4
 
468bd4
@@ -119,9 +119,6 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv)
468bd4
 
468bd4
 GRUB_MOD_INIT(memrw)
468bd4
 {
468bd4
-  if (grub_efi_secure_boot())
468bd4
-    return;
468bd4
-
468bd4
   cmd_read_byte =
468bd4
     grub_register_extcmd ("inb", grub_cmd_read, 0,
468bd4
 			  N_("PORT"), N_("Read 8-bit value from PORT."),
468bd4
@@ -135,24 +132,21 @@ GRUB_MOD_INIT(memrw)
468bd4
 			  N_("PORT"), N_("Read 32-bit value from PORT."),
468bd4
 			  options);
468bd4
   cmd_write_byte =
468bd4
-    grub_register_command ("outb", grub_cmd_write,
468bd4
-			   N_("PORT VALUE [MASK]"),
468bd4
-			   N_("Write 8-bit VALUE to PORT."));
468bd4
+    grub_register_command_lockdown ("outb", grub_cmd_write,
468bd4
+                                    N_("PORT VALUE [MASK]"),
468bd4
+                                    N_("Write 8-bit VALUE to PORT."));
468bd4
   cmd_write_word =
468bd4
-    grub_register_command ("outw", grub_cmd_write,
468bd4
-			   N_("PORT VALUE [MASK]"),
468bd4
-			   N_("Write 16-bit VALUE to PORT."));
468bd4
+    grub_register_command_lockdown ("outw", grub_cmd_write,
468bd4
+                                    N_("PORT VALUE [MASK]"),
468bd4
+                                    N_("Write 16-bit VALUE to PORT."));
468bd4
   cmd_write_dword =
468bd4
-    grub_register_command ("outl", grub_cmd_write,
468bd4
-			   N_("ADDR VALUE [MASK]"),
468bd4
-			   N_("Write 32-bit VALUE to PORT."));
468bd4
+    grub_register_command_lockdown ("outl", grub_cmd_write,
468bd4
+                                    N_("ADDR VALUE [MASK]"),
468bd4
+                                    N_("Write 32-bit VALUE to PORT."));
468bd4
 }
468bd4
 
468bd4
 GRUB_MOD_FINI(memrw)
468bd4
 {
468bd4
-  if (grub_efi_secure_boot())
468bd4
-    return;
468bd4
-
468bd4
   grub_unregister_extcmd (cmd_read_byte);
468bd4
   grub_unregister_extcmd (cmd_read_word);
468bd4
   grub_unregister_extcmd (cmd_read_dword);
468bd4
diff --git a/grub-core/commands/memrw.c b/grub-core/commands/memrw.c
030dc3
index 088cbe9e2bc..d401a6db0ef 100644
468bd4
--- a/grub-core/commands/memrw.c
468bd4
+++ b/grub-core/commands/memrw.c
468bd4
@@ -22,7 +22,7 @@
468bd4
 #include <grub/extcmd.h>
468bd4
 #include <grub/env.h>
468bd4
 #include <grub/i18n.h>
468bd4
-#include <grub/efi/sb.h>
468bd4
+#include <grub/lockdown.h>
468bd4
 
468bd4
 GRUB_MOD_LICENSE ("GPLv3+");
468bd4
 
468bd4
@@ -121,9 +121,6 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv)
468bd4
 
468bd4
 GRUB_MOD_INIT(memrw)
468bd4
 {
468bd4
-  if (grub_efi_secure_boot())
468bd4
-    return;
468bd4
-
468bd4
   cmd_read_byte =
468bd4
     grub_register_extcmd ("read_byte", grub_cmd_read, 0,
468bd4
 			  N_("ADDR"), N_("Read 8-bit value from ADDR."),
468bd4
@@ -137,24 +134,21 @@ GRUB_MOD_INIT(memrw)
468bd4
 			  N_("ADDR"), N_("Read 32-bit value from ADDR."),
468bd4
 			  options);
468bd4
   cmd_write_byte =
468bd4
-    grub_register_command ("write_byte", grub_cmd_write,
468bd4
-			   N_("ADDR VALUE [MASK]"),
468bd4
-			   N_("Write 8-bit VALUE to ADDR."));
468bd4
+    grub_register_command_lockdown ("write_byte", grub_cmd_write,
468bd4
+                                    N_("ADDR VALUE [MASK]"),
468bd4
+                                    N_("Write 8-bit VALUE to ADDR."));
468bd4
   cmd_write_word =
468bd4
-    grub_register_command ("write_word", grub_cmd_write,
468bd4
-			   N_("ADDR VALUE [MASK]"),
468bd4
-			   N_("Write 16-bit VALUE to ADDR."));
468bd4
+    grub_register_command_lockdown ("write_word", grub_cmd_write,
468bd4
+                                    N_("ADDR VALUE [MASK]"),
468bd4
+                                    N_("Write 16-bit VALUE to ADDR."));
468bd4
   cmd_write_dword =
468bd4
-    grub_register_command ("write_dword", grub_cmd_write,
468bd4
-			   N_("ADDR VALUE [MASK]"),
468bd4
-			   N_("Write 32-bit VALUE to ADDR."));
468bd4
+    grub_register_command_lockdown ("write_dword", grub_cmd_write,
468bd4
+                                    N_("ADDR VALUE [MASK]"),
468bd4
+                                    N_("Write 32-bit VALUE to ADDR."));
468bd4
 }
468bd4
 
468bd4
 GRUB_MOD_FINI(memrw)
468bd4
 {
468bd4
-  if (grub_efi_secure_boot())
468bd4
-    return;
468bd4
-
468bd4
   grub_unregister_extcmd (cmd_read_byte);
468bd4
   grub_unregister_extcmd (cmd_read_word);
468bd4
   grub_unregister_extcmd (cmd_read_dword);