1 // SPDX-License-Identifier: GPL-2.0
3 * security/tomoyo/load_policy.c
5 * Copyright (C) 2005-2011 NTT DATA CORPORATION
10 #ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
13 * Path to the policy loader. (default = CONFIG_SECURITY_TOMOYO_POLICY_LOADER)
15 static const char *tomoyo_loader;
18 * tomoyo_loader_setup - Set policy loader.
20 * @str: Program to use as a policy loader (e.g. /sbin/tomoyo-init ).
24 static int __init tomoyo_loader_setup(char *str)
30 __setup("TOMOYO_loader=", tomoyo_loader_setup);
33 * tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists.
35 * Returns true if /sbin/tomoyo-init exists, false otherwise.
37 static bool tomoyo_policy_loader_exists(void)
41 tomoyo_loader = CONFIG_SECURITY_TOMOYO_POLICY_LOADER;
42 if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) {
43 printk(KERN_INFO "Not activating Mandatory Access Control "
44 "as %s does not exist.\n", tomoyo_loader);
52 * Path to the trigger. (default = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER)
54 static const char *tomoyo_trigger;
57 * tomoyo_trigger_setup - Set trigger for activation.
59 * @str: Program to use as an activation trigger (e.g. /sbin/init ).
63 static int __init tomoyo_trigger_setup(char *str)
69 __setup("TOMOYO_trigger=", tomoyo_trigger_setup);
72 * tomoyo_load_policy - Run external policy loader to load policy.
74 * @filename: The program about to start.
76 * This function checks whether @filename is /sbin/init , and if so
77 * invoke /sbin/tomoyo-init and wait for the termination of /sbin/tomoyo-init
78 * and then continues invocation of /sbin/init.
79 * /sbin/tomoyo-init reads policy files in /etc/tomoyo/ directory and
80 * writes to /sys/kernel/security/tomoyo/ interfaces.
84 void tomoyo_load_policy(const char *filename)
90 if (tomoyo_policy_loaded || done)
93 tomoyo_trigger = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER;
94 if (strcmp(filename, tomoyo_trigger))
96 if (!tomoyo_policy_loader_exists())
99 printk(KERN_INFO "Calling %s to load policy. Please wait.\n",
101 argv[0] = (char *) tomoyo_loader;
104 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
106 call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
107 tomoyo_check_profile();