History

Merge tag 'integrity-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity

Pull integrity subsystem updates from Mimi Zohar: "The few changes are all kexec related: - The MOK keys are loaded onto the .platform keyring in order to verify the kexec kernel image signature. However, the MOK keys should only be trusted when secure boot is enabled. Before loading the MOK keys onto the .platform keyring, make sure the system is booted in secure boot mode. - When carrying the IMA measurement list across kexec, limit dumping the measurement list to when dynamic debug or CONFIG_DEBUG is enabled. - kselftest: add kexec_file_load selftest support for PowerNV and other cleanup" * tag 'integrity-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: selftests/kexec: Enable secureboot tests for PowerPC ima: silence measurement list hexdump during kexec selftests/kexec: update searching for the Kconfig selftest/kexec: fix "ignored null byte in input" warning integrity: Do not load MOK and MOKx when secure boot be disabled ima: Fix undefined arch_ima_get_secureboot() and co

Linus Torvalds committed 4 years ago

Commit 84bfcc02 parents 5d7e522 65e38e36 files · +74 −33Browse files

Unified · Split

6 files
  1. include/linux/ima.h +15 −15
  2. security/integrity/ima/ima_kexec.c +3 −3
  3. security/integrity/platform_certs/load_uefi.c +5 −0
  4. tools/testing/selftests/kexec/Makefile +1 −1
  5. tools/testing/selftests/kexec/kexec_common_lib.sh +41 −10
  6. tools/testing/selftests/kexec/test_kexec_file_load.sh +9 −4
