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