blob: b275c9c90a02132428b87c3809195a56b1679a1e [file] [log] [blame]
Joel Stanleya1fccbf2020-06-23 17:25:56 +09301From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Nayna Jain <nayna@linux.ibm.com>
3Date: Tue, 5 Nov 2019 17:00:22 -0600
Joel Stanleycb9bf572020-09-29 16:18:12 +09304Subject: [PATCH 02/19] powerpc: Detect the secure boot mode of the system
Joel Stanleya1fccbf2020-06-23 17:25:56 +09305
6This patch defines a function to detect the secure boot state of a
7PowerNV system.
8
9The PPC_SECURE_BOOT config represents the base enablement of secure
10boot for powerpc.
11
12Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
13Signed-off-by: Eric Richter <erichte@linux.ibm.com>
14[mpe: Fold in change from Nayna to add "ibm,secureboot" to ids]
15Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
16Link: https://lore.kernel.org/r/46b003b9-3225-6bf7-9101-ed6580bb748c@linux.ibm.com
17(cherry picked from commit 1a8916ee3ac29054322cdac687d36e1b5894d272)
18Signed-off-by: Joel Stanley <joel@jms.id.au>
19---
20 arch/powerpc/Kconfig | 10 ++++++++
21 arch/powerpc/include/asm/secure_boot.h | 23 +++++++++++++++++
22 arch/powerpc/kernel/Makefile | 2 ++
23 arch/powerpc/kernel/secure_boot.c | 35 ++++++++++++++++++++++++++
24 4 files changed, 70 insertions(+)
25 create mode 100644 arch/powerpc/include/asm/secure_boot.h
26 create mode 100644 arch/powerpc/kernel/secure_boot.c
27
28diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
Joel Stanleyaf12a6a2021-03-24 15:22:49 +103029index c4cbb65e742f..1a2db06962c7 100644
Joel Stanleya1fccbf2020-06-23 17:25:56 +093030--- a/arch/powerpc/Kconfig
31+++ b/arch/powerpc/Kconfig
Joel Stanleyaf12a6a2021-03-24 15:22:49 +103032@@ -936,6 +936,16 @@ config PPC_MEM_KEYS
Joel Stanleya1fccbf2020-06-23 17:25:56 +093033
34 If unsure, say y.
35
36+config PPC_SECURE_BOOT
37+ prompt "Enable secure boot support"
38+ bool
39+ depends on PPC_POWERNV
40+ help
41+ Systems with firmware secure boot enabled need to define security
42+ policies to extend secure boot to the OS. This config allows a user
43+ to enable OS secure boot on systems that have firmware support for
44+ it. If in doubt say N.
45+
46 endmenu
47
48 config ISA_DMA_API
49diff --git a/arch/powerpc/include/asm/secure_boot.h b/arch/powerpc/include/asm/secure_boot.h
50new file mode 100644
51index 000000000000..07d0fe0ca81f
52--- /dev/null
53+++ b/arch/powerpc/include/asm/secure_boot.h
54@@ -0,0 +1,23 @@
55+/* SPDX-License-Identifier: GPL-2.0 */
56+/*
57+ * Secure boot definitions
58+ *
59+ * Copyright (C) 2019 IBM Corporation
60+ * Author: Nayna Jain
61+ */
62+#ifndef _ASM_POWER_SECURE_BOOT_H
63+#define _ASM_POWER_SECURE_BOOT_H
64+
65+#ifdef CONFIG_PPC_SECURE_BOOT
66+
67+bool is_ppc_secureboot_enabled(void);
68+
69+#else
70+
71+static inline bool is_ppc_secureboot_enabled(void)
72+{
73+ return false;
74+}
75+
76+#endif
77+#endif
78diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
Joel Stanleyaf12a6a2021-03-24 15:22:49 +103079index afbd47b0a75c..36605a7b6ef2 100644
Joel Stanleya1fccbf2020-06-23 17:25:56 +093080--- a/arch/powerpc/kernel/Makefile
81+++ b/arch/powerpc/kernel/Makefile
82@@ -158,6 +158,8 @@ ifneq ($(CONFIG_PPC_POWERNV)$(CONFIG_PPC_SVM),)
83 obj-y += ucall.o
84 endif
85
86+obj-$(CONFIG_PPC_SECURE_BOOT) += secure_boot.o
87+
88 # Disable GCOV, KCOV & sanitizers in odd or sensitive code
89 GCOV_PROFILE_prom_init.o := n
90 KCOV_INSTRUMENT_prom_init.o := n
91diff --git a/arch/powerpc/kernel/secure_boot.c b/arch/powerpc/kernel/secure_boot.c
92new file mode 100644
93index 000000000000..583c2c4edaf0
94--- /dev/null
95+++ b/arch/powerpc/kernel/secure_boot.c
96@@ -0,0 +1,35 @@
97+// SPDX-License-Identifier: GPL-2.0
98+/*
99+ * Copyright (C) 2019 IBM Corporation
100+ * Author: Nayna Jain
101+ */
102+#include <linux/types.h>
103+#include <linux/of.h>
104+#include <asm/secure_boot.h>
105+
106+static struct device_node *get_ppc_fw_sb_node(void)
107+{
108+ static const struct of_device_id ids[] = {
109+ { .compatible = "ibm,secureboot", },
110+ { .compatible = "ibm,secureboot-v1", },
111+ { .compatible = "ibm,secureboot-v2", },
112+ {},
113+ };
114+
115+ return of_find_matching_node(NULL, ids);
116+}
117+
118+bool is_ppc_secureboot_enabled(void)
119+{
120+ struct device_node *node;
121+ bool enabled = false;
122+
123+ node = get_ppc_fw_sb_node();
124+ enabled = of_property_read_bool(node, "os-secureboot-enforcing");
125+
126+ of_node_put(node);
127+
128+ pr_info("Secure boot mode %s\n", enabled ? "enabled" : "disabled");
129+
130+ return enabled;
131+}