ima_mok.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 2015 Juniper Networks, Inc.
  3. *
  4. * Author:
  5. * Petko Manolov <petko.manolov@konsulko.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation, version 2 of the
  10. * License.
  11. *
  12. */
  13. #include <linux/export.h>
  14. #include <linux/kernel.h>
  15. #include <linux/sched.h>
  16. #include <linux/cred.h>
  17. #include <linux/err.h>
  18. #include <linux/init.h>
  19. #include <linux/slab.h>
  20. #include <keys/system_keyring.h>
  21. struct key *ima_blacklist_keyring;
  22. /*
  23. * Allocate the IMA blacklist keyring
  24. */
  25. __init int ima_mok_init(void)
  26. {
  27. struct key_restriction *restriction;
  28. pr_notice("Allocating IMA blacklist keyring.\n");
  29. restriction = kzalloc(sizeof(struct key_restriction), GFP_KERNEL);
  30. if (!restriction)
  31. panic("Can't allocate IMA blacklist restriction.");
  32. restriction->check = restrict_link_by_builtin_trusted;
  33. ima_blacklist_keyring = keyring_alloc(".ima_blacklist",
  34. KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
  35. (KEY_POS_ALL & ~KEY_POS_SETATTR) |
  36. KEY_USR_VIEW | KEY_USR_READ |
  37. KEY_USR_WRITE | KEY_USR_SEARCH,
  38. KEY_ALLOC_NOT_IN_QUOTA |
  39. KEY_ALLOC_SET_KEEP,
  40. restriction, NULL);
  41. if (IS_ERR(ima_blacklist_keyring))
  42. panic("Can't allocate IMA blacklist keyring.");
  43. return 0;
  44. }
  45. device_initcall(ima_mok_init);