platform_keyring.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Platform keyring for firmware/platform keys
  4. *
  5. * Copyright IBM Corporation, 2018
  6. * Author(s): Nayna Jain <nayna@linux.ibm.com>
  7. */
  8. #include <linux/export.h>
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/cred.h>
  12. #include <linux/err.h>
  13. #include <linux/slab.h>
  14. #include "../integrity.h"
  15. /**
  16. * add_to_platform_keyring - Add to platform keyring without validation.
  17. * @source: Source of key
  18. * @data: The blob holding the key
  19. * @len: The length of the data blob
  20. *
  21. * Add a key to the platform keyring without checking its trust chain. This
  22. * is available only during kernel initialisation.
  23. */
  24. void __init add_to_platform_keyring(const char *source, const void *data,
  25. size_t len)
  26. {
  27. key_perm_t perm;
  28. int rc;
  29. perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW;
  30. rc = integrity_load_cert(INTEGRITY_KEYRING_PLATFORM, source, data, len,
  31. perm);
  32. if (rc)
  33. pr_info("Error adding keys to platform keyring %s\n", source);
  34. }
  35. /*
  36. * Create the trusted keyrings.
  37. */
  38. static __init int platform_keyring_init(void)
  39. {
  40. int rc;
  41. rc = integrity_init_keyring(INTEGRITY_KEYRING_PLATFORM);
  42. if (rc)
  43. return rc;
  44. pr_notice("Platform Keyring initialized\n");
  45. return 0;
  46. }
  47. /*
  48. * Must be initialised before we try and load the keys into the keyring.
  49. */
  50. device_initcall(platform_keyring_init);