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