1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 /* 2 /* 3 * security/tomoyo/load_policy.c 3 * security/tomoyo/load_policy.c 4 * 4 * 5 * Copyright (C) 2005-2011 NTT DATA CORPORATI 5 * Copyright (C) 2005-2011 NTT DATA CORPORATION 6 */ 6 */ 7 7 8 #include "common.h" 8 #include "common.h" 9 9 10 #ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_ 10 #ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER 11 11 12 /* 12 /* 13 * Path to the policy loader. (default = CONFI 13 * Path to the policy loader. (default = CONFIG_SECURITY_TOMOYO_POLICY_LOADER) 14 */ 14 */ 15 static const char *tomoyo_loader; 15 static const char *tomoyo_loader; 16 16 17 /** 17 /** 18 * tomoyo_loader_setup - Set policy loader. 18 * tomoyo_loader_setup - Set policy loader. 19 * 19 * 20 * @str: Program to use as a policy loader (e. 20 * @str: Program to use as a policy loader (e.g. /sbin/tomoyo-init ). 21 * 21 * 22 * Returns 0. 22 * Returns 0. 23 */ 23 */ 24 static int __init tomoyo_loader_setup(char *st 24 static int __init tomoyo_loader_setup(char *str) 25 { 25 { 26 tomoyo_loader = str; 26 tomoyo_loader = str; 27 return 1; !! 27 return 0; 28 } 28 } 29 29 30 __setup("TOMOYO_loader=", tomoyo_loader_setup) 30 __setup("TOMOYO_loader=", tomoyo_loader_setup); 31 31 32 /** 32 /** 33 * tomoyo_policy_loader_exists - Check whether 33 * tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists. 34 * 34 * 35 * Returns true if /sbin/tomoyo-init exists, f 35 * Returns true if /sbin/tomoyo-init exists, false otherwise. 36 */ 36 */ 37 static bool tomoyo_policy_loader_exists(void) 37 static bool tomoyo_policy_loader_exists(void) 38 { 38 { 39 struct path path; 39 struct path path; 40 << 41 if (!tomoyo_loader) 40 if (!tomoyo_loader) 42 tomoyo_loader = CONFIG_SECURIT 41 tomoyo_loader = CONFIG_SECURITY_TOMOYO_POLICY_LOADER; 43 if (kern_path(tomoyo_loader, LOOKUP_FO 42 if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) { 44 pr_info("Not activating Mandat !! 43 printk(KERN_INFO "Not activating Mandatory Access Control " 45 tomoyo_loader); !! 44 "as %s does not exist.\n", tomoyo_loader); 46 return false; 45 return false; 47 } 46 } 48 path_put(&path); 47 path_put(&path); 49 return true; 48 return true; 50 } 49 } 51 50 52 /* 51 /* 53 * Path to the trigger. (default = CONFIG_SECU 52 * Path to the trigger. (default = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER) 54 */ 53 */ 55 static const char *tomoyo_trigger; 54 static const char *tomoyo_trigger; 56 55 57 /** 56 /** 58 * tomoyo_trigger_setup - Set trigger for acti 57 * tomoyo_trigger_setup - Set trigger for activation. 59 * 58 * 60 * @str: Program to use as an activation trigg 59 * @str: Program to use as an activation trigger (e.g. /sbin/init ). 61 * 60 * 62 * Returns 0. 61 * Returns 0. 63 */ 62 */ 64 static int __init tomoyo_trigger_setup(char *s 63 static int __init tomoyo_trigger_setup(char *str) 65 { 64 { 66 tomoyo_trigger = str; 65 tomoyo_trigger = str; 67 return 1; !! 66 return 0; 68 } 67 } 69 68 70 __setup("TOMOYO_trigger=", tomoyo_trigger_setu 69 __setup("TOMOYO_trigger=", tomoyo_trigger_setup); 71 70 72 /** 71 /** 73 * tomoyo_load_policy - Run external policy lo 72 * tomoyo_load_policy - Run external policy loader to load policy. 74 * 73 * 75 * @filename: The program about to start. 74 * @filename: The program about to start. 76 * 75 * 77 * This function checks whether @filename is / 76 * This function checks whether @filename is /sbin/init , and if so 78 * invoke /sbin/tomoyo-init and wait for the t 77 * invoke /sbin/tomoyo-init and wait for the termination of /sbin/tomoyo-init 79 * and then continues invocation of /sbin/init 78 * and then continues invocation of /sbin/init. 80 * /sbin/tomoyo-init reads policy files in /et 79 * /sbin/tomoyo-init reads policy files in /etc/tomoyo/ directory and 81 * writes to /sys/kernel/security/tomoyo/ inte 80 * writes to /sys/kernel/security/tomoyo/ interfaces. 82 * 81 * 83 * Returns nothing. 82 * Returns nothing. 84 */ 83 */ 85 void tomoyo_load_policy(const char *filename) 84 void tomoyo_load_policy(const char *filename) 86 { 85 { 87 static bool done; 86 static bool done; 88 char *argv[2]; 87 char *argv[2]; 89 char *envp[3]; 88 char *envp[3]; 90 89 91 if (tomoyo_policy_loaded || done) 90 if (tomoyo_policy_loaded || done) 92 return; 91 return; 93 if (!tomoyo_trigger) 92 if (!tomoyo_trigger) 94 tomoyo_trigger = CONFIG_SECURI 93 tomoyo_trigger = CONFIG_SECURITY_TOMOYO_ACTIVATION_TRIGGER; 95 if (strcmp(filename, tomoyo_trigger)) 94 if (strcmp(filename, tomoyo_trigger)) 96 return; 95 return; 97 if (!tomoyo_policy_loader_exists()) 96 if (!tomoyo_policy_loader_exists()) 98 return; 97 return; 99 done = true; 98 done = true; 100 pr_info("Calling %s to load policy. Pl !! 99 printk(KERN_INFO "Calling %s to load policy. Please wait.\n", >> 100 tomoyo_loader); 101 argv[0] = (char *) tomoyo_loader; 101 argv[0] = (char *) tomoyo_loader; 102 argv[1] = NULL; 102 argv[1] = NULL; 103 envp[0] = "HOME=/"; 103 envp[0] = "HOME=/"; 104 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/ 104 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; 105 envp[2] = NULL; 105 envp[2] = NULL; 106 call_usermodehelper(argv[0], argv, env 106 call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC); 107 tomoyo_check_profile(); 107 tomoyo_check_profile(); 108 } 108 } 109 109 110 #endif 110 #endif 111 111
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.