// SPDX-License-Identifier: GPL-2.01/*2* security/tomoyo/load_policy.c3*4* Copyright (C) 2005-2011 NTT DATA CORPORATION5*/67#include "common.h"89#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER1011/*12* Path to the policy loader. (default = CONFIG_SECURITY_TOMOYO_POLICY_LOADER)13*/14static const char *tomoyo_loader;1516/**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{25tomoyo_loader = str;26return 1;27}2829__setup("TOMOYO_loader=", tomoyo_loader_setup);3031/**32* tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists.33*34* Returns true if /sbin/tomoyo-init exists, false otherwise.35*/36static bool tomoyo_policy_loader_exists(void)37{38struct path path;3940if (!tomoyo_loader)41tomoyo_loader = CONFIG_SECURITY_TOMOYO_POLICY_LOADER;42if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) {43pr_info("Not activating Mandatory Access Control as %s does not exist.\n",44tomoyo_loader);45return false;46}47path_put(&path);48return true;49}5051/*52* Path to the trigger. (default = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER)53*/54static const char *tomoyo_trigger;5556/**57* tomoyo_trigger_setup - Set trigger for activation.58*59* @str: Program to use as an activation trigger (e.g. /sbin/init ).60*61* Returns 0.62*/63static int __init tomoyo_trigger_setup(char *str)64{65tomoyo_trigger = str;66return 1;67}6869__setup("TOMOYO_trigger=", tomoyo_trigger_setup);7071/**72* tomoyo_load_policy - Run external policy loader to load policy.73*74* @filename: The program about to start.75*76* This function checks whether @filename is /sbin/init , and if so77* invoke /sbin/tomoyo-init and wait for the termination of /sbin/tomoyo-init78* and then continues invocation of /sbin/init.79* /sbin/tomoyo-init reads policy files in /etc/tomoyo/ directory and80* writes to /sys/kernel/security/tomoyo/ interfaces.81*82* Returns nothing.83*/84void tomoyo_load_policy(const char *filename)85{86static bool done;87char *argv[2];88char *envp[3];8990if (tomoyo_policy_loaded || done)91return;92if (!tomoyo_trigger)93tomoyo_trigger = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER;94if (strcmp(filename, tomoyo_trigger))95return;96if (!tomoyo_policy_loader_exists())97return;98done = true;99pr_info("Calling %s to load policy. Please wait.\n", tomoyo_loader);100argv[0] = (char *) tomoyo_loader;101argv[1] = NULL;102envp[0] = "HOME=/";103envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";104envp[2] = NULL;105call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);106tomoyo_check_profile();107}108109#endif110111112