Joel Stanley | a1fccbf | 2020-06-23 17:25:56 +0930 | [diff] [blame] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Nayna Jain <nayna@linux.ibm.com> |
| 3 | Date: Wed, 30 Oct 2019 23:31:27 -0400 |
| 4 | Subject: [PATCH 03/18] powerpc/ima: Add support to initialize ima policy rules |
| 5 | |
| 6 | PowerNV systems use a Linux-based bootloader, which rely on the IMA |
| 7 | subsystem to enforce different secure boot modes. Since the |
| 8 | verification policy may differ based on the secure boot mode of the |
| 9 | system, the policies must be defined at runtime. |
| 10 | |
| 11 | This patch implements arch-specific support to define IMA policy rules |
| 12 | based on the runtime secure boot mode of the system. |
| 13 | |
| 14 | This patch provides arch-specific IMA policies if PPC_SECURE_BOOT |
| 15 | config is enabled. |
| 16 | |
| 17 | Signed-off-by: Nayna Jain <nayna@linux.ibm.com> |
| 18 | Signed-off-by: Mimi Zohar <zohar@linux.ibm.com> |
| 19 | Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> |
| 20 | Link: https://lore.kernel.org/r/1572492694-6520-3-git-send-email-zohar@linux.ibm.com |
| 21 | (cherry picked from commit 4238fad366a660cbc6499ca1ea4be42bd4d1ac5b) |
| 22 | Signed-off-by: Joel Stanley <joel@jms.id.au> |
| 23 | --- |
| 24 | arch/powerpc/Kconfig | 1 + |
| 25 | arch/powerpc/kernel/Makefile | 2 +- |
| 26 | arch/powerpc/kernel/ima_arch.c | 43 ++++++++++++++++++++++++++++++++++ |
| 27 | include/linux/ima.h | 3 ++- |
| 28 | 4 files changed, 47 insertions(+), 2 deletions(-) |
| 29 | create mode 100644 arch/powerpc/kernel/ima_arch.c |
| 30 | |
| 31 | diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig |
| 32 | index bdf584b85199..eea6c358b86c 100644 |
| 33 | --- a/arch/powerpc/Kconfig |
| 34 | +++ b/arch/powerpc/Kconfig |
| 35 | @@ -938,6 +938,7 @@ config PPC_SECURE_BOOT |
| 36 | prompt "Enable secure boot support" |
| 37 | bool |
| 38 | depends on PPC_POWERNV |
| 39 | + depends on IMA_ARCH_POLICY |
| 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 | diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile |
| 44 | index 40170ee52178..b82f7f5e5121 100644 |
| 45 | --- a/arch/powerpc/kernel/Makefile |
| 46 | +++ b/arch/powerpc/kernel/Makefile |
| 47 | @@ -158,7 +158,7 @@ ifneq ($(CONFIG_PPC_POWERNV)$(CONFIG_PPC_SVM),) |
| 48 | obj-y += ucall.o |
| 49 | endif |
| 50 | |
| 51 | -obj-$(CONFIG_PPC_SECURE_BOOT) += secure_boot.o |
| 52 | +obj-$(CONFIG_PPC_SECURE_BOOT) += secure_boot.o ima_arch.o |
| 53 | |
| 54 | # Disable GCOV, KCOV & sanitizers in odd or sensitive code |
| 55 | GCOV_PROFILE_prom_init.o := n |
| 56 | diff --git a/arch/powerpc/kernel/ima_arch.c b/arch/powerpc/kernel/ima_arch.c |
| 57 | new file mode 100644 |
| 58 | index 000000000000..d88913dc0da7 |
| 59 | --- /dev/null |
| 60 | +++ b/arch/powerpc/kernel/ima_arch.c |
| 61 | @@ -0,0 +1,43 @@ |
| 62 | +// SPDX-License-Identifier: GPL-2.0 |
| 63 | +/* |
| 64 | + * Copyright (C) 2019 IBM Corporation |
| 65 | + * Author: Nayna Jain |
| 66 | + */ |
| 67 | + |
| 68 | +#include <linux/ima.h> |
| 69 | +#include <asm/secure_boot.h> |
| 70 | + |
| 71 | +bool arch_ima_get_secureboot(void) |
| 72 | +{ |
| 73 | + return is_ppc_secureboot_enabled(); |
| 74 | +} |
| 75 | + |
| 76 | +/* |
| 77 | + * The "secure_rules" are enabled only on "secureboot" enabled systems. |
| 78 | + * These rules verify the file signatures against known good values. |
| 79 | + * The "appraise_type=imasig|modsig" option allows the known good signature |
| 80 | + * to be stored as an xattr or as an appended signature. |
| 81 | + * |
| 82 | + * To avoid duplicate signature verification as much as possible, the IMA |
| 83 | + * policy rule for module appraisal is added only if CONFIG_MODULE_SIG_FORCE |
| 84 | + * is not enabled. |
| 85 | + */ |
| 86 | +static const char *const secure_rules[] = { |
| 87 | + "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig", |
| 88 | +#ifndef CONFIG_MODULE_SIG_FORCE |
| 89 | + "appraise func=MODULE_CHECK appraise_type=imasig|modsig", |
| 90 | +#endif |
| 91 | + NULL |
| 92 | +}; |
| 93 | + |
| 94 | +/* |
| 95 | + * Returns the relevant IMA arch-specific policies based on the system secure |
| 96 | + * boot state. |
| 97 | + */ |
| 98 | +const char *const *arch_get_ima_policy(void) |
| 99 | +{ |
| 100 | + if (is_ppc_secureboot_enabled()) |
| 101 | + return secure_rules; |
| 102 | + |
| 103 | + return NULL; |
| 104 | +} |
| 105 | diff --git a/include/linux/ima.h b/include/linux/ima.h |
| 106 | index 1c37f17f7203..6d904754d858 100644 |
| 107 | --- a/include/linux/ima.h |
| 108 | +++ b/include/linux/ima.h |
| 109 | @@ -29,7 +29,8 @@ extern void ima_kexec_cmdline(const void *buf, int size); |
| 110 | extern void ima_add_kexec_buffer(struct kimage *image); |
| 111 | #endif |
| 112 | |
| 113 | -#if (defined(CONFIG_X86) && defined(CONFIG_EFI)) || defined(CONFIG_S390) |
| 114 | +#if (defined(CONFIG_X86) && defined(CONFIG_EFI)) || defined(CONFIG_S390) \ |
| 115 | + || defined(CONFIG_PPC_SECURE_BOOT) |
| 116 | extern bool arch_ima_get_secureboot(void); |
| 117 | extern const char * const *arch_get_ima_policy(void); |
| 118 | #else |