include/linux/ima.h+15−15
@@ -50,21 +50,6 @@ static inline void ima_appraise_parse_cmdline(void) {} · 49 unmodified lines
5050 extern void ima_add_kexec_buffer(struct kimage *image);
5151 #endif
5252
53−#ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
54−extern bool arch_ima_get_secureboot(void);
55−extern const char * const *arch_get_ima_policy(void);
56−#else
57−static inline bool arch_ima_get_secureboot(void)
58−{
59− return false;
60−}
61−
62−static inline const char * const *arch_get_ima_policy(void)
63−{
64− return NULL;
65−}
66−#endif
67−
6853 #else
6954 static inline enum hash_algo ima_get_current_hash_algo(void)
7055 {
@@ -155,6 +140,21 @@ static inline int ima_measure_critical_data(const char *event_label, · 84 unmodified lines
155140
156141 #endif /* CONFIG_IMA */
157142
143+#ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
144+extern bool arch_ima_get_secureboot(void);
145+extern const char * const *arch_get_ima_policy(void);
146+#else
147+static inline bool arch_ima_get_secureboot(void)
148+{
149+ return false;
150+}
151+
152+static inline const char * const *arch_get_ima_policy(void)
153+{
154+ return NULL;
155+}
156+#endif
157+
158158 #ifndef CONFIG_IMA_KEXEC
159159 struct kimage;
160160
security/integrity/ima/ima_kexec.c+3−3
@@ -61,9 +61,9 @@ static int ima_dump_measurement_list(unsigned long *buffer_size, void **buffer, · 60 unmodified lines
6161 }
6262 memcpy(file.buf, &khdr, sizeof(khdr));
6363
64− print_hex_dump(KERN_DEBUG, "ima dump: ", DUMP_PREFIX_NONE,
65− 16, 1, file.buf,
66− file.count < 100 ? file.count : 100, true);
64+ print_hex_dump_debug("ima dump: ", DUMP_PREFIX_NONE, 16, 1,
65+ file.buf, file.count < 100 ? file.count : 100,
66+ true);
6767
6868 *buffer_size = file.count;
6969 *buffer = file.buf;
security/integrity/platform_certs/load_uefi.c+5−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 #include <linux/err.h>
77 #include <linux/efi.h>
88 #include <linux/slab.h>
9+#include <linux/ima.h>
910 #include <keys/asymmetric-type.h>
1011 #include <keys/system_keyring.h>
1112 #include "../integrity.h"
@@ -176,6 +177,10 @@ static int __init load_uefi_certs(void) · 164 unmodified lines
176177 kfree(dbx);
177178 }
178179
180+ /* the MOK/MOKx can not be trusted when secure boot is disabled */
181+ if (!arch_ima_get_secureboot())
182+ return 0;
183+
179184 mokx = get_cert_list(L"MokListXRT", &mok_var, &mokxsize, &status);
180185 if (!mokx) {
181186 if (status == EFI_NOT_FOUND)
tools/testing/selftests/kexec/Makefile+1−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 uname_M := $(shell uname -m 2>/dev/null || echo not)
55 ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
66
7−ifeq ($(ARCH),x86)
7+ifeq ($(ARCH),$(filter $(ARCH),x86 ppc64le))
88 TEST_PROGS := test_kexec_load.sh test_kexec_file_load.sh
99 TEST_FILES := kexec_common_lib.sh
1010
tools/testing/selftests/kexec/kexec_common_lib.sh+41−10
@@ -91,6 +91,27 @@ get_efi_var_secureboot_mode() · 90 unmodified lines
9191 return 0;
9292 }
9393
94+# On powerpc platform, check device-tree property
95+# /proc/device-tree/ibm,secureboot/os-secureboot-enforcing
96+# to detect secureboot state.
97+get_ppc64_secureboot_mode()
98+{
99+ local secure_boot_file="/proc/device-tree/ibm,secureboot/os-secureboot-enforcing"
100+ # Check for secure boot file existence
101+ if [ -f $secure_boot_file ]; then
102+ log_info "Secureboot is enabled (Device tree)"
103+ return 1;
104+ fi
105+ log_info "Secureboot is not enabled (Device tree)"
106+ return 0;
107+}
108+
109+# Return the architecture of the system
110+get_arch()
111+{
112+ echo $(arch)
113+}
114+
94115 # Check efivar SecureBoot-$(the UUID) and SetupMode-$(the UUID).
95116 # The secure boot mode can be accessed either as the last integer
96117 # of "od -An -t u1 /sys/firmware/efi/efivars/SecureBoot-*" or from
@@ -100,14 +121,19 @@ get_efi_var_secureboot_mode() · 3 unmodified lines
100121 get_secureboot_mode()
101122 {
102123 local secureboot_mode=0
124+ local system_arch=$(get_arch)
103125
104− get_efivarfs_secureboot_mode
105− secureboot_mode=$?
106−
107− # fallback to using the efi_var files
108− if [ $secureboot_mode -eq 0 ]; then
109− get_efi_var_secureboot_mode
126+ if [ "$system_arch" == "ppc64le" ]; then
127+ get_ppc64_secureboot_mode
128+ secureboot_mode=$?
129+ else
130+ get_efivarfs_secureboot_mode
110131 secureboot_mode=$?
132+ # fallback to using the efi_var files
133+ if [ $secureboot_mode -eq 0 ]; then
134+ get_efi_var_secureboot_mode
135+ secureboot_mode=$?
136+ fi
111137 fi
112138
113139 if [ $secureboot_mode -eq 0 ]; then
@@ -138,15 +164,20 @@ kconfig_enabled() · 24 unmodified lines
138164 return 0
139165 }
140166
141−# Attempt to get the kernel config first via proc, and then by
142−# extracting it from the kernel image or the configs.ko using
143−# scripts/extract-ikconfig.
167+# Attempt to get the kernel config first by checking the modules directory
168+# then via proc, and finally by extracting it from the kernel image or the
169+# configs.ko using scripts/extract-ikconfig.
144170 # Return 1 for found.
145171 get_kconfig()
146172 {
147173 local proc_config="/proc/config.gz"
148174 local module_dir="/lib/modules/`uname -r`"
149− local configs_module="$module_dir/kernel/kernel/configs.ko"
175+ local configs_module="$module_dir/kernel/kernel/configs.ko*"
176+
177+ if [ -f $module_dir/config ]; then
178+ IKCONFIG=$module_dir/config
179+ return 1
180+ fi
150181
151182 if [ ! -f $proc_config ]; then
152183 modprobe configs > /dev/null 2>&1
tools/testing/selftests/kexec/test_kexec_file_load.sh+9−4
@@ -97,10 +97,11 @@ check_for_imasig() · 96 unmodified lines
9797 check_for_modsig()
9898 {
9999 local module_sig_string="~Module signature appended~"
100− local sig="$(tail --bytes $((${#module_sig_string} + 1)) $KERNEL_IMAGE)"
101100 local ret=0
102101
103− if [ "$sig" == "$module_sig_string" ]; then
102+ tail --bytes $((${#module_sig_string} + 1)) $KERNEL_IMAGE | \
103+ grep -q "$module_sig_string"
104+ if [ $? -eq 0 ]; then
104105 ret=1
105106 log_info "kexec kernel image modsig signed"
106107 else
@@ -225,8 +226,12 @@ get_secureboot_mode · 118 unmodified lines
225226 secureboot=$?
226227
227228 # Are there pe and ima signatures
228−check_for_pesig
229−pe_signed=$?
229+if [ "$(get_arch)" == 'ppc64le' ]; then
230+ pe_signed=0
231+else
232+ check_for_pesig
233+ pe_signed=$?
234+fi
230235
231236 check_for_imasig
232237 ima_signed=$?

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t