blob: 6a5463d266352152ea6277b190f645852996dc50 [file] [log] [blame]
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001/*
2 * security/tomoyo/load_policy.c
3 *
4 * Policy loader launcher for TOMOYO.
5 *
6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
7 */
8
9#include "common.h"
10
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +090011#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
12
13/*
14 * Path to the policy loader. (default = CONFIG_SECURITY_TOMOYO_POLICY_LOADER)
15 */
16static const char *tomoyo_loader;
17
18/**
19 * tomoyo_loader_setup - Set policy loader.
20 *
21 * @str: Program to use as a policy loader (e.g. /sbin/tomoyo-init ).
22 *
23 * Returns 0.
24 */
25static int __init tomoyo_loader_setup(char *str)
26{
27 tomoyo_loader = str;
28 return 0;
29}
30
31__setup("TOMOYO_loader=", tomoyo_loader_setup);
Tetsuo Handac3ef1502010-05-17 10:12:46 +090032
33/**
34 * tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists.
35 *
36 * Returns true if /sbin/tomoyo-init exists, false otherwise.
37 */
38static bool tomoyo_policy_loader_exists(void)
39{
Tetsuo Handac3ef1502010-05-17 10:12:46 +090040 struct path path;
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +090041 if (!tomoyo_loader)
42 tomoyo_loader = CONFIG_SECURITY_TOMOYO_POLICY_LOADER;
Tetsuo Handac3ef1502010-05-17 10:12:46 +090043 if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) {
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +090044 printk(KERN_INFO "Not activating Mandatory Access Control "
45 "as %s does not exist.\n", tomoyo_loader);
Tetsuo Handac3ef1502010-05-17 10:12:46 +090046 return false;
47 }
48 path_put(&path);
49 return true;
50}
51
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +090052/*
53 * Path to the trigger. (default = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER)
54 */
55static const char *tomoyo_trigger;
56
57/**
58 * tomoyo_trigger_setup - Set trigger for activation.
59 *
60 * @str: Program to use as an activation trigger (e.g. /sbin/init ).
61 *
62 * Returns 0.
63 */
64static int __init tomoyo_trigger_setup(char *str)
65{
66 tomoyo_trigger = str;
67 return 0;
68}
69
70__setup("TOMOYO_trigger=", tomoyo_trigger_setup);
71
Tetsuo Handac3ef1502010-05-17 10:12:46 +090072/**
73 * tomoyo_load_policy - Run external policy loader to load policy.
74 *
75 * @filename: The program about to start.
76 *
77 * This function checks whether @filename is /sbin/init , and if so
78 * invoke /sbin/tomoyo-init and wait for the termination of /sbin/tomoyo-init
79 * and then continues invocation of /sbin/init.
80 * /sbin/tomoyo-init reads policy files in /etc/tomoyo/ directory and
81 * writes to /sys/kernel/security/tomoyo/ interfaces.
82 *
83 * Returns nothing.
84 */
85void tomoyo_load_policy(const char *filename)
86{
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +090087 static bool done;
Tetsuo Handac3ef1502010-05-17 10:12:46 +090088 char *argv[2];
89 char *envp[3];
90
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +090091 if (tomoyo_policy_loaded || done)
Tetsuo Handac3ef1502010-05-17 10:12:46 +090092 return;
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +090093 if (!tomoyo_trigger)
94 tomoyo_trigger = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER;
95 if (strcmp(filename, tomoyo_trigger))
Tetsuo Handac3ef1502010-05-17 10:12:46 +090096 return;
97 if (!tomoyo_policy_loader_exists())
98 return;
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +090099 done = true;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900100 printk(KERN_INFO "Calling %s to load policy. Please wait.\n",
101 tomoyo_loader);
102 argv[0] = (char *) tomoyo_loader;
103 argv[1] = NULL;
104 envp[0] = "HOME=/";
105 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
106 envp[2] = NULL;
107 call_usermodehelper(argv[0], argv, envp, 1);
108 tomoyo_check_profile();
109}
Tetsuo Handa0e4ae0e2011-06-26 23:22:59 +0900110
111#endif