46968b6
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
46968b6
From: Daniel Axtens <dja@axtens.net>
46968b6
Date: Mon, 28 Sep 2020 11:11:17 +1000
46968b6
Subject: [PATCH] ieee1275: enter lockdown based on /ibm,secure-boot
46968b6
46968b6
If the 'ibm,secure-boot' property of the root node is 2 or greater,
46968b6
enter lockdown.
46968b6
46968b6
Signed-off-by: Daniel Axtens <dja@axtens.net>
46968b6
---
46968b6
 grub-core/Makefile.core.def    |  1 +
46968b6
 grub-core/kern/ieee1275/init.c | 27 +++++++++++++++++++++++++++
46968b6
 include/grub/lockdown.h        |  3 ++-
46968b6
 docs/grub.texi                 |  4 ++--
46968b6
 4 files changed, 32 insertions(+), 3 deletions(-)
46968b6
46968b6
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
ed1787d
index 9ea5fb38f1..4a57de975e 100644
46968b6
--- a/grub-core/Makefile.core.def
46968b6
+++ b/grub-core/Makefile.core.def
46968b6
@@ -323,6 +323,7 @@ kernel = {
46968b6
   powerpc_ieee1275 = kern/powerpc/cache.S;
46968b6
   powerpc_ieee1275 = kern/powerpc/dl.c;
46968b6
   powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
46968b6
+  powerpc_ieee1275 = kern/lockdown.c;
46968b6
 
46968b6
   sparc64_ieee1275 = kern/sparc64/cache.S;
46968b6
   sparc64_ieee1275 = kern/sparc64/dl.c;
46968b6
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
e622855
index 937c1bc44c..fc7d971272 100644
46968b6
--- a/grub-core/kern/ieee1275/init.c
46968b6
+++ b/grub-core/kern/ieee1275/init.c
46968b6
@@ -44,6 +44,7 @@
46968b6
 #ifdef __sparc__
46968b6
 #include <grub/machine/kernel.h>
46968b6
 #endif
46968b6
+#include <grub/lockdown.h>
46968b6
 
46968b6
 /* The minimal heap size we can live with. */
46968b6
 #define HEAP_MIN_SIZE		(unsigned long) (2 * 1024 * 1024)
46968b6
@@ -271,6 +272,30 @@ grub_parse_cmdline (void)
46968b6
     }
46968b6
 }
46968b6
 
46968b6
+static void
46968b6
+grub_get_ieee1275_secure_boot (void)
46968b6
+{
46968b6
+  grub_ieee1275_phandle_t root;
46968b6
+  int rc;
46968b6
+  grub_uint32_t is_sb;
46968b6
+
46968b6
+  grub_ieee1275_finddevice ("/", &root);
46968b6
+
46968b6
+  rc = grub_ieee1275_get_integer_property (root, "ibm,secure-boot", &is_sb,
46968b6
+                                           sizeof (is_sb), 0);
46968b6
+
46968b6
+  /* ibm,secure-boot:
46968b6
+   * 0 - disabled
46968b6
+   * 1 - audit
46968b6
+   * 2 - enforce
46968b6
+   * 3 - enforce + OS-specific behaviour
46968b6
+   *
46968b6
+   * We only support enforce.
46968b6
+   */
46968b6
+  if (rc >= 0 && is_sb >= 2)
46968b6
+    grub_lockdown ();
46968b6
+}
46968b6
+
46968b6
 grub_addr_t grub_modbase;
46968b6
 
46968b6
 void
46968b6
@@ -296,6 +321,8 @@ grub_machine_init (void)
46968b6
 #else
46968b6
   grub_install_get_time_ms (grub_rtc_get_time_ms);
46968b6
 #endif
46968b6
+
46968b6
+  grub_get_ieee1275_secure_boot ();
46968b6
 }
46968b6
 
46968b6
 void
46968b6
diff --git a/include/grub/lockdown.h b/include/grub/lockdown.h
e622855
index 40531fa823..ebfee4bf06 100644
46968b6
--- a/include/grub/lockdown.h
46968b6
+++ b/include/grub/lockdown.h
46968b6
@@ -24,7 +24,8 @@
46968b6
 #define GRUB_LOCKDOWN_DISABLED       0
46968b6
 #define GRUB_LOCKDOWN_ENABLED        1
46968b6
 
46968b6
-#ifdef GRUB_MACHINE_EFI
46968b6
+#if defined(GRUB_MACHINE_EFI) || \
46968b6
+    (defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275))
46968b6
 extern void
46968b6
 EXPORT_FUNC (grub_lockdown) (void);
46968b6
 extern int
46968b6
diff --git a/docs/grub.texi b/docs/grub.texi
e622855
index 4816be8561..a4da9c2a1b 100644
46968b6
--- a/docs/grub.texi
46968b6
+++ b/docs/grub.texi
13985b0
@@ -6227,8 +6227,8 @@ Measured boot is currently only supported on EFI platforms.
46968b6
 @section Lockdown when booting on a secure setup
46968b6
 
46968b6
 The GRUB can be locked down when booted on a secure boot environment, for example
46968b6
-if the UEFI secure boot is enabled. On a locked down configuration, the GRUB will
46968b6
-be restricted and some operations/commands cannot be executed.
46968b6
+if UEFI or Power secure boot is enabled. On a locked down configuration, the
46968b6
+GRUB will be restricted and some operations/commands cannot be executed.
46968b6
 
46968b6
 The @samp{lockdown} variable is set to @samp{y} when the GRUB is locked down.
46968b6
 Otherwise it does not exit.