aboutsummaryrefslogtreecommitdiffstats
path: root/security/tomoyo/load_policy.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/tomoyo/load_policy.c')
-rw-r--r--security/tomoyo/load_policy.c80
1 files changed, 54 insertions, 26 deletions
diff --git a/security/tomoyo/load_policy.c b/security/tomoyo/load_policy.c
index 3312e5624f24..67975405140f 100644
--- a/security/tomoyo/load_policy.c
+++ b/security/tomoyo/load_policy.c
@@ -1,15 +1,32 @@
1/* 1/*
2 * security/tomoyo/load_policy.c 2 * security/tomoyo/load_policy.c
3 * 3 *
4 * Policy loader launcher for TOMOYO. 4 * Copyright (C) 2005-2011 NTT DATA CORPORATION
5 *
6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
7 */ 5 */
8 6
9#include "common.h" 7#include "common.h"
10 8
11/* path to policy loader */ 9#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
12static const char *tomoyo_loader = "/sbin/tomoyo-init"; 10
11/*
12 * Path to the policy loader. (default = CONFIG_SECURITY_TOMOYO_POLICY_LOADER)
13 */
14static const char *tomoyo_loader;
15
16/**
17 * tomoyo_loader_setup - Set policy loader.
18 *
19 * @str: Program to use as a policy loader (e.g. /sbin/tomoyo-init ).
20 *
21 * Returns 0.
22 */
23static int __init tomoyo_loader_setup(char *str)
24{
25 tomoyo_loader = str;
26 return 0;
27}
28
29__setup("TOMOYO_loader=", tomoyo_loader_setup);
13 30
14/** 31/**
15 * tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists. 32 * tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists.
@@ -18,24 +35,38 @@ static const char *tomoyo_loader = "/sbin/tomoyo-init";
18 */ 35 */
19static bool tomoyo_policy_loader_exists(void) 36static bool tomoyo_policy_loader_exists(void)
20{ 37{
21 /*
22 * Don't activate MAC if the policy loader doesn't exist.
23 * If the initrd includes /sbin/init but real-root-dev has not
24 * mounted on / yet, activating MAC will block the system since
25 * policies are not loaded yet.
26 * Thus, let do_execve() call this function every time.
27 */
28 struct path path; 38 struct path path;
29 39 if (!tomoyo_loader)
40 tomoyo_loader = CONFIG_SECURITY_TOMOYO_POLICY_LOADER;
30 if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) { 41 if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) {
31 printk(KERN_INFO "Not activating Mandatory Access Control now " 42 printk(KERN_INFO "Not activating Mandatory Access Control "
32 "since %s doesn't exist.\n", tomoyo_loader); 43 "as %s does not exist.\n", tomoyo_loader);
33 return false; 44 return false;
34 } 45 }
35 path_put(&path); 46 path_put(&path);
36 return true; 47 return true;
37} 48}
38 49
50/*
51 * Path to the trigger. (default = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER)
52 */
53static const char *tomoyo_trigger;
54
55/**
56 * tomoyo_trigger_setup - Set trigger for activation.
57 *
58 * @str: Program to use as an activation trigger (e.g. /sbin/init ).
59 *
60 * Returns 0.
61 */
62static int __init tomoyo_trigger_setup(char *str)
63{
64 tomoyo_trigger = str;
65 return 0;
66}
67
68__setup("TOMOYO_trigger=", tomoyo_trigger_setup);
69
39/** 70/**
40 * tomoyo_load_policy - Run external policy loader to load policy. 71 * tomoyo_load_policy - Run external policy loader to load policy.
41 * 72 *
@@ -51,24 +82,19 @@ static bool tomoyo_policy_loader_exists(void)
51 */ 82 */
52void tomoyo_load_policy(const char *filename) 83void tomoyo_load_policy(const char *filename)
53{ 84{
85 static bool done;
54 char *argv[2]; 86 char *argv[2];
55 char *envp[3]; 87 char *envp[3];
56 88
57 if (tomoyo_policy_loaded) 89 if (tomoyo_policy_loaded || done)
58 return; 90 return;
59 /* 91 if (!tomoyo_trigger)
60 * Check filename is /sbin/init or /sbin/tomoyo-start. 92 tomoyo_trigger = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER;
61 * /sbin/tomoyo-start is a dummy filename in case where /sbin/init can't 93 if (strcmp(filename, tomoyo_trigger))
62 * be passed.
63 * You can create /sbin/tomoyo-start by
64 * "ln -s /bin/true /sbin/tomoyo-start".
65 */
66 if (strcmp(filename, "/sbin/init") &&
67 strcmp(filename, "/sbin/tomoyo-start"))
68 return; 94 return;
69 if (!tomoyo_policy_loader_exists()) 95 if (!tomoyo_policy_loader_exists())
70 return; 96 return;
71 97 done = true;
72 printk(KERN_INFO "Calling %s to load policy. Please wait.\n", 98 printk(KERN_INFO "Calling %s to load policy. Please wait.\n",
73 tomoyo_loader); 99 tomoyo_loader);
74 argv[0] = (char *) tomoyo_loader; 100 argv[0] = (char *) tomoyo_loader;
@@ -79,3 +105,5 @@ void tomoyo_load_policy(const char *filename)
79 call_usermodehelper(argv[0], argv, envp, 1); 105 call_usermodehelper(argv[0], argv, envp, 1);
80 tomoyo_check_profile(); 106 tomoyo_check_profile();
81} 107}
108
109#endif