Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1 | /* |
| 2 | * security/tomoyo/common.h |
| 3 | * |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 4 | * Header file for TOMOYO. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 5 | * |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 6 | * Copyright (C) 2005-2010 NTT DATA CORPORATION |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _SECURITY_TOMOYO_COMMON_H |
| 10 | #define _SECURITY_TOMOYO_COMMON_H |
| 11 | |
| 12 | #include <linux/ctype.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <linux/mm.h> |
| 15 | #include <linux/file.h> |
| 16 | #include <linux/kmod.h> |
| 17 | #include <linux/fs.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/namei.h> |
| 20 | #include <linux/mount.h> |
| 21 | #include <linux/list.h> |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 22 | #include <linux/cred.h> |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 23 | #include <linux/poll.h> |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 24 | struct linux_binprm; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 25 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 26 | /********** Constants definitions. **********/ |
| 27 | |
| 28 | /* |
| 29 | * TOMOYO uses this hash only when appending a string into the string |
| 30 | * table. Frequency of appending strings is very low. So we don't need |
| 31 | * large (e.g. 64k) hash size. 256 will be sufficient. |
| 32 | */ |
| 33 | #define TOMOYO_HASH_BITS 8 |
| 34 | #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) |
| 35 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 36 | #define TOMOYO_EXEC_TMPSIZE 4096 |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 37 | |
| 38 | /* Profile number is an integer between 0 and 255. */ |
| 39 | #define TOMOYO_MAX_PROFILES 256 |
| 40 | |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 41 | enum tomoyo_mode_index { |
| 42 | TOMOYO_CONFIG_DISABLED, |
| 43 | TOMOYO_CONFIG_LEARNING, |
| 44 | TOMOYO_CONFIG_PERMISSIVE, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 45 | TOMOYO_CONFIG_ENFORCING, |
| 46 | TOMOYO_CONFIG_USE_DEFAULT = 255 |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 47 | }; |
| 48 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 49 | /* Keywords for ACLs. */ |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 50 | #define TOMOYO_KEYWORD_AGGREGATOR "aggregator " |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 51 | #define TOMOYO_KEYWORD_ALIAS "alias " |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 52 | #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount " |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 53 | #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " |
| 54 | #define TOMOYO_KEYWORD_DELETE "delete " |
| 55 | #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " |
| 56 | #define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern " |
| 57 | #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " |
| 58 | #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " |
| 59 | #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " |
| 60 | #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 61 | #define TOMOYO_KEYWORD_PATH_GROUP "path_group " |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 62 | #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group " |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 63 | #define TOMOYO_KEYWORD_SELECT "select " |
| 64 | #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " |
| 65 | #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" |
Tetsuo Handa | 9b244373 | 2010-06-03 20:35:53 +0900 | [diff] [blame] | 66 | #define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded" |
| 67 | #define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed" |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 68 | /* A domain definition starts with <kernel>. */ |
| 69 | #define TOMOYO_ROOT_NAME "<kernel>" |
| 70 | #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) |
| 71 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 72 | /* Value type definition. */ |
| 73 | #define TOMOYO_VALUE_TYPE_INVALID 0 |
| 74 | #define TOMOYO_VALUE_TYPE_DECIMAL 1 |
| 75 | #define TOMOYO_VALUE_TYPE_OCTAL 2 |
| 76 | #define TOMOYO_VALUE_TYPE_HEXADECIMAL 3 |
| 77 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 78 | /* Index numbers for Access Controls. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 79 | enum tomoyo_acl_entry_type_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 80 | TOMOYO_TYPE_PATH_ACL, |
| 81 | TOMOYO_TYPE_PATH2_ACL, |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 82 | TOMOYO_TYPE_PATH_NUMBER_ACL, |
| 83 | TOMOYO_TYPE_PATH_NUMBER3_ACL, |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 84 | TOMOYO_TYPE_MOUNT_ACL, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 85 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 86 | |
| 87 | /* Index numbers for File Controls. */ |
| 88 | |
| 89 | /* |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 90 | * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically |
| 91 | * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set. |
| 92 | * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if |
| 93 | * TOMOYO_TYPE_READ_WRITE is set. |
| 94 | * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ |
| 95 | * or TOMOYO_TYPE_WRITE is cleared. |
| 96 | * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if |
| 97 | * TOMOYO_TYPE_READ_WRITE is cleared. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 98 | */ |
| 99 | |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 100 | enum tomoyo_path_acl_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 101 | TOMOYO_TYPE_READ_WRITE, |
| 102 | TOMOYO_TYPE_EXECUTE, |
| 103 | TOMOYO_TYPE_READ, |
| 104 | TOMOYO_TYPE_WRITE, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 105 | TOMOYO_TYPE_UNLINK, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 106 | TOMOYO_TYPE_RMDIR, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 107 | TOMOYO_TYPE_TRUNCATE, |
| 108 | TOMOYO_TYPE_SYMLINK, |
| 109 | TOMOYO_TYPE_REWRITE, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 110 | TOMOYO_TYPE_CHROOT, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 111 | TOMOYO_TYPE_UMOUNT, |
| 112 | TOMOYO_MAX_PATH_OPERATION |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 113 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 114 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 115 | #define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE)) |
| 116 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 117 | enum tomoyo_path_number3_acl_index { |
| 118 | TOMOYO_TYPE_MKBLOCK, |
| 119 | TOMOYO_TYPE_MKCHAR, |
| 120 | TOMOYO_MAX_PATH_NUMBER3_OPERATION |
| 121 | }; |
| 122 | |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 123 | enum tomoyo_path2_acl_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 124 | TOMOYO_TYPE_LINK, |
| 125 | TOMOYO_TYPE_RENAME, |
| 126 | TOMOYO_TYPE_PIVOT_ROOT, |
| 127 | TOMOYO_MAX_PATH2_OPERATION |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 128 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 129 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 130 | enum tomoyo_path_number_acl_index { |
| 131 | TOMOYO_TYPE_CREATE, |
| 132 | TOMOYO_TYPE_MKDIR, |
| 133 | TOMOYO_TYPE_MKFIFO, |
| 134 | TOMOYO_TYPE_MKSOCK, |
| 135 | TOMOYO_TYPE_IOCTL, |
| 136 | TOMOYO_TYPE_CHMOD, |
| 137 | TOMOYO_TYPE_CHOWN, |
| 138 | TOMOYO_TYPE_CHGRP, |
| 139 | TOMOYO_MAX_PATH_NUMBER_OPERATION |
| 140 | }; |
| 141 | |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 142 | enum tomoyo_securityfs_interface_index { |
| 143 | TOMOYO_DOMAINPOLICY, |
| 144 | TOMOYO_EXCEPTIONPOLICY, |
| 145 | TOMOYO_DOMAIN_STATUS, |
| 146 | TOMOYO_PROCESS_STATUS, |
| 147 | TOMOYO_MEMINFO, |
| 148 | TOMOYO_SELFDOMAIN, |
| 149 | TOMOYO_VERSION, |
| 150 | TOMOYO_PROFILE, |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 151 | TOMOYO_QUERY, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 152 | TOMOYO_MANAGER |
| 153 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 154 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 155 | enum tomoyo_mac_index { |
| 156 | TOMOYO_MAC_FILE_EXECUTE, |
| 157 | TOMOYO_MAC_FILE_OPEN, |
| 158 | TOMOYO_MAC_FILE_CREATE, |
| 159 | TOMOYO_MAC_FILE_UNLINK, |
| 160 | TOMOYO_MAC_FILE_MKDIR, |
| 161 | TOMOYO_MAC_FILE_RMDIR, |
| 162 | TOMOYO_MAC_FILE_MKFIFO, |
| 163 | TOMOYO_MAC_FILE_MKSOCK, |
| 164 | TOMOYO_MAC_FILE_TRUNCATE, |
| 165 | TOMOYO_MAC_FILE_SYMLINK, |
| 166 | TOMOYO_MAC_FILE_REWRITE, |
| 167 | TOMOYO_MAC_FILE_MKBLOCK, |
| 168 | TOMOYO_MAC_FILE_MKCHAR, |
| 169 | TOMOYO_MAC_FILE_LINK, |
| 170 | TOMOYO_MAC_FILE_RENAME, |
| 171 | TOMOYO_MAC_FILE_CHMOD, |
| 172 | TOMOYO_MAC_FILE_CHOWN, |
| 173 | TOMOYO_MAC_FILE_CHGRP, |
| 174 | TOMOYO_MAC_FILE_IOCTL, |
| 175 | TOMOYO_MAC_FILE_CHROOT, |
| 176 | TOMOYO_MAC_FILE_MOUNT, |
| 177 | TOMOYO_MAC_FILE_UMOUNT, |
| 178 | TOMOYO_MAC_FILE_PIVOT_ROOT, |
| 179 | TOMOYO_MAX_MAC_INDEX |
| 180 | }; |
| 181 | |
| 182 | enum tomoyo_mac_category_index { |
| 183 | TOMOYO_MAC_CATEGORY_FILE, |
| 184 | TOMOYO_MAX_MAC_CATEGORY_INDEX |
| 185 | }; |
| 186 | |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 187 | #define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */ |
| 188 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 189 | /********** Structure definitions. **********/ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 190 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 191 | /* |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 192 | * tomoyo_acl_head is a structure which is used for holding elements not in |
| 193 | * domain policy. |
| 194 | * It has following fields. |
| 195 | * |
| 196 | * (1) "list" which is linked to tomoyo_policy_list[] . |
| 197 | * (2) "is_deleted" is a bool which is true if marked as deleted, false |
| 198 | * otherwise. |
| 199 | */ |
| 200 | struct tomoyo_acl_head { |
| 201 | struct list_head list; |
| 202 | bool is_deleted; |
| 203 | } __packed; |
| 204 | |
| 205 | /* |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 206 | * tomoyo_request_info is a structure which is used for holding |
| 207 | * |
| 208 | * (1) Domain information of current process. |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 209 | * (2) How many retries are made for this request. |
| 210 | * (3) Profile number used for this request. |
| 211 | * (4) Access control mode of the profile. |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 212 | */ |
| 213 | struct tomoyo_request_info { |
| 214 | struct tomoyo_domain_info *domain; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 215 | u8 retry; |
| 216 | u8 profile; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 217 | u8 mode; /* One of tomoyo_mode_index . */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 218 | u8 type; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | /* |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 222 | * tomoyo_path_info is a structure which is used for holding a string data |
| 223 | * used by TOMOYO. |
| 224 | * This structure has several fields for supporting pattern matching. |
| 225 | * |
| 226 | * (1) "name" is the '\0' terminated string data. |
| 227 | * (2) "hash" is full_name_hash(name, strlen(name)). |
| 228 | * This allows tomoyo_pathcmp() to compare by hash before actually compare |
| 229 | * using strcmp(). |
| 230 | * (3) "const_len" is the length of the initial segment of "name" which |
| 231 | * consists entirely of non wildcard characters. In other words, the length |
| 232 | * which we can compare two strings using strncmp(). |
| 233 | * (4) "is_dir" is a bool which is true if "name" ends with "/", |
| 234 | * false otherwise. |
| 235 | * TOMOYO distinguishes directory and non-directory. A directory ends with |
| 236 | * "/" and non-directory does not end with "/". |
| 237 | * (5) "is_patterned" is a bool which is true if "name" contains wildcard |
| 238 | * characters, false otherwise. This allows TOMOYO to use "hash" and |
| 239 | * strcmp() for string comparison if "is_patterned" is false. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 240 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 241 | struct tomoyo_path_info { |
| 242 | const char *name; |
| 243 | u32 hash; /* = full_name_hash(name, strlen(name)) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 244 | u16 const_len; /* = tomoyo_const_part_length(name) */ |
| 245 | bool is_dir; /* = tomoyo_strendswith(name, "/") */ |
| 246 | bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | /* |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 250 | * tomoyo_name_entry is a structure which is used for linking |
| 251 | * "struct tomoyo_path_info" into tomoyo_name_list . |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 252 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 253 | struct tomoyo_name_entry { |
| 254 | struct list_head list; |
| 255 | atomic_t users; |
| 256 | struct tomoyo_path_info entry; |
| 257 | }; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 258 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 259 | struct tomoyo_name_union { |
| 260 | const struct tomoyo_path_info *filename; |
| 261 | struct tomoyo_path_group *group; |
| 262 | u8 is_group; |
| 263 | }; |
| 264 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 265 | struct tomoyo_number_union { |
| 266 | unsigned long values[2]; |
| 267 | struct tomoyo_number_group *group; |
| 268 | u8 min_type; |
| 269 | u8 max_type; |
| 270 | u8 is_group; |
| 271 | }; |
| 272 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 273 | /* Structure for "path_group" directive. */ |
| 274 | struct tomoyo_path_group { |
| 275 | struct list_head list; |
| 276 | const struct tomoyo_path_info *group_name; |
| 277 | struct list_head member_list; |
| 278 | atomic_t users; |
| 279 | }; |
| 280 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 281 | /* Structure for "number_group" directive. */ |
| 282 | struct tomoyo_number_group { |
| 283 | struct list_head list; |
| 284 | const struct tomoyo_path_info *group_name; |
| 285 | struct list_head member_list; |
| 286 | atomic_t users; |
| 287 | }; |
| 288 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 289 | /* Structure for "path_group" directive. */ |
| 290 | struct tomoyo_path_group_member { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 291 | struct tomoyo_acl_head head; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 292 | const struct tomoyo_path_info *member_name; |
| 293 | }; |
| 294 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 295 | /* Structure for "number_group" directive. */ |
| 296 | struct tomoyo_number_group_member { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 297 | struct tomoyo_acl_head head; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 298 | struct tomoyo_number_union number; |
| 299 | }; |
| 300 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 301 | /* |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 302 | * tomoyo_acl_info is a structure which is used for holding |
| 303 | * |
| 304 | * (1) "list" which is linked to the ->acl_info_list of |
| 305 | * "struct tomoyo_domain_info" |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 306 | * (2) "is_deleted" is a bool which is true if this domain is marked as |
| 307 | * "deleted", false otherwise. |
| 308 | * (3) "type" which tells type of the entry. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 309 | * |
| 310 | * Packing "struct tomoyo_acl_info" allows |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 311 | * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl" |
| 312 | * "struct tomoyo_path_number_acl" "struct tomoyo_path_number3_acl" to embed |
| 313 | * "u8" without enlarging their structure size. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 314 | */ |
| 315 | struct tomoyo_acl_info { |
| 316 | struct list_head list; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 317 | bool is_deleted; |
| 318 | u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 319 | } __packed; |
| 320 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 321 | /* |
| 322 | * tomoyo_domain_info is a structure which is used for holding permissions |
| 323 | * (e.g. "allow_read /lib/libc-2.5.so") given to each domain. |
| 324 | * It has following fields. |
| 325 | * |
| 326 | * (1) "list" which is linked to tomoyo_domain_list . |
| 327 | * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info". |
| 328 | * (3) "domainname" which holds the name of the domain. |
| 329 | * (4) "profile" which remembers profile number assigned to this domain. |
| 330 | * (5) "is_deleted" is a bool which is true if this domain is marked as |
| 331 | * "deleted", false otherwise. |
| 332 | * (6) "quota_warned" is a bool which is used for suppressing warning message |
| 333 | * when learning mode learned too much entries. |
Tetsuo Handa | ea13ddb | 2010-02-03 06:43:06 +0900 | [diff] [blame] | 334 | * (7) "ignore_global_allow_read" is a bool which is true if this domain |
| 335 | * should ignore "allow_read" directive in exception policy. |
| 336 | * (8) "transition_failed" is a bool which is set to true when this domain was |
| 337 | * unable to create a new domain at tomoyo_find_next_domain() because the |
| 338 | * name of the domain to be created was too long or it could not allocate |
| 339 | * memory. If set to true, more than one process continued execve() |
| 340 | * without domain transition. |
Tetsuo Handa | ec8e6a4 | 2010-02-11 09:43:20 +0900 | [diff] [blame] | 341 | * (9) "users" is an atomic_t that holds how many "struct cred"->security |
| 342 | * are referring this "struct tomoyo_domain_info". If is_deleted == true |
| 343 | * and users == 0, this struct will be kfree()d upon next garbage |
| 344 | * collection. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 345 | * |
| 346 | * A domain's lifecycle is an analogy of files on / directory. |
| 347 | * Multiple domains with the same domainname cannot be created (as with |
| 348 | * creating files with the same filename fails with -EEXIST). |
| 349 | * If a process reached a domain, that process can reside in that domain after |
| 350 | * that domain is marked as "deleted" (as with a process can access an already |
| 351 | * open()ed file after that file was unlink()ed). |
| 352 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 353 | struct tomoyo_domain_info { |
| 354 | struct list_head list; |
| 355 | struct list_head acl_info_list; |
| 356 | /* Name of this domain. Never NULL. */ |
| 357 | const struct tomoyo_path_info *domainname; |
| 358 | u8 profile; /* Profile number to use. */ |
Tetsuo Handa | a0558fc | 2009-04-06 20:49:14 +0900 | [diff] [blame] | 359 | bool is_deleted; /* Delete flag. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 360 | bool quota_warned; /* Quota warnning flag. */ |
Tetsuo Handa | ea13ddb | 2010-02-03 06:43:06 +0900 | [diff] [blame] | 361 | bool ignore_global_allow_read; /* Ignore "allow_read" flag. */ |
| 362 | bool transition_failed; /* Domain transition failed flag. */ |
Tetsuo Handa | ec8e6a4 | 2010-02-11 09:43:20 +0900 | [diff] [blame] | 363 | atomic_t users; /* Number of referring credentials. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 364 | }; |
| 365 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 366 | /* |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 367 | * tomoyo_path_acl is a structure which is used for holding an |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 368 | * entry with one pathname operation (e.g. open(), mkdir()). |
| 369 | * It has following fields. |
| 370 | * |
| 371 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 372 | * (2) "perm" which is a bitmask of permitted operations. |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 373 | * (3) "name" is the pathname. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 374 | * |
| 375 | * Directives held by this structure are "allow_read/write", "allow_execute", |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 376 | * "allow_read", "allow_write", "allow_unlink", "allow_rmdir", |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 377 | * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and |
| 378 | * "allow_unmount". |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 379 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 380 | struct tomoyo_path_acl { |
| 381 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 382 | u16 perm; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 383 | struct tomoyo_name_union name; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 384 | }; |
| 385 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 386 | /* |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 387 | * tomoyo_path_number_acl is a structure which is used for holding an |
| 388 | * entry with one pathname and one number operation. |
| 389 | * It has following fields. |
| 390 | * |
| 391 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 392 | * (2) "perm" which is a bitmask of permitted operations. |
| 393 | * (3) "name" is the pathname. |
| 394 | * (4) "number" is the numeric value. |
| 395 | * |
| 396 | * Directives held by this structure are "allow_create", "allow_mkdir", |
| 397 | * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown" |
| 398 | * and "allow_chgrp". |
| 399 | * |
| 400 | */ |
| 401 | struct tomoyo_path_number_acl { |
| 402 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ |
| 403 | u8 perm; |
| 404 | struct tomoyo_name_union name; |
| 405 | struct tomoyo_number_union number; |
| 406 | }; |
| 407 | |
| 408 | /* |
| 409 | * tomoyo_path_number3_acl is a structure which is used for holding an |
| 410 | * entry with one pathname and three numbers operation. |
| 411 | * It has following fields. |
| 412 | * |
| 413 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 414 | * (2) "perm" which is a bitmask of permitted operations. |
| 415 | * (3) "mode" is the create mode. |
| 416 | * (4) "major" is the major number of device node. |
| 417 | * (5) "minor" is the minor number of device node. |
| 418 | * |
| 419 | * Directives held by this structure are "allow_mkchar", "allow_mkblock". |
| 420 | * |
| 421 | */ |
| 422 | struct tomoyo_path_number3_acl { |
| 423 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER3_ACL */ |
| 424 | u8 perm; |
| 425 | struct tomoyo_name_union name; |
| 426 | struct tomoyo_number_union mode; |
| 427 | struct tomoyo_number_union major; |
| 428 | struct tomoyo_number_union minor; |
| 429 | }; |
| 430 | |
| 431 | /* |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 432 | * tomoyo_path2_acl is a structure which is used for holding an |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 433 | * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 434 | * It has following fields. |
| 435 | * |
| 436 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 437 | * (2) "perm" which is a bitmask of permitted operations. |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 438 | * (3) "name1" is the source/old pathname. |
| 439 | * (4) "name2" is the destination/new pathname. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 440 | * |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 441 | * Directives held by this structure are "allow_rename", "allow_link" and |
| 442 | * "allow_pivot_root". |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 443 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 444 | struct tomoyo_path2_acl { |
| 445 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 446 | u8 perm; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 447 | struct tomoyo_name_union name1; |
| 448 | struct tomoyo_name_union name2; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 449 | }; |
| 450 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 451 | /* |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 452 | * tomoyo_mount_acl is a structure which is used for holding an |
| 453 | * entry for mount operation. |
| 454 | * It has following fields. |
| 455 | * |
| 456 | * (1) "head" which is a "struct tomoyo_acl_info". |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 457 | * (2) "dev_name" is the device name. |
| 458 | * (3) "dir_name" is the mount point. |
| 459 | * (4) "fs_type" is the filesystem type. |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 460 | * (5) "flags" is the mount flags. |
| 461 | * |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 462 | * Directive held by this structure is "allow_mount". |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 463 | */ |
| 464 | struct tomoyo_mount_acl { |
| 465 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 466 | struct tomoyo_name_union dev_name; |
| 467 | struct tomoyo_name_union dir_name; |
| 468 | struct tomoyo_name_union fs_type; |
| 469 | struct tomoyo_number_union flags; |
| 470 | }; |
| 471 | |
| 472 | /* |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 473 | * tomoyo_io_buffer is a structure which is used for reading and modifying |
| 474 | * configuration via /sys/kernel/security/tomoyo/ interface. |
| 475 | * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as |
| 476 | * cursors. |
| 477 | * |
| 478 | * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of |
| 479 | * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info" |
| 480 | * entry has a list of "struct tomoyo_acl_info", we need two cursors when |
| 481 | * reading (one is for traversing tomoyo_domain_list and the other is for |
| 482 | * traversing "struct tomoyo_acl_info"->acl_info_list ). |
| 483 | * |
| 484 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with |
| 485 | * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the |
| 486 | * domain with the domainname specified by the rest of that line (NULL is set |
| 487 | * if seek failed). |
| 488 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with |
| 489 | * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that |
| 490 | * line (->write_var1 is set to NULL if a domain was deleted). |
| 491 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with |
| 492 | * neither "select " nor "delete ", an entry or a domain specified by that line |
| 493 | * is appended. |
| 494 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 495 | struct tomoyo_io_buffer { |
| 496 | int (*read) (struct tomoyo_io_buffer *); |
| 497 | int (*write) (struct tomoyo_io_buffer *); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 498 | int (*poll) (struct file *file, poll_table *wait); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 499 | /* Exclusive lock for this structure. */ |
| 500 | struct mutex io_sem; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 501 | /* Index returned by tomoyo_read_lock(). */ |
| 502 | int reader_idx; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 503 | /* The position currently reading from. */ |
| 504 | struct list_head *read_var1; |
| 505 | /* Extra variables for reading. */ |
| 506 | struct list_head *read_var2; |
| 507 | /* The position currently writing to. */ |
| 508 | struct tomoyo_domain_info *write_var1; |
| 509 | /* The step for reading. */ |
| 510 | int read_step; |
| 511 | /* Buffer for reading. */ |
| 512 | char *read_buf; |
| 513 | /* EOF flag for reading. */ |
| 514 | bool read_eof; |
| 515 | /* Read domain ACL of specified PID? */ |
| 516 | bool read_single_domain; |
| 517 | /* Extra variable for reading. */ |
| 518 | u8 read_bit; |
| 519 | /* Bytes available for reading. */ |
| 520 | int read_avail; |
| 521 | /* Size of read buffer. */ |
| 522 | int readbuf_size; |
| 523 | /* Buffer for writing. */ |
| 524 | char *write_buf; |
| 525 | /* Bytes available for writing. */ |
| 526 | int write_avail; |
| 527 | /* Size of write buffer. */ |
| 528 | int writebuf_size; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 529 | /* Type of this interface. */ |
| 530 | u8 type; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 531 | }; |
| 532 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 533 | /* |
| 534 | * tomoyo_globally_readable_file_entry is a structure which is used for holding |
| 535 | * "allow_read" entries. |
| 536 | * It has following fields. |
| 537 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 538 | * (1) "head" is "struct tomoyo_acl_head". |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 539 | * (2) "filename" is a pathname which is allowed to open(O_RDONLY). |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 540 | */ |
| 541 | struct tomoyo_globally_readable_file_entry { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 542 | struct tomoyo_acl_head head; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 543 | const struct tomoyo_path_info *filename; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 544 | }; |
| 545 | |
| 546 | /* |
| 547 | * tomoyo_pattern_entry is a structure which is used for holding |
| 548 | * "tomoyo_pattern_list" entries. |
| 549 | * It has following fields. |
| 550 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 551 | * (1) "head" is "struct tomoyo_acl_head". |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 552 | * (2) "pattern" is a pathname pattern which is used for converting pathnames |
| 553 | * to pathname patterns during learning mode. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 554 | */ |
| 555 | struct tomoyo_pattern_entry { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 556 | struct tomoyo_acl_head head; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 557 | const struct tomoyo_path_info *pattern; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 558 | }; |
| 559 | |
| 560 | /* |
| 561 | * tomoyo_no_rewrite_entry is a structure which is used for holding |
| 562 | * "deny_rewrite" entries. |
| 563 | * It has following fields. |
| 564 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 565 | * (1) "head" is "struct tomoyo_acl_head". |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 566 | * (2) "pattern" is a pathname which is by default not permitted to modify |
| 567 | * already existing content. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 568 | */ |
| 569 | struct tomoyo_no_rewrite_entry { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 570 | struct tomoyo_acl_head head; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 571 | const struct tomoyo_path_info *pattern; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 572 | }; |
| 573 | |
| 574 | /* |
| 575 | * tomoyo_domain_initializer_entry is a structure which is used for holding |
| 576 | * "initialize_domain" and "no_initialize_domain" entries. |
| 577 | * It has following fields. |
| 578 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 579 | * (1) "head" is "struct tomoyo_acl_head". |
| 580 | * (2) "is_not" is a bool which is true if "no_initialize_domain", false |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 581 | * otherwise. |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 582 | * (3) "is_last_name" is a bool which is true if "domainname" is "the last |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 583 | * component of a domainname", false otherwise. |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 584 | * (4) "domainname" which is "a domainname" or "the last component of a |
| 585 | * domainname". This field is NULL if "from" clause is not specified. |
| 586 | * (5) "program" which is a program's pathname. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 587 | */ |
| 588 | struct tomoyo_domain_initializer_entry { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 589 | struct tomoyo_acl_head head; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 590 | bool is_not; /* True if this entry is "no_initialize_domain". */ |
| 591 | /* True if the domainname is tomoyo_get_last_name(). */ |
| 592 | bool is_last_name; |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 593 | const struct tomoyo_path_info *domainname; /* This may be NULL */ |
| 594 | const struct tomoyo_path_info *program; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 595 | }; |
| 596 | |
| 597 | /* |
| 598 | * tomoyo_domain_keeper_entry is a structure which is used for holding |
| 599 | * "keep_domain" and "no_keep_domain" entries. |
| 600 | * It has following fields. |
| 601 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 602 | * (1) "head" is "struct tomoyo_acl_head". |
| 603 | * (2) "is_not" is a bool which is true if "no_initialize_domain", false |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 604 | * otherwise. |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 605 | * (3) "is_last_name" is a bool which is true if "domainname" is "the last |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 606 | * component of a domainname", false otherwise. |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 607 | * (4) "domainname" which is "a domainname" or "the last component of a |
| 608 | * domainname". |
| 609 | * (5) "program" which is a program's pathname. |
| 610 | * This field is NULL if "from" clause is not specified. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 611 | */ |
| 612 | struct tomoyo_domain_keeper_entry { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 613 | struct tomoyo_acl_head head; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 614 | bool is_not; /* True if this entry is "no_keep_domain". */ |
| 615 | /* True if the domainname is tomoyo_get_last_name(). */ |
| 616 | bool is_last_name; |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 617 | const struct tomoyo_path_info *domainname; |
| 618 | const struct tomoyo_path_info *program; /* This may be NULL */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 619 | }; |
| 620 | |
| 621 | /* |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 622 | * tomoyo_aggregator_entry is a structure which is used for holding |
| 623 | * "aggregator" entries. |
| 624 | * It has following fields. |
| 625 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 626 | * (1) "head" is "struct tomoyo_acl_head". |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 627 | * (2) "original_name" which is originally requested name. |
| 628 | * (3) "aggregated_name" which is name to rewrite. |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 629 | */ |
| 630 | struct tomoyo_aggregator_entry { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 631 | struct tomoyo_acl_head head; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 632 | const struct tomoyo_path_info *original_name; |
| 633 | const struct tomoyo_path_info *aggregated_name; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 634 | }; |
| 635 | |
| 636 | /* |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 637 | * tomoyo_alias_entry is a structure which is used for holding "alias" entries. |
| 638 | * It has following fields. |
| 639 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 640 | * (1) "head" is "struct tomoyo_acl_head". |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 641 | * (2) "original_name" which is a dereferenced pathname. |
| 642 | * (3) "aliased_name" which is a symlink's pathname. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 643 | */ |
| 644 | struct tomoyo_alias_entry { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 645 | struct tomoyo_acl_head head; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 646 | const struct tomoyo_path_info *original_name; |
| 647 | const struct tomoyo_path_info *aliased_name; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 648 | }; |
| 649 | |
| 650 | /* |
| 651 | * tomoyo_policy_manager_entry is a structure which is used for holding list of |
| 652 | * domainnames or programs which are permitted to modify configuration via |
| 653 | * /sys/kernel/security/tomoyo/ interface. |
| 654 | * It has following fields. |
| 655 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 656 | * (1) "head" is "struct tomoyo_acl_head". |
| 657 | * (2) "is_domain" is a bool which is true if "manager" is a domainname, false |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 658 | * otherwise. |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 659 | * (3) "manager" is a domainname or a program's pathname. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 660 | */ |
| 661 | struct tomoyo_policy_manager_entry { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame^] | 662 | struct tomoyo_acl_head head; |
| 663 | bool is_domain; /* True if manager is a domainname. */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 664 | /* A path to program or a domainname. */ |
| 665 | const struct tomoyo_path_info *manager; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 666 | }; |
| 667 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 668 | struct tomoyo_preference { |
| 669 | unsigned int learning_max_entry; |
| 670 | bool enforcing_verbose; |
| 671 | bool learning_verbose; |
| 672 | bool permissive_verbose; |
| 673 | }; |
| 674 | |
| 675 | struct tomoyo_profile { |
| 676 | const struct tomoyo_path_info *comment; |
| 677 | struct tomoyo_preference *learning; |
| 678 | struct tomoyo_preference *permissive; |
| 679 | struct tomoyo_preference *enforcing; |
| 680 | struct tomoyo_preference preference; |
| 681 | u8 default_config; |
| 682 | u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; |
| 683 | }; |
| 684 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 685 | /********** Function prototypes. **********/ |
| 686 | |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 687 | extern asmlinkage long sys_getpid(void); |
| 688 | extern asmlinkage long sys_getppid(void); |
| 689 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 690 | /* Check whether the given string starts with the given keyword. */ |
| 691 | bool tomoyo_str_starts(char **src, const char *find); |
| 692 | /* Get tomoyo_realpath() of current process. */ |
| 693 | const char *tomoyo_get_exe(void); |
| 694 | /* Format string. */ |
| 695 | void tomoyo_normalize_line(unsigned char *buffer); |
| 696 | /* Print warning or error message on console. */ |
| 697 | void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...) |
| 698 | __attribute__ ((format(printf, 2, 3))); |
| 699 | /* Check all profiles currently assigned to domains are defined. */ |
| 700 | void tomoyo_check_profile(void); |
| 701 | /* Open operation for /sys/kernel/security/tomoyo/ interface. */ |
| 702 | int tomoyo_open_control(const u8 type, struct file *file); |
| 703 | /* Close /sys/kernel/security/tomoyo/ interface. */ |
| 704 | int tomoyo_close_control(struct file *file); |
| 705 | /* Read operation for /sys/kernel/security/tomoyo/ interface. */ |
| 706 | int tomoyo_read_control(struct file *file, char __user *buffer, |
| 707 | const int buffer_len); |
| 708 | /* Write operation for /sys/kernel/security/tomoyo/ interface. */ |
| 709 | int tomoyo_write_control(struct file *file, const char __user *buffer, |
| 710 | const int buffer_len); |
| 711 | /* Check whether the domain has too many ACL entries to hold. */ |
| 712 | bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); |
| 713 | /* Print out of memory warning message. */ |
| 714 | void tomoyo_warn_oom(const char *function); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 715 | /* Check whether the given name matches the given name_union. */ |
| 716 | bool tomoyo_compare_name_union(const struct tomoyo_path_info *name, |
| 717 | const struct tomoyo_name_union *ptr); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 718 | /* Check whether the given number matches the given number_union. */ |
| 719 | bool tomoyo_compare_number_union(const unsigned long value, |
| 720 | const struct tomoyo_number_union *ptr); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 721 | int tomoyo_get_mode(const u8 profile, const u8 index); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 722 | /* Transactional sprintf() for policy dump. */ |
| 723 | bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) |
| 724 | __attribute__ ((format(printf, 2, 3))); |
| 725 | /* Check whether the domainname is correct. */ |
Tetsuo Handa | 1708000 | 2010-02-16 21:14:48 +0900 | [diff] [blame] | 726 | bool tomoyo_is_correct_domain(const unsigned char *domainname); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 727 | /* Check whether the token is correct. */ |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 728 | bool tomoyo_is_correct_path(const char *filename); |
| 729 | bool tomoyo_is_correct_word(const char *string); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 730 | /* Check whether the token can be a domainname. */ |
| 731 | bool tomoyo_is_domain_def(const unsigned char *buffer); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 732 | bool tomoyo_parse_name_union(const char *filename, |
| 733 | struct tomoyo_name_union *ptr); |
| 734 | /* Check whether the given filename matches the given path_group. */ |
| 735 | bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 736 | const struct tomoyo_path_group *group); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 737 | /* Check whether the given value matches the given number_group. */ |
| 738 | bool tomoyo_number_matches_group(const unsigned long min, |
| 739 | const unsigned long max, |
| 740 | const struct tomoyo_number_group *group); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 741 | /* Check whether the given filename matches the given pattern. */ |
| 742 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, |
| 743 | const struct tomoyo_path_info *pattern); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 744 | |
| 745 | bool tomoyo_print_number_union(struct tomoyo_io_buffer *head, |
| 746 | const struct tomoyo_number_union *ptr); |
| 747 | bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num); |
| 748 | |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 749 | /* Read "aggregator" entry in exception policy. */ |
| 750 | bool tomoyo_read_aggregator_policy(struct tomoyo_io_buffer *head); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 751 | /* Read "alias" entry in exception policy. */ |
| 752 | bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head); |
| 753 | /* |
| 754 | * Read "initialize_domain" and "no_initialize_domain" entry |
| 755 | * in exception policy. |
| 756 | */ |
| 757 | bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head); |
| 758 | /* Read "keep_domain" and "no_keep_domain" entry in exception policy. */ |
| 759 | bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head); |
| 760 | /* Read "file_pattern" entry in exception policy. */ |
| 761 | bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 762 | /* Read "path_group" entry in exception policy. */ |
| 763 | bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 764 | /* Read "number_group" entry in exception policy. */ |
| 765 | bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 766 | /* Read "allow_read" entry in exception policy. */ |
| 767 | bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head); |
| 768 | /* Read "deny_rewrite" entry in exception policy. */ |
| 769 | bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 770 | /* Tokenize a line. */ |
| 771 | bool tomoyo_tokenize(char *buffer, char *w[], size_t size); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 772 | /* Write domain policy violation warning message to console? */ |
| 773 | bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); |
| 774 | /* Convert double path operation to operation name. */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 775 | const char *tomoyo_path22keyword(const u8 operation); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 776 | const char *tomoyo_path_number2keyword(const u8 operation); |
| 777 | const char *tomoyo_path_number32keyword(const u8 operation); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 778 | /* Get the last component of the given domainname. */ |
| 779 | const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 780 | /* Convert single path operation to operation name. */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 781 | const char *tomoyo_path2keyword(const u8 operation); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 782 | /* Fill "struct tomoyo_request_info". */ |
| 783 | int tomoyo_init_request_info(struct tomoyo_request_info *r, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 784 | struct tomoyo_domain_info *domain, |
| 785 | const u8 index); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 786 | /* Check permission for mount operation. */ |
| 787 | int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, |
| 788 | unsigned long flags, void *data_page); |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 789 | /* Create "aggregator" entry in exception policy. */ |
| 790 | int tomoyo_write_aggregator_policy(char *data, const bool is_delete); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 791 | /* Create "alias" entry in exception policy. */ |
| 792 | int tomoyo_write_alias_policy(char *data, const bool is_delete); |
| 793 | /* |
| 794 | * Create "initialize_domain" and "no_initialize_domain" entry |
| 795 | * in exception policy. |
| 796 | */ |
| 797 | int tomoyo_write_domain_initializer_policy(char *data, const bool is_not, |
| 798 | const bool is_delete); |
| 799 | /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */ |
| 800 | int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, |
| 801 | const bool is_delete); |
| 802 | /* |
| 803 | * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", |
| 804 | * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", |
| 805 | * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", |
| 806 | * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and |
| 807 | * "allow_link" entry in domain policy. |
| 808 | */ |
| 809 | int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, |
| 810 | const bool is_delete); |
| 811 | /* Create "allow_read" entry in exception policy. */ |
| 812 | int tomoyo_write_globally_readable_policy(char *data, const bool is_delete); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 813 | /* Create "allow_mount" entry in domain policy. */ |
| 814 | int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain, |
| 815 | const bool is_delete); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 816 | /* Create "deny_rewrite" entry in exception policy. */ |
| 817 | int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); |
| 818 | /* Create "file_pattern" entry in exception policy. */ |
| 819 | int tomoyo_write_pattern_policy(char *data, const bool is_delete); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 820 | /* Create "path_group" entry in exception policy. */ |
| 821 | int tomoyo_write_path_group_policy(char *data, const bool is_delete); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 822 | int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) |
| 823 | __attribute__ ((format(printf, 2, 3))); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 824 | /* Create "number_group" entry in exception policy. */ |
| 825 | int tomoyo_write_number_group_policy(char *data, const bool is_delete); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 826 | /* Find a domain by the given name. */ |
| 827 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); |
| 828 | /* Find or create a domain by the given name. */ |
| 829 | struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * |
| 830 | domainname, |
| 831 | const u8 profile); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 832 | struct tomoyo_profile *tomoyo_profile(const u8 profile); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 833 | /* Allocate memory for "struct tomoyo_path_group". */ |
| 834 | struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 835 | struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 836 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 837 | /* Check mode for specified functionality. */ |
| 838 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, |
| 839 | const u8 index); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 840 | /* Fill in "struct tomoyo_path_info" members. */ |
| 841 | void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); |
| 842 | /* Run policy loader when /sbin/init starts. */ |
| 843 | void tomoyo_load_policy(const char *filename); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 844 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 845 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr); |
| 846 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 847 | /* Convert binary string to ascii string. */ |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 848 | char *tomoyo_encode(const char *str); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 849 | |
| 850 | /* |
| 851 | * Returns realpath(3) of the given pathname but ignores chroot'ed root. |
| 852 | * These functions use kzalloc(), so the caller must call kfree() |
| 853 | * if these functions didn't return NULL. |
| 854 | */ |
| 855 | char *tomoyo_realpath(const char *pathname); |
| 856 | /* |
| 857 | * Same with tomoyo_realpath() except that it doesn't follow the final symlink. |
| 858 | */ |
| 859 | char *tomoyo_realpath_nofollow(const char *pathname); |
| 860 | /* Same with tomoyo_realpath() except that the pathname is already solved. */ |
| 861 | char *tomoyo_realpath_from_path(struct path *path); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 862 | /* Get patterned pathname. */ |
| 863 | const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 864 | |
| 865 | /* Check memory quota. */ |
| 866 | bool tomoyo_memory_ok(void *ptr); |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 867 | void *tomoyo_commit_ok(void *data, const unsigned int size); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 868 | |
| 869 | /* |
| 870 | * Keep the given name on the RAM. |
| 871 | * The RAM is shared, so NEVER try to modify or kfree() the returned name. |
| 872 | */ |
| 873 | const struct tomoyo_path_info *tomoyo_get_name(const char *name); |
| 874 | |
| 875 | /* Check for memory usage. */ |
| 876 | int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); |
| 877 | |
| 878 | /* Set memory quota. */ |
| 879 | int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); |
| 880 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 881 | /* Initialize mm related code. */ |
| 882 | void __init tomoyo_mm_init(void); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 883 | int tomoyo_check_exec_perm(struct tomoyo_request_info *r, |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 884 | const struct tomoyo_path_info *filename); |
| 885 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |
| 886 | struct path *path, const int flag); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 887 | int tomoyo_path_number_perm(const u8 operation, struct path *path, |
| 888 | unsigned long number); |
| 889 | int tomoyo_path_number3_perm(const u8 operation, struct path *path, |
| 890 | const unsigned int mode, unsigned int dev); |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 891 | int tomoyo_path_perm(const u8 operation, struct path *path); |
| 892 | int tomoyo_path2_perm(const u8 operation, struct path *path1, |
| 893 | struct path *path2); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 894 | int tomoyo_find_next_domain(struct linux_binprm *bprm); |
| 895 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 896 | void tomoyo_print_ulong(char *buffer, const int buffer_len, |
| 897 | const unsigned long value, const u8 type); |
| 898 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 899 | /* Drop refcount on tomoyo_name_union. */ |
| 900 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr); |
| 901 | |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 902 | /* Run garbage collector. */ |
| 903 | void tomoyo_run_gc(void); |
| 904 | |
| 905 | void tomoyo_memory_free(void *ptr); |
| 906 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 907 | int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, |
| 908 | bool is_delete, struct tomoyo_domain_info *domain, |
| 909 | bool (*check_duplicate) (const struct tomoyo_acl_info |
| 910 | *, |
| 911 | const struct tomoyo_acl_info |
| 912 | *), |
| 913 | bool (*merge_duplicate) (struct tomoyo_acl_info *, |
| 914 | struct tomoyo_acl_info *, |
| 915 | const bool)); |
| 916 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 917 | /********** External variable definitions. **********/ |
| 918 | |
| 919 | /* Lock for GC. */ |
| 920 | extern struct srcu_struct tomoyo_ss; |
| 921 | |
| 922 | /* The list for "struct tomoyo_domain_info". */ |
| 923 | extern struct list_head tomoyo_domain_list; |
| 924 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 925 | extern struct list_head tomoyo_path_group_list; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 926 | extern struct list_head tomoyo_number_group_list; |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 927 | extern struct list_head tomoyo_domain_initializer_list; |
| 928 | extern struct list_head tomoyo_domain_keeper_list; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 929 | extern struct list_head tomoyo_aggregator_list; |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 930 | extern struct list_head tomoyo_alias_list; |
| 931 | extern struct list_head tomoyo_globally_readable_list; |
| 932 | extern struct list_head tomoyo_pattern_list; |
| 933 | extern struct list_head tomoyo_no_rewrite_list; |
| 934 | extern struct list_head tomoyo_policy_manager_list; |
| 935 | extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 936 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 937 | /* Lock for protecting policy. */ |
| 938 | extern struct mutex tomoyo_policy_lock; |
| 939 | |
| 940 | /* Has /sbin/init started? */ |
| 941 | extern bool tomoyo_policy_loaded; |
| 942 | |
| 943 | /* The kernel's domain. */ |
| 944 | extern struct tomoyo_domain_info tomoyo_kernel_domain; |
| 945 | |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 946 | extern unsigned int tomoyo_quota_for_query; |
| 947 | extern unsigned int tomoyo_query_memory_size; |
| 948 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 949 | /********** Inlined functions. **********/ |
| 950 | |
| 951 | static inline int tomoyo_read_lock(void) |
| 952 | { |
| 953 | return srcu_read_lock(&tomoyo_ss); |
| 954 | } |
| 955 | |
| 956 | static inline void tomoyo_read_unlock(int idx) |
| 957 | { |
| 958 | srcu_read_unlock(&tomoyo_ss, idx); |
| 959 | } |
| 960 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 961 | /* strcmp() for "struct tomoyo_path_info" structure. */ |
| 962 | static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, |
| 963 | const struct tomoyo_path_info *b) |
| 964 | { |
| 965 | return a->hash != b->hash || strcmp(a->name, b->name); |
| 966 | } |
| 967 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 968 | /** |
| 969 | * tomoyo_is_valid - Check whether the character is a valid char. |
| 970 | * |
| 971 | * @c: The character to check. |
| 972 | * |
| 973 | * Returns true if @c is a valid character, false otherwise. |
| 974 | */ |
| 975 | static inline bool tomoyo_is_valid(const unsigned char c) |
| 976 | { |
| 977 | return c > ' ' && c < 127; |
| 978 | } |
| 979 | |
| 980 | /** |
| 981 | * tomoyo_is_invalid - Check whether the character is an invalid char. |
| 982 | * |
| 983 | * @c: The character to check. |
| 984 | * |
| 985 | * Returns true if @c is an invalid character, false otherwise. |
| 986 | */ |
| 987 | static inline bool tomoyo_is_invalid(const unsigned char c) |
| 988 | { |
| 989 | return c && (c <= ' ' || c >= 127); |
| 990 | } |
| 991 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 992 | static inline void tomoyo_put_name(const struct tomoyo_path_info *name) |
| 993 | { |
| 994 | if (name) { |
| 995 | struct tomoyo_name_entry *ptr = |
| 996 | container_of(name, struct tomoyo_name_entry, entry); |
| 997 | atomic_dec(&ptr->users); |
| 998 | } |
| 999 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1000 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 1001 | static inline void tomoyo_put_path_group(struct tomoyo_path_group *group) |
| 1002 | { |
| 1003 | if (group) |
| 1004 | atomic_dec(&group->users); |
| 1005 | } |
| 1006 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 1007 | static inline void tomoyo_put_number_group(struct tomoyo_number_group *group) |
| 1008 | { |
| 1009 | if (group) |
| 1010 | atomic_dec(&group->users); |
| 1011 | } |
| 1012 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 1013 | static inline struct tomoyo_domain_info *tomoyo_domain(void) |
| 1014 | { |
| 1015 | return current_cred()->security; |
| 1016 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1017 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 1018 | static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct |
| 1019 | *task) |
| 1020 | { |
| 1021 | return task_cred_xxx(task, security); |
| 1022 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1023 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 1024 | static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1, |
| 1025 | const struct tomoyo_acl_info *p2) |
| 1026 | { |
| 1027 | return p1->type == p2->type; |
| 1028 | } |
| 1029 | |
| 1030 | static inline bool tomoyo_is_same_name_union |
| 1031 | (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) |
| 1032 | { |
| 1033 | return p1->filename == p2->filename && p1->group == p2->group && |
| 1034 | p1->is_group == p2->is_group; |
| 1035 | } |
| 1036 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 1037 | static inline bool tomoyo_is_same_number_union |
| 1038 | (const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2) |
| 1039 | { |
| 1040 | return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1] |
| 1041 | && p1->group == p2->group && p1->min_type == p2->min_type && |
| 1042 | p1->max_type == p2->max_type && p1->is_group == p2->is_group; |
| 1043 | } |
| 1044 | |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 1045 | static inline bool tomoyo_is_same_domain_initializer_entry |
| 1046 | (const struct tomoyo_domain_initializer_entry *p1, |
| 1047 | const struct tomoyo_domain_initializer_entry *p2) |
| 1048 | { |
| 1049 | return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name |
| 1050 | && p1->domainname == p2->domainname |
| 1051 | && p1->program == p2->program; |
| 1052 | } |
| 1053 | |
| 1054 | static inline bool tomoyo_is_same_domain_keeper_entry |
| 1055 | (const struct tomoyo_domain_keeper_entry *p1, |
| 1056 | const struct tomoyo_domain_keeper_entry *p2) |
| 1057 | { |
| 1058 | return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name |
| 1059 | && p1->domainname == p2->domainname |
| 1060 | && p1->program == p2->program; |
| 1061 | } |
| 1062 | |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 1063 | static inline bool tomoyo_is_same_aggregator_entry |
| 1064 | (const struct tomoyo_aggregator_entry *p1, |
| 1065 | const struct tomoyo_aggregator_entry *p2) |
| 1066 | { |
| 1067 | return p1->original_name == p2->original_name && |
| 1068 | p1->aggregated_name == p2->aggregated_name; |
| 1069 | } |
| 1070 | |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 1071 | static inline bool tomoyo_is_same_alias_entry |
| 1072 | (const struct tomoyo_alias_entry *p1, const struct tomoyo_alias_entry *p2) |
| 1073 | { |
| 1074 | return p1->original_name == p2->original_name && |
| 1075 | p1->aliased_name == p2->aliased_name; |
| 1076 | } |
| 1077 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1078 | /** |
| 1079 | * list_for_each_cookie - iterate over a list with cookie. |
| 1080 | * @pos: the &struct list_head to use as a loop cursor. |
| 1081 | * @cookie: the &struct list_head to use as a cookie. |
| 1082 | * @head: the head for your list. |
| 1083 | * |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1084 | * Same with list_for_each_rcu() except that this primitive uses @cookie |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1085 | * so that we can continue iteration. |
| 1086 | * @cookie must be NULL when iteration starts, and @cookie will become |
| 1087 | * NULL when iteration finishes. |
| 1088 | */ |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1089 | #define list_for_each_cookie(pos, cookie, head) \ |
| 1090 | for (({ if (!cookie) \ |
| 1091 | cookie = head; }), \ |
| 1092 | pos = rcu_dereference((cookie)->next); \ |
| 1093 | prefetch(pos->next), pos != (head) || ((cookie) = NULL); \ |
| 1094 | (cookie) = pos, pos = rcu_dereference(pos->next)) |
| 1095 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1096 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ |