ima_mok.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2015 Juniper Networks, Inc.
  4. *
  5. * Author:
  6. * Petko Manolov <[email protected]>
  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/init.h>
  14. #include <linux/slab.h>
  15. #include <keys/system_keyring.h>
  16. struct key *ima_blacklist_keyring;
  17. /*
  18. * Allocate the IMA blacklist keyring
  19. */
  20. static __init int ima_mok_init(void)
  21. {
  22. struct key_restriction *restriction;
  23. pr_notice("Allocating IMA blacklist keyring.\n");
  24. restriction = kzalloc(sizeof(struct key_restriction), GFP_KERNEL);
  25. if (!restriction)
  26. panic("Can't allocate IMA blacklist restriction.");
  27. restriction->check = restrict_link_by_builtin_trusted;
  28. ima_blacklist_keyring = keyring_alloc(".ima_blacklist",
  29. KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
  30. (KEY_POS_ALL & ~KEY_POS_SETATTR) |
  31. KEY_USR_VIEW | KEY_USR_READ |
  32. KEY_USR_WRITE | KEY_USR_SEARCH,
  33. KEY_ALLOC_NOT_IN_QUOTA |
  34. KEY_ALLOC_SET_KEEP,
  35. restriction, NULL);
  36. if (IS_ERR(ima_blacklist_keyring))
  37. panic("Can't allocate IMA blacklist keyring.");
  38. return 0;
  39. }
  40. device_initcall(ima_mok_init);