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
50extern void ima_add_kexec_buffer(struct kimage *image);50extern void ima_add_kexec_buffer(struct kimage *image);
51#endif51#endif
52 52
53#ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
54extern bool arch_ima_get_secureboot(void);
55extern const char * const *arch_get_ima_policy(void);
56#else
57static inline bool arch_ima_get_secureboot(void)
58{
59 return false;
60}
61
62static inline const char * const *arch_get_ima_policy(void)
63{
64 return NULL;
65}
66#endif
67
68#else53#else
69static inline enum hash_algo ima_get_current_hash_algo(void)54static inline enum hash_algo ima_get_current_hash_algo(void)
70{55{
@@ -155,6 +140,21 @@ static inline int ima_measure_critical_data(const char *event_label, · 84 unmodified lines
155 140
156#endif /* CONFIG_IMA */141#endif /* CONFIG_IMA */
157 142
143#ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
144extern bool arch_ima_get_secureboot(void);
145extern const char * const *arch_get_ima_policy(void);
146#else
147static inline bool arch_ima_get_secureboot(void)
148{
149 return false;
150}
151
152static inline const char * const *arch_get_ima_policy(void)
153{
154 return NULL;
155}
156#endif
157
158#ifndef CONFIG_IMA_KEXEC158#ifndef CONFIG_IMA_KEXEC
159struct kimage;159struct kimage;
160 160
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
61 }61 }
62 memcpy(file.buf, &khdr, sizeof(khdr));62 memcpy(file.buf, &khdr, sizeof(khdr));
63 63
64 print_hex_dump(KERN_DEBUG, "ima dump: ", DUMP_PREFIX_NONE,64 print_hex_dump_debug("ima dump: ", DUMP_PREFIX_NONE, 16, 1,
65 16, 1, file.buf,65 file.buf, file.count < 100 ? file.count : 100,
66 file.count < 100 ? file.count : 100, true);66 true);
67 67
68 *buffer_size = file.count;68 *buffer_size = file.count;
69 *buffer = file.buf;69 *buffer = file.buf;
security/integrity/platform_certs/load_uefi.c+5−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
6#include <linux/err.h>6#include <linux/err.h>
7#include <linux/efi.h>7#include <linux/efi.h>
8#include <linux/slab.h>8#include <linux/slab.h>
9#include <linux/ima.h>
9#include <keys/asymmetric-type.h>10#include <keys/asymmetric-type.h>
10#include <keys/system_keyring.h>11#include <keys/system_keyring.h>
11#include "../integrity.h"12#include "../integrity.h"
@@ -176,6 +177,10 @@ static int __init load_uefi_certs(void) · 164 unmodified lines
176 kfree(dbx);177 kfree(dbx);
177 }178 }
178 179
180 /* the MOK/MOKx can not be trusted when secure boot is disabled */
181 if (!arch_ima_get_secureboot())
182 return 0;
183
179 mokx = get_cert_list(L"MokListXRT", &mok_var, &mokxsize, &status);184 mokx = get_cert_list(L"MokListXRT", &mok_var, &mokxsize, &status);
180 if (!mokx) {185 if (!mokx) {
181 if (status == EFI_NOT_FOUND)186 if (status == EFI_NOT_FOUND)
tools/testing/selftests/kexec/Makefile+1−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
4uname_M := $(shell uname -m 2>/dev/null || echo not)4uname_M := $(shell uname -m 2>/dev/null || echo not)
5ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)5ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
6 6
7ifeq ($(ARCH),x86)7ifeq ($(ARCH),$(filter $(ARCH),x86 ppc64le))
8TEST_PROGS := test_kexec_load.sh test_kexec_file_load.sh8TEST_PROGS := test_kexec_load.sh test_kexec_file_load.sh
9TEST_FILES := kexec_common_lib.sh9TEST_FILES := kexec_common_lib.sh
10 10
tools/testing/selftests/kexec/kexec_common_lib.sh+41−10
@@ -91,6 +91,27 @@ get_efi_var_secureboot_mode() · 90 unmodified lines
91 return 0;91 return 0;
92}92}
93 93
94# On powerpc platform, check device-tree property
95# /proc/device-tree/ibm,secureboot/os-secureboot-enforcing
96# to detect secureboot state.
97get_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
110get_arch()
111{
112 echo $(arch)
113}
114
94# Check efivar SecureBoot-$(the UUID) and SetupMode-$(the UUID).115# Check efivar SecureBoot-$(the UUID) and SetupMode-$(the UUID).
95# The secure boot mode can be accessed either as the last integer116# The secure boot mode can be accessed either as the last integer
96# of "od -An -t u1 /sys/firmware/efi/efivars/SecureBoot-*" or from117# of "od -An -t u1 /sys/firmware/efi/efivars/SecureBoot-*" or from
@@ -100,14 +121,19 @@ get_efi_var_secureboot_mode() · 3 unmodified lines
100get_secureboot_mode()121get_secureboot_mode()
101{122{
102 local secureboot_mode=0123 local secureboot_mode=0
124 local system_arch=$(get_arch)
103 125
104 get_efivarfs_secureboot_mode126 if [ "$system_arch" == "ppc64le" ]; then
105 secureboot_mode=$?127 get_ppc64_secureboot_mode
106 128 secureboot_mode=$?
107 # fallback to using the efi_var files129 else
108 if [ $secureboot_mode -eq 0 ]; then130 get_efivarfs_secureboot_mode
109 get_efi_var_secureboot_mode
110 secureboot_mode=$?131 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
111 fi137 fi
112 138
113 if [ $secureboot_mode -eq 0 ]; then139 if [ $secureboot_mode -eq 0 ]; then
@@ -138,15 +164,20 @@ kconfig_enabled() · 24 unmodified lines
138 return 0164 return 0
139}165}
140 166
141# Attempt to get the kernel config first via proc, and then by167# Attempt to get the kernel config first by checking the modules directory
142# extracting it from the kernel image or the configs.ko using168# then via proc, and finally by extracting it from the kernel image or the
143# scripts/extract-ikconfig.169# configs.ko using scripts/extract-ikconfig.
144# Return 1 for found.170# Return 1 for found.
145get_kconfig()171get_kconfig()
146{172{
147 local proc_config="/proc/config.gz"173 local proc_config="/proc/config.gz"
148 local module_dir="/lib/modules/`uname -r`"174 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
150 181
151 if [ ! -f $proc_config ]; then182 if [ ! -f $proc_config ]; then
152 modprobe configs > /dev/null 2>&1183 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
97check_for_modsig()97check_for_modsig()
98{98{
99 local module_sig_string="~Module signature appended~"99 local module_sig_string="~Module signature appended~"
100 local sig="$(tail --bytes $((${#module_sig_string} + 1)) $KERNEL_IMAGE)"
101 local ret=0100 local ret=0
102 101
103 if [ "$sig" == "$module_sig_string" ]; then102 tail --bytes $((${#module_sig_string} + 1)) $KERNEL_IMAGE | \
103 grep -q "$module_sig_string"
104 if [ $? -eq 0 ]; then
104 ret=1105 ret=1
105 log_info "kexec kernel image modsig signed"106 log_info "kexec kernel image modsig signed"
106 else107 else
@@ -225,8 +226,12 @@ get_secureboot_mode · 118 unmodified lines
225secureboot=$?226secureboot=$?
226 227
227# Are there pe and ima signatures228# Are there pe and ima signatures
228check_for_pesig229if [ "$(get_arch)" == 'ppc64le' ]; then
229pe_signed=$?230 pe_signed=0
231else
232 check_for_pesig
233 pe_signed=$?
234fi
230 235
231check_for_imasig236check_for_imasig
232ima_signed=$?237ima_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