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 | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame^] | 41 | /* Group number is an integer between 0 and 255. */ |
| 42 | #define TOMOYO_MAX_ACL_GROUPS 256 |
| 43 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 44 | /* Index numbers for operation mode. */ |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 45 | enum tomoyo_mode_index { |
| 46 | TOMOYO_CONFIG_DISABLED, |
| 47 | TOMOYO_CONFIG_LEARNING, |
| 48 | TOMOYO_CONFIG_PERMISSIVE, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 49 | TOMOYO_CONFIG_ENFORCING, |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 50 | TOMOYO_CONFIG_MAX_MODE, |
| 51 | TOMOYO_CONFIG_WANT_REJECT_LOG = 64, |
| 52 | TOMOYO_CONFIG_WANT_GRANT_LOG = 128, |
| 53 | TOMOYO_CONFIG_USE_DEFAULT = 255, |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 54 | }; |
| 55 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 56 | /* Index numbers for entry type. */ |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 57 | enum tomoyo_policy_id { |
| 58 | TOMOYO_ID_GROUP, |
| 59 | TOMOYO_ID_PATH_GROUP, |
| 60 | TOMOYO_ID_NUMBER_GROUP, |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 61 | TOMOYO_ID_TRANSITION_CONTROL, |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 62 | TOMOYO_ID_AGGREGATOR, |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 63 | TOMOYO_ID_MANAGER, |
| 64 | TOMOYO_ID_NAME, |
| 65 | TOMOYO_ID_ACL, |
| 66 | TOMOYO_ID_DOMAIN, |
| 67 | TOMOYO_MAX_POLICY |
| 68 | }; |
| 69 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 70 | /* Index numbers for group entries. */ |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 71 | enum tomoyo_group_id { |
| 72 | TOMOYO_PATH_GROUP, |
| 73 | TOMOYO_NUMBER_GROUP, |
| 74 | TOMOYO_MAX_GROUP |
| 75 | }; |
| 76 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 77 | /* A domain definition starts with <kernel>. */ |
| 78 | #define TOMOYO_ROOT_NAME "<kernel>" |
| 79 | #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) |
| 80 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 81 | /* Index numbers for type of numeric values. */ |
| 82 | enum tomoyo_value_type { |
| 83 | TOMOYO_VALUE_TYPE_INVALID, |
| 84 | TOMOYO_VALUE_TYPE_DECIMAL, |
| 85 | TOMOYO_VALUE_TYPE_OCTAL, |
| 86 | TOMOYO_VALUE_TYPE_HEXADECIMAL, |
| 87 | }; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 88 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 89 | /* Index numbers for domain transition control keywords. */ |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 90 | enum tomoyo_transition_type { |
| 91 | /* Do not change this order, */ |
| 92 | TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, |
| 93 | TOMOYO_TRANSITION_CONTROL_INITIALIZE, |
| 94 | TOMOYO_TRANSITION_CONTROL_NO_KEEP, |
| 95 | TOMOYO_TRANSITION_CONTROL_KEEP, |
| 96 | TOMOYO_MAX_TRANSITION_TYPE |
| 97 | }; |
| 98 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 99 | /* Index numbers for Access Controls. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 100 | enum tomoyo_acl_entry_type_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 101 | TOMOYO_TYPE_PATH_ACL, |
| 102 | TOMOYO_TYPE_PATH2_ACL, |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 103 | TOMOYO_TYPE_PATH_NUMBER_ACL, |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 104 | TOMOYO_TYPE_MKDEV_ACL, |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 105 | TOMOYO_TYPE_MOUNT_ACL, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 106 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 107 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 108 | /* Index numbers for access controls with one pathname. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 109 | enum tomoyo_path_acl_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 110 | TOMOYO_TYPE_EXECUTE, |
| 111 | TOMOYO_TYPE_READ, |
| 112 | TOMOYO_TYPE_WRITE, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 113 | TOMOYO_TYPE_APPEND, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 114 | TOMOYO_TYPE_UNLINK, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 115 | TOMOYO_TYPE_GETATTR, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 116 | TOMOYO_TYPE_RMDIR, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 117 | TOMOYO_TYPE_TRUNCATE, |
| 118 | TOMOYO_TYPE_SYMLINK, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 119 | TOMOYO_TYPE_CHROOT, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 120 | TOMOYO_TYPE_UMOUNT, |
| 121 | TOMOYO_MAX_PATH_OPERATION |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 122 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 123 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 124 | enum tomoyo_memory_stat_type { |
| 125 | TOMOYO_MEMORY_POLICY, |
| 126 | TOMOYO_MEMORY_AUDIT, |
| 127 | TOMOYO_MEMORY_QUERY, |
| 128 | TOMOYO_MAX_MEMORY_STAT |
| 129 | }; |
| 130 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 131 | enum tomoyo_mkdev_acl_index { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 132 | TOMOYO_TYPE_MKBLOCK, |
| 133 | TOMOYO_TYPE_MKCHAR, |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 134 | TOMOYO_MAX_MKDEV_OPERATION |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 135 | }; |
| 136 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 137 | /* Index numbers for access controls with two pathnames. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 138 | enum tomoyo_path2_acl_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 139 | TOMOYO_TYPE_LINK, |
| 140 | TOMOYO_TYPE_RENAME, |
| 141 | TOMOYO_TYPE_PIVOT_ROOT, |
| 142 | TOMOYO_MAX_PATH2_OPERATION |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 143 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 144 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 145 | /* Index numbers for access controls with one pathname and one number. */ |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 146 | enum tomoyo_path_number_acl_index { |
| 147 | TOMOYO_TYPE_CREATE, |
| 148 | TOMOYO_TYPE_MKDIR, |
| 149 | TOMOYO_TYPE_MKFIFO, |
| 150 | TOMOYO_TYPE_MKSOCK, |
| 151 | TOMOYO_TYPE_IOCTL, |
| 152 | TOMOYO_TYPE_CHMOD, |
| 153 | TOMOYO_TYPE_CHOWN, |
| 154 | TOMOYO_TYPE_CHGRP, |
| 155 | TOMOYO_MAX_PATH_NUMBER_OPERATION |
| 156 | }; |
| 157 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 158 | /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 159 | enum tomoyo_securityfs_interface_index { |
| 160 | TOMOYO_DOMAINPOLICY, |
| 161 | TOMOYO_EXCEPTIONPOLICY, |
| 162 | TOMOYO_DOMAIN_STATUS, |
| 163 | TOMOYO_PROCESS_STATUS, |
| 164 | TOMOYO_MEMINFO, |
| 165 | TOMOYO_SELFDOMAIN, |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 166 | TOMOYO_AUDIT, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 167 | TOMOYO_VERSION, |
| 168 | TOMOYO_PROFILE, |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 169 | TOMOYO_QUERY, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 170 | TOMOYO_MANAGER |
| 171 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 172 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 173 | /* Index numbers for special mount operations. */ |
| 174 | enum tomoyo_special_mount { |
| 175 | TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */ |
| 176 | TOMOYO_MOUNT_MOVE, /* mount --move /old /new */ |
| 177 | TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */ |
| 178 | TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */ |
| 179 | TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */ |
| 180 | TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */ |
| 181 | TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */ |
| 182 | TOMOYO_MAX_SPECIAL_MOUNT |
| 183 | }; |
| 184 | |
| 185 | /* Index numbers for functionality. */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 186 | enum tomoyo_mac_index { |
| 187 | TOMOYO_MAC_FILE_EXECUTE, |
| 188 | TOMOYO_MAC_FILE_OPEN, |
| 189 | TOMOYO_MAC_FILE_CREATE, |
| 190 | TOMOYO_MAC_FILE_UNLINK, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 191 | TOMOYO_MAC_FILE_GETATTR, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 192 | TOMOYO_MAC_FILE_MKDIR, |
| 193 | TOMOYO_MAC_FILE_RMDIR, |
| 194 | TOMOYO_MAC_FILE_MKFIFO, |
| 195 | TOMOYO_MAC_FILE_MKSOCK, |
| 196 | TOMOYO_MAC_FILE_TRUNCATE, |
| 197 | TOMOYO_MAC_FILE_SYMLINK, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 198 | TOMOYO_MAC_FILE_MKBLOCK, |
| 199 | TOMOYO_MAC_FILE_MKCHAR, |
| 200 | TOMOYO_MAC_FILE_LINK, |
| 201 | TOMOYO_MAC_FILE_RENAME, |
| 202 | TOMOYO_MAC_FILE_CHMOD, |
| 203 | TOMOYO_MAC_FILE_CHOWN, |
| 204 | TOMOYO_MAC_FILE_CHGRP, |
| 205 | TOMOYO_MAC_FILE_IOCTL, |
| 206 | TOMOYO_MAC_FILE_CHROOT, |
| 207 | TOMOYO_MAC_FILE_MOUNT, |
| 208 | TOMOYO_MAC_FILE_UMOUNT, |
| 209 | TOMOYO_MAC_FILE_PIVOT_ROOT, |
| 210 | TOMOYO_MAX_MAC_INDEX |
| 211 | }; |
| 212 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 213 | /* Index numbers for category of functionality. */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 214 | enum tomoyo_mac_category_index { |
| 215 | TOMOYO_MAC_CATEGORY_FILE, |
| 216 | TOMOYO_MAX_MAC_CATEGORY_INDEX |
| 217 | }; |
| 218 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 219 | /* |
| 220 | * Retry this request. Returned by tomoyo_supervisor() if policy violation has |
| 221 | * occurred in enforcing mode and the userspace daemon decided to retry. |
| 222 | * |
| 223 | * We must choose a positive value in order to distinguish "granted" (which is |
| 224 | * 0) and "rejected" (which is a negative value) and "retry". |
| 225 | */ |
| 226 | #define TOMOYO_RETRY_REQUEST 1 |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 227 | |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 228 | /* Index numbers for profile's PREFERENCE values. */ |
| 229 | enum tomoyo_pref_index { |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 230 | TOMOYO_PREF_MAX_AUDIT_LOG, |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 231 | TOMOYO_PREF_MAX_LEARNING_ENTRY, |
| 232 | TOMOYO_MAX_PREF |
| 233 | }; |
| 234 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 235 | /********** Structure definitions. **********/ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 236 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 237 | /* Common header for holding ACL entries. */ |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 238 | struct tomoyo_acl_head { |
| 239 | struct list_head list; |
| 240 | bool is_deleted; |
| 241 | } __packed; |
| 242 | |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 243 | /* Common header for shared entries. */ |
| 244 | struct tomoyo_shared_acl_head { |
| 245 | struct list_head list; |
| 246 | atomic_t users; |
| 247 | } __packed; |
| 248 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 249 | /* Structure for request info. */ |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 250 | struct tomoyo_request_info { |
| 251 | struct tomoyo_domain_info *domain; |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 252 | /* For holding parameters. */ |
| 253 | union { |
| 254 | struct { |
| 255 | const struct tomoyo_path_info *filename; |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 256 | /* For using wildcards at tomoyo_find_next_domain(). */ |
| 257 | const struct tomoyo_path_info *matched_path; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 258 | /* One of values in "enum tomoyo_path_acl_index". */ |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 259 | u8 operation; |
| 260 | } path; |
| 261 | struct { |
| 262 | const struct tomoyo_path_info *filename1; |
| 263 | const struct tomoyo_path_info *filename2; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 264 | /* One of values in "enum tomoyo_path2_acl_index". */ |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 265 | u8 operation; |
| 266 | } path2; |
| 267 | struct { |
| 268 | const struct tomoyo_path_info *filename; |
| 269 | unsigned int mode; |
| 270 | unsigned int major; |
| 271 | unsigned int minor; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 272 | /* One of values in "enum tomoyo_mkdev_acl_index". */ |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 273 | u8 operation; |
| 274 | } mkdev; |
| 275 | struct { |
| 276 | const struct tomoyo_path_info *filename; |
| 277 | unsigned long number; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 278 | /* |
| 279 | * One of values in |
| 280 | * "enum tomoyo_path_number_acl_index". |
| 281 | */ |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 282 | u8 operation; |
| 283 | } path_number; |
| 284 | struct { |
| 285 | const struct tomoyo_path_info *type; |
| 286 | const struct tomoyo_path_info *dir; |
| 287 | const struct tomoyo_path_info *dev; |
| 288 | unsigned long flags; |
| 289 | int need_dev; |
| 290 | } mount; |
| 291 | } param; |
| 292 | u8 param_type; |
| 293 | bool granted; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 294 | u8 retry; |
| 295 | u8 profile; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 296 | u8 mode; /* One of tomoyo_mode_index . */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 297 | u8 type; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 298 | }; |
| 299 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 300 | /* Structure for holding a token. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 301 | struct tomoyo_path_info { |
| 302 | const char *name; |
| 303 | u32 hash; /* = full_name_hash(name, strlen(name)) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 304 | u16 const_len; /* = tomoyo_const_part_length(name) */ |
| 305 | bool is_dir; /* = tomoyo_strendswith(name, "/") */ |
| 306 | bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 307 | }; |
| 308 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 309 | /* Structure for holding string data. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 310 | struct tomoyo_name { |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 311 | struct tomoyo_shared_acl_head head; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 312 | struct tomoyo_path_info entry; |
| 313 | }; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 314 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 315 | /* Structure for holding a word. */ |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 316 | struct tomoyo_name_union { |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 317 | /* Either @filename or @group is NULL. */ |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 318 | const struct tomoyo_path_info *filename; |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 319 | struct tomoyo_group *group; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 320 | }; |
| 321 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 322 | /* Structure for holding a number. */ |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 323 | struct tomoyo_number_union { |
| 324 | unsigned long values[2]; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 325 | struct tomoyo_group *group; /* Maybe NULL. */ |
| 326 | /* One of values in "enum tomoyo_value_type". */ |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 327 | u8 value_type[2]; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 328 | }; |
| 329 | |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 330 | /* Structure for "path_group"/"number_group" directive. */ |
| 331 | struct tomoyo_group { |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 332 | struct tomoyo_shared_acl_head head; |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 333 | const struct tomoyo_path_info *group_name; |
| 334 | struct list_head member_list; |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 335 | }; |
| 336 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 337 | /* Structure for "path_group" directive. */ |
| 338 | struct tomoyo_path_group { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 339 | struct tomoyo_acl_head head; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 340 | const struct tomoyo_path_info *member_name; |
| 341 | }; |
| 342 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 343 | /* Structure for "number_group" directive. */ |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 344 | struct tomoyo_number_group { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 345 | struct tomoyo_acl_head head; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 346 | struct tomoyo_number_union number; |
| 347 | }; |
| 348 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 349 | /* Common header for individual entries. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 350 | struct tomoyo_acl_info { |
| 351 | struct list_head list; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 352 | bool is_deleted; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 353 | u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 354 | } __packed; |
| 355 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 356 | /* Structure for domain information. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 357 | struct tomoyo_domain_info { |
| 358 | struct list_head list; |
| 359 | struct list_head acl_info_list; |
| 360 | /* Name of this domain. Never NULL. */ |
| 361 | const struct tomoyo_path_info *domainname; |
| 362 | u8 profile; /* Profile number to use. */ |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame^] | 363 | u8 group; /* Group number to use. */ |
Tetsuo Handa | a0558fc | 2009-04-06 20:49:14 +0900 | [diff] [blame] | 364 | bool is_deleted; /* Delete flag. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 365 | bool quota_warned; /* Quota warnning flag. */ |
Tetsuo Handa | ea13ddb | 2010-02-03 06:43:06 +0900 | [diff] [blame] | 366 | bool transition_failed; /* Domain transition failed flag. */ |
Tetsuo Handa | ec8e6a4 | 2010-02-11 09:43:20 +0900 | [diff] [blame] | 367 | atomic_t users; /* Number of referring credentials. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 368 | }; |
| 369 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 370 | /* |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 371 | * Structure for "file execute", "file read", "file write", "file append", |
| 372 | * "file unlink", "file getattr", "file rmdir", "file truncate", |
| 373 | * "file symlink", "file chroot" and "file unmount" directive. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 374 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 375 | struct tomoyo_path_acl { |
| 376 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 377 | u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */ |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 378 | struct tomoyo_name_union name; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 379 | }; |
| 380 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 381 | /* |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 382 | * Structure for "file create", "file mkdir", "file mkfifo", "file mksock", |
| 383 | * "file ioctl", "file chmod", "file chown" and "file chgrp" directive. |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 384 | */ |
| 385 | struct tomoyo_path_number_acl { |
| 386 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 387 | /* Bitmask of values in "enum tomoyo_path_number_acl_index". */ |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 388 | u8 perm; |
| 389 | struct tomoyo_name_union name; |
| 390 | struct tomoyo_number_union number; |
| 391 | }; |
| 392 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 393 | /* Structure for "file mkblock" and "file mkchar" directive. */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 394 | struct tomoyo_mkdev_acl { |
| 395 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 396 | u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */ |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 397 | struct tomoyo_name_union name; |
| 398 | struct tomoyo_number_union mode; |
| 399 | struct tomoyo_number_union major; |
| 400 | struct tomoyo_number_union minor; |
| 401 | }; |
| 402 | |
| 403 | /* |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 404 | * Structure for "file rename", "file link" and "file pivot_root" directive. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 405 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 406 | struct tomoyo_path2_acl { |
| 407 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 408 | u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */ |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 409 | struct tomoyo_name_union name1; |
| 410 | struct tomoyo_name_union name2; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 411 | }; |
| 412 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 413 | /* Structure for "file mount" directive. */ |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 414 | struct tomoyo_mount_acl { |
| 415 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 416 | struct tomoyo_name_union dev_name; |
| 417 | struct tomoyo_name_union dir_name; |
| 418 | struct tomoyo_name_union fs_type; |
| 419 | struct tomoyo_number_union flags; |
| 420 | }; |
| 421 | |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 422 | /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */ |
| 423 | struct tomoyo_acl_param { |
| 424 | char *data; |
| 425 | struct list_head *list; |
| 426 | bool is_delete; |
| 427 | }; |
| 428 | |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 429 | #define TOMOYO_MAX_IO_READ_QUEUE 64 |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 430 | |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 431 | /* |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 432 | * Structure for reading/writing policy via /sys/kernel/security/tomoyo |
| 433 | * interfaces. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 434 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 435 | struct tomoyo_io_buffer { |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 436 | void (*read) (struct tomoyo_io_buffer *); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 437 | int (*write) (struct tomoyo_io_buffer *); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 438 | int (*poll) (struct file *file, poll_table *wait); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 439 | /* Exclusive lock for this structure. */ |
| 440 | struct mutex io_sem; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 441 | /* Index returned by tomoyo_read_lock(). */ |
| 442 | int reader_idx; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 443 | char __user *read_user_buf; |
| 444 | int read_user_buf_avail; |
| 445 | struct { |
| 446 | struct list_head *domain; |
| 447 | struct list_head *group; |
| 448 | struct list_head *acl; |
| 449 | int avail; |
| 450 | int step; |
| 451 | int query_index; |
| 452 | u16 index; |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame^] | 453 | u8 acl_group_index; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 454 | u8 bit; |
| 455 | u8 w_pos; |
| 456 | bool eof; |
| 457 | bool print_this_domain_only; |
| 458 | bool print_execute_only; |
| 459 | const char *w[TOMOYO_MAX_IO_READ_QUEUE]; |
| 460 | } r; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 461 | struct { |
| 462 | /* The position currently writing to. */ |
| 463 | struct tomoyo_domain_info *domain; |
| 464 | /* Bytes available for writing. */ |
| 465 | int avail; |
| 466 | } w; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 467 | /* Buffer for reading. */ |
| 468 | char *read_buf; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 469 | /* Size of read buffer. */ |
| 470 | int readbuf_size; |
| 471 | /* Buffer for writing. */ |
| 472 | char *write_buf; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 473 | /* Size of write buffer. */ |
| 474 | int writebuf_size; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 475 | /* Type of this interface. */ |
| 476 | u8 type; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 477 | }; |
| 478 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 479 | /* |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 480 | * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/ |
| 481 | * "no_keep_domain" keyword. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 482 | */ |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 483 | struct tomoyo_transition_control { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 484 | struct tomoyo_acl_head head; |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 485 | u8 type; /* One of values in "enum tomoyo_transition_type". */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 486 | /* True if the domainname is tomoyo_get_last_name(). */ |
| 487 | bool is_last_name; |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 488 | const struct tomoyo_path_info *domainname; /* Maybe NULL */ |
| 489 | const struct tomoyo_path_info *program; /* Maybe NULL */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 490 | }; |
| 491 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 492 | /* Structure for "aggregator" keyword. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 493 | struct tomoyo_aggregator { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 494 | struct tomoyo_acl_head head; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 495 | const struct tomoyo_path_info *original_name; |
| 496 | const struct tomoyo_path_info *aggregated_name; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 497 | }; |
| 498 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 499 | /* Structure for policy manager. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 500 | struct tomoyo_manager { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 501 | struct tomoyo_acl_head head; |
| 502 | bool is_domain; /* True if manager is a domainname. */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 503 | /* A path to program or a domainname. */ |
| 504 | const struct tomoyo_path_info *manager; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 505 | }; |
| 506 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 507 | struct tomoyo_preference { |
| 508 | unsigned int learning_max_entry; |
| 509 | bool enforcing_verbose; |
| 510 | bool learning_verbose; |
| 511 | bool permissive_verbose; |
| 512 | }; |
| 513 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 514 | /* Structure for /sys/kernel/security/tomnoyo/profile interface. */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 515 | struct tomoyo_profile { |
| 516 | const struct tomoyo_path_info *comment; |
| 517 | struct tomoyo_preference *learning; |
| 518 | struct tomoyo_preference *permissive; |
| 519 | struct tomoyo_preference *enforcing; |
| 520 | struct tomoyo_preference preference; |
| 521 | u8 default_config; |
| 522 | u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 523 | unsigned int pref[TOMOYO_MAX_PREF]; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 524 | }; |
| 525 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 526 | /* Structure for representing YYYY/MM/DD hh/mm/ss. */ |
| 527 | struct tomoyo_time { |
| 528 | u16 year; |
| 529 | u8 month; |
| 530 | u8 day; |
| 531 | u8 hour; |
| 532 | u8 min; |
| 533 | u8 sec; |
| 534 | }; |
| 535 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 536 | /********** Function prototypes. **********/ |
| 537 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 538 | bool tomoyo_str_starts(char **src, const char *find); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 539 | const char *tomoyo_get_exe(void); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 540 | void tomoyo_normalize_line(unsigned char *buffer); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 541 | void tomoyo_check_profile(void); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 542 | int tomoyo_open_control(const u8 type, struct file *file); |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 543 | int tomoyo_close_control(struct tomoyo_io_buffer *head); |
Tetsuo Handa | 0849e3b | 2010-06-25 12:22:09 +0900 | [diff] [blame] | 544 | int tomoyo_poll_control(struct file *file, poll_table *wait); |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 545 | int tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 546 | const int buffer_len); |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 547 | int tomoyo_write_control(struct tomoyo_io_buffer *head, |
| 548 | const char __user *buffer, const int buffer_len); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 549 | bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 550 | void tomoyo_warn_oom(const char *function); |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 551 | const struct tomoyo_path_info * |
| 552 | tomoyo_compare_name_union(const struct tomoyo_path_info *name, |
| 553 | const struct tomoyo_name_union *ptr); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 554 | bool tomoyo_compare_number_union(const unsigned long value, |
| 555 | const struct tomoyo_number_union *ptr); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 556 | int tomoyo_get_mode(const u8 profile, const u8 index); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 557 | void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 558 | __attribute__ ((format(printf, 2, 3))); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 559 | bool tomoyo_correct_domain(const unsigned char *domainname); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 560 | bool tomoyo_correct_path(const char *filename); |
| 561 | bool tomoyo_correct_word(const char *string); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 562 | bool tomoyo_domain_def(const unsigned char *buffer); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 563 | bool tomoyo_parse_name_union(struct tomoyo_acl_param *param, |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 564 | struct tomoyo_name_union *ptr); |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 565 | const struct tomoyo_path_info * |
| 566 | tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, |
| 567 | const struct tomoyo_group *group); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 568 | bool tomoyo_number_matches_group(const unsigned long min, |
| 569 | const unsigned long max, |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 570 | const struct tomoyo_group *group); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 571 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, |
| 572 | const struct tomoyo_path_info *pattern); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 573 | bool tomoyo_parse_number_union(struct tomoyo_acl_param *param, |
| 574 | struct tomoyo_number_union *ptr); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 575 | bool tomoyo_tokenize(char *buffer, char *w[], size_t size); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 576 | bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 577 | int tomoyo_init_request_info(struct tomoyo_request_info *r, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 578 | struct tomoyo_domain_info *domain, |
| 579 | const u8 index); |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 580 | int tomoyo_mount_permission(char *dev_name, struct path *path, |
| 581 | const char *type, unsigned long flags, |
| 582 | void *data_page); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 583 | int tomoyo_write_aggregator(struct tomoyo_acl_param *param); |
| 584 | int tomoyo_write_transition_control(struct tomoyo_acl_param *param, |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 585 | const u8 type); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 586 | int tomoyo_write_file(struct tomoyo_acl_param *param); |
| 587 | int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 588 | int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) |
| 589 | __attribute__ ((format(printf, 2, 3))); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 590 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 591 | struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, |
| 592 | const u8 profile); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 593 | struct tomoyo_profile *tomoyo_profile(const u8 profile); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 594 | struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param, |
| 595 | const u8 idx); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 596 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, |
| 597 | const u8 index); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 598 | void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 599 | void tomoyo_load_policy(const char *filename); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 600 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 601 | char *tomoyo_encode(const char *str); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 602 | char *tomoyo_realpath_nofollow(const char *pathname); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 603 | char *tomoyo_realpath_from_path(struct path *path); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 604 | bool tomoyo_memory_ok(void *ptr); |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 605 | void *tomoyo_commit_ok(void *data, const unsigned int size); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 606 | const struct tomoyo_path_info *tomoyo_get_name(const char *name); |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 607 | void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 608 | int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 609 | void __init tomoyo_mm_init(void); |
Tetsuo Handa | 05336de | 2010-06-16 16:20:24 +0900 | [diff] [blame] | 610 | int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 611 | const struct tomoyo_path_info *filename); |
| 612 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |
| 613 | struct path *path, const int flag); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 614 | int tomoyo_path_number_perm(const u8 operation, struct path *path, |
| 615 | unsigned long number); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 616 | int tomoyo_mkdev_perm(const u8 operation, struct path *path, |
| 617 | const unsigned int mode, unsigned int dev); |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 618 | int tomoyo_path_perm(const u8 operation, struct path *path); |
| 619 | int tomoyo_path2_perm(const u8 operation, struct path *path1, |
| 620 | struct path *path2); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 621 | int tomoyo_find_next_domain(struct linux_binprm *bprm); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 622 | void tomoyo_print_ulong(char *buffer, const int buffer_len, |
| 623 | const unsigned long value, const u8 type); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 624 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr); |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 625 | void tomoyo_run_gc(void); |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 626 | void tomoyo_memory_free(void *ptr); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 627 | int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 628 | struct tomoyo_acl_param *param, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 629 | bool (*check_duplicate) (const struct tomoyo_acl_info |
| 630 | *, |
| 631 | const struct tomoyo_acl_info |
| 632 | *), |
| 633 | bool (*merge_duplicate) (struct tomoyo_acl_info *, |
| 634 | struct tomoyo_acl_info *, |
| 635 | const bool)); |
Tetsuo Handa | 36f5e1f | 2010-06-15 09:23:26 +0900 | [diff] [blame] | 636 | int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 637 | struct tomoyo_acl_param *param, |
Tetsuo Handa | 36f5e1f | 2010-06-15 09:23:26 +0900 | [diff] [blame] | 638 | bool (*check_duplicate) (const struct tomoyo_acl_head |
| 639 | *, |
| 640 | const struct tomoyo_acl_head |
| 641 | *)); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 642 | void tomoyo_check_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 643 | bool (*check_entry) (struct tomoyo_request_info *, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 644 | const struct tomoyo_acl_info *)); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 645 | char *tomoyo_read_token(struct tomoyo_acl_param *param); |
| 646 | bool tomoyo_permstr(const char *string, const char *keyword); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 647 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 648 | const char *tomoyo_yesno(const unsigned int value); |
| 649 | void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt, |
| 650 | va_list args); |
| 651 | void tomoyo_read_log(struct tomoyo_io_buffer *head); |
| 652 | int tomoyo_poll_log(struct file *file, poll_table *wait); |
| 653 | char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt, |
| 654 | va_list args); |
| 655 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 656 | /********** External variable definitions. **********/ |
| 657 | |
| 658 | /* Lock for GC. */ |
| 659 | extern struct srcu_struct tomoyo_ss; |
| 660 | |
| 661 | /* The list for "struct tomoyo_domain_info". */ |
| 662 | extern struct list_head tomoyo_domain_list; |
| 663 | |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 664 | extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY]; |
| 665 | extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP]; |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 666 | extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 667 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 668 | /* Lock for protecting policy. */ |
| 669 | extern struct mutex tomoyo_policy_lock; |
| 670 | |
| 671 | /* Has /sbin/init started? */ |
| 672 | extern bool tomoyo_policy_loaded; |
| 673 | |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame^] | 674 | extern struct list_head tomoyo_acl_group[TOMOYO_MAX_ACL_GROUPS]; |
| 675 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 676 | /* The kernel's domain. */ |
| 677 | extern struct tomoyo_domain_info tomoyo_kernel_domain; |
| 678 | |
Tetsuo Handa | 71c2823 | 2010-06-16 16:26:38 +0900 | [diff] [blame] | 679 | extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; |
| 680 | extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION]; |
| 681 | extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION]; |
| 682 | extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION]; |
| 683 | |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 684 | extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION]; |
| 685 | extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION]; |
| 686 | extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION]; |
| 687 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 688 | extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE]; |
| 689 | extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT]; |
| 690 | extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT]; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 691 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 692 | /********** Inlined functions. **********/ |
| 693 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 694 | /** |
| 695 | * tomoyo_read_lock - Take lock for protecting policy. |
| 696 | * |
| 697 | * Returns index number for tomoyo_read_unlock(). |
| 698 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 699 | static inline int tomoyo_read_lock(void) |
| 700 | { |
| 701 | return srcu_read_lock(&tomoyo_ss); |
| 702 | } |
| 703 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 704 | /** |
| 705 | * tomoyo_read_unlock - Release lock for protecting policy. |
| 706 | * |
| 707 | * @idx: Index number returned by tomoyo_read_lock(). |
| 708 | * |
| 709 | * Returns nothing. |
| 710 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 711 | static inline void tomoyo_read_unlock(int idx) |
| 712 | { |
| 713 | srcu_read_unlock(&tomoyo_ss, idx); |
| 714 | } |
| 715 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 716 | /** |
| 717 | * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure. |
| 718 | * |
| 719 | * @a: Pointer to "struct tomoyo_path_info". |
| 720 | * @b: Pointer to "struct tomoyo_path_info". |
| 721 | * |
| 722 | * Returns true if @a == @b, false otherwise. |
| 723 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 724 | static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, |
| 725 | const struct tomoyo_path_info *b) |
| 726 | { |
| 727 | return a->hash != b->hash || strcmp(a->name, b->name); |
| 728 | } |
| 729 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 730 | /** |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 731 | * tomoyo_put_name - Drop reference on "struct tomoyo_name". |
| 732 | * |
| 733 | * @name: Pointer to "struct tomoyo_path_info". Maybe NULL. |
| 734 | * |
| 735 | * Returns nothing. |
| 736 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 737 | static inline void tomoyo_put_name(const struct tomoyo_path_info *name) |
| 738 | { |
| 739 | if (name) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 740 | struct tomoyo_name *ptr = |
| 741 | container_of(name, typeof(*ptr), entry); |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 742 | atomic_dec(&ptr->head.users); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 743 | } |
| 744 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 745 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 746 | /** |
| 747 | * tomoyo_put_group - Drop reference on "struct tomoyo_group". |
| 748 | * |
| 749 | * @group: Pointer to "struct tomoyo_group". Maybe NULL. |
| 750 | * |
| 751 | * Returns nothing. |
| 752 | */ |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 753 | static inline void tomoyo_put_group(struct tomoyo_group *group) |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 754 | { |
| 755 | if (group) |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 756 | atomic_dec(&group->head.users); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 757 | } |
| 758 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 759 | /** |
| 760 | * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread. |
| 761 | * |
| 762 | * Returns pointer to "struct tomoyo_domain_info" for current thread. |
| 763 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 764 | static inline struct tomoyo_domain_info *tomoyo_domain(void) |
| 765 | { |
| 766 | return current_cred()->security; |
| 767 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 768 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 769 | /** |
| 770 | * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread. |
| 771 | * |
| 772 | * @task: Pointer to "struct task_struct". |
| 773 | * |
| 774 | * Returns pointer to "struct tomoyo_security" for specified thread. |
| 775 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 776 | static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct |
| 777 | *task) |
| 778 | { |
| 779 | return task_cred_xxx(task, security); |
| 780 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 781 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 782 | /** |
| 783 | * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry. |
| 784 | * |
| 785 | * @a: Pointer to "struct tomoyo_name_union". |
| 786 | * @b: Pointer to "struct tomoyo_name_union". |
| 787 | * |
| 788 | * Returns true if @a == @b, false otherwise. |
| 789 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 790 | static inline bool tomoyo_same_name_union |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 791 | (const struct tomoyo_name_union *a, const struct tomoyo_name_union *b) |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 792 | { |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 793 | return a->filename == b->filename && a->group == b->group; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 794 | } |
| 795 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 796 | /** |
| 797 | * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry. |
| 798 | * |
| 799 | * @a: Pointer to "struct tomoyo_number_union". |
| 800 | * @b: Pointer to "struct tomoyo_number_union". |
| 801 | * |
| 802 | * Returns true if @a == @b, false otherwise. |
| 803 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 804 | static inline bool tomoyo_same_number_union |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 805 | (const struct tomoyo_number_union *a, const struct tomoyo_number_union *b) |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 806 | { |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 807 | return a->values[0] == b->values[0] && a->values[1] == b->values[1] && |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 808 | a->group == b->group && a->value_type[0] == b->value_type[0] && |
| 809 | a->value_type[1] == b->value_type[1]; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 810 | } |
| 811 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 812 | #if defined(CONFIG_SLOB) |
| 813 | |
| 814 | /** |
| 815 | * tomoyo_round2 - Round up to power of 2 for calculating memory usage. |
| 816 | * |
| 817 | * @size: Size to be rounded up. |
| 818 | * |
| 819 | * Returns @size. |
| 820 | * |
| 821 | * Since SLOB does not round up, this function simply returns @size. |
| 822 | */ |
| 823 | static inline int tomoyo_round2(size_t size) |
| 824 | { |
| 825 | return size; |
| 826 | } |
| 827 | |
| 828 | #else |
| 829 | |
| 830 | /** |
| 831 | * tomoyo_round2 - Round up to power of 2 for calculating memory usage. |
| 832 | * |
| 833 | * @size: Size to be rounded up. |
| 834 | * |
| 835 | * Returns rounded size. |
| 836 | * |
| 837 | * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of |
| 838 | * (e.g.) 128 bytes. |
| 839 | */ |
| 840 | static inline int tomoyo_round2(size_t size) |
| 841 | { |
| 842 | #if PAGE_SIZE == 4096 |
| 843 | size_t bsize = 32; |
| 844 | #else |
| 845 | size_t bsize = 64; |
| 846 | #endif |
| 847 | if (!size) |
| 848 | return 0; |
| 849 | while (size > bsize) |
| 850 | bsize <<= 1; |
| 851 | return bsize; |
| 852 | } |
| 853 | |
| 854 | #endif |
| 855 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 856 | /** |
| 857 | * list_for_each_cookie - iterate over a list with cookie. |
| 858 | * @pos: the &struct list_head to use as a loop cursor. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 859 | * @head: the head for your list. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 860 | */ |
Tetsuo Handa | 475e6fa | 2010-06-24 11:28:14 +0900 | [diff] [blame] | 861 | #define list_for_each_cookie(pos, head) \ |
| 862 | if (!pos) \ |
| 863 | pos = srcu_dereference((head)->next, &tomoyo_ss); \ |
| 864 | for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss)) |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 865 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 866 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ |