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