load_policy.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * security/tomoyo/load_policy.c
  3. *
  4. * Policy loader launcher for TOMOYO.
  5. *
  6. * Copyright (C) 2005-2010 NTT DATA CORPORATION
  7. */
  8. #include "common.h"
  9. /* path to policy loader */
  10. static const char *tomoyo_loader = "/sbin/tomoyo-init";
  11. /**
  12. * tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists.
  13. *
  14. * Returns true if /sbin/tomoyo-init exists, false otherwise.
  15. */
  16. static bool tomoyo_policy_loader_exists(void)
  17. {
  18. /*
  19. * Don't activate MAC if the policy loader doesn't exist.
  20. * If the initrd includes /sbin/init but real-root-dev has not
  21. * mounted on / yet, activating MAC will block the system since
  22. * policies are not loaded yet.
  23. * Thus, let do_execve() call this function everytime.
  24. */
  25. struct path path;
  26. if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) {
  27. printk(KERN_INFO "Not activating Mandatory Access Control now "
  28. "since %s doesn't exist.\n", tomoyo_loader);
  29. return false;
  30. }
  31. path_put(&path);
  32. return true;
  33. }
  34. /**
  35. * tomoyo_load_policy - Run external policy loader to load policy.
  36. *
  37. * @filename: The program about to start.
  38. *
  39. * This function checks whether @filename is /sbin/init , and if so
  40. * invoke /sbin/tomoyo-init and wait for the termination of /sbin/tomoyo-init
  41. * and then continues invocation of /sbin/init.
  42. * /sbin/tomoyo-init reads policy files in /etc/tomoyo/ directory and
  43. * writes to /sys/kernel/security/tomoyo/ interfaces.
  44. *
  45. * Returns nothing.
  46. */
  47. void tomoyo_load_policy(const char *filename)
  48. {
  49. char *argv[2];
  50. char *envp[3];
  51. if (tomoyo_policy_loaded)
  52. return;
  53. /*
  54. * Check filename is /sbin/init or /sbin/tomoyo-start.
  55. * /sbin/tomoyo-start is a dummy filename in case where /sbin/init can't
  56. * be passed.
  57. * You can create /sbin/tomoyo-start by
  58. * "ln -s /bin/true /sbin/tomoyo-start".
  59. */
  60. if (strcmp(filename, "/sbin/init") &&
  61. strcmp(filename, "/sbin/tomoyo-start"))
  62. return;
  63. if (!tomoyo_policy_loader_exists())
  64. return;
  65. printk(KERN_INFO "Calling %s to load policy. Please wait.\n",
  66. tomoyo_loader);
  67. argv[0] = (char *) tomoyo_loader;
  68. argv[1] = NULL;
  69. envp[0] = "HOME=/";
  70. envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
  71. envp[2] = NULL;
  72. call_usermodehelper(argv[0], argv, envp, 1);
  73. tomoyo_check_profile();
  74. }