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 | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 49 | enum tomoyo_policy_id { |
| 50 | TOMOYO_ID_GROUP, |
| 51 | TOMOYO_ID_PATH_GROUP, |
| 52 | TOMOYO_ID_NUMBER_GROUP, |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 53 | TOMOYO_ID_TRANSITION_CONTROL, |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 54 | TOMOYO_ID_AGGREGATOR, |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 55 | TOMOYO_ID_MANAGER, |
| 56 | TOMOYO_ID_NAME, |
| 57 | TOMOYO_ID_ACL, |
| 58 | TOMOYO_ID_DOMAIN, |
| 59 | TOMOYO_MAX_POLICY |
| 60 | }; |
| 61 | |
| 62 | enum tomoyo_group_id { |
| 63 | TOMOYO_PATH_GROUP, |
| 64 | TOMOYO_NUMBER_GROUP, |
| 65 | TOMOYO_MAX_GROUP |
| 66 | }; |
| 67 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 68 | /* Keywords for ACLs. */ |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 69 | #define TOMOYO_KEYWORD_AGGREGATOR "aggregator " |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 70 | #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount " |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 71 | #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " |
| 72 | #define TOMOYO_KEYWORD_DELETE "delete " |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 73 | #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " |
| 74 | #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " |
| 75 | #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " |
| 76 | #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 77 | #define TOMOYO_KEYWORD_PATH_GROUP "path_group " |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 78 | #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group " |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 79 | #define TOMOYO_KEYWORD_SELECT "select " |
| 80 | #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " |
Tetsuo Handa | 9b24437 | 2010-06-03 20:35:53 +0900 | [diff] [blame] | 81 | #define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded" |
| 82 | #define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed" |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 83 | /* A domain definition starts with <kernel>. */ |
| 84 | #define TOMOYO_ROOT_NAME "<kernel>" |
| 85 | #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) |
| 86 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 87 | /* Value type definition. */ |
| 88 | #define TOMOYO_VALUE_TYPE_INVALID 0 |
| 89 | #define TOMOYO_VALUE_TYPE_DECIMAL 1 |
| 90 | #define TOMOYO_VALUE_TYPE_OCTAL 2 |
| 91 | #define TOMOYO_VALUE_TYPE_HEXADECIMAL 3 |
| 92 | |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 93 | enum tomoyo_transition_type { |
| 94 | /* Do not change this order, */ |
| 95 | TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, |
| 96 | TOMOYO_TRANSITION_CONTROL_INITIALIZE, |
| 97 | TOMOYO_TRANSITION_CONTROL_NO_KEEP, |
| 98 | TOMOYO_TRANSITION_CONTROL_KEEP, |
| 99 | TOMOYO_MAX_TRANSITION_TYPE |
| 100 | }; |
| 101 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 102 | /* Index numbers for Access Controls. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 103 | enum tomoyo_acl_entry_type_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 104 | TOMOYO_TYPE_PATH_ACL, |
| 105 | TOMOYO_TYPE_PATH2_ACL, |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 106 | TOMOYO_TYPE_PATH_NUMBER_ACL, |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 107 | TOMOYO_TYPE_MKDEV_ACL, |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 108 | TOMOYO_TYPE_MOUNT_ACL, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 109 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 110 | |
| 111 | /* Index numbers for File Controls. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 112 | enum tomoyo_path_acl_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 113 | TOMOYO_TYPE_EXECUTE, |
| 114 | TOMOYO_TYPE_READ, |
| 115 | TOMOYO_TYPE_WRITE, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 116 | TOMOYO_TYPE_APPEND, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 117 | TOMOYO_TYPE_UNLINK, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 118 | TOMOYO_TYPE_GETATTR, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 119 | TOMOYO_TYPE_RMDIR, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 120 | TOMOYO_TYPE_TRUNCATE, |
| 121 | TOMOYO_TYPE_SYMLINK, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 122 | TOMOYO_TYPE_CHROOT, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 123 | TOMOYO_TYPE_UMOUNT, |
| 124 | TOMOYO_MAX_PATH_OPERATION |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 125 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 126 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 127 | enum tomoyo_mkdev_acl_index { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 128 | TOMOYO_TYPE_MKBLOCK, |
| 129 | TOMOYO_TYPE_MKCHAR, |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 130 | TOMOYO_MAX_MKDEV_OPERATION |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 131 | }; |
| 132 | |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 133 | enum tomoyo_path2_acl_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 134 | TOMOYO_TYPE_LINK, |
| 135 | TOMOYO_TYPE_RENAME, |
| 136 | TOMOYO_TYPE_PIVOT_ROOT, |
| 137 | TOMOYO_MAX_PATH2_OPERATION |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 138 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 139 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 140 | enum tomoyo_path_number_acl_index { |
| 141 | TOMOYO_TYPE_CREATE, |
| 142 | TOMOYO_TYPE_MKDIR, |
| 143 | TOMOYO_TYPE_MKFIFO, |
| 144 | TOMOYO_TYPE_MKSOCK, |
| 145 | TOMOYO_TYPE_IOCTL, |
| 146 | TOMOYO_TYPE_CHMOD, |
| 147 | TOMOYO_TYPE_CHOWN, |
| 148 | TOMOYO_TYPE_CHGRP, |
| 149 | TOMOYO_MAX_PATH_NUMBER_OPERATION |
| 150 | }; |
| 151 | |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 152 | enum tomoyo_securityfs_interface_index { |
| 153 | TOMOYO_DOMAINPOLICY, |
| 154 | TOMOYO_EXCEPTIONPOLICY, |
| 155 | TOMOYO_DOMAIN_STATUS, |
| 156 | TOMOYO_PROCESS_STATUS, |
| 157 | TOMOYO_MEMINFO, |
| 158 | TOMOYO_SELFDOMAIN, |
| 159 | TOMOYO_VERSION, |
| 160 | TOMOYO_PROFILE, |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 161 | TOMOYO_QUERY, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 162 | TOMOYO_MANAGER |
| 163 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 164 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 165 | enum tomoyo_mac_index { |
| 166 | TOMOYO_MAC_FILE_EXECUTE, |
| 167 | TOMOYO_MAC_FILE_OPEN, |
| 168 | TOMOYO_MAC_FILE_CREATE, |
| 169 | TOMOYO_MAC_FILE_UNLINK, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 170 | TOMOYO_MAC_FILE_GETATTR, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 171 | TOMOYO_MAC_FILE_MKDIR, |
| 172 | TOMOYO_MAC_FILE_RMDIR, |
| 173 | TOMOYO_MAC_FILE_MKFIFO, |
| 174 | TOMOYO_MAC_FILE_MKSOCK, |
| 175 | TOMOYO_MAC_FILE_TRUNCATE, |
| 176 | TOMOYO_MAC_FILE_SYMLINK, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 177 | TOMOYO_MAC_FILE_MKBLOCK, |
| 178 | TOMOYO_MAC_FILE_MKCHAR, |
| 179 | TOMOYO_MAC_FILE_LINK, |
| 180 | TOMOYO_MAC_FILE_RENAME, |
| 181 | TOMOYO_MAC_FILE_CHMOD, |
| 182 | TOMOYO_MAC_FILE_CHOWN, |
| 183 | TOMOYO_MAC_FILE_CHGRP, |
| 184 | TOMOYO_MAC_FILE_IOCTL, |
| 185 | TOMOYO_MAC_FILE_CHROOT, |
| 186 | TOMOYO_MAC_FILE_MOUNT, |
| 187 | TOMOYO_MAC_FILE_UMOUNT, |
| 188 | TOMOYO_MAC_FILE_PIVOT_ROOT, |
| 189 | TOMOYO_MAX_MAC_INDEX |
| 190 | }; |
| 191 | |
| 192 | enum tomoyo_mac_category_index { |
| 193 | TOMOYO_MAC_CATEGORY_FILE, |
| 194 | TOMOYO_MAX_MAC_CATEGORY_INDEX |
| 195 | }; |
| 196 | |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 197 | #define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */ |
| 198 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 199 | /********** Structure definitions. **********/ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 200 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 201 | /* |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 202 | * tomoyo_acl_head is a structure which is used for holding elements not in |
| 203 | * domain policy. |
| 204 | * It has following fields. |
| 205 | * |
| 206 | * (1) "list" which is linked to tomoyo_policy_list[] . |
| 207 | * (2) "is_deleted" is a bool which is true if marked as deleted, false |
| 208 | * otherwise. |
| 209 | */ |
| 210 | struct tomoyo_acl_head { |
| 211 | struct list_head list; |
| 212 | bool is_deleted; |
| 213 | } __packed; |
| 214 | |
| 215 | /* |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 216 | * tomoyo_request_info is a structure which is used for holding |
| 217 | * |
| 218 | * (1) Domain information of current process. |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 219 | * (2) How many retries are made for this request. |
| 220 | * (3) Profile number used for this request. |
| 221 | * (4) Access control mode of the profile. |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 222 | */ |
| 223 | struct tomoyo_request_info { |
| 224 | struct tomoyo_domain_info *domain; |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 225 | /* For holding parameters. */ |
| 226 | union { |
| 227 | struct { |
| 228 | const struct tomoyo_path_info *filename; |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 229 | /* For using wildcards at tomoyo_find_next_domain(). */ |
| 230 | const struct tomoyo_path_info *matched_path; |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 231 | u8 operation; |
| 232 | } path; |
| 233 | struct { |
| 234 | const struct tomoyo_path_info *filename1; |
| 235 | const struct tomoyo_path_info *filename2; |
| 236 | u8 operation; |
| 237 | } path2; |
| 238 | struct { |
| 239 | const struct tomoyo_path_info *filename; |
| 240 | unsigned int mode; |
| 241 | unsigned int major; |
| 242 | unsigned int minor; |
| 243 | u8 operation; |
| 244 | } mkdev; |
| 245 | struct { |
| 246 | const struct tomoyo_path_info *filename; |
| 247 | unsigned long number; |
| 248 | u8 operation; |
| 249 | } path_number; |
| 250 | struct { |
| 251 | const struct tomoyo_path_info *type; |
| 252 | const struct tomoyo_path_info *dir; |
| 253 | const struct tomoyo_path_info *dev; |
| 254 | unsigned long flags; |
| 255 | int need_dev; |
| 256 | } mount; |
| 257 | } param; |
| 258 | u8 param_type; |
| 259 | bool granted; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 260 | u8 retry; |
| 261 | u8 profile; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 262 | u8 mode; /* One of tomoyo_mode_index . */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 263 | u8 type; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | /* |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 267 | * tomoyo_path_info is a structure which is used for holding a string data |
| 268 | * used by TOMOYO. |
| 269 | * This structure has several fields for supporting pattern matching. |
| 270 | * |
| 271 | * (1) "name" is the '\0' terminated string data. |
| 272 | * (2) "hash" is full_name_hash(name, strlen(name)). |
| 273 | * This allows tomoyo_pathcmp() to compare by hash before actually compare |
| 274 | * using strcmp(). |
| 275 | * (3) "const_len" is the length of the initial segment of "name" which |
| 276 | * consists entirely of non wildcard characters. In other words, the length |
| 277 | * which we can compare two strings using strncmp(). |
| 278 | * (4) "is_dir" is a bool which is true if "name" ends with "/", |
| 279 | * false otherwise. |
| 280 | * TOMOYO distinguishes directory and non-directory. A directory ends with |
| 281 | * "/" and non-directory does not end with "/". |
| 282 | * (5) "is_patterned" is a bool which is true if "name" contains wildcard |
| 283 | * characters, false otherwise. This allows TOMOYO to use "hash" and |
| 284 | * strcmp() for string comparison if "is_patterned" is false. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 285 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 286 | struct tomoyo_path_info { |
| 287 | const char *name; |
| 288 | u32 hash; /* = full_name_hash(name, strlen(name)) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 289 | u16 const_len; /* = tomoyo_const_part_length(name) */ |
| 290 | bool is_dir; /* = tomoyo_strendswith(name, "/") */ |
| 291 | bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | /* |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 295 | * tomoyo_name is a structure which is used for linking |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 296 | * "struct tomoyo_path_info" into tomoyo_name_list . |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 297 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 298 | struct tomoyo_name { |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 299 | struct list_head list; |
| 300 | atomic_t users; |
| 301 | struct tomoyo_path_info entry; |
| 302 | }; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 303 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 304 | struct tomoyo_name_union { |
| 305 | const struct tomoyo_path_info *filename; |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 306 | struct tomoyo_group *group; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 307 | u8 is_group; |
| 308 | }; |
| 309 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 310 | struct tomoyo_number_union { |
| 311 | unsigned long values[2]; |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 312 | struct tomoyo_group *group; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 313 | u8 min_type; |
| 314 | u8 max_type; |
| 315 | u8 is_group; |
| 316 | }; |
| 317 | |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 318 | /* Structure for "path_group"/"number_group" directive. */ |
| 319 | struct tomoyo_group { |
| 320 | struct list_head list; |
| 321 | const struct tomoyo_path_info *group_name; |
| 322 | struct list_head member_list; |
| 323 | atomic_t users; |
| 324 | }; |
| 325 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 326 | /* Structure for "path_group" directive. */ |
| 327 | struct tomoyo_path_group { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 328 | struct tomoyo_acl_head head; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 329 | const struct tomoyo_path_info *member_name; |
| 330 | }; |
| 331 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 332 | /* Structure for "number_group" directive. */ |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 333 | struct tomoyo_number_group { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 334 | struct tomoyo_acl_head head; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 335 | struct tomoyo_number_union number; |
| 336 | }; |
| 337 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 338 | /* |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 339 | * tomoyo_acl_info is a structure which is used for holding |
| 340 | * |
| 341 | * (1) "list" which is linked to the ->acl_info_list of |
| 342 | * "struct tomoyo_domain_info" |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 343 | * (2) "is_deleted" is a bool which is true if this domain is marked as |
| 344 | * "deleted", false otherwise. |
| 345 | * (3) "type" which tells type of the entry. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 346 | * |
| 347 | * Packing "struct tomoyo_acl_info" allows |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 348 | * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl" |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 349 | * "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 350 | * "u8" without enlarging their structure size. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 351 | */ |
| 352 | struct tomoyo_acl_info { |
| 353 | struct list_head list; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 354 | bool is_deleted; |
| 355 | u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 356 | } __packed; |
| 357 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 358 | /* |
| 359 | * tomoyo_domain_info is a structure which is used for holding permissions |
| 360 | * (e.g. "allow_read /lib/libc-2.5.so") given to each domain. |
| 361 | * It has following fields. |
| 362 | * |
| 363 | * (1) "list" which is linked to tomoyo_domain_list . |
| 364 | * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info". |
| 365 | * (3) "domainname" which holds the name of the domain. |
| 366 | * (4) "profile" which remembers profile number assigned to this domain. |
| 367 | * (5) "is_deleted" is a bool which is true if this domain is marked as |
| 368 | * "deleted", false otherwise. |
| 369 | * (6) "quota_warned" is a bool which is used for suppressing warning message |
| 370 | * when learning mode learned too much entries. |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 371 | * (7) "transition_failed" is a bool which is set to true when this domain was |
Tetsuo Handa | ea13ddb | 2010-02-03 06:43:06 +0900 | [diff] [blame] | 372 | * unable to create a new domain at tomoyo_find_next_domain() because the |
| 373 | * name of the domain to be created was too long or it could not allocate |
| 374 | * memory. If set to true, more than one process continued execve() |
| 375 | * without domain transition. |
Tetsuo Handa | ec8e6a4 | 2010-02-11 09:43:20 +0900 | [diff] [blame] | 376 | * (9) "users" is an atomic_t that holds how many "struct cred"->security |
| 377 | * are referring this "struct tomoyo_domain_info". If is_deleted == true |
| 378 | * and users == 0, this struct will be kfree()d upon next garbage |
| 379 | * collection. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 380 | * |
| 381 | * A domain's lifecycle is an analogy of files on / directory. |
| 382 | * Multiple domains with the same domainname cannot be created (as with |
| 383 | * creating files with the same filename fails with -EEXIST). |
| 384 | * If a process reached a domain, that process can reside in that domain after |
| 385 | * that domain is marked as "deleted" (as with a process can access an already |
| 386 | * open()ed file after that file was unlink()ed). |
| 387 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 388 | struct tomoyo_domain_info { |
| 389 | struct list_head list; |
| 390 | struct list_head acl_info_list; |
| 391 | /* Name of this domain. Never NULL. */ |
| 392 | const struct tomoyo_path_info *domainname; |
| 393 | u8 profile; /* Profile number to use. */ |
Tetsuo Handa | a0558fc | 2009-04-06 20:49:14 +0900 | [diff] [blame] | 394 | bool is_deleted; /* Delete flag. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 395 | bool quota_warned; /* Quota warnning flag. */ |
Tetsuo Handa | ea13ddb | 2010-02-03 06:43:06 +0900 | [diff] [blame] | 396 | bool transition_failed; /* Domain transition failed flag. */ |
Tetsuo Handa | ec8e6a4 | 2010-02-11 09:43:20 +0900 | [diff] [blame] | 397 | atomic_t users; /* Number of referring credentials. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 398 | }; |
| 399 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 400 | /* |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 401 | * tomoyo_path_acl is a structure which is used for holding an |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 402 | * entry with one pathname operation (e.g. open(), mkdir()). |
| 403 | * It has following fields. |
| 404 | * |
| 405 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 406 | * (2) "perm" which is a bitmask of permitted operations. |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 407 | * (3) "name" is the pathname. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 408 | * |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 409 | * Directives held by this structure are "allow_execute", "allow_read", |
| 410 | * "allow_write", "allow_append", "allow_unlink", "allow_rmdir", |
| 411 | * "allow_truncate", "allow_symlink", "allow_chroot" and "allow_unmount". |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 412 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 413 | struct tomoyo_path_acl { |
| 414 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 415 | u16 perm; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 416 | struct tomoyo_name_union name; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 417 | }; |
| 418 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 419 | /* |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 420 | * tomoyo_path_number_acl is a structure which is used for holding an |
| 421 | * entry with one pathname and one number operation. |
| 422 | * It has following fields. |
| 423 | * |
| 424 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 425 | * (2) "perm" which is a bitmask of permitted operations. |
| 426 | * (3) "name" is the pathname. |
| 427 | * (4) "number" is the numeric value. |
| 428 | * |
| 429 | * Directives held by this structure are "allow_create", "allow_mkdir", |
| 430 | * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown" |
| 431 | * and "allow_chgrp". |
| 432 | * |
| 433 | */ |
| 434 | struct tomoyo_path_number_acl { |
| 435 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ |
| 436 | u8 perm; |
| 437 | struct tomoyo_name_union name; |
| 438 | struct tomoyo_number_union number; |
| 439 | }; |
| 440 | |
| 441 | /* |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 442 | * tomoyo_mkdev_acl is a structure which is used for holding an |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 443 | * entry with one pathname and three numbers operation. |
| 444 | * It has following fields. |
| 445 | * |
| 446 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 447 | * (2) "perm" which is a bitmask of permitted operations. |
| 448 | * (3) "mode" is the create mode. |
| 449 | * (4) "major" is the major number of device node. |
| 450 | * (5) "minor" is the minor number of device node. |
| 451 | * |
| 452 | * Directives held by this structure are "allow_mkchar", "allow_mkblock". |
| 453 | * |
| 454 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 455 | struct tomoyo_mkdev_acl { |
| 456 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 457 | u8 perm; |
| 458 | struct tomoyo_name_union name; |
| 459 | struct tomoyo_number_union mode; |
| 460 | struct tomoyo_number_union major; |
| 461 | struct tomoyo_number_union minor; |
| 462 | }; |
| 463 | |
| 464 | /* |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 465 | * tomoyo_path2_acl is a structure which is used for holding an |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 466 | * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 467 | * It has following fields. |
| 468 | * |
| 469 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 470 | * (2) "perm" which is a bitmask of permitted operations. |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 471 | * (3) "name1" is the source/old pathname. |
| 472 | * (4) "name2" is the destination/new pathname. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 473 | * |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 474 | * Directives held by this structure are "allow_rename", "allow_link" and |
| 475 | * "allow_pivot_root". |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 476 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 477 | struct tomoyo_path2_acl { |
| 478 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 479 | u8 perm; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 480 | struct tomoyo_name_union name1; |
| 481 | struct tomoyo_name_union name2; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 482 | }; |
| 483 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 484 | /* |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 485 | * tomoyo_mount_acl is a structure which is used for holding an |
| 486 | * entry for mount operation. |
| 487 | * It has following fields. |
| 488 | * |
| 489 | * (1) "head" which is a "struct tomoyo_acl_info". |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 490 | * (2) "dev_name" is the device name. |
| 491 | * (3) "dir_name" is the mount point. |
| 492 | * (4) "fs_type" is the filesystem type. |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 493 | * (5) "flags" is the mount flags. |
| 494 | * |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 495 | * Directive held by this structure is "allow_mount". |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 496 | */ |
| 497 | struct tomoyo_mount_acl { |
| 498 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 499 | struct tomoyo_name_union dev_name; |
| 500 | struct tomoyo_name_union dir_name; |
| 501 | struct tomoyo_name_union fs_type; |
| 502 | struct tomoyo_number_union flags; |
| 503 | }; |
| 504 | |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 505 | #define TOMOYO_MAX_IO_READ_QUEUE 32 |
| 506 | |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 507 | /* |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 508 | * Structure for reading/writing policy via /sys/kernel/security/tomoyo |
| 509 | * interfaces. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 510 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 511 | struct tomoyo_io_buffer { |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 512 | void (*read) (struct tomoyo_io_buffer *); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 513 | int (*write) (struct tomoyo_io_buffer *); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 514 | int (*poll) (struct file *file, poll_table *wait); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 515 | /* Exclusive lock for this structure. */ |
| 516 | struct mutex io_sem; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 517 | /* Index returned by tomoyo_read_lock(). */ |
| 518 | int reader_idx; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 519 | char __user *read_user_buf; |
| 520 | int read_user_buf_avail; |
| 521 | struct { |
| 522 | struct list_head *domain; |
| 523 | struct list_head *group; |
| 524 | struct list_head *acl; |
| 525 | int avail; |
| 526 | int step; |
| 527 | int query_index; |
| 528 | u16 index; |
| 529 | u8 bit; |
| 530 | u8 w_pos; |
| 531 | bool eof; |
| 532 | bool print_this_domain_only; |
| 533 | bool print_execute_only; |
| 534 | const char *w[TOMOYO_MAX_IO_READ_QUEUE]; |
| 535 | } r; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 536 | /* The position currently writing to. */ |
| 537 | struct tomoyo_domain_info *write_var1; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 538 | /* Buffer for reading. */ |
| 539 | char *read_buf; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 540 | /* Size of read buffer. */ |
| 541 | int readbuf_size; |
| 542 | /* Buffer for writing. */ |
| 543 | char *write_buf; |
| 544 | /* Bytes available for writing. */ |
| 545 | int write_avail; |
| 546 | /* Size of write buffer. */ |
| 547 | int writebuf_size; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 548 | /* Type of this interface. */ |
| 549 | u8 type; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 550 | }; |
| 551 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 552 | /* |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 553 | * tomoyo_transition_control is a structure which is used for holding |
| 554 | * "initialize_domain"/"no_initialize_domain"/"keep_domain"/"no_keep_domain" |
| 555 | * entries. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 556 | * It has following fields. |
| 557 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 558 | * (1) "head" is "struct tomoyo_acl_head". |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 559 | * (2) "type" is type of this entry. |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 560 | * (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] | 561 | * component of a domainname", false otherwise. |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 562 | * (4) "domainname" which is "a domainname" or "the last component of a |
| 563 | * domainname". |
| 564 | * (5) "program" which is a program's pathname. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 565 | */ |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 566 | struct tomoyo_transition_control { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 567 | struct tomoyo_acl_head head; |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 568 | u8 type; /* One of values in "enum tomoyo_transition_type". */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 569 | /* True if the domainname is tomoyo_get_last_name(). */ |
| 570 | bool is_last_name; |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 571 | const struct tomoyo_path_info *domainname; /* Maybe NULL */ |
| 572 | const struct tomoyo_path_info *program; /* Maybe NULL */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 573 | }; |
| 574 | |
| 575 | /* |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 576 | * tomoyo_aggregator is a structure which is used for holding |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 577 | * "aggregator" entries. |
| 578 | * It has following fields. |
| 579 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 580 | * (1) "head" is "struct tomoyo_acl_head". |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 581 | * (2) "original_name" which is originally requested name. |
| 582 | * (3) "aggregated_name" which is name to rewrite. |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 583 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 584 | struct tomoyo_aggregator { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 585 | struct tomoyo_acl_head head; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 586 | const struct tomoyo_path_info *original_name; |
| 587 | const struct tomoyo_path_info *aggregated_name; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 588 | }; |
| 589 | |
| 590 | /* |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 591 | * tomoyo_manager is a structure which is used for holding list of |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 592 | * domainnames or programs which are permitted to modify configuration via |
| 593 | * /sys/kernel/security/tomoyo/ interface. |
| 594 | * It has following fields. |
| 595 | * |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 596 | * (1) "head" is "struct tomoyo_acl_head". |
| 597 | * (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] | 598 | * otherwise. |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 599 | * (3) "manager" is a domainname or a program's pathname. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 600 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 601 | struct tomoyo_manager { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 602 | struct tomoyo_acl_head head; |
| 603 | bool is_domain; /* True if manager is a domainname. */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 604 | /* A path to program or a domainname. */ |
| 605 | const struct tomoyo_path_info *manager; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 606 | }; |
| 607 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 608 | struct tomoyo_preference { |
| 609 | unsigned int learning_max_entry; |
| 610 | bool enforcing_verbose; |
| 611 | bool learning_verbose; |
| 612 | bool permissive_verbose; |
| 613 | }; |
| 614 | |
| 615 | struct tomoyo_profile { |
| 616 | const struct tomoyo_path_info *comment; |
| 617 | struct tomoyo_preference *learning; |
| 618 | struct tomoyo_preference *permissive; |
| 619 | struct tomoyo_preference *enforcing; |
| 620 | struct tomoyo_preference preference; |
| 621 | u8 default_config; |
| 622 | u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; |
| 623 | }; |
| 624 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 625 | /********** Function prototypes. **********/ |
| 626 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 627 | /* Check whether the given string starts with the given keyword. */ |
| 628 | bool tomoyo_str_starts(char **src, const char *find); |
| 629 | /* Get tomoyo_realpath() of current process. */ |
| 630 | const char *tomoyo_get_exe(void); |
| 631 | /* Format string. */ |
| 632 | void tomoyo_normalize_line(unsigned char *buffer); |
| 633 | /* Print warning or error message on console. */ |
| 634 | void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...) |
| 635 | __attribute__ ((format(printf, 2, 3))); |
| 636 | /* Check all profiles currently assigned to domains are defined. */ |
| 637 | void tomoyo_check_profile(void); |
| 638 | /* Open operation for /sys/kernel/security/tomoyo/ interface. */ |
| 639 | int tomoyo_open_control(const u8 type, struct file *file); |
| 640 | /* Close /sys/kernel/security/tomoyo/ interface. */ |
| 641 | int tomoyo_close_control(struct file *file); |
Tetsuo Handa | 0849e3b | 2010-06-25 12:22:09 +0900 | [diff] [blame] | 642 | /* Poll operation for /sys/kernel/security/tomoyo/ interface. */ |
| 643 | int tomoyo_poll_control(struct file *file, poll_table *wait); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 644 | /* Read operation for /sys/kernel/security/tomoyo/ interface. */ |
| 645 | int tomoyo_read_control(struct file *file, char __user *buffer, |
| 646 | const int buffer_len); |
| 647 | /* Write operation for /sys/kernel/security/tomoyo/ interface. */ |
| 648 | int tomoyo_write_control(struct file *file, const char __user *buffer, |
| 649 | const int buffer_len); |
| 650 | /* Check whether the domain has too many ACL entries to hold. */ |
| 651 | bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); |
| 652 | /* Print out of memory warning message. */ |
| 653 | void tomoyo_warn_oom(const char *function); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 654 | /* Check whether the given name matches the given name_union. */ |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 655 | const struct tomoyo_path_info * |
| 656 | tomoyo_compare_name_union(const struct tomoyo_path_info *name, |
| 657 | const struct tomoyo_name_union *ptr); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 658 | /* Check whether the given number matches the given number_union. */ |
| 659 | bool tomoyo_compare_number_union(const unsigned long value, |
| 660 | const struct tomoyo_number_union *ptr); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 661 | int tomoyo_get_mode(const u8 profile, const u8 index); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 662 | void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 663 | __attribute__ ((format(printf, 2, 3))); |
| 664 | /* Check whether the domainname is correct. */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 665 | bool tomoyo_correct_domain(const unsigned char *domainname); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 666 | /* Check whether the token is correct. */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 667 | bool tomoyo_correct_path(const char *filename); |
| 668 | bool tomoyo_correct_word(const char *string); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 669 | /* Check whether the token can be a domainname. */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 670 | bool tomoyo_domain_def(const unsigned char *buffer); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 671 | bool tomoyo_parse_name_union(const char *filename, |
| 672 | struct tomoyo_name_union *ptr); |
| 673 | /* Check whether the given filename matches the given path_group. */ |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 674 | const struct tomoyo_path_info * |
| 675 | tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, |
| 676 | const struct tomoyo_group *group); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 677 | /* Check whether the given value matches the given number_group. */ |
| 678 | bool tomoyo_number_matches_group(const unsigned long min, |
| 679 | const unsigned long max, |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 680 | const struct tomoyo_group *group); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 681 | /* Check whether the given filename matches the given pattern. */ |
| 682 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, |
| 683 | const struct tomoyo_path_info *pattern); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 684 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 685 | bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 686 | /* Tokenize a line. */ |
| 687 | bool tomoyo_tokenize(char *buffer, char *w[], size_t size); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 688 | /* Write domain policy violation warning message to console? */ |
| 689 | bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 690 | /* Fill "struct tomoyo_request_info". */ |
| 691 | int tomoyo_init_request_info(struct tomoyo_request_info *r, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 692 | struct tomoyo_domain_info *domain, |
| 693 | const u8 index); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 694 | /* Check permission for mount operation. */ |
| 695 | int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, |
| 696 | unsigned long flags, void *data_page); |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 697 | /* Create "aggregator" entry in exception policy. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 698 | int tomoyo_write_aggregator(char *data, const bool is_delete); |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 699 | int tomoyo_write_transition_control(char *data, const bool is_delete, |
| 700 | const u8 type); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 701 | /* |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 702 | * Create "allow_execute", "allow_read", "allow_write", "allow_append", |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 703 | * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", |
| 704 | * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 705 | * "allow_truncate", "allow_symlink", "allow_rename" and "allow_link" entry |
| 706 | * in domain policy. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 707 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 708 | int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain, |
| 709 | const bool is_delete); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 710 | /* Create "allow_mount" entry in domain policy. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 711 | int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain, |
| 712 | const bool is_delete); |
Tetsuo Handa | 7c2ea22 | 2010-06-17 16:55:58 +0900 | [diff] [blame] | 713 | /* Create "path_group"/"number_group" entry in exception policy. */ |
| 714 | int tomoyo_write_group(char *data, const bool is_delete, const u8 type); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 715 | int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) |
| 716 | __attribute__ ((format(printf, 2, 3))); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 717 | /* Find a domain by the given name. */ |
| 718 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); |
| 719 | /* Find or create a domain by the given name. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 720 | struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, |
| 721 | const u8 profile); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 722 | struct tomoyo_profile *tomoyo_profile(const u8 profile); |
Tetsuo Handa | 7c2ea22 | 2010-06-17 16:55:58 +0900 | [diff] [blame] | 723 | /* |
| 724 | * Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group". |
| 725 | */ |
| 726 | struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 727 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 728 | /* Check mode for specified functionality. */ |
| 729 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, |
| 730 | const u8 index); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 731 | /* Fill in "struct tomoyo_path_info" members. */ |
| 732 | void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); |
| 733 | /* Run policy loader when /sbin/init starts. */ |
| 734 | void tomoyo_load_policy(const char *filename); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 735 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 736 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr); |
| 737 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 738 | /* Convert binary string to ascii string. */ |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 739 | char *tomoyo_encode(const char *str); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 740 | |
| 741 | /* |
Tetsuo Handa | 0617c7f | 2010-06-21 09:58:53 +0900 | [diff] [blame] | 742 | * Returns realpath(3) of the given pathname except that |
| 743 | * ignores chroot'ed root and does not follow the final symlink. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 744 | */ |
| 745 | char *tomoyo_realpath_nofollow(const char *pathname); |
Tetsuo Handa | 0617c7f | 2010-06-21 09:58:53 +0900 | [diff] [blame] | 746 | /* |
| 747 | * Returns realpath(3) of the given pathname except that |
| 748 | * ignores chroot'ed root and the pathname is already solved. |
| 749 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 750 | char *tomoyo_realpath_from_path(struct path *path); |
| 751 | |
| 752 | /* Check memory quota. */ |
| 753 | bool tomoyo_memory_ok(void *ptr); |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 754 | void *tomoyo_commit_ok(void *data, const unsigned int size); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 755 | |
| 756 | /* |
| 757 | * Keep the given name on the RAM. |
| 758 | * The RAM is shared, so NEVER try to modify or kfree() the returned name. |
| 759 | */ |
| 760 | const struct tomoyo_path_info *tomoyo_get_name(const char *name); |
| 761 | |
| 762 | /* Check for memory usage. */ |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 763 | void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 764 | |
| 765 | /* Set memory quota. */ |
| 766 | int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); |
| 767 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 768 | /* Initialize mm related code. */ |
| 769 | void __init tomoyo_mm_init(void); |
Tetsuo Handa | 05336de | 2010-06-16 16:20:24 +0900 | [diff] [blame] | 770 | int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 771 | const struct tomoyo_path_info *filename); |
| 772 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |
| 773 | struct path *path, const int flag); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 774 | int tomoyo_path_number_perm(const u8 operation, struct path *path, |
| 775 | unsigned long number); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 776 | int tomoyo_mkdev_perm(const u8 operation, struct path *path, |
| 777 | const unsigned int mode, unsigned int dev); |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 778 | int tomoyo_path_perm(const u8 operation, struct path *path); |
| 779 | int tomoyo_path2_perm(const u8 operation, struct path *path1, |
| 780 | struct path *path2); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 781 | int tomoyo_find_next_domain(struct linux_binprm *bprm); |
| 782 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 783 | void tomoyo_print_ulong(char *buffer, const int buffer_len, |
| 784 | const unsigned long value, const u8 type); |
| 785 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 786 | /* Drop refcount on tomoyo_name_union. */ |
| 787 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr); |
| 788 | |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 789 | /* Run garbage collector. */ |
| 790 | void tomoyo_run_gc(void); |
| 791 | |
| 792 | void tomoyo_memory_free(void *ptr); |
| 793 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 794 | int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, |
| 795 | bool is_delete, struct tomoyo_domain_info *domain, |
| 796 | bool (*check_duplicate) (const struct tomoyo_acl_info |
| 797 | *, |
| 798 | const struct tomoyo_acl_info |
| 799 | *), |
| 800 | bool (*merge_duplicate) (struct tomoyo_acl_info *, |
| 801 | struct tomoyo_acl_info *, |
| 802 | const bool)); |
Tetsuo Handa | 36f5e1f | 2010-06-15 09:23:26 +0900 | [diff] [blame] | 803 | int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, |
| 804 | bool is_delete, struct list_head *list, |
| 805 | bool (*check_duplicate) (const struct tomoyo_acl_head |
| 806 | *, |
| 807 | const struct tomoyo_acl_head |
| 808 | *)); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 809 | void tomoyo_check_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 810 | bool (*check_entry) (struct tomoyo_request_info *, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 811 | const struct tomoyo_acl_info *)); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 812 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 813 | /********** External variable definitions. **********/ |
| 814 | |
| 815 | /* Lock for GC. */ |
| 816 | extern struct srcu_struct tomoyo_ss; |
| 817 | |
| 818 | /* The list for "struct tomoyo_domain_info". */ |
| 819 | extern struct list_head tomoyo_domain_list; |
| 820 | |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 821 | extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY]; |
| 822 | extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP]; |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 823 | extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 824 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 825 | /* Lock for protecting policy. */ |
| 826 | extern struct mutex tomoyo_policy_lock; |
| 827 | |
| 828 | /* Has /sbin/init started? */ |
| 829 | extern bool tomoyo_policy_loaded; |
| 830 | |
| 831 | /* The kernel's domain. */ |
| 832 | extern struct tomoyo_domain_info tomoyo_kernel_domain; |
| 833 | |
Tetsuo Handa | 71c2823 | 2010-06-16 16:26:38 +0900 | [diff] [blame] | 834 | extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; |
| 835 | extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION]; |
| 836 | extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION]; |
| 837 | extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION]; |
| 838 | |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 839 | extern unsigned int tomoyo_quota_for_query; |
| 840 | extern unsigned int tomoyo_query_memory_size; |
| 841 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 842 | /********** Inlined functions. **********/ |
| 843 | |
| 844 | static inline int tomoyo_read_lock(void) |
| 845 | { |
| 846 | return srcu_read_lock(&tomoyo_ss); |
| 847 | } |
| 848 | |
| 849 | static inline void tomoyo_read_unlock(int idx) |
| 850 | { |
| 851 | srcu_read_unlock(&tomoyo_ss, idx); |
| 852 | } |
| 853 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 854 | /* strcmp() for "struct tomoyo_path_info" structure. */ |
| 855 | static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, |
| 856 | const struct tomoyo_path_info *b) |
| 857 | { |
| 858 | return a->hash != b->hash || strcmp(a->name, b->name); |
| 859 | } |
| 860 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 861 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 862 | * tomoyo_valid - Check whether the character is a valid char. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 863 | * |
| 864 | * @c: The character to check. |
| 865 | * |
| 866 | * Returns true if @c is a valid character, false otherwise. |
| 867 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 868 | static inline bool tomoyo_valid(const unsigned char c) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 869 | { |
| 870 | return c > ' ' && c < 127; |
| 871 | } |
| 872 | |
| 873 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 874 | * tomoyo_invalid - Check whether the character is an invalid char. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 875 | * |
| 876 | * @c: The character to check. |
| 877 | * |
| 878 | * Returns true if @c is an invalid character, false otherwise. |
| 879 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 880 | static inline bool tomoyo_invalid(const unsigned char c) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 881 | { |
| 882 | return c && (c <= ' ' || c >= 127); |
| 883 | } |
| 884 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 885 | static inline void tomoyo_put_name(const struct tomoyo_path_info *name) |
| 886 | { |
| 887 | if (name) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 888 | struct tomoyo_name *ptr = |
| 889 | container_of(name, typeof(*ptr), entry); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 890 | atomic_dec(&ptr->users); |
| 891 | } |
| 892 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 893 | |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 894 | static inline void tomoyo_put_group(struct tomoyo_group *group) |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 895 | { |
| 896 | if (group) |
| 897 | atomic_dec(&group->users); |
| 898 | } |
| 899 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 900 | static inline struct tomoyo_domain_info *tomoyo_domain(void) |
| 901 | { |
| 902 | return current_cred()->security; |
| 903 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 904 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 905 | static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct |
| 906 | *task) |
| 907 | { |
| 908 | return task_cred_xxx(task, security); |
| 909 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 910 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 911 | static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1, |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 912 | const struct tomoyo_acl_info *p2) |
| 913 | { |
| 914 | return p1->type == p2->type; |
| 915 | } |
| 916 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 917 | static inline bool tomoyo_same_name_union |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 918 | (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) |
| 919 | { |
| 920 | return p1->filename == p2->filename && p1->group == p2->group && |
| 921 | p1->is_group == p2->is_group; |
| 922 | } |
| 923 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 924 | static inline bool tomoyo_same_number_union |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 925 | (const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2) |
| 926 | { |
| 927 | return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1] |
| 928 | && p1->group == p2->group && p1->min_type == p2->min_type && |
| 929 | p1->max_type == p2->max_type && p1->is_group == p2->is_group; |
| 930 | } |
| 931 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 932 | /** |
| 933 | * list_for_each_cookie - iterate over a list with cookie. |
| 934 | * @pos: the &struct list_head to use as a loop cursor. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 935 | * @head: the head for your list. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 936 | */ |
Tetsuo Handa | 475e6fa | 2010-06-24 11:28:14 +0900 | [diff] [blame] | 937 | #define list_for_each_cookie(pos, head) \ |
| 938 | if (!pos) \ |
| 939 | pos = srcu_dereference((head)->next, &tomoyo_ss); \ |
| 940 | for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss)) |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 941 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 942 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ |