diff options
Diffstat (limited to 'security/tomoyo/common.h')
| -rw-r--r-- | security/tomoyo/common.h | 850 |
1 files changed, 505 insertions, 345 deletions
diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h index 9f1ae5e3ba5..04454cb7b24 100644 --- a/security/tomoyo/common.h +++ b/security/tomoyo/common.h | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <linux/mount.h> | 20 | #include <linux/mount.h> |
| 21 | #include <linux/list.h> | 21 | #include <linux/list.h> |
| 22 | #include <linux/cred.h> | 22 | #include <linux/cred.h> |
| 23 | #include <linux/poll.h> | ||
| 23 | struct linux_binprm; | 24 | struct linux_binprm; |
| 24 | 25 | ||
| 25 | /********** Constants definitions. **********/ | 26 | /********** Constants definitions. **********/ |
| @@ -32,20 +33,44 @@ struct linux_binprm; | |||
| 32 | #define TOMOYO_HASH_BITS 8 | 33 | #define TOMOYO_HASH_BITS 8 |
| 33 | #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) | 34 | #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) |
| 34 | 35 | ||
| 35 | /* | 36 | #define TOMOYO_EXEC_TMPSIZE 4096 |
| 36 | * This is the max length of a token. | ||
| 37 | * | ||
| 38 | * A token consists of only ASCII printable characters. | ||
| 39 | * Non printable characters in a token is represented in \ooo style | ||
| 40 | * octal string. Thus, \ itself is represented as \\. | ||
| 41 | */ | ||
| 42 | #define TOMOYO_MAX_PATHNAME_LEN 4000 | ||
| 43 | 37 | ||
| 44 | /* Profile number is an integer between 0 and 255. */ | 38 | /* Profile number is an integer between 0 and 255. */ |
| 45 | #define TOMOYO_MAX_PROFILES 256 | 39 | #define TOMOYO_MAX_PROFILES 256 |
| 46 | 40 | ||
| 41 | enum tomoyo_mode_index { | ||
| 42 | TOMOYO_CONFIG_DISABLED, | ||
| 43 | TOMOYO_CONFIG_LEARNING, | ||
| 44 | TOMOYO_CONFIG_PERMISSIVE, | ||
| 45 | TOMOYO_CONFIG_ENFORCING, | ||
| 46 | TOMOYO_CONFIG_USE_DEFAULT = 255 | ||
| 47 | }; | ||
| 48 | |||
| 49 | enum tomoyo_policy_id { | ||
| 50 | TOMOYO_ID_GROUP, | ||
| 51 | TOMOYO_ID_PATH_GROUP, | ||
| 52 | TOMOYO_ID_NUMBER_GROUP, | ||
| 53 | TOMOYO_ID_TRANSITION_CONTROL, | ||
| 54 | TOMOYO_ID_AGGREGATOR, | ||
| 55 | TOMOYO_ID_GLOBALLY_READABLE, | ||
| 56 | TOMOYO_ID_PATTERN, | ||
| 57 | TOMOYO_ID_NO_REWRITE, | ||
| 58 | TOMOYO_ID_MANAGER, | ||
| 59 | TOMOYO_ID_NAME, | ||
| 60 | TOMOYO_ID_ACL, | ||
| 61 | TOMOYO_ID_DOMAIN, | ||
| 62 | TOMOYO_MAX_POLICY | ||
| 63 | }; | ||
| 64 | |||
| 65 | enum tomoyo_group_id { | ||
| 66 | TOMOYO_PATH_GROUP, | ||
| 67 | TOMOYO_NUMBER_GROUP, | ||
| 68 | TOMOYO_MAX_GROUP | ||
| 69 | }; | ||
| 70 | |||
| 47 | /* Keywords for ACLs. */ | 71 | /* Keywords for ACLs. */ |
| 48 | #define TOMOYO_KEYWORD_ALIAS "alias " | 72 | #define TOMOYO_KEYWORD_AGGREGATOR "aggregator " |
| 73 | #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount " | ||
| 49 | #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " | 74 | #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " |
| 50 | #define TOMOYO_KEYWORD_DELETE "delete " | 75 | #define TOMOYO_KEYWORD_DELETE "delete " |
| 51 | #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " | 76 | #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " |
| @@ -55,36 +80,51 @@ struct linux_binprm; | |||
| 55 | #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " | 80 | #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " |
| 56 | #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " | 81 | #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " |
| 57 | #define TOMOYO_KEYWORD_PATH_GROUP "path_group " | 82 | #define TOMOYO_KEYWORD_PATH_GROUP "path_group " |
| 83 | #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group " | ||
| 58 | #define TOMOYO_KEYWORD_SELECT "select " | 84 | #define TOMOYO_KEYWORD_SELECT "select " |
| 59 | #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " | 85 | #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " |
| 60 | #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" | 86 | #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" |
| 87 | #define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded" | ||
| 88 | #define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed" | ||
| 61 | /* A domain definition starts with <kernel>. */ | 89 | /* A domain definition starts with <kernel>. */ |
| 62 | #define TOMOYO_ROOT_NAME "<kernel>" | 90 | #define TOMOYO_ROOT_NAME "<kernel>" |
| 63 | #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) | 91 | #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) |
| 64 | 92 | ||
| 65 | /* Index numbers for Access Controls. */ | 93 | /* Value type definition. */ |
| 66 | enum tomoyo_mac_index { | 94 | #define TOMOYO_VALUE_TYPE_INVALID 0 |
| 67 | TOMOYO_MAC_FOR_FILE, /* domain_policy.conf */ | 95 | #define TOMOYO_VALUE_TYPE_DECIMAL 1 |
| 68 | TOMOYO_MAX_ACCEPT_ENTRY, | 96 | #define TOMOYO_VALUE_TYPE_OCTAL 2 |
| 69 | TOMOYO_VERBOSE, | 97 | #define TOMOYO_VALUE_TYPE_HEXADECIMAL 3 |
| 70 | TOMOYO_MAX_CONTROL_INDEX | 98 | |
| 99 | enum tomoyo_transition_type { | ||
| 100 | /* Do not change this order, */ | ||
| 101 | TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, | ||
| 102 | TOMOYO_TRANSITION_CONTROL_INITIALIZE, | ||
| 103 | TOMOYO_TRANSITION_CONTROL_NO_KEEP, | ||
| 104 | TOMOYO_TRANSITION_CONTROL_KEEP, | ||
| 105 | TOMOYO_MAX_TRANSITION_TYPE | ||
| 71 | }; | 106 | }; |
| 72 | 107 | ||
| 73 | /* Index numbers for Access Controls. */ | 108 | /* Index numbers for Access Controls. */ |
| 74 | enum tomoyo_acl_entry_type_index { | 109 | enum tomoyo_acl_entry_type_index { |
| 75 | TOMOYO_TYPE_PATH_ACL, | 110 | TOMOYO_TYPE_PATH_ACL, |
| 76 | TOMOYO_TYPE_PATH2_ACL, | 111 | TOMOYO_TYPE_PATH2_ACL, |
| 112 | TOMOYO_TYPE_PATH_NUMBER_ACL, | ||
| 113 | TOMOYO_TYPE_MKDEV_ACL, | ||
| 114 | TOMOYO_TYPE_MOUNT_ACL, | ||
| 77 | }; | 115 | }; |
| 78 | 116 | ||
| 79 | /* Index numbers for File Controls. */ | 117 | /* Index numbers for File Controls. */ |
| 80 | 118 | ||
| 81 | /* | 119 | /* |
| 82 | * TYPE_READ_WRITE_ACL is special. TYPE_READ_WRITE_ACL is automatically set | 120 | * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically |
| 83 | * if both TYPE_READ_ACL and TYPE_WRITE_ACL are set. Both TYPE_READ_ACL and | 121 | * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set. |
| 84 | * TYPE_WRITE_ACL are automatically set if TYPE_READ_WRITE_ACL is set. | 122 | * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if |
| 85 | * TYPE_READ_WRITE_ACL is automatically cleared if either TYPE_READ_ACL or | 123 | * TOMOYO_TYPE_READ_WRITE is set. |
| 86 | * TYPE_WRITE_ACL is cleared. Both TYPE_READ_ACL and TYPE_WRITE_ACL are | 124 | * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ |
| 87 | * automatically cleared if TYPE_READ_WRITE_ACL is cleared. | 125 | * or TOMOYO_TYPE_WRITE is cleared. |
| 126 | * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if | ||
| 127 | * TOMOYO_TYPE_READ_WRITE is cleared. | ||
| 88 | */ | 128 | */ |
| 89 | 129 | ||
| 90 | enum tomoyo_path_acl_index { | 130 | enum tomoyo_path_acl_index { |
| @@ -92,27 +132,24 @@ enum tomoyo_path_acl_index { | |||
| 92 | TOMOYO_TYPE_EXECUTE, | 132 | TOMOYO_TYPE_EXECUTE, |
| 93 | TOMOYO_TYPE_READ, | 133 | TOMOYO_TYPE_READ, |
| 94 | TOMOYO_TYPE_WRITE, | 134 | TOMOYO_TYPE_WRITE, |
| 95 | TOMOYO_TYPE_CREATE, | ||
| 96 | TOMOYO_TYPE_UNLINK, | 135 | TOMOYO_TYPE_UNLINK, |
| 97 | TOMOYO_TYPE_MKDIR, | ||
| 98 | TOMOYO_TYPE_RMDIR, | 136 | TOMOYO_TYPE_RMDIR, |
| 99 | TOMOYO_TYPE_MKFIFO, | ||
| 100 | TOMOYO_TYPE_MKSOCK, | ||
| 101 | TOMOYO_TYPE_MKBLOCK, | ||
| 102 | TOMOYO_TYPE_MKCHAR, | ||
| 103 | TOMOYO_TYPE_TRUNCATE, | 137 | TOMOYO_TYPE_TRUNCATE, |
| 104 | TOMOYO_TYPE_SYMLINK, | 138 | TOMOYO_TYPE_SYMLINK, |
| 105 | TOMOYO_TYPE_REWRITE, | 139 | TOMOYO_TYPE_REWRITE, |
| 106 | TOMOYO_TYPE_IOCTL, | ||
| 107 | TOMOYO_TYPE_CHMOD, | ||
| 108 | TOMOYO_TYPE_CHOWN, | ||
| 109 | TOMOYO_TYPE_CHGRP, | ||
| 110 | TOMOYO_TYPE_CHROOT, | 140 | TOMOYO_TYPE_CHROOT, |
| 111 | TOMOYO_TYPE_MOUNT, | ||
| 112 | TOMOYO_TYPE_UMOUNT, | 141 | TOMOYO_TYPE_UMOUNT, |
| 113 | TOMOYO_MAX_PATH_OPERATION | 142 | TOMOYO_MAX_PATH_OPERATION |
| 114 | }; | 143 | }; |
| 115 | 144 | ||
| 145 | #define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE)) | ||
| 146 | |||
| 147 | enum tomoyo_mkdev_acl_index { | ||
| 148 | TOMOYO_TYPE_MKBLOCK, | ||
| 149 | TOMOYO_TYPE_MKCHAR, | ||
| 150 | TOMOYO_MAX_MKDEV_OPERATION | ||
| 151 | }; | ||
| 152 | |||
| 116 | enum tomoyo_path2_acl_index { | 153 | enum tomoyo_path2_acl_index { |
| 117 | TOMOYO_TYPE_LINK, | 154 | TOMOYO_TYPE_LINK, |
| 118 | TOMOYO_TYPE_RENAME, | 155 | TOMOYO_TYPE_RENAME, |
| @@ -120,6 +157,18 @@ enum tomoyo_path2_acl_index { | |||
| 120 | TOMOYO_MAX_PATH2_OPERATION | 157 | TOMOYO_MAX_PATH2_OPERATION |
| 121 | }; | 158 | }; |
| 122 | 159 | ||
| 160 | enum tomoyo_path_number_acl_index { | ||
| 161 | TOMOYO_TYPE_CREATE, | ||
| 162 | TOMOYO_TYPE_MKDIR, | ||
| 163 | TOMOYO_TYPE_MKFIFO, | ||
| 164 | TOMOYO_TYPE_MKSOCK, | ||
| 165 | TOMOYO_TYPE_IOCTL, | ||
| 166 | TOMOYO_TYPE_CHMOD, | ||
| 167 | TOMOYO_TYPE_CHOWN, | ||
| 168 | TOMOYO_TYPE_CHGRP, | ||
| 169 | TOMOYO_MAX_PATH_NUMBER_OPERATION | ||
| 170 | }; | ||
| 171 | |||
| 123 | enum tomoyo_securityfs_interface_index { | 172 | enum tomoyo_securityfs_interface_index { |
| 124 | TOMOYO_DOMAINPOLICY, | 173 | TOMOYO_DOMAINPOLICY, |
| 125 | TOMOYO_EXCEPTIONPOLICY, | 174 | TOMOYO_EXCEPTIONPOLICY, |
| @@ -129,20 +178,109 @@ enum tomoyo_securityfs_interface_index { | |||
| 129 | TOMOYO_SELFDOMAIN, | 178 | TOMOYO_SELFDOMAIN, |
| 130 | TOMOYO_VERSION, | 179 | TOMOYO_VERSION, |
| 131 | TOMOYO_PROFILE, | 180 | TOMOYO_PROFILE, |
| 181 | TOMOYO_QUERY, | ||
| 132 | TOMOYO_MANAGER | 182 | TOMOYO_MANAGER |
| 133 | }; | 183 | }; |
| 134 | 184 | ||
| 185 | enum tomoyo_mac_index { | ||
| 186 | TOMOYO_MAC_FILE_EXECUTE, | ||
| 187 | TOMOYO_MAC_FILE_OPEN, | ||
| 188 | TOMOYO_MAC_FILE_CREATE, | ||
| 189 | TOMOYO_MAC_FILE_UNLINK, | ||
| 190 | TOMOYO_MAC_FILE_MKDIR, | ||
| 191 | TOMOYO_MAC_FILE_RMDIR, | ||
| 192 | TOMOYO_MAC_FILE_MKFIFO, | ||
| 193 | TOMOYO_MAC_FILE_MKSOCK, | ||
| 194 | TOMOYO_MAC_FILE_TRUNCATE, | ||
| 195 | TOMOYO_MAC_FILE_SYMLINK, | ||
| 196 | TOMOYO_MAC_FILE_REWRITE, | ||
| 197 | TOMOYO_MAC_FILE_MKBLOCK, | ||
| 198 | TOMOYO_MAC_FILE_MKCHAR, | ||
| 199 | TOMOYO_MAC_FILE_LINK, | ||
| 200 | TOMOYO_MAC_FILE_RENAME, | ||
| 201 | TOMOYO_MAC_FILE_CHMOD, | ||
| 202 | TOMOYO_MAC_FILE_CHOWN, | ||
| 203 | TOMOYO_MAC_FILE_CHGRP, | ||
| 204 | TOMOYO_MAC_FILE_IOCTL, | ||
| 205 | TOMOYO_MAC_FILE_CHROOT, | ||
| 206 | TOMOYO_MAC_FILE_MOUNT, | ||
| 207 | TOMOYO_MAC_FILE_UMOUNT, | ||
| 208 | TOMOYO_MAC_FILE_PIVOT_ROOT, | ||
| 209 | TOMOYO_MAX_MAC_INDEX | ||
| 210 | }; | ||
| 211 | |||
| 212 | enum tomoyo_mac_category_index { | ||
| 213 | TOMOYO_MAC_CATEGORY_FILE, | ||
| 214 | TOMOYO_MAX_MAC_CATEGORY_INDEX | ||
| 215 | }; | ||
| 216 | |||
| 217 | #define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */ | ||
| 218 | |||
| 135 | /********** Structure definitions. **********/ | 219 | /********** Structure definitions. **********/ |
| 136 | 220 | ||
| 137 | /* | 221 | /* |
| 138 | * tomoyo_page_buffer is a structure which is used for holding a pathname | 222 | * tomoyo_acl_head is a structure which is used for holding elements not in |
| 139 | * obtained from "struct dentry" and "struct vfsmount" pair. | 223 | * domain policy. |
| 140 | * As of now, it is 4096 bytes. If users complain that 4096 bytes is too small | 224 | * It has following fields. |
| 141 | * (because TOMOYO escapes non ASCII printable characters using \ooo format), | 225 | * |
| 142 | * we will make the buffer larger. | 226 | * (1) "list" which is linked to tomoyo_policy_list[] . |
| 227 | * (2) "is_deleted" is a bool which is true if marked as deleted, false | ||
| 228 | * otherwise. | ||
| 143 | */ | 229 | */ |
| 144 | struct tomoyo_page_buffer { | 230 | struct tomoyo_acl_head { |
| 145 | char buffer[4096]; | 231 | struct list_head list; |
| 232 | bool is_deleted; | ||
| 233 | } __packed; | ||
| 234 | |||
| 235 | /* | ||
| 236 | * tomoyo_request_info is a structure which is used for holding | ||
| 237 | * | ||
| 238 | * (1) Domain information of current process. | ||
| 239 | * (2) How many retries are made for this request. | ||
| 240 | * (3) Profile number used for this request. | ||
| 241 | * (4) Access control mode of the profile. | ||
| 242 | */ | ||
| 243 | struct tomoyo_request_info { | ||
| 244 | struct tomoyo_domain_info *domain; | ||
| 245 | /* For holding parameters. */ | ||
| 246 | union { | ||
| 247 | struct { | ||
| 248 | const struct tomoyo_path_info *filename; | ||
| 249 | /* For using wildcards at tomoyo_find_next_domain(). */ | ||
| 250 | const struct tomoyo_path_info *matched_path; | ||
| 251 | u8 operation; | ||
| 252 | } path; | ||
| 253 | struct { | ||
| 254 | const struct tomoyo_path_info *filename1; | ||
| 255 | const struct tomoyo_path_info *filename2; | ||
| 256 | u8 operation; | ||
| 257 | } path2; | ||
| 258 | struct { | ||
| 259 | const struct tomoyo_path_info *filename; | ||
| 260 | unsigned int mode; | ||
| 261 | unsigned int major; | ||
| 262 | unsigned int minor; | ||
| 263 | u8 operation; | ||
| 264 | } mkdev; | ||
| 265 | struct { | ||
| 266 | const struct tomoyo_path_info *filename; | ||
| 267 | unsigned long number; | ||
| 268 | u8 operation; | ||
| 269 | } path_number; | ||
| 270 | struct { | ||
| 271 | const struct tomoyo_path_info *type; | ||
| 272 | const struct tomoyo_path_info *dir; | ||
| 273 | const struct tomoyo_path_info *dev; | ||
| 274 | unsigned long flags; | ||
| 275 | int need_dev; | ||
| 276 | } mount; | ||
| 277 | } param; | ||
| 278 | u8 param_type; | ||
| 279 | bool granted; | ||
| 280 | u8 retry; | ||
| 281 | u8 profile; | ||
| 282 | u8 mode; /* One of tomoyo_mode_index . */ | ||
| 283 | u8 type; | ||
| 146 | }; | 284 | }; |
| 147 | 285 | ||
| 148 | /* | 286 | /* |
| @@ -174,45 +312,31 @@ struct tomoyo_path_info { | |||
| 174 | }; | 312 | }; |
| 175 | 313 | ||
| 176 | /* | 314 | /* |
| 177 | * tomoyo_name_entry is a structure which is used for linking | 315 | * tomoyo_name is a structure which is used for linking |
| 178 | * "struct tomoyo_path_info" into tomoyo_name_list . | 316 | * "struct tomoyo_path_info" into tomoyo_name_list . |
| 179 | */ | 317 | */ |
| 180 | struct tomoyo_name_entry { | 318 | struct tomoyo_name { |
| 181 | struct list_head list; | 319 | struct list_head list; |
| 182 | atomic_t users; | 320 | atomic_t users; |
| 183 | struct tomoyo_path_info entry; | 321 | struct tomoyo_path_info entry; |
| 184 | }; | 322 | }; |
| 185 | 323 | ||
| 186 | /* | ||
| 187 | * tomoyo_path_info_with_data is a structure which is used for holding a | ||
| 188 | * pathname obtained from "struct dentry" and "struct vfsmount" pair. | ||
| 189 | * | ||
| 190 | * "struct tomoyo_path_info_with_data" consists of "struct tomoyo_path_info" | ||
| 191 | * and buffer for the pathname, while "struct tomoyo_page_buffer" consists of | ||
| 192 | * buffer for the pathname only. | ||
| 193 | * | ||
| 194 | * "struct tomoyo_path_info_with_data" is intended to allow TOMOYO to release | ||
| 195 | * both "struct tomoyo_path_info" and buffer for the pathname by single kfree() | ||
| 196 | * so that we don't need to return two pointers to the caller. If the caller | ||
| 197 | * puts "struct tomoyo_path_info" on stack memory, we will be able to remove | ||
| 198 | * "struct tomoyo_path_info_with_data". | ||
| 199 | */ | ||
| 200 | struct tomoyo_path_info_with_data { | ||
| 201 | /* Keep "head" first, for this pointer is passed to kfree(). */ | ||
| 202 | struct tomoyo_path_info head; | ||
| 203 | char barrier1[16]; /* Safeguard for overrun. */ | ||
| 204 | char body[TOMOYO_MAX_PATHNAME_LEN]; | ||
| 205 | char barrier2[16]; /* Safeguard for overrun. */ | ||
| 206 | }; | ||
| 207 | |||
| 208 | struct tomoyo_name_union { | 324 | struct tomoyo_name_union { |
| 209 | const struct tomoyo_path_info *filename; | 325 | const struct tomoyo_path_info *filename; |
| 210 | struct tomoyo_path_group *group; | 326 | struct tomoyo_group *group; |
| 211 | u8 is_group; | 327 | u8 is_group; |
| 212 | }; | 328 | }; |
| 213 | 329 | ||
| 214 | /* Structure for "path_group" directive. */ | 330 | struct tomoyo_number_union { |
| 215 | struct tomoyo_path_group { | 331 | unsigned long values[2]; |
| 332 | struct tomoyo_group *group; | ||
| 333 | u8 min_type; | ||
| 334 | u8 max_type; | ||
| 335 | u8 is_group; | ||
| 336 | }; | ||
| 337 | |||
| 338 | /* Structure for "path_group"/"number_group" directive. */ | ||
| 339 | struct tomoyo_group { | ||
| 216 | struct list_head list; | 340 | struct list_head list; |
| 217 | const struct tomoyo_path_info *group_name; | 341 | const struct tomoyo_path_info *group_name; |
| 218 | struct list_head member_list; | 342 | struct list_head member_list; |
| @@ -220,28 +344,35 @@ struct tomoyo_path_group { | |||
| 220 | }; | 344 | }; |
| 221 | 345 | ||
| 222 | /* Structure for "path_group" directive. */ | 346 | /* Structure for "path_group" directive. */ |
| 223 | struct tomoyo_path_group_member { | 347 | struct tomoyo_path_group { |
| 224 | struct list_head list; | 348 | struct tomoyo_acl_head head; |
| 225 | bool is_deleted; | ||
| 226 | const struct tomoyo_path_info *member_name; | 349 | const struct tomoyo_path_info *member_name; |
| 227 | }; | 350 | }; |
| 228 | 351 | ||
| 352 | /* Structure for "number_group" directive. */ | ||
| 353 | struct tomoyo_number_group { | ||
| 354 | struct tomoyo_acl_head head; | ||
| 355 | struct tomoyo_number_union number; | ||
| 356 | }; | ||
| 357 | |||
| 229 | /* | 358 | /* |
| 230 | * tomoyo_acl_info is a structure which is used for holding | 359 | * tomoyo_acl_info is a structure which is used for holding |
| 231 | * | 360 | * |
| 232 | * (1) "list" which is linked to the ->acl_info_list of | 361 | * (1) "list" which is linked to the ->acl_info_list of |
| 233 | * "struct tomoyo_domain_info" | 362 | * "struct tomoyo_domain_info" |
| 234 | * (2) "type" which tells type of the entry (either | 363 | * (2) "is_deleted" is a bool which is true if this domain is marked as |
| 235 | * "struct tomoyo_path_acl" or "struct tomoyo_path2_acl"). | 364 | * "deleted", false otherwise. |
| 365 | * (3) "type" which tells type of the entry. | ||
| 236 | * | 366 | * |
| 237 | * Packing "struct tomoyo_acl_info" allows | 367 | * Packing "struct tomoyo_acl_info" allows |
| 238 | * "struct tomoyo_path_acl" to embed "u8" + "u16" and | 368 | * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl" |
| 239 | * "struct tomoyo_path2_acl" to embed "u8" | 369 | * "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed |
| 240 | * without enlarging their structure size. | 370 | * "u8" without enlarging their structure size. |
| 241 | */ | 371 | */ |
| 242 | struct tomoyo_acl_info { | 372 | struct tomoyo_acl_info { |
| 243 | struct list_head list; | 373 | struct list_head list; |
| 244 | u8 type; | 374 | bool is_deleted; |
| 375 | u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */ | ||
| 245 | } __packed; | 376 | } __packed; |
| 246 | 377 | ||
| 247 | /* | 378 | /* |
| @@ -299,20 +430,62 @@ struct tomoyo_domain_info { | |||
| 299 | * (3) "name" is the pathname. | 430 | * (3) "name" is the pathname. |
| 300 | * | 431 | * |
| 301 | * Directives held by this structure are "allow_read/write", "allow_execute", | 432 | * Directives held by this structure are "allow_read/write", "allow_execute", |
| 302 | * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir", | 433 | * "allow_read", "allow_write", "allow_unlink", "allow_rmdir", |
| 303 | * "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock", | 434 | * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and |
| 304 | * "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite", | 435 | * "allow_unmount". |
| 305 | * "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot", "allow_mount" | ||
| 306 | * and "allow_unmount". | ||
| 307 | */ | 436 | */ |
| 308 | struct tomoyo_path_acl { | 437 | struct tomoyo_path_acl { |
| 309 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ | 438 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ |
| 310 | u8 perm_high; | ||
| 311 | u16 perm; | 439 | u16 perm; |
| 312 | struct tomoyo_name_union name; | 440 | struct tomoyo_name_union name; |
| 313 | }; | 441 | }; |
| 314 | 442 | ||
| 315 | /* | 443 | /* |
| 444 | * tomoyo_path_number_acl is a structure which is used for holding an | ||
| 445 | * entry with one pathname and one number operation. | ||
| 446 | * It has following fields. | ||
| 447 | * | ||
| 448 | * (1) "head" which is a "struct tomoyo_acl_info". | ||
| 449 | * (2) "perm" which is a bitmask of permitted operations. | ||
| 450 | * (3) "name" is the pathname. | ||
| 451 | * (4) "number" is the numeric value. | ||
| 452 | * | ||
| 453 | * Directives held by this structure are "allow_create", "allow_mkdir", | ||
| 454 | * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown" | ||
| 455 | * and "allow_chgrp". | ||
| 456 | * | ||
| 457 | */ | ||
| 458 | struct tomoyo_path_number_acl { | ||
| 459 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ | ||
| 460 | u8 perm; | ||
| 461 | struct tomoyo_name_union name; | ||
| 462 | struct tomoyo_number_union number; | ||
| 463 | }; | ||
| 464 | |||
| 465 | /* | ||
| 466 | * tomoyo_mkdev_acl is a structure which is used for holding an | ||
| 467 | * entry with one pathname and three numbers operation. | ||
| 468 | * It has following fields. | ||
| 469 | * | ||
| 470 | * (1) "head" which is a "struct tomoyo_acl_info". | ||
| 471 | * (2) "perm" which is a bitmask of permitted operations. | ||
| 472 | * (3) "mode" is the create mode. | ||
| 473 | * (4) "major" is the major number of device node. | ||
| 474 | * (5) "minor" is the minor number of device node. | ||
| 475 | * | ||
| 476 | * Directives held by this structure are "allow_mkchar", "allow_mkblock". | ||
| 477 | * | ||
| 478 | */ | ||
| 479 | struct tomoyo_mkdev_acl { | ||
| 480 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ | ||
| 481 | u8 perm; | ||
| 482 | struct tomoyo_name_union name; | ||
| 483 | struct tomoyo_number_union mode; | ||
| 484 | struct tomoyo_number_union major; | ||
| 485 | struct tomoyo_number_union minor; | ||
| 486 | }; | ||
| 487 | |||
| 488 | /* | ||
| 316 | * tomoyo_path2_acl is a structure which is used for holding an | 489 | * tomoyo_path2_acl is a structure which is used for holding an |
| 317 | * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). | 490 | * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). |
| 318 | * It has following fields. | 491 | * It has following fields. |
| @@ -333,53 +506,61 @@ struct tomoyo_path2_acl { | |||
| 333 | }; | 506 | }; |
| 334 | 507 | ||
| 335 | /* | 508 | /* |
| 336 | * tomoyo_io_buffer is a structure which is used for reading and modifying | 509 | * tomoyo_mount_acl is a structure which is used for holding an |
| 337 | * configuration via /sys/kernel/security/tomoyo/ interface. | 510 | * entry for mount operation. |
| 338 | * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as | 511 | * It has following fields. |
| 339 | * cursors. | ||
| 340 | * | 512 | * |
| 341 | * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of | 513 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 342 | * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info" | 514 | * (2) "dev_name" is the device name. |
| 343 | * entry has a list of "struct tomoyo_acl_info", we need two cursors when | 515 | * (3) "dir_name" is the mount point. |
| 344 | * reading (one is for traversing tomoyo_domain_list and the other is for | 516 | * (4) "fs_type" is the filesystem type. |
| 345 | * traversing "struct tomoyo_acl_info"->acl_info_list ). | 517 | * (5) "flags" is the mount flags. |
| 346 | * | 518 | * |
| 347 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with | 519 | * Directive held by this structure is "allow_mount". |
| 348 | * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the | 520 | */ |
| 349 | * domain with the domainname specified by the rest of that line (NULL is set | 521 | struct tomoyo_mount_acl { |
| 350 | * if seek failed). | 522 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ |
| 351 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with | 523 | struct tomoyo_name_union dev_name; |
| 352 | * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that | 524 | struct tomoyo_name_union dir_name; |
| 353 | * line (->write_var1 is set to NULL if a domain was deleted). | 525 | struct tomoyo_name_union fs_type; |
| 354 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with | 526 | struct tomoyo_number_union flags; |
| 355 | * neither "select " nor "delete ", an entry or a domain specified by that line | 527 | }; |
| 356 | * is appended. | 528 | |
| 529 | #define TOMOYO_MAX_IO_READ_QUEUE 32 | ||
| 530 | |||
| 531 | /* | ||
| 532 | * Structure for reading/writing policy via /sys/kernel/security/tomoyo | ||
| 533 | * interfaces. | ||
| 357 | */ | 534 | */ |
| 358 | struct tomoyo_io_buffer { | 535 | struct tomoyo_io_buffer { |
| 359 | int (*read) (struct tomoyo_io_buffer *); | 536 | void (*read) (struct tomoyo_io_buffer *); |
| 360 | int (*write) (struct tomoyo_io_buffer *); | 537 | int (*write) (struct tomoyo_io_buffer *); |
| 538 | int (*poll) (struct file *file, poll_table *wait); | ||
| 361 | /* Exclusive lock for this structure. */ | 539 | /* Exclusive lock for this structure. */ |
| 362 | struct mutex io_sem; | 540 | struct mutex io_sem; |
| 363 | /* Index returned by tomoyo_read_lock(). */ | 541 | /* Index returned by tomoyo_read_lock(). */ |
| 364 | int reader_idx; | 542 | int reader_idx; |
| 365 | /* The position currently reading from. */ | 543 | char __user *read_user_buf; |
| 366 | struct list_head *read_var1; | 544 | int read_user_buf_avail; |
| 367 | /* Extra variables for reading. */ | 545 | struct { |
| 368 | struct list_head *read_var2; | 546 | struct list_head *domain; |
| 547 | struct list_head *group; | ||
| 548 | struct list_head *acl; | ||
| 549 | int avail; | ||
| 550 | int step; | ||
| 551 | int query_index; | ||
| 552 | u16 index; | ||
| 553 | u8 bit; | ||
| 554 | u8 w_pos; | ||
| 555 | bool eof; | ||
| 556 | bool print_this_domain_only; | ||
| 557 | bool print_execute_only; | ||
| 558 | const char *w[TOMOYO_MAX_IO_READ_QUEUE]; | ||
| 559 | } r; | ||
| 369 | /* The position currently writing to. */ | 560 | /* The position currently writing to. */ |
| 370 | struct tomoyo_domain_info *write_var1; | 561 | struct tomoyo_domain_info *write_var1; |
| 371 | /* The step for reading. */ | ||
| 372 | int read_step; | ||
| 373 | /* Buffer for reading. */ | 562 | /* Buffer for reading. */ |
| 374 | char *read_buf; | 563 | char *read_buf; |
| 375 | /* EOF flag for reading. */ | ||
| 376 | bool read_eof; | ||
| 377 | /* Read domain ACL of specified PID? */ | ||
| 378 | bool read_single_domain; | ||
| 379 | /* Extra variable for reading. */ | ||
| 380 | u8 read_bit; | ||
| 381 | /* Bytes available for reading. */ | ||
| 382 | int read_avail; | ||
| 383 | /* Size of read buffer. */ | 564 | /* Size of read buffer. */ |
| 384 | int readbuf_size; | 565 | int readbuf_size; |
| 385 | /* Buffer for writing. */ | 566 | /* Buffer for writing. */ |
| @@ -388,215 +569,203 @@ struct tomoyo_io_buffer { | |||
| 388 | int write_avail; | 569 | int write_avail; |
| 389 | /* Size of write buffer. */ | 570 | /* Size of write buffer. */ |
| 390 | int writebuf_size; | 571 | int writebuf_size; |
| 572 | /* Type of this interface. */ | ||
| 573 | u8 type; | ||
| 391 | }; | 574 | }; |
| 392 | 575 | ||
| 393 | /* | 576 | /* |
| 394 | * tomoyo_globally_readable_file_entry is a structure which is used for holding | 577 | * tomoyo_readable_file is a structure which is used for holding |
| 395 | * "allow_read" entries. | 578 | * "allow_read" entries. |
| 396 | * It has following fields. | 579 | * It has following fields. |
| 397 | * | 580 | * |
| 398 | * (1) "list" which is linked to tomoyo_globally_readable_list . | 581 | * (1) "head" is "struct tomoyo_acl_head". |
| 399 | * (2) "filename" is a pathname which is allowed to open(O_RDONLY). | 582 | * (2) "filename" is a pathname which is allowed to open(O_RDONLY). |
| 400 | * (3) "is_deleted" is a bool which is true if marked as deleted, false | ||
| 401 | * otherwise. | ||
| 402 | */ | 583 | */ |
| 403 | struct tomoyo_globally_readable_file_entry { | 584 | struct tomoyo_readable_file { |
| 404 | struct list_head list; | 585 | struct tomoyo_acl_head head; |
| 405 | const struct tomoyo_path_info *filename; | 586 | const struct tomoyo_path_info *filename; |
| 406 | bool is_deleted; | ||
| 407 | }; | 587 | }; |
| 408 | 588 | ||
| 409 | /* | 589 | /* |
| 410 | * tomoyo_pattern_entry is a structure which is used for holding | 590 | * tomoyo_no_pattern is a structure which is used for holding |
| 411 | * "tomoyo_pattern_list" entries. | 591 | * "file_pattern" entries. |
| 412 | * It has following fields. | 592 | * It has following fields. |
| 413 | * | 593 | * |
| 414 | * (1) "list" which is linked to tomoyo_pattern_list . | 594 | * (1) "head" is "struct tomoyo_acl_head". |
| 415 | * (2) "pattern" is a pathname pattern which is used for converting pathnames | 595 | * (2) "pattern" is a pathname pattern which is used for converting pathnames |
| 416 | * to pathname patterns during learning mode. | 596 | * to pathname patterns during learning mode. |
| 417 | * (3) "is_deleted" is a bool which is true if marked as deleted, false | ||
| 418 | * otherwise. | ||
| 419 | */ | 597 | */ |
| 420 | struct tomoyo_pattern_entry { | 598 | struct tomoyo_no_pattern { |
| 421 | struct list_head list; | 599 | struct tomoyo_acl_head head; |
| 422 | const struct tomoyo_path_info *pattern; | 600 | const struct tomoyo_path_info *pattern; |
| 423 | bool is_deleted; | ||
| 424 | }; | 601 | }; |
| 425 | 602 | ||
| 426 | /* | 603 | /* |
| 427 | * tomoyo_no_rewrite_entry is a structure which is used for holding | 604 | * tomoyo_no_rewrite is a structure which is used for holding |
| 428 | * "deny_rewrite" entries. | 605 | * "deny_rewrite" entries. |
| 429 | * It has following fields. | 606 | * It has following fields. |
| 430 | * | 607 | * |
| 431 | * (1) "list" which is linked to tomoyo_no_rewrite_list . | 608 | * (1) "head" is "struct tomoyo_acl_head". |
| 432 | * (2) "pattern" is a pathname which is by default not permitted to modify | 609 | * (2) "pattern" is a pathname which is by default not permitted to modify |
| 433 | * already existing content. | 610 | * already existing content. |
| 434 | * (3) "is_deleted" is a bool which is true if marked as deleted, false | ||
| 435 | * otherwise. | ||
| 436 | */ | 611 | */ |
| 437 | struct tomoyo_no_rewrite_entry { | 612 | struct tomoyo_no_rewrite { |
| 438 | struct list_head list; | 613 | struct tomoyo_acl_head head; |
| 439 | const struct tomoyo_path_info *pattern; | 614 | const struct tomoyo_path_info *pattern; |
| 440 | bool is_deleted; | ||
| 441 | }; | 615 | }; |
| 442 | 616 | ||
| 443 | /* | 617 | /* |
| 444 | * tomoyo_domain_initializer_entry is a structure which is used for holding | 618 | * tomoyo_transition_control is a structure which is used for holding |
| 445 | * "initialize_domain" and "no_initialize_domain" entries. | 619 | * "initialize_domain"/"no_initialize_domain"/"keep_domain"/"no_keep_domain" |
| 620 | * entries. | ||
| 446 | * It has following fields. | 621 | * It has following fields. |
| 447 | * | 622 | * |
| 448 | * (1) "list" which is linked to tomoyo_domain_initializer_list . | 623 | * (1) "head" is "struct tomoyo_acl_head". |
| 449 | * (2) "domainname" which is "a domainname" or "the last component of a | 624 | * (2) "type" is type of this entry. |
| 450 | * domainname". This field is NULL if "from" clause is not specified. | 625 | * (3) "is_last_name" is a bool which is true if "domainname" is "the last |
| 451 | * (3) "program" which is a program's pathname. | ||
| 452 | * (4) "is_deleted" is a bool which is true if marked as deleted, false | ||
| 453 | * otherwise. | ||
| 454 | * (5) "is_not" is a bool which is true if "no_initialize_domain", false | ||
| 455 | * otherwise. | ||
| 456 | * (6) "is_last_name" is a bool which is true if "domainname" is "the last | ||
| 457 | * component of a domainname", false otherwise. | 626 | * component of a domainname", false otherwise. |
| 458 | */ | 627 | * (4) "domainname" which is "a domainname" or "the last component of a |
| 459 | struct tomoyo_domain_initializer_entry { | ||
| 460 | struct list_head list; | ||
| 461 | const struct tomoyo_path_info *domainname; /* This may be NULL */ | ||
| 462 | const struct tomoyo_path_info *program; | ||
| 463 | bool is_deleted; | ||
| 464 | bool is_not; /* True if this entry is "no_initialize_domain". */ | ||
| 465 | /* True if the domainname is tomoyo_get_last_name(). */ | ||
| 466 | bool is_last_name; | ||
| 467 | }; | ||
| 468 | |||
| 469 | /* | ||
| 470 | * tomoyo_domain_keeper_entry is a structure which is used for holding | ||
| 471 | * "keep_domain" and "no_keep_domain" entries. | ||
| 472 | * It has following fields. | ||
| 473 | * | ||
| 474 | * (1) "list" which is linked to tomoyo_domain_keeper_list . | ||
| 475 | * (2) "domainname" which is "a domainname" or "the last component of a | ||
| 476 | * domainname". | 628 | * domainname". |
| 477 | * (3) "program" which is a program's pathname. | 629 | * (5) "program" which is a program's pathname. |
| 478 | * This field is NULL if "from" clause is not specified. | ||
| 479 | * (4) "is_deleted" is a bool which is true if marked as deleted, false | ||
| 480 | * otherwise. | ||
| 481 | * (5) "is_not" is a bool which is true if "no_initialize_domain", false | ||
| 482 | * otherwise. | ||
| 483 | * (6) "is_last_name" is a bool which is true if "domainname" is "the last | ||
| 484 | * component of a domainname", false otherwise. | ||
| 485 | */ | 630 | */ |
| 486 | struct tomoyo_domain_keeper_entry { | 631 | struct tomoyo_transition_control { |
| 487 | struct list_head list; | 632 | struct tomoyo_acl_head head; |
| 488 | const struct tomoyo_path_info *domainname; | 633 | u8 type; /* One of values in "enum tomoyo_transition_type". */ |
| 489 | const struct tomoyo_path_info *program; /* This may be NULL */ | ||
| 490 | bool is_deleted; | ||
| 491 | bool is_not; /* True if this entry is "no_keep_domain". */ | ||
| 492 | /* True if the domainname is tomoyo_get_last_name(). */ | 634 | /* True if the domainname is tomoyo_get_last_name(). */ |
| 493 | bool is_last_name; | 635 | bool is_last_name; |
| 636 | const struct tomoyo_path_info *domainname; /* Maybe NULL */ | ||
| 637 | const struct tomoyo_path_info *program; /* Maybe NULL */ | ||
| 494 | }; | 638 | }; |
| 495 | 639 | ||
| 496 | /* | 640 | /* |
| 497 | * tomoyo_alias_entry is a structure which is used for holding "alias" entries. | 641 | * tomoyo_aggregator is a structure which is used for holding |
| 642 | * "aggregator" entries. | ||
| 498 | * It has following fields. | 643 | * It has following fields. |
| 499 | * | 644 | * |
| 500 | * (1) "list" which is linked to tomoyo_alias_list . | 645 | * (1) "head" is "struct tomoyo_acl_head". |
| 501 | * (2) "original_name" which is a dereferenced pathname. | 646 | * (2) "original_name" which is originally requested name. |
| 502 | * (3) "aliased_name" which is a symlink's pathname. | 647 | * (3) "aggregated_name" which is name to rewrite. |
| 503 | * (4) "is_deleted" is a bool which is true if marked as deleted, false | ||
| 504 | * otherwise. | ||
| 505 | */ | 648 | */ |
| 506 | struct tomoyo_alias_entry { | 649 | struct tomoyo_aggregator { |
| 507 | struct list_head list; | 650 | struct tomoyo_acl_head head; |
| 508 | const struct tomoyo_path_info *original_name; | 651 | const struct tomoyo_path_info *original_name; |
| 509 | const struct tomoyo_path_info *aliased_name; | 652 | const struct tomoyo_path_info *aggregated_name; |
| 510 | bool is_deleted; | ||
| 511 | }; | 653 | }; |
| 512 | 654 | ||
| 513 | /* | 655 | /* |
| 514 | * tomoyo_policy_manager_entry is a structure which is used for holding list of | 656 | * tomoyo_manager is a structure which is used for holding list of |
| 515 | * domainnames or programs which are permitted to modify configuration via | 657 | * domainnames or programs which are permitted to modify configuration via |
| 516 | * /sys/kernel/security/tomoyo/ interface. | 658 | * /sys/kernel/security/tomoyo/ interface. |
| 517 | * It has following fields. | 659 | * It has following fields. |
| 518 | * | 660 | * |
| 519 | * (1) "list" which is linked to tomoyo_policy_manager_list . | 661 | * (1) "head" is "struct tomoyo_acl_head". |
| 520 | * (2) "manager" is a domainname or a program's pathname. | 662 | * (2) "is_domain" is a bool which is true if "manager" is a domainname, false |
| 521 | * (3) "is_domain" is a bool which is true if "manager" is a domainname, false | ||
| 522 | * otherwise. | ||
| 523 | * (4) "is_deleted" is a bool which is true if marked as deleted, false | ||
| 524 | * otherwise. | 663 | * otherwise. |
| 664 | * (3) "manager" is a domainname or a program's pathname. | ||
| 525 | */ | 665 | */ |
| 526 | struct tomoyo_policy_manager_entry { | 666 | struct tomoyo_manager { |
| 527 | struct list_head list; | 667 | struct tomoyo_acl_head head; |
| 668 | bool is_domain; /* True if manager is a domainname. */ | ||
| 528 | /* A path to program or a domainname. */ | 669 | /* A path to program or a domainname. */ |
| 529 | const struct tomoyo_path_info *manager; | 670 | const struct tomoyo_path_info *manager; |
| 530 | bool is_domain; /* True if manager is a domainname. */ | 671 | }; |
| 531 | bool is_deleted; /* True if this entry is deleted. */ | 672 | |
| 673 | struct tomoyo_preference { | ||
| 674 | unsigned int learning_max_entry; | ||
| 675 | bool enforcing_verbose; | ||
| 676 | bool learning_verbose; | ||
| 677 | bool permissive_verbose; | ||
| 678 | }; | ||
| 679 | |||
| 680 | struct tomoyo_profile { | ||
| 681 | const struct tomoyo_path_info *comment; | ||
| 682 | struct tomoyo_preference *learning; | ||
| 683 | struct tomoyo_preference *permissive; | ||
| 684 | struct tomoyo_preference *enforcing; | ||
| 685 | struct tomoyo_preference preference; | ||
| 686 | u8 default_config; | ||
| 687 | u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; | ||
| 532 | }; | 688 | }; |
| 533 | 689 | ||
| 534 | /********** Function prototypes. **********/ | 690 | /********** Function prototypes. **********/ |
| 535 | 691 | ||
| 536 | /* Check whether the given name matches the given name_union. */ | 692 | extern asmlinkage long sys_getpid(void); |
| 537 | bool tomoyo_compare_name_union(const struct tomoyo_path_info *name, | 693 | extern asmlinkage long sys_getppid(void); |
| 538 | const struct tomoyo_name_union *ptr); | 694 | |
| 695 | /* Check whether the given string starts with the given keyword. */ | ||
| 696 | bool tomoyo_str_starts(char **src, const char *find); | ||
| 697 | /* Get tomoyo_realpath() of current process. */ | ||
| 698 | const char *tomoyo_get_exe(void); | ||
| 699 | /* Format string. */ | ||
| 700 | void tomoyo_normalize_line(unsigned char *buffer); | ||
| 701 | /* Print warning or error message on console. */ | ||
| 702 | void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...) | ||
| 703 | __attribute__ ((format(printf, 2, 3))); | ||
| 704 | /* Check all profiles currently assigned to domains are defined. */ | ||
| 705 | void tomoyo_check_profile(void); | ||
| 706 | /* Open operation for /sys/kernel/security/tomoyo/ interface. */ | ||
| 707 | int tomoyo_open_control(const u8 type, struct file *file); | ||
| 708 | /* Close /sys/kernel/security/tomoyo/ interface. */ | ||
| 709 | int tomoyo_close_control(struct file *file); | ||
| 710 | /* Poll operation for /sys/kernel/security/tomoyo/ interface. */ | ||
| 711 | int tomoyo_poll_control(struct file *file, poll_table *wait); | ||
| 712 | /* Read operation for /sys/kernel/security/tomoyo/ interface. */ | ||
| 713 | int tomoyo_read_control(struct file *file, char __user *buffer, | ||
| 714 | const int buffer_len); | ||
| 715 | /* Write operation for /sys/kernel/security/tomoyo/ interface. */ | ||
| 716 | int tomoyo_write_control(struct file *file, const char __user *buffer, | ||
| 717 | const int buffer_len); | ||
| 539 | /* Check whether the domain has too many ACL entries to hold. */ | 718 | /* Check whether the domain has too many ACL entries to hold. */ |
| 540 | bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain); | 719 | bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); |
| 541 | /* Transactional sprintf() for policy dump. */ | 720 | /* Print out of memory warning message. */ |
| 542 | bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) | 721 | void tomoyo_warn_oom(const char *function); |
| 722 | /* Check whether the given name matches the given name_union. */ | ||
| 723 | const struct tomoyo_path_info * | ||
| 724 | tomoyo_compare_name_union(const struct tomoyo_path_info *name, | ||
| 725 | const struct tomoyo_name_union *ptr); | ||
| 726 | /* Check whether the given number matches the given number_union. */ | ||
| 727 | bool tomoyo_compare_number_union(const unsigned long value, | ||
| 728 | const struct tomoyo_number_union *ptr); | ||
| 729 | int tomoyo_get_mode(const u8 profile, const u8 index); | ||
| 730 | void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) | ||
| 543 | __attribute__ ((format(printf, 2, 3))); | 731 | __attribute__ ((format(printf, 2, 3))); |
| 544 | /* Check whether the domainname is correct. */ | 732 | /* Check whether the domainname is correct. */ |
| 545 | bool tomoyo_is_correct_domain(const unsigned char *domainname); | 733 | bool tomoyo_correct_domain(const unsigned char *domainname); |
| 546 | /* Check whether the token is correct. */ | 734 | /* Check whether the token is correct. */ |
| 547 | bool tomoyo_is_correct_path(const char *filename, const s8 start_type, | 735 | bool tomoyo_correct_path(const char *filename); |
| 548 | const s8 pattern_type, const s8 end_type); | 736 | bool tomoyo_correct_word(const char *string); |
| 549 | /* Check whether the token can be a domainname. */ | 737 | /* Check whether the token can be a domainname. */ |
| 550 | bool tomoyo_is_domain_def(const unsigned char *buffer); | 738 | bool tomoyo_domain_def(const unsigned char *buffer); |
| 551 | bool tomoyo_parse_name_union(const char *filename, | 739 | bool tomoyo_parse_name_union(const char *filename, |
| 552 | struct tomoyo_name_union *ptr); | 740 | struct tomoyo_name_union *ptr); |
| 553 | /* Check whether the given filename matches the given path_group. */ | 741 | /* Check whether the given filename matches the given path_group. */ |
| 554 | bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, | 742 | const struct tomoyo_path_info * |
| 555 | const struct tomoyo_path_group *group, | 743 | tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, |
| 556 | const bool may_use_pattern); | 744 | const struct tomoyo_group *group); |
| 745 | /* Check whether the given value matches the given number_group. */ | ||
| 746 | bool tomoyo_number_matches_group(const unsigned long min, | ||
| 747 | const unsigned long max, | ||
| 748 | const struct tomoyo_group *group); | ||
| 557 | /* Check whether the given filename matches the given pattern. */ | 749 | /* Check whether the given filename matches the given pattern. */ |
| 558 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, | 750 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, |
| 559 | const struct tomoyo_path_info *pattern); | 751 | const struct tomoyo_path_info *pattern); |
| 560 | /* Read "alias" entry in exception policy. */ | 752 | |
| 561 | bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head); | 753 | bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num); |
| 562 | /* | ||
| 563 | * Read "initialize_domain" and "no_initialize_domain" entry | ||
| 564 | * in exception policy. | ||
| 565 | */ | ||
| 566 | bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head); | ||
| 567 | /* Read "keep_domain" and "no_keep_domain" entry in exception policy. */ | ||
| 568 | bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head); | ||
| 569 | /* Read "file_pattern" entry in exception policy. */ | ||
| 570 | bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head); | ||
| 571 | /* Read "path_group" entry in exception policy. */ | ||
| 572 | bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head); | ||
| 573 | /* Read "allow_read" entry in exception policy. */ | ||
| 574 | bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head); | ||
| 575 | /* Read "deny_rewrite" entry in exception policy. */ | ||
| 576 | bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head); | ||
| 577 | /* Tokenize a line. */ | 754 | /* Tokenize a line. */ |
| 578 | bool tomoyo_tokenize(char *buffer, char *w[], size_t size); | 755 | bool tomoyo_tokenize(char *buffer, char *w[], size_t size); |
| 579 | /* Write domain policy violation warning message to console? */ | 756 | /* Write domain policy violation warning message to console? */ |
| 580 | bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); | 757 | bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); |
| 581 | /* Convert double path operation to operation name. */ | 758 | /* Fill "struct tomoyo_request_info". */ |
| 582 | const char *tomoyo_path22keyword(const u8 operation); | 759 | int tomoyo_init_request_info(struct tomoyo_request_info *r, |
| 583 | /* Get the last component of the given domainname. */ | 760 | struct tomoyo_domain_info *domain, |
| 584 | const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); | 761 | const u8 index); |
| 585 | /* Get warning message. */ | 762 | /* Check permission for mount operation. */ |
| 586 | const char *tomoyo_get_msg(const bool is_enforce); | 763 | int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, |
| 587 | /* Convert single path operation to operation name. */ | 764 | unsigned long flags, void *data_page); |
| 588 | const char *tomoyo_path2keyword(const u8 operation); | 765 | /* Create "aggregator" entry in exception policy. */ |
| 589 | /* Create "alias" entry in exception policy. */ | 766 | int tomoyo_write_aggregator(char *data, const bool is_delete); |
| 590 | int tomoyo_write_alias_policy(char *data, const bool is_delete); | 767 | int tomoyo_write_transition_control(char *data, const bool is_delete, |
| 591 | /* | 768 | const u8 type); |
| 592 | * Create "initialize_domain" and "no_initialize_domain" entry | ||
| 593 | * in exception policy. | ||
| 594 | */ | ||
| 595 | int tomoyo_write_domain_initializer_policy(char *data, const bool is_not, | ||
| 596 | const bool is_delete); | ||
| 597 | /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */ | ||
| 598 | int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, | ||
| 599 | const bool is_delete); | ||
| 600 | /* | 769 | /* |
| 601 | * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", | 770 | * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", |
| 602 | * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", | 771 | * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", |
| @@ -604,25 +773,31 @@ int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, | |||
| 604 | * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and | 773 | * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and |
| 605 | * "allow_link" entry in domain policy. | 774 | * "allow_link" entry in domain policy. |
| 606 | */ | 775 | */ |
| 607 | int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, | 776 | int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain, |
| 608 | const bool is_delete); | 777 | const bool is_delete); |
| 609 | /* Create "allow_read" entry in exception policy. */ | 778 | /* Create "allow_read" entry in exception policy. */ |
| 610 | int tomoyo_write_globally_readable_policy(char *data, const bool is_delete); | 779 | int tomoyo_write_globally_readable(char *data, const bool is_delete); |
| 780 | /* Create "allow_mount" entry in domain policy. */ | ||
| 781 | int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain, | ||
| 782 | const bool is_delete); | ||
| 611 | /* Create "deny_rewrite" entry in exception policy. */ | 783 | /* Create "deny_rewrite" entry in exception policy. */ |
| 612 | int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); | 784 | int tomoyo_write_no_rewrite(char *data, const bool is_delete); |
| 613 | /* Create "file_pattern" entry in exception policy. */ | 785 | /* Create "file_pattern" entry in exception policy. */ |
| 614 | int tomoyo_write_pattern_policy(char *data, const bool is_delete); | 786 | int tomoyo_write_pattern(char *data, const bool is_delete); |
| 615 | /* Create "path_group" entry in exception policy. */ | 787 | /* Create "path_group"/"number_group" entry in exception policy. */ |
| 616 | int tomoyo_write_path_group_policy(char *data, const bool is_delete); | 788 | int tomoyo_write_group(char *data, const bool is_delete, const u8 type); |
| 789 | int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) | ||
| 790 | __attribute__ ((format(printf, 2, 3))); | ||
| 617 | /* Find a domain by the given name. */ | 791 | /* Find a domain by the given name. */ |
| 618 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); | 792 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); |
| 619 | /* Find or create a domain by the given name. */ | 793 | /* Find or create a domain by the given name. */ |
| 620 | struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * | 794 | struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, |
| 621 | domainname, | 795 | const u8 profile); |
| 622 | const u8 profile); | 796 | struct tomoyo_profile *tomoyo_profile(const u8 profile); |
| 623 | 797 | /* | |
| 624 | /* Allocate memory for "struct tomoyo_path_group". */ | 798 | * Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group". |
| 625 | struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name); | 799 | */ |
| 800 | struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type); | ||
| 626 | 801 | ||
| 627 | /* Check mode for specified functionality. */ | 802 | /* Check mode for specified functionality. */ |
| 628 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, | 803 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, |
| @@ -632,25 +807,23 @@ void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); | |||
| 632 | /* Run policy loader when /sbin/init starts. */ | 807 | /* Run policy loader when /sbin/init starts. */ |
| 633 | void tomoyo_load_policy(const char *filename); | 808 | void tomoyo_load_policy(const char *filename); |
| 634 | 809 | ||
| 635 | /* Convert binary string to ascii string. */ | 810 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr); |
| 636 | int tomoyo_encode(char *buffer, int buflen, const char *str); | ||
| 637 | 811 | ||
| 638 | /* Returns realpath(3) of the given pathname but ignores chroot'ed root. */ | 812 | /* Convert binary string to ascii string. */ |
| 639 | int tomoyo_realpath_from_path2(struct path *path, char *newname, | 813 | char *tomoyo_encode(const char *str); |
| 640 | int newname_len); | ||
| 641 | 814 | ||
| 642 | /* | 815 | /* |
| 643 | * Returns realpath(3) of the given pathname but ignores chroot'ed root. | 816 | * Returns realpath(3) of the given pathname except that |
| 644 | * These functions use kzalloc(), so the caller must call kfree() | 817 | * ignores chroot'ed root and does not follow the final symlink. |
| 645 | * if these functions didn't return NULL. | ||
| 646 | */ | 818 | */ |
| 647 | char *tomoyo_realpath(const char *pathname); | 819 | char *tomoyo_realpath_nofollow(const char *pathname); |
| 648 | /* | 820 | /* |
| 649 | * Same with tomoyo_realpath() except that it doesn't follow the final symlink. | 821 | * Returns realpath(3) of the given pathname except that |
| 822 | * ignores chroot'ed root and the pathname is already solved. | ||
| 650 | */ | 823 | */ |
| 651 | char *tomoyo_realpath_nofollow(const char *pathname); | ||
| 652 | /* Same with tomoyo_realpath() except that the pathname is already solved. */ | ||
| 653 | char *tomoyo_realpath_from_path(struct path *path); | 824 | char *tomoyo_realpath_from_path(struct path *path); |
| 825 | /* Get patterned pathname. */ | ||
| 826 | const char *tomoyo_pattern(const struct tomoyo_path_info *filename); | ||
| 654 | 827 | ||
| 655 | /* Check memory quota. */ | 828 | /* Check memory quota. */ |
| 656 | bool tomoyo_memory_ok(void *ptr); | 829 | bool tomoyo_memory_ok(void *ptr); |
| @@ -663,23 +836,29 @@ void *tomoyo_commit_ok(void *data, const unsigned int size); | |||
| 663 | const struct tomoyo_path_info *tomoyo_get_name(const char *name); | 836 | const struct tomoyo_path_info *tomoyo_get_name(const char *name); |
| 664 | 837 | ||
| 665 | /* Check for memory usage. */ | 838 | /* Check for memory usage. */ |
| 666 | int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); | 839 | void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); |
| 667 | 840 | ||
| 668 | /* Set memory quota. */ | 841 | /* Set memory quota. */ |
| 669 | int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); | 842 | int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); |
| 670 | 843 | ||
| 671 | /* Initialize realpath related code. */ | 844 | /* Initialize mm related code. */ |
| 672 | void __init tomoyo_realpath_init(void); | 845 | void __init tomoyo_mm_init(void); |
| 673 | int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain, | 846 | int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
| 674 | const struct tomoyo_path_info *filename); | 847 | const struct tomoyo_path_info *filename); |
| 675 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, | 848 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |
| 676 | struct path *path, const int flag); | 849 | struct path *path, const int flag); |
| 850 | int tomoyo_path_number_perm(const u8 operation, struct path *path, | ||
| 851 | unsigned long number); | ||
| 852 | int tomoyo_mkdev_perm(const u8 operation, struct path *path, | ||
| 853 | const unsigned int mode, unsigned int dev); | ||
| 677 | int tomoyo_path_perm(const u8 operation, struct path *path); | 854 | int tomoyo_path_perm(const u8 operation, struct path *path); |
| 678 | int tomoyo_path2_perm(const u8 operation, struct path *path1, | 855 | int tomoyo_path2_perm(const u8 operation, struct path *path1, |
| 679 | struct path *path2); | 856 | struct path *path2); |
| 680 | int tomoyo_check_rewrite_permission(struct file *filp); | ||
| 681 | int tomoyo_find_next_domain(struct linux_binprm *bprm); | 857 | int tomoyo_find_next_domain(struct linux_binprm *bprm); |
| 682 | 858 | ||
| 859 | void tomoyo_print_ulong(char *buffer, const int buffer_len, | ||
| 860 | const unsigned long value, const u8 type); | ||
| 861 | |||
| 683 | /* Drop refcount on tomoyo_name_union. */ | 862 | /* Drop refcount on tomoyo_name_union. */ |
| 684 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr); | 863 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr); |
| 685 | 864 | ||
| @@ -688,6 +867,25 @@ void tomoyo_run_gc(void); | |||
| 688 | 867 | ||
| 689 | void tomoyo_memory_free(void *ptr); | 868 | void tomoyo_memory_free(void *ptr); |
| 690 | 869 | ||
| 870 | int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, | ||
| 871 | bool is_delete, struct tomoyo_domain_info *domain, | ||
| 872 | bool (*check_duplicate) (const struct tomoyo_acl_info | ||
| 873 | *, | ||
| 874 | const struct tomoyo_acl_info | ||
| 875 | *), | ||
| 876 | bool (*merge_duplicate) (struct tomoyo_acl_info *, | ||
| 877 | struct tomoyo_acl_info *, | ||
| 878 | const bool)); | ||
| 879 | int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, | ||
| 880 | bool is_delete, struct list_head *list, | ||
| 881 | bool (*check_duplicate) (const struct tomoyo_acl_head | ||
| 882 | *, | ||
| 883 | const struct tomoyo_acl_head | ||
| 884 | *)); | ||
| 885 | void tomoyo_check_acl(struct tomoyo_request_info *r, | ||
| 886 | bool (*check_entry) (struct tomoyo_request_info *, | ||
| 887 | const struct tomoyo_acl_info *)); | ||
| 888 | |||
| 691 | /********** External variable definitions. **********/ | 889 | /********** External variable definitions. **********/ |
| 692 | 890 | ||
| 693 | /* Lock for GC. */ | 891 | /* Lock for GC. */ |
| @@ -696,14 +894,8 @@ extern struct srcu_struct tomoyo_ss; | |||
| 696 | /* The list for "struct tomoyo_domain_info". */ | 894 | /* The list for "struct tomoyo_domain_info". */ |
| 697 | extern struct list_head tomoyo_domain_list; | 895 | extern struct list_head tomoyo_domain_list; |
| 698 | 896 | ||
| 699 | extern struct list_head tomoyo_path_group_list; | 897 | extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY]; |
| 700 | extern struct list_head tomoyo_domain_initializer_list; | 898 | extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP]; |
| 701 | extern struct list_head tomoyo_domain_keeper_list; | ||
| 702 | extern struct list_head tomoyo_alias_list; | ||
| 703 | extern struct list_head tomoyo_globally_readable_list; | ||
| 704 | extern struct list_head tomoyo_pattern_list; | ||
| 705 | extern struct list_head tomoyo_no_rewrite_list; | ||
| 706 | extern struct list_head tomoyo_policy_manager_list; | ||
| 707 | extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; | 899 | extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; |
| 708 | 900 | ||
| 709 | /* Lock for protecting policy. */ | 901 | /* Lock for protecting policy. */ |
| @@ -715,6 +907,14 @@ extern bool tomoyo_policy_loaded; | |||
| 715 | /* The kernel's domain. */ | 907 | /* The kernel's domain. */ |
| 716 | extern struct tomoyo_domain_info tomoyo_kernel_domain; | 908 | extern struct tomoyo_domain_info tomoyo_kernel_domain; |
| 717 | 909 | ||
| 910 | extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; | ||
| 911 | extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION]; | ||
| 912 | extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION]; | ||
| 913 | extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION]; | ||
| 914 | |||
| 915 | extern unsigned int tomoyo_quota_for_query; | ||
| 916 | extern unsigned int tomoyo_query_memory_size; | ||
| 917 | |||
| 718 | /********** Inlined functions. **********/ | 918 | /********** Inlined functions. **********/ |
| 719 | 919 | ||
| 720 | static inline int tomoyo_read_lock(void) | 920 | static inline int tomoyo_read_lock(void) |
| @@ -735,25 +935,25 @@ static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, | |||
| 735 | } | 935 | } |
| 736 | 936 | ||
| 737 | /** | 937 | /** |
| 738 | * tomoyo_is_valid - Check whether the character is a valid char. | 938 | * tomoyo_valid - Check whether the character is a valid char. |
| 739 | * | 939 | * |
| 740 | * @c: The character to check. | 940 | * @c: The character to check. |
| 741 | * | 941 | * |
| 742 | * Returns true if @c is a valid character, false otherwise. | 942 | * Returns true if @c is a valid character, false otherwise. |
| 743 | */ | 943 | */ |
| 744 | static inline bool tomoyo_is_valid(const unsigned char c) | 944 | static inline bool tomoyo_valid(const unsigned char c) |
| 745 | { | 945 | { |
| 746 | return c > ' ' && c < 127; | 946 | return c > ' ' && c < 127; |
| 747 | } | 947 | } |
| 748 | 948 | ||
| 749 | /** | 949 | /** |
| 750 | * tomoyo_is_invalid - Check whether the character is an invalid char. | 950 | * tomoyo_invalid - Check whether the character is an invalid char. |
| 751 | * | 951 | * |
| 752 | * @c: The character to check. | 952 | * @c: The character to check. |
| 753 | * | 953 | * |
| 754 | * Returns true if @c is an invalid character, false otherwise. | 954 | * Returns true if @c is an invalid character, false otherwise. |
| 755 | */ | 955 | */ |
| 756 | static inline bool tomoyo_is_invalid(const unsigned char c) | 956 | static inline bool tomoyo_invalid(const unsigned char c) |
| 757 | { | 957 | { |
| 758 | return c && (c <= ' ' || c >= 127); | 958 | return c && (c <= ' ' || c >= 127); |
| 759 | } | 959 | } |
| @@ -761,13 +961,13 @@ static inline bool tomoyo_is_invalid(const unsigned char c) | |||
| 761 | static inline void tomoyo_put_name(const struct tomoyo_path_info *name) | 961 | static inline void tomoyo_put_name(const struct tomoyo_path_info *name) |
| 762 | { | 962 | { |
| 763 | if (name) { | 963 | if (name) { |
| 764 | struct tomoyo_name_entry *ptr = | 964 | struct tomoyo_name *ptr = |
| 765 | container_of(name, struct tomoyo_name_entry, entry); | 965 | container_of(name, typeof(*ptr), entry); |
| 766 | atomic_dec(&ptr->users); | 966 | atomic_dec(&ptr->users); |
| 767 | } | 967 | } |
| 768 | } | 968 | } |
| 769 | 969 | ||
| 770 | static inline void tomoyo_put_path_group(struct tomoyo_path_group *group) | 970 | static inline void tomoyo_put_group(struct tomoyo_group *group) |
| 771 | { | 971 | { |
| 772 | if (group) | 972 | if (group) |
| 773 | atomic_dec(&group->users); | 973 | atomic_dec(&group->users); |
| @@ -784,75 +984,35 @@ static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct | |||
| 784 | return task_cred_xxx(task, security); | 984 | return task_cred_xxx(task, security); |
| 785 | } | 985 | } |
| 786 | 986 | ||
| 787 | static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1, | 987 | static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1, |
| 788 | const struct tomoyo_acl_info *p2) | 988 | const struct tomoyo_acl_info *p2) |
| 789 | { | 989 | { |
| 790 | return p1->type == p2->type; | 990 | return p1->type == p2->type; |
| 791 | } | 991 | } |
| 792 | 992 | ||
| 793 | static inline bool tomoyo_is_same_name_union | 993 | static inline bool tomoyo_same_name_union |
| 794 | (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) | 994 | (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) |
| 795 | { | 995 | { |
| 796 | return p1->filename == p2->filename && p1->group == p2->group && | 996 | return p1->filename == p2->filename && p1->group == p2->group && |
| 797 | p1->is_group == p2->is_group; | 997 | p1->is_group == p2->is_group; |
| 798 | } | 998 | } |
| 799 | 999 | ||
| 800 | static inline bool tomoyo_is_same_path_acl(const struct tomoyo_path_acl *p1, | 1000 | static inline bool tomoyo_same_number_union |
| 801 | const struct tomoyo_path_acl *p2) | 1001 | (const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2) |
| 802 | { | ||
| 803 | return tomoyo_is_same_acl_head(&p1->head, &p2->head) && | ||
| 804 | tomoyo_is_same_name_union(&p1->name, &p2->name); | ||
| 805 | } | ||
| 806 | |||
| 807 | static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1, | ||
| 808 | const struct tomoyo_path2_acl *p2) | ||
| 809 | { | 1002 | { |
| 810 | return tomoyo_is_same_acl_head(&p1->head, &p2->head) && | 1003 | return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1] |
| 811 | tomoyo_is_same_name_union(&p1->name1, &p2->name1) && | 1004 | && p1->group == p2->group && p1->min_type == p2->min_type && |
| 812 | tomoyo_is_same_name_union(&p1->name2, &p2->name2); | 1005 | p1->max_type == p2->max_type && p1->is_group == p2->is_group; |
| 813 | } | ||
| 814 | |||
| 815 | static inline bool tomoyo_is_same_domain_initializer_entry | ||
| 816 | (const struct tomoyo_domain_initializer_entry *p1, | ||
| 817 | const struct tomoyo_domain_initializer_entry *p2) | ||
| 818 | { | ||
| 819 | return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name | ||
| 820 | && p1->domainname == p2->domainname | ||
| 821 | && p1->program == p2->program; | ||
| 822 | } | ||
| 823 | |||
| 824 | static inline bool tomoyo_is_same_domain_keeper_entry | ||
| 825 | (const struct tomoyo_domain_keeper_entry *p1, | ||
| 826 | const struct tomoyo_domain_keeper_entry *p2) | ||
| 827 | { | ||
| 828 | return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name | ||
| 829 | && p1->domainname == p2->domainname | ||
| 830 | && p1->program == p2->program; | ||
| 831 | } | ||
| 832 | |||
| 833 | static inline bool tomoyo_is_same_alias_entry | ||
| 834 | (const struct tomoyo_alias_entry *p1, const struct tomoyo_alias_entry *p2) | ||
| 835 | { | ||
| 836 | return p1->original_name == p2->original_name && | ||
| 837 | p1->aliased_name == p2->aliased_name; | ||
| 838 | } | 1006 | } |
| 839 | 1007 | ||
| 840 | /** | 1008 | /** |
| 841 | * list_for_each_cookie - iterate over a list with cookie. | 1009 | * list_for_each_cookie - iterate over a list with cookie. |
| 842 | * @pos: the &struct list_head to use as a loop cursor. | 1010 | * @pos: the &struct list_head to use as a loop cursor. |
| 843 | * @cookie: the &struct list_head to use as a cookie. | ||
| 844 | * @head: the head for your list. | 1011 | * @head: the head for your list. |
| 845 | * | ||
| 846 | * Same with list_for_each_rcu() except that this primitive uses @cookie | ||
| 847 | * so that we can continue iteration. | ||
| 848 | * @cookie must be NULL when iteration starts, and @cookie will become | ||
| 849 | * NULL when iteration finishes. | ||
| 850 | */ | 1012 | */ |
| 851 | #define list_for_each_cookie(pos, cookie, head) \ | 1013 | #define list_for_each_cookie(pos, head) \ |
| 852 | for (({ if (!cookie) \ | 1014 | if (!pos) \ |
| 853 | cookie = head; }), \ | 1015 | pos = srcu_dereference((head)->next, &tomoyo_ss); \ |
| 854 | pos = rcu_dereference((cookie)->next); \ | 1016 | for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss)) |
| 855 | prefetch(pos->next), pos != (head) || ((cookie) = NULL); \ | ||
| 856 | (cookie) = pos, pos = rcu_dereference(pos->next)) | ||
| 857 | 1017 | ||
| 858 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ | 1018 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ |
