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