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