ima_arch.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2019 IBM Corporation
  4. * Author: Nayna Jain
  5. */
  6. #include <linux/ima.h>
  7. #include <asm/secure_boot.h>
  8. bool arch_ima_get_secureboot(void)
  9. {
  10. return is_ppc_secureboot_enabled();
  11. }
  12. /*
  13. * The "secure_rules" are enabled only on "secureboot" enabled systems.
  14. * These rules verify the file signatures against known good values.
  15. * The "appraise_type=imasig|modsig" option allows the known good signature
  16. * to be stored as an xattr or as an appended signature.
  17. *
  18. * To avoid duplicate signature verification as much as possible, the IMA
  19. * policy rule for module appraisal is added only if CONFIG_MODULE_SIG
  20. * is not enabled.
  21. */
  22. static const char *const secure_rules[] = {
  23. "appraise func=KEXEC_KERNEL_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig",
  24. #ifndef CONFIG_MODULE_SIG
  25. "appraise func=MODULE_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig",
  26. #endif
  27. NULL
  28. };
  29. /*
  30. * The "trusted_rules" are enabled only on "trustedboot" enabled systems.
  31. * These rules add the kexec kernel image and kernel modules file hashes to
  32. * the IMA measurement list.
  33. */
  34. static const char *const trusted_rules[] = {
  35. "measure func=KEXEC_KERNEL_CHECK",
  36. "measure func=MODULE_CHECK",
  37. NULL
  38. };
  39. /*
  40. * The "secure_and_trusted_rules" contains rules for both the secure boot and
  41. * trusted boot. The "template=ima-modsig" option includes the appended
  42. * signature, when available, in the IMA measurement list.
  43. */
  44. static const char *const secure_and_trusted_rules[] = {
  45. "measure func=KEXEC_KERNEL_CHECK template=ima-modsig",
  46. "measure func=MODULE_CHECK template=ima-modsig",
  47. "appraise func=KEXEC_KERNEL_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig",
  48. #ifndef CONFIG_MODULE_SIG
  49. "appraise func=MODULE_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig",
  50. #endif
  51. NULL
  52. };
  53. /*
  54. * Returns the relevant IMA arch-specific policies based on the system secure
  55. * boot state.
  56. */
  57. const char *const *arch_get_ima_policy(void)
  58. {
  59. if (is_ppc_secureboot_enabled()) {
  60. if (IS_ENABLED(CONFIG_MODULE_SIG))
  61. set_module_sig_enforced();
  62. if (is_ppc_trustedboot_enabled())
  63. return secure_and_trusted_rules;
  64. else
  65. return secure_rules;
  66. } else if (is_ppc_trustedboot_enabled()) {
  67. return trusted_rules;
  68. }
  69. return NULL;
  70. }