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 | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 24 | #include <linux/binfmts.h> |
| 25 | #include <linux/highmem.h> |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 26 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 27 | /********** Constants definitions. **********/ |
| 28 | |
| 29 | /* |
| 30 | * TOMOYO uses this hash only when appending a string into the string |
| 31 | * table. Frequency of appending strings is very low. So we don't need |
| 32 | * large (e.g. 64k) hash size. 256 will be sufficient. |
| 33 | */ |
| 34 | #define TOMOYO_HASH_BITS 8 |
| 35 | #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) |
| 36 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 37 | #define TOMOYO_EXEC_TMPSIZE 4096 |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 38 | |
| 39 | /* Profile number is an integer between 0 and 255. */ |
| 40 | #define TOMOYO_MAX_PROFILES 256 |
| 41 | |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 42 | /* Group number is an integer between 0 and 255. */ |
| 43 | #define TOMOYO_MAX_ACL_GROUPS 256 |
| 44 | |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 45 | /* Index numbers for "struct tomoyo_condition". */ |
| 46 | enum tomoyo_conditions_index { |
| 47 | TOMOYO_TASK_UID, /* current_uid() */ |
| 48 | TOMOYO_TASK_EUID, /* current_euid() */ |
| 49 | TOMOYO_TASK_SUID, /* current_suid() */ |
| 50 | TOMOYO_TASK_FSUID, /* current_fsuid() */ |
| 51 | TOMOYO_TASK_GID, /* current_gid() */ |
| 52 | TOMOYO_TASK_EGID, /* current_egid() */ |
| 53 | TOMOYO_TASK_SGID, /* current_sgid() */ |
| 54 | TOMOYO_TASK_FSGID, /* current_fsgid() */ |
| 55 | TOMOYO_TASK_PID, /* sys_getpid() */ |
| 56 | TOMOYO_TASK_PPID, /* sys_getppid() */ |
Tetsuo Handa | 8761afd | 2011-07-08 13:22:41 +0900 | [diff] [blame^] | 57 | TOMOYO_TYPE_IS_SOCKET, /* S_IFSOCK */ |
| 58 | TOMOYO_TYPE_IS_SYMLINK, /* S_IFLNK */ |
| 59 | TOMOYO_TYPE_IS_FILE, /* S_IFREG */ |
| 60 | TOMOYO_TYPE_IS_BLOCK_DEV, /* S_IFBLK */ |
| 61 | TOMOYO_TYPE_IS_DIRECTORY, /* S_IFDIR */ |
| 62 | TOMOYO_TYPE_IS_CHAR_DEV, /* S_IFCHR */ |
| 63 | TOMOYO_TYPE_IS_FIFO, /* S_IFIFO */ |
| 64 | TOMOYO_MODE_SETUID, /* S_ISUID */ |
| 65 | TOMOYO_MODE_SETGID, /* S_ISGID */ |
| 66 | TOMOYO_MODE_STICKY, /* S_ISVTX */ |
| 67 | TOMOYO_MODE_OWNER_READ, /* S_IRUSR */ |
| 68 | TOMOYO_MODE_OWNER_WRITE, /* S_IWUSR */ |
| 69 | TOMOYO_MODE_OWNER_EXECUTE, /* S_IXUSR */ |
| 70 | TOMOYO_MODE_GROUP_READ, /* S_IRGRP */ |
| 71 | TOMOYO_MODE_GROUP_WRITE, /* S_IWGRP */ |
| 72 | TOMOYO_MODE_GROUP_EXECUTE, /* S_IXGRP */ |
| 73 | TOMOYO_MODE_OTHERS_READ, /* S_IROTH */ |
| 74 | TOMOYO_MODE_OTHERS_WRITE, /* S_IWOTH */ |
| 75 | TOMOYO_MODE_OTHERS_EXECUTE, /* S_IXOTH */ |
| 76 | TOMOYO_PATH1_UID, |
| 77 | TOMOYO_PATH1_GID, |
| 78 | TOMOYO_PATH1_INO, |
| 79 | TOMOYO_PATH1_MAJOR, |
| 80 | TOMOYO_PATH1_MINOR, |
| 81 | TOMOYO_PATH1_PERM, |
| 82 | TOMOYO_PATH1_TYPE, |
| 83 | TOMOYO_PATH1_DEV_MAJOR, |
| 84 | TOMOYO_PATH1_DEV_MINOR, |
| 85 | TOMOYO_PATH2_UID, |
| 86 | TOMOYO_PATH2_GID, |
| 87 | TOMOYO_PATH2_INO, |
| 88 | TOMOYO_PATH2_MAJOR, |
| 89 | TOMOYO_PATH2_MINOR, |
| 90 | TOMOYO_PATH2_PERM, |
| 91 | TOMOYO_PATH2_TYPE, |
| 92 | TOMOYO_PATH2_DEV_MAJOR, |
| 93 | TOMOYO_PATH2_DEV_MINOR, |
| 94 | TOMOYO_PATH1_PARENT_UID, |
| 95 | TOMOYO_PATH1_PARENT_GID, |
| 96 | TOMOYO_PATH1_PARENT_INO, |
| 97 | TOMOYO_PATH1_PARENT_PERM, |
| 98 | TOMOYO_PATH2_PARENT_UID, |
| 99 | TOMOYO_PATH2_PARENT_GID, |
| 100 | TOMOYO_PATH2_PARENT_INO, |
| 101 | TOMOYO_PATH2_PARENT_PERM, |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 102 | TOMOYO_MAX_CONDITION_KEYWORD, |
| 103 | TOMOYO_NUMBER_UNION, |
| 104 | }; |
| 105 | |
Tetsuo Handa | 8761afd | 2011-07-08 13:22:41 +0900 | [diff] [blame^] | 106 | |
| 107 | /* Index numbers for stat(). */ |
| 108 | enum tomoyo_path_stat_index { |
| 109 | /* Do not change this order. */ |
| 110 | TOMOYO_PATH1, |
| 111 | TOMOYO_PATH1_PARENT, |
| 112 | TOMOYO_PATH2, |
| 113 | TOMOYO_PATH2_PARENT, |
| 114 | TOMOYO_MAX_PATH_STAT |
| 115 | }; |
| 116 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 117 | /* Index numbers for operation mode. */ |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 118 | enum tomoyo_mode_index { |
| 119 | TOMOYO_CONFIG_DISABLED, |
| 120 | TOMOYO_CONFIG_LEARNING, |
| 121 | TOMOYO_CONFIG_PERMISSIVE, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 122 | TOMOYO_CONFIG_ENFORCING, |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 123 | TOMOYO_CONFIG_MAX_MODE, |
| 124 | TOMOYO_CONFIG_WANT_REJECT_LOG = 64, |
| 125 | TOMOYO_CONFIG_WANT_GRANT_LOG = 128, |
| 126 | TOMOYO_CONFIG_USE_DEFAULT = 255, |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 127 | }; |
| 128 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 129 | /* Index numbers for entry type. */ |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 130 | enum tomoyo_policy_id { |
| 131 | TOMOYO_ID_GROUP, |
| 132 | TOMOYO_ID_PATH_GROUP, |
| 133 | TOMOYO_ID_NUMBER_GROUP, |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 134 | TOMOYO_ID_TRANSITION_CONTROL, |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 135 | TOMOYO_ID_AGGREGATOR, |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 136 | TOMOYO_ID_MANAGER, |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 137 | TOMOYO_ID_CONDITION, |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 138 | TOMOYO_ID_NAME, |
| 139 | TOMOYO_ID_ACL, |
| 140 | TOMOYO_ID_DOMAIN, |
| 141 | TOMOYO_MAX_POLICY |
| 142 | }; |
| 143 | |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 144 | /* Index numbers for domain's attributes. */ |
| 145 | enum tomoyo_domain_info_flags_index { |
| 146 | /* Quota warnning flag. */ |
| 147 | TOMOYO_DIF_QUOTA_WARNED, |
| 148 | /* |
| 149 | * This domain was unable to create a new domain at |
| 150 | * tomoyo_find_next_domain() because the name of the domain to be |
| 151 | * created was too long or it could not allocate memory. |
| 152 | * More than one process continued execve() without domain transition. |
| 153 | */ |
| 154 | TOMOYO_DIF_TRANSITION_FAILED, |
| 155 | TOMOYO_MAX_DOMAIN_INFO_FLAGS |
| 156 | }; |
| 157 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 158 | /* Index numbers for group entries. */ |
Tetsuo Handa | a230f9e | 2010-06-17 16:53:24 +0900 | [diff] [blame] | 159 | enum tomoyo_group_id { |
| 160 | TOMOYO_PATH_GROUP, |
| 161 | TOMOYO_NUMBER_GROUP, |
| 162 | TOMOYO_MAX_GROUP |
| 163 | }; |
| 164 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 165 | /* Index numbers for type of numeric values. */ |
| 166 | enum tomoyo_value_type { |
| 167 | TOMOYO_VALUE_TYPE_INVALID, |
| 168 | TOMOYO_VALUE_TYPE_DECIMAL, |
| 169 | TOMOYO_VALUE_TYPE_OCTAL, |
| 170 | TOMOYO_VALUE_TYPE_HEXADECIMAL, |
| 171 | }; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 172 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 173 | /* Index numbers for domain transition control keywords. */ |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 174 | enum tomoyo_transition_type { |
| 175 | /* Do not change this order, */ |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 176 | TOMOYO_TRANSITION_CONTROL_NO_RESET, |
| 177 | TOMOYO_TRANSITION_CONTROL_RESET, |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 178 | TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, |
| 179 | TOMOYO_TRANSITION_CONTROL_INITIALIZE, |
| 180 | TOMOYO_TRANSITION_CONTROL_NO_KEEP, |
| 181 | TOMOYO_TRANSITION_CONTROL_KEEP, |
| 182 | TOMOYO_MAX_TRANSITION_TYPE |
| 183 | }; |
| 184 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 185 | /* Index numbers for Access Controls. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 186 | enum tomoyo_acl_entry_type_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 187 | TOMOYO_TYPE_PATH_ACL, |
| 188 | TOMOYO_TYPE_PATH2_ACL, |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 189 | TOMOYO_TYPE_PATH_NUMBER_ACL, |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 190 | TOMOYO_TYPE_MKDEV_ACL, |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 191 | TOMOYO_TYPE_MOUNT_ACL, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 192 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 193 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 194 | /* Index numbers for access controls with one pathname. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 195 | enum tomoyo_path_acl_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 196 | TOMOYO_TYPE_EXECUTE, |
| 197 | TOMOYO_TYPE_READ, |
| 198 | TOMOYO_TYPE_WRITE, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 199 | TOMOYO_TYPE_APPEND, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 200 | TOMOYO_TYPE_UNLINK, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 201 | TOMOYO_TYPE_GETATTR, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 202 | TOMOYO_TYPE_RMDIR, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 203 | TOMOYO_TYPE_TRUNCATE, |
| 204 | TOMOYO_TYPE_SYMLINK, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 205 | TOMOYO_TYPE_CHROOT, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 206 | TOMOYO_TYPE_UMOUNT, |
| 207 | TOMOYO_MAX_PATH_OPERATION |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 208 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 209 | |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 210 | /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */ |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 211 | enum tomoyo_memory_stat_type { |
| 212 | TOMOYO_MEMORY_POLICY, |
| 213 | TOMOYO_MEMORY_AUDIT, |
| 214 | TOMOYO_MEMORY_QUERY, |
| 215 | TOMOYO_MAX_MEMORY_STAT |
| 216 | }; |
| 217 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 218 | enum tomoyo_mkdev_acl_index { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 219 | TOMOYO_TYPE_MKBLOCK, |
| 220 | TOMOYO_TYPE_MKCHAR, |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 221 | TOMOYO_MAX_MKDEV_OPERATION |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 222 | }; |
| 223 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 224 | /* Index numbers for access controls with two pathnames. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 225 | enum tomoyo_path2_acl_index { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 226 | TOMOYO_TYPE_LINK, |
| 227 | TOMOYO_TYPE_RENAME, |
| 228 | TOMOYO_TYPE_PIVOT_ROOT, |
| 229 | TOMOYO_MAX_PATH2_OPERATION |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 230 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 231 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 232 | /* Index numbers for access controls with one pathname and one number. */ |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 233 | enum tomoyo_path_number_acl_index { |
| 234 | TOMOYO_TYPE_CREATE, |
| 235 | TOMOYO_TYPE_MKDIR, |
| 236 | TOMOYO_TYPE_MKFIFO, |
| 237 | TOMOYO_TYPE_MKSOCK, |
| 238 | TOMOYO_TYPE_IOCTL, |
| 239 | TOMOYO_TYPE_CHMOD, |
| 240 | TOMOYO_TYPE_CHOWN, |
| 241 | TOMOYO_TYPE_CHGRP, |
| 242 | TOMOYO_MAX_PATH_NUMBER_OPERATION |
| 243 | }; |
| 244 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 245 | /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */ |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 246 | enum tomoyo_securityfs_interface_index { |
| 247 | TOMOYO_DOMAINPOLICY, |
| 248 | TOMOYO_EXCEPTIONPOLICY, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 249 | TOMOYO_PROCESS_STATUS, |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 250 | TOMOYO_STAT, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 251 | TOMOYO_SELFDOMAIN, |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 252 | TOMOYO_AUDIT, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 253 | TOMOYO_VERSION, |
| 254 | TOMOYO_PROFILE, |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 255 | TOMOYO_QUERY, |
Tetsuo Handa | 084da35 | 2010-02-15 15:10:39 +0900 | [diff] [blame] | 256 | TOMOYO_MANAGER |
| 257 | }; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 258 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 259 | /* Index numbers for special mount operations. */ |
| 260 | enum tomoyo_special_mount { |
| 261 | TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */ |
| 262 | TOMOYO_MOUNT_MOVE, /* mount --move /old /new */ |
| 263 | TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */ |
| 264 | TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */ |
| 265 | TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */ |
| 266 | TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */ |
| 267 | TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */ |
| 268 | TOMOYO_MAX_SPECIAL_MOUNT |
| 269 | }; |
| 270 | |
| 271 | /* Index numbers for functionality. */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 272 | enum tomoyo_mac_index { |
| 273 | TOMOYO_MAC_FILE_EXECUTE, |
| 274 | TOMOYO_MAC_FILE_OPEN, |
| 275 | TOMOYO_MAC_FILE_CREATE, |
| 276 | TOMOYO_MAC_FILE_UNLINK, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 277 | TOMOYO_MAC_FILE_GETATTR, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 278 | TOMOYO_MAC_FILE_MKDIR, |
| 279 | TOMOYO_MAC_FILE_RMDIR, |
| 280 | TOMOYO_MAC_FILE_MKFIFO, |
| 281 | TOMOYO_MAC_FILE_MKSOCK, |
| 282 | TOMOYO_MAC_FILE_TRUNCATE, |
| 283 | TOMOYO_MAC_FILE_SYMLINK, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 284 | TOMOYO_MAC_FILE_MKBLOCK, |
| 285 | TOMOYO_MAC_FILE_MKCHAR, |
| 286 | TOMOYO_MAC_FILE_LINK, |
| 287 | TOMOYO_MAC_FILE_RENAME, |
| 288 | TOMOYO_MAC_FILE_CHMOD, |
| 289 | TOMOYO_MAC_FILE_CHOWN, |
| 290 | TOMOYO_MAC_FILE_CHGRP, |
| 291 | TOMOYO_MAC_FILE_IOCTL, |
| 292 | TOMOYO_MAC_FILE_CHROOT, |
| 293 | TOMOYO_MAC_FILE_MOUNT, |
| 294 | TOMOYO_MAC_FILE_UMOUNT, |
| 295 | TOMOYO_MAC_FILE_PIVOT_ROOT, |
| 296 | TOMOYO_MAX_MAC_INDEX |
| 297 | }; |
| 298 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 299 | /* Index numbers for category of functionality. */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 300 | enum tomoyo_mac_category_index { |
| 301 | TOMOYO_MAC_CATEGORY_FILE, |
| 302 | TOMOYO_MAX_MAC_CATEGORY_INDEX |
| 303 | }; |
| 304 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 305 | /* |
| 306 | * Retry this request. Returned by tomoyo_supervisor() if policy violation has |
| 307 | * occurred in enforcing mode and the userspace daemon decided to retry. |
| 308 | * |
| 309 | * We must choose a positive value in order to distinguish "granted" (which is |
| 310 | * 0) and "rejected" (which is a negative value) and "retry". |
| 311 | */ |
| 312 | #define TOMOYO_RETRY_REQUEST 1 |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 313 | |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 314 | /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */ |
| 315 | enum tomoyo_policy_stat_type { |
| 316 | /* Do not change this order. */ |
| 317 | TOMOYO_STAT_POLICY_UPDATES, |
| 318 | TOMOYO_STAT_POLICY_LEARNING, /* == TOMOYO_CONFIG_LEARNING */ |
| 319 | TOMOYO_STAT_POLICY_PERMISSIVE, /* == TOMOYO_CONFIG_PERMISSIVE */ |
| 320 | TOMOYO_STAT_POLICY_ENFORCING, /* == TOMOYO_CONFIG_ENFORCING */ |
| 321 | TOMOYO_MAX_POLICY_STAT |
| 322 | }; |
| 323 | |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 324 | /* Index numbers for profile's PREFERENCE values. */ |
| 325 | enum tomoyo_pref_index { |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 326 | TOMOYO_PREF_MAX_AUDIT_LOG, |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 327 | TOMOYO_PREF_MAX_LEARNING_ENTRY, |
| 328 | TOMOYO_MAX_PREF |
| 329 | }; |
| 330 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 331 | /********** Structure definitions. **********/ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 332 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 333 | /* Common header for holding ACL entries. */ |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 334 | struct tomoyo_acl_head { |
| 335 | struct list_head list; |
| 336 | bool is_deleted; |
| 337 | } __packed; |
| 338 | |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 339 | /* Common header for shared entries. */ |
| 340 | struct tomoyo_shared_acl_head { |
| 341 | struct list_head list; |
| 342 | atomic_t users; |
| 343 | } __packed; |
| 344 | |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 345 | struct tomoyo_policy_namespace; |
| 346 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 347 | /* Structure for request info. */ |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 348 | struct tomoyo_request_info { |
Tetsuo Handa | 8761afd | 2011-07-08 13:22:41 +0900 | [diff] [blame^] | 349 | /* |
| 350 | * For holding parameters specific to operations which deal files. |
| 351 | * NULL if not dealing files. |
| 352 | */ |
| 353 | struct tomoyo_obj_info *obj; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 354 | struct tomoyo_domain_info *domain; |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 355 | /* For holding parameters. */ |
| 356 | union { |
| 357 | struct { |
| 358 | const struct tomoyo_path_info *filename; |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 359 | /* For using wildcards at tomoyo_find_next_domain(). */ |
| 360 | const struct tomoyo_path_info *matched_path; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 361 | /* One of values in "enum tomoyo_path_acl_index". */ |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 362 | u8 operation; |
| 363 | } path; |
| 364 | struct { |
| 365 | const struct tomoyo_path_info *filename1; |
| 366 | const struct tomoyo_path_info *filename2; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 367 | /* One of values in "enum tomoyo_path2_acl_index". */ |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 368 | u8 operation; |
| 369 | } path2; |
| 370 | struct { |
| 371 | const struct tomoyo_path_info *filename; |
| 372 | unsigned int mode; |
| 373 | unsigned int major; |
| 374 | unsigned int minor; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 375 | /* One of values in "enum tomoyo_mkdev_acl_index". */ |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 376 | u8 operation; |
| 377 | } mkdev; |
| 378 | struct { |
| 379 | const struct tomoyo_path_info *filename; |
| 380 | unsigned long number; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 381 | /* |
| 382 | * One of values in |
| 383 | * "enum tomoyo_path_number_acl_index". |
| 384 | */ |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 385 | u8 operation; |
| 386 | } path_number; |
| 387 | struct { |
| 388 | const struct tomoyo_path_info *type; |
| 389 | const struct tomoyo_path_info *dir; |
| 390 | const struct tomoyo_path_info *dev; |
| 391 | unsigned long flags; |
| 392 | int need_dev; |
| 393 | } mount; |
| 394 | } param; |
| 395 | u8 param_type; |
| 396 | bool granted; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 397 | u8 retry; |
| 398 | u8 profile; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 399 | u8 mode; /* One of tomoyo_mode_index . */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 400 | u8 type; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 401 | }; |
| 402 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 403 | /* Structure for holding a token. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 404 | struct tomoyo_path_info { |
| 405 | const char *name; |
| 406 | u32 hash; /* = full_name_hash(name, strlen(name)) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 407 | u16 const_len; /* = tomoyo_const_part_length(name) */ |
| 408 | bool is_dir; /* = tomoyo_strendswith(name, "/") */ |
| 409 | bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 410 | }; |
| 411 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 412 | /* Structure for holding string data. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 413 | struct tomoyo_name { |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 414 | struct tomoyo_shared_acl_head head; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 415 | struct tomoyo_path_info entry; |
| 416 | }; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 417 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 418 | /* Structure for holding a word. */ |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 419 | struct tomoyo_name_union { |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 420 | /* Either @filename or @group is NULL. */ |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 421 | const struct tomoyo_path_info *filename; |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 422 | struct tomoyo_group *group; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 423 | }; |
| 424 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 425 | /* Structure for holding a number. */ |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 426 | struct tomoyo_number_union { |
| 427 | unsigned long values[2]; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 428 | struct tomoyo_group *group; /* Maybe NULL. */ |
| 429 | /* One of values in "enum tomoyo_value_type". */ |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 430 | u8 value_type[2]; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 431 | }; |
| 432 | |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 433 | /* Structure for "path_group"/"number_group" directive. */ |
| 434 | struct tomoyo_group { |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 435 | struct tomoyo_shared_acl_head head; |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 436 | const struct tomoyo_path_info *group_name; |
| 437 | struct list_head member_list; |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 438 | }; |
| 439 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 440 | /* Structure for "path_group" directive. */ |
| 441 | struct tomoyo_path_group { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 442 | struct tomoyo_acl_head head; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 443 | const struct tomoyo_path_info *member_name; |
| 444 | }; |
| 445 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 446 | /* Structure for "number_group" directive. */ |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 447 | struct tomoyo_number_group { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 448 | struct tomoyo_acl_head head; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 449 | struct tomoyo_number_union number; |
| 450 | }; |
| 451 | |
Tetsuo Handa | 8761afd | 2011-07-08 13:22:41 +0900 | [diff] [blame^] | 452 | /* Subset of "struct stat". Used by conditional ACL and audit logs. */ |
| 453 | struct tomoyo_mini_stat { |
| 454 | uid_t uid; |
| 455 | gid_t gid; |
| 456 | ino_t ino; |
| 457 | mode_t mode; |
| 458 | dev_t dev; |
| 459 | dev_t rdev; |
| 460 | }; |
| 461 | |
| 462 | /* Structure for attribute checks in addition to pathname checks. */ |
| 463 | struct tomoyo_obj_info { |
| 464 | /* |
| 465 | * True if tomoyo_get_attributes() was already called, false otherwise. |
| 466 | */ |
| 467 | bool validate_done; |
| 468 | /* True if @stat[] is valid. */ |
| 469 | bool stat_valid[TOMOYO_MAX_PATH_STAT]; |
| 470 | /* First pathname. Initialized with { NULL, NULL } if no path. */ |
| 471 | struct path path1; |
| 472 | /* Second pathname. Initialized with { NULL, NULL } if no path. */ |
| 473 | struct path path2; |
| 474 | /* |
| 475 | * Information on @path1, @path1's parent directory, @path2, @path2's |
| 476 | * parent directory. |
| 477 | */ |
| 478 | struct tomoyo_mini_stat stat[TOMOYO_MAX_PATH_STAT]; |
| 479 | }; |
| 480 | |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 481 | /* Structure for entries which follows "struct tomoyo_condition". */ |
| 482 | struct tomoyo_condition_element { |
| 483 | /* Left hand operand. */ |
| 484 | u8 left; |
| 485 | /* Right hand operand. */ |
| 486 | u8 right; |
| 487 | /* Equation operator. True if equals or overlaps, false otherwise. */ |
| 488 | bool equals; |
| 489 | }; |
| 490 | |
| 491 | /* Structure for optional arguments. */ |
| 492 | struct tomoyo_condition { |
| 493 | struct tomoyo_shared_acl_head head; |
| 494 | u32 size; /* Memory size allocated for this entry. */ |
| 495 | u16 condc; /* Number of conditions in this struct. */ |
| 496 | u16 numbers_count; /* Number of "struct tomoyo_number_union values". */ |
| 497 | /* |
| 498 | * struct tomoyo_condition_element condition[condc]; |
| 499 | * struct tomoyo_number_union values[numbers_count]; |
| 500 | */ |
| 501 | }; |
| 502 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 503 | /* Common header for individual entries. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 504 | struct tomoyo_acl_info { |
| 505 | struct list_head list; |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 506 | struct tomoyo_condition *cond; /* Maybe NULL. */ |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 507 | bool is_deleted; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 508 | u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 509 | } __packed; |
| 510 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 511 | /* Structure for domain information. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 512 | struct tomoyo_domain_info { |
| 513 | struct list_head list; |
| 514 | struct list_head acl_info_list; |
| 515 | /* Name of this domain. Never NULL. */ |
| 516 | const struct tomoyo_path_info *domainname; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 517 | /* Namespace for this domain. Never NULL. */ |
| 518 | struct tomoyo_policy_namespace *ns; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 519 | u8 profile; /* Profile number to use. */ |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 520 | u8 group; /* Group number to use. */ |
Tetsuo Handa | a0558fc | 2009-04-06 20:49:14 +0900 | [diff] [blame] | 521 | bool is_deleted; /* Delete flag. */ |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 522 | bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS]; |
Tetsuo Handa | ec8e6a4 | 2010-02-11 09:43:20 +0900 | [diff] [blame] | 523 | atomic_t users; /* Number of referring credentials. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 524 | }; |
| 525 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 526 | /* |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 527 | * Structure for "file execute", "file read", "file write", "file append", |
| 528 | * "file unlink", "file getattr", "file rmdir", "file truncate", |
| 529 | * "file symlink", "file chroot" and "file unmount" directive. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 530 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 531 | struct tomoyo_path_acl { |
| 532 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 533 | u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */ |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 534 | struct tomoyo_name_union name; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 535 | }; |
| 536 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 537 | /* |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 538 | * Structure for "file create", "file mkdir", "file mkfifo", "file mksock", |
| 539 | * "file ioctl", "file chmod", "file chown" and "file chgrp" directive. |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 540 | */ |
| 541 | struct tomoyo_path_number_acl { |
| 542 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 543 | /* Bitmask of values in "enum tomoyo_path_number_acl_index". */ |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 544 | u8 perm; |
| 545 | struct tomoyo_name_union name; |
| 546 | struct tomoyo_number_union number; |
| 547 | }; |
| 548 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 549 | /* Structure for "file mkblock" and "file mkchar" directive. */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 550 | struct tomoyo_mkdev_acl { |
| 551 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 552 | u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */ |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 553 | struct tomoyo_name_union name; |
| 554 | struct tomoyo_number_union mode; |
| 555 | struct tomoyo_number_union major; |
| 556 | struct tomoyo_number_union minor; |
| 557 | }; |
| 558 | |
| 559 | /* |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 560 | * Structure for "file rename", "file link" and "file pivot_root" directive. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 561 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 562 | struct tomoyo_path2_acl { |
| 563 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 564 | u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */ |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 565 | struct tomoyo_name_union name1; |
| 566 | struct tomoyo_name_union name2; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 567 | }; |
| 568 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 569 | /* Structure for "file mount" directive. */ |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 570 | struct tomoyo_mount_acl { |
| 571 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 572 | struct tomoyo_name_union dev_name; |
| 573 | struct tomoyo_name_union dir_name; |
| 574 | struct tomoyo_name_union fs_type; |
| 575 | struct tomoyo_number_union flags; |
| 576 | }; |
| 577 | |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 578 | /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */ |
| 579 | struct tomoyo_acl_param { |
| 580 | char *data; |
| 581 | struct list_head *list; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 582 | struct tomoyo_policy_namespace *ns; |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 583 | bool is_delete; |
| 584 | }; |
| 585 | |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 586 | #define TOMOYO_MAX_IO_READ_QUEUE 64 |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 587 | |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 588 | /* |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 589 | * Structure for reading/writing policy via /sys/kernel/security/tomoyo |
| 590 | * interfaces. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 591 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 592 | struct tomoyo_io_buffer { |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 593 | void (*read) (struct tomoyo_io_buffer *); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 594 | int (*write) (struct tomoyo_io_buffer *); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 595 | int (*poll) (struct file *file, poll_table *wait); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 596 | /* Exclusive lock for this structure. */ |
| 597 | struct mutex io_sem; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 598 | char __user *read_user_buf; |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 599 | size_t read_user_buf_avail; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 600 | struct { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 601 | struct list_head *ns; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 602 | struct list_head *domain; |
| 603 | struct list_head *group; |
| 604 | struct list_head *acl; |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 605 | size_t avail; |
| 606 | unsigned int step; |
| 607 | unsigned int query_index; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 608 | u16 index; |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 609 | u16 cond_index; |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 610 | u8 acl_group_index; |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 611 | u8 cond_step; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 612 | u8 bit; |
| 613 | u8 w_pos; |
| 614 | bool eof; |
| 615 | bool print_this_domain_only; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 616 | bool print_transition_related_only; |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 617 | bool print_cond_part; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 618 | const char *w[TOMOYO_MAX_IO_READ_QUEUE]; |
| 619 | } r; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 620 | struct { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 621 | struct tomoyo_policy_namespace *ns; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 622 | /* The position currently writing to. */ |
| 623 | struct tomoyo_domain_info *domain; |
| 624 | /* Bytes available for writing. */ |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 625 | size_t avail; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 626 | bool is_delete; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 627 | } w; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 628 | /* Buffer for reading. */ |
| 629 | char *read_buf; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 630 | /* Size of read buffer. */ |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 631 | size_t readbuf_size; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 632 | /* Buffer for writing. */ |
| 633 | char *write_buf; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 634 | /* Size of write buffer. */ |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 635 | size_t writebuf_size; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 636 | /* Type of this interface. */ |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 637 | enum tomoyo_securityfs_interface_index type; |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 638 | /* Users counter protected by tomoyo_io_buffer_list_lock. */ |
| 639 | u8 users; |
| 640 | /* List for telling GC not to kfree() elements. */ |
| 641 | struct list_head list; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 642 | }; |
| 643 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 644 | /* |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 645 | * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/ |
| 646 | * "no_keep_domain" keyword. |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 647 | */ |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 648 | struct tomoyo_transition_control { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 649 | struct tomoyo_acl_head head; |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 650 | u8 type; /* One of values in "enum tomoyo_transition_type". */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 651 | /* True if the domainname is tomoyo_get_last_name(). */ |
| 652 | bool is_last_name; |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 653 | const struct tomoyo_path_info *domainname; /* Maybe NULL */ |
| 654 | const struct tomoyo_path_info *program; /* Maybe NULL */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 655 | }; |
| 656 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 657 | /* Structure for "aggregator" keyword. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 658 | struct tomoyo_aggregator { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 659 | struct tomoyo_acl_head head; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 660 | const struct tomoyo_path_info *original_name; |
| 661 | const struct tomoyo_path_info *aggregated_name; |
Tetsuo Handa | 1084307 | 2010-06-03 20:38:03 +0900 | [diff] [blame] | 662 | }; |
| 663 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 664 | /* Structure for policy manager. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 665 | struct tomoyo_manager { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 666 | struct tomoyo_acl_head head; |
| 667 | bool is_domain; /* True if manager is a domainname. */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 668 | /* A path to program or a domainname. */ |
| 669 | const struct tomoyo_path_info *manager; |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 670 | }; |
| 671 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 672 | struct tomoyo_preference { |
| 673 | unsigned int learning_max_entry; |
| 674 | bool enforcing_verbose; |
| 675 | bool learning_verbose; |
| 676 | bool permissive_verbose; |
| 677 | }; |
| 678 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 679 | /* Structure for /sys/kernel/security/tomnoyo/profile interface. */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 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]; |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 688 | unsigned int pref[TOMOYO_MAX_PREF]; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 689 | }; |
| 690 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 691 | /* Structure for representing YYYY/MM/DD hh/mm/ss. */ |
| 692 | struct tomoyo_time { |
| 693 | u16 year; |
| 694 | u8 month; |
| 695 | u8 day; |
| 696 | u8 hour; |
| 697 | u8 min; |
| 698 | u8 sec; |
| 699 | }; |
| 700 | |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 701 | /* Structure for policy namespace. */ |
| 702 | struct tomoyo_policy_namespace { |
| 703 | /* Profile table. Memory is allocated as needed. */ |
| 704 | struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES]; |
| 705 | /* List of "struct tomoyo_group". */ |
| 706 | struct list_head group_list[TOMOYO_MAX_GROUP]; |
| 707 | /* List of policy. */ |
| 708 | struct list_head policy_list[TOMOYO_MAX_POLICY]; |
| 709 | /* The global ACL referred by "use_group" keyword. */ |
| 710 | struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS]; |
| 711 | /* List for connecting to tomoyo_namespace_list list. */ |
| 712 | struct list_head namespace_list; |
| 713 | /* Profile version. Currently only 20100903 is defined. */ |
| 714 | unsigned int profile_version; |
| 715 | /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */ |
| 716 | const char *name; |
| 717 | }; |
| 718 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 719 | /********** Function prototypes. **********/ |
| 720 | |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 721 | bool tomoyo_compare_number_union(const unsigned long value, |
| 722 | const struct tomoyo_number_union *ptr); |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 723 | bool tomoyo_condition(struct tomoyo_request_info *r, |
| 724 | const struct tomoyo_condition *cond); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 725 | bool tomoyo_correct_domain(const unsigned char *domainname); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 726 | bool tomoyo_correct_path(const char *filename); |
| 727 | bool tomoyo_correct_word(const char *string); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 728 | bool tomoyo_domain_def(const unsigned char *buffer); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 729 | bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); |
| 730 | bool tomoyo_memory_ok(void *ptr); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 731 | bool tomoyo_number_matches_group(const unsigned long min, |
| 732 | const unsigned long max, |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 733 | const struct tomoyo_group *group); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 734 | bool tomoyo_parse_name_union(struct tomoyo_acl_param *param, |
| 735 | struct tomoyo_name_union *ptr); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 736 | bool tomoyo_parse_number_union(struct tomoyo_acl_param *param, |
| 737 | struct tomoyo_number_union *ptr); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 738 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, |
| 739 | const struct tomoyo_path_info *pattern); |
| 740 | bool tomoyo_permstr(const char *string, const char *keyword); |
| 741 | bool tomoyo_str_starts(char **src, const char *find); |
| 742 | char *tomoyo_encode(const char *str); |
| 743 | char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt, |
| 744 | va_list args); |
| 745 | char *tomoyo_read_token(struct tomoyo_acl_param *param); |
| 746 | char *tomoyo_realpath_from_path(struct path *path); |
| 747 | char *tomoyo_realpath_nofollow(const char *pathname); |
| 748 | const char *tomoyo_get_exe(void); |
| 749 | const char *tomoyo_yesno(const unsigned int value); |
| 750 | const struct tomoyo_path_info *tomoyo_compare_name_union |
| 751 | (const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr); |
| 752 | const struct tomoyo_path_info *tomoyo_get_name(const char *name); |
| 753 | const struct tomoyo_path_info *tomoyo_path_matches_group |
| 754 | (const struct tomoyo_path_info *pathname, const struct tomoyo_group *group); |
| 755 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |
| 756 | struct path *path, const int flag); |
| 757 | int tomoyo_close_control(struct tomoyo_io_buffer *head); |
| 758 | int tomoyo_find_next_domain(struct linux_binprm *bprm); |
| 759 | int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile, |
| 760 | const u8 index); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 761 | int tomoyo_init_request_info(struct tomoyo_request_info *r, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 762 | struct tomoyo_domain_info *domain, |
| 763 | const u8 index); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 764 | int tomoyo_mkdev_perm(const u8 operation, struct path *path, |
| 765 | const unsigned int mode, unsigned int dev); |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 766 | int tomoyo_mount_permission(char *dev_name, struct path *path, |
| 767 | const char *type, unsigned long flags, |
| 768 | void *data_page); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 769 | int tomoyo_open_control(const u8 type, struct file *file); |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 770 | int tomoyo_path2_perm(const u8 operation, struct path *path1, |
| 771 | struct path *path2); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 772 | int tomoyo_path_number_perm(const u8 operation, struct path *path, |
| 773 | unsigned long number); |
| 774 | int tomoyo_path_perm(const u8 operation, struct path *path); |
| 775 | int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
| 776 | const struct tomoyo_path_info *filename); |
| 777 | int tomoyo_poll_control(struct file *file, poll_table *wait); |
| 778 | int tomoyo_poll_log(struct file *file, poll_table *wait); |
| 779 | int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) |
| 780 | __printf(2, 3); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 781 | 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] | 782 | struct tomoyo_acl_param *param, |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 783 | bool (*check_duplicate) |
| 784 | (const struct tomoyo_acl_info *, |
| 785 | const struct tomoyo_acl_info *), |
| 786 | bool (*merge_duplicate) |
| 787 | (struct tomoyo_acl_info *, struct tomoyo_acl_info *, |
| 788 | const bool)); |
Tetsuo Handa | 36f5e1f | 2010-06-15 09:23:26 +0900 | [diff] [blame] | 789 | 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] | 790 | struct tomoyo_acl_param *param, |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 791 | bool (*check_duplicate) |
| 792 | (const struct tomoyo_acl_head *, |
| 793 | const struct tomoyo_acl_head *)); |
| 794 | int tomoyo_write_aggregator(struct tomoyo_acl_param *param); |
| 795 | int tomoyo_write_file(struct tomoyo_acl_param *param); |
| 796 | int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type); |
| 797 | int tomoyo_write_transition_control(struct tomoyo_acl_param *param, |
| 798 | const u8 type); |
| 799 | ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, |
| 800 | const int buffer_len); |
| 801 | ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head, |
| 802 | const char __user *buffer, const int buffer_len); |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 803 | struct tomoyo_condition *tomoyo_get_condition(struct tomoyo_acl_param *param); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 804 | struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, |
| 805 | const bool transit); |
| 806 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); |
| 807 | struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param, |
| 808 | const u8 idx); |
| 809 | struct tomoyo_policy_namespace *tomoyo_assign_namespace |
| 810 | (const char *domainname); |
| 811 | struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns, |
| 812 | const u8 profile); |
| 813 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, |
| 814 | const u8 index); |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 815 | u8 tomoyo_parse_ulong(unsigned long *result, char **str); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 816 | void *tomoyo_commit_ok(void *data, const unsigned int size); |
| 817 | void __init tomoyo_load_builtin_policy(void); |
| 818 | void __init tomoyo_mm_init(void); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 819 | void tomoyo_check_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 820 | bool (*check_entry) (struct tomoyo_request_info *, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 821 | const struct tomoyo_acl_info *)); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 822 | void tomoyo_check_profile(void); |
| 823 | void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp); |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 824 | void tomoyo_del_condition(struct list_head *element); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 825 | void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); |
Tetsuo Handa | 8761afd | 2011-07-08 13:22:41 +0900 | [diff] [blame^] | 826 | void tomoyo_get_attributes(struct tomoyo_obj_info *obj); |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 827 | void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns); |
| 828 | void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) |
| 829 | __printf(2, 3); |
| 830 | void tomoyo_load_policy(const char *filename); |
| 831 | void tomoyo_memory_free(void *ptr); |
| 832 | void tomoyo_normalize_line(unsigned char *buffer); |
| 833 | void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register); |
| 834 | void tomoyo_print_ulong(char *buffer, const int buffer_len, |
| 835 | const unsigned long value, const u8 type); |
| 836 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr); |
| 837 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr); |
| 838 | void tomoyo_read_log(struct tomoyo_io_buffer *head); |
| 839 | void tomoyo_update_stat(const u8 index); |
| 840 | void tomoyo_warn_oom(const char *function); |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 841 | void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...) |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 842 | __printf(2, 3); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 843 | void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt, |
| 844 | va_list args); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 845 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 846 | /********** External variable definitions. **********/ |
| 847 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 848 | extern bool tomoyo_policy_loaded; |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 849 | extern const char * const tomoyo_condition_keyword |
| 850 | [TOMOYO_MAX_CONDITION_KEYWORD]; |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 851 | extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS]; |
| 852 | extern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX |
| 853 | + TOMOYO_MAX_MAC_CATEGORY_INDEX]; |
| 854 | extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE]; |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 855 | extern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; |
| 856 | extern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX]; |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 857 | extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION]; |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 858 | extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION]; |
| 859 | extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION]; |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 860 | extern struct list_head tomoyo_condition_list; |
Tetsuo Handa | 3ddf17f | 2011-06-29 14:22:37 +0900 | [diff] [blame] | 861 | extern struct list_head tomoyo_domain_list; |
| 862 | extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; |
| 863 | extern struct list_head tomoyo_namespace_list; |
| 864 | extern struct mutex tomoyo_policy_lock; |
| 865 | extern struct srcu_struct tomoyo_ss; |
| 866 | extern struct tomoyo_domain_info tomoyo_kernel_domain; |
| 867 | extern struct tomoyo_policy_namespace tomoyo_kernel_namespace; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 868 | extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT]; |
| 869 | extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT]; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 870 | |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 871 | /********** Inlined functions. **********/ |
| 872 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 873 | /** |
| 874 | * tomoyo_read_lock - Take lock for protecting policy. |
| 875 | * |
| 876 | * Returns index number for tomoyo_read_unlock(). |
| 877 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 878 | static inline int tomoyo_read_lock(void) |
| 879 | { |
| 880 | return srcu_read_lock(&tomoyo_ss); |
| 881 | } |
| 882 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 883 | /** |
| 884 | * tomoyo_read_unlock - Release lock for protecting policy. |
| 885 | * |
| 886 | * @idx: Index number returned by tomoyo_read_lock(). |
| 887 | * |
| 888 | * Returns nothing. |
| 889 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 890 | static inline void tomoyo_read_unlock(int idx) |
| 891 | { |
| 892 | srcu_read_unlock(&tomoyo_ss, idx); |
| 893 | } |
| 894 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 895 | /** |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 896 | * tomoyo_sys_getppid - Copy of getppid(). |
| 897 | * |
| 898 | * Returns parent process's PID. |
| 899 | * |
| 900 | * Alpha does not have getppid() defined. To be able to build this module on |
| 901 | * Alpha, I have to copy getppid() from kernel/timer.c. |
| 902 | */ |
| 903 | static inline pid_t tomoyo_sys_getppid(void) |
| 904 | { |
| 905 | pid_t pid; |
| 906 | rcu_read_lock(); |
| 907 | pid = task_tgid_vnr(current->real_parent); |
| 908 | rcu_read_unlock(); |
| 909 | return pid; |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * tomoyo_sys_getpid - Copy of getpid(). |
| 914 | * |
| 915 | * Returns current thread's PID. |
| 916 | * |
| 917 | * Alpha does not have getpid() defined. To be able to build this module on |
| 918 | * Alpha, I have to copy getpid() from kernel/timer.c. |
| 919 | */ |
| 920 | static inline pid_t tomoyo_sys_getpid(void) |
| 921 | { |
| 922 | return task_tgid_vnr(current); |
| 923 | } |
| 924 | |
| 925 | /** |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 926 | * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure. |
| 927 | * |
| 928 | * @a: Pointer to "struct tomoyo_path_info". |
| 929 | * @b: Pointer to "struct tomoyo_path_info". |
| 930 | * |
| 931 | * Returns true if @a == @b, false otherwise. |
| 932 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 933 | static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, |
| 934 | const struct tomoyo_path_info *b) |
| 935 | { |
| 936 | return a->hash != b->hash || strcmp(a->name, b->name); |
| 937 | } |
| 938 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 939 | /** |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 940 | * tomoyo_put_name - Drop reference on "struct tomoyo_name". |
| 941 | * |
| 942 | * @name: Pointer to "struct tomoyo_path_info". Maybe NULL. |
| 943 | * |
| 944 | * Returns nothing. |
| 945 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 946 | static inline void tomoyo_put_name(const struct tomoyo_path_info *name) |
| 947 | { |
| 948 | if (name) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 949 | struct tomoyo_name *ptr = |
| 950 | container_of(name, typeof(*ptr), entry); |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 951 | atomic_dec(&ptr->head.users); |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 952 | } |
| 953 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 954 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 955 | /** |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 956 | * tomoyo_put_condition - Drop reference on "struct tomoyo_condition". |
| 957 | * |
| 958 | * @cond: Pointer to "struct tomoyo_condition". Maybe NULL. |
| 959 | * |
| 960 | * Returns nothing. |
| 961 | */ |
| 962 | static inline void tomoyo_put_condition(struct tomoyo_condition *cond) |
| 963 | { |
| 964 | if (cond) |
| 965 | atomic_dec(&cond->head.users); |
| 966 | } |
| 967 | |
| 968 | /** |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 969 | * tomoyo_put_group - Drop reference on "struct tomoyo_group". |
| 970 | * |
| 971 | * @group: Pointer to "struct tomoyo_group". Maybe NULL. |
| 972 | * |
| 973 | * Returns nothing. |
| 974 | */ |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 975 | static inline void tomoyo_put_group(struct tomoyo_group *group) |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 976 | { |
| 977 | if (group) |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 978 | atomic_dec(&group->head.users); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 979 | } |
| 980 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 981 | /** |
| 982 | * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread. |
| 983 | * |
| 984 | * Returns pointer to "struct tomoyo_domain_info" for current thread. |
| 985 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 986 | static inline struct tomoyo_domain_info *tomoyo_domain(void) |
| 987 | { |
| 988 | return current_cred()->security; |
| 989 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 990 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 991 | /** |
| 992 | * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread. |
| 993 | * |
| 994 | * @task: Pointer to "struct task_struct". |
| 995 | * |
| 996 | * Returns pointer to "struct tomoyo_security" for specified thread. |
| 997 | */ |
Tetsuo Handa | 76bb089 | 2010-02-11 09:42:40 +0900 | [diff] [blame] | 998 | static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct |
| 999 | *task) |
| 1000 | { |
| 1001 | return task_cred_xxx(task, security); |
| 1002 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1003 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1004 | /** |
| 1005 | * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry. |
| 1006 | * |
| 1007 | * @a: Pointer to "struct tomoyo_name_union". |
| 1008 | * @b: Pointer to "struct tomoyo_name_union". |
| 1009 | * |
| 1010 | * Returns true if @a == @b, false otherwise. |
| 1011 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 1012 | static inline bool tomoyo_same_name_union |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1013 | (const struct tomoyo_name_union *a, const struct tomoyo_name_union *b) |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 1014 | { |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 1015 | return a->filename == b->filename && a->group == b->group; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 1016 | } |
| 1017 | |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1018 | /** |
| 1019 | * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry. |
| 1020 | * |
| 1021 | * @a: Pointer to "struct tomoyo_number_union". |
| 1022 | * @b: Pointer to "struct tomoyo_number_union". |
| 1023 | * |
| 1024 | * Returns true if @a == @b, false otherwise. |
| 1025 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 1026 | static inline bool tomoyo_same_number_union |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1027 | (const struct tomoyo_number_union *a, const struct tomoyo_number_union *b) |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 1028 | { |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1029 | 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] | 1030 | a->group == b->group && a->value_type[0] == b->value_type[0] && |
| 1031 | a->value_type[1] == b->value_type[1]; |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 1032 | } |
| 1033 | |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1034 | /** |
| 1035 | * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread. |
| 1036 | * |
| 1037 | * Returns pointer to "struct tomoyo_policy_namespace" for current thread. |
| 1038 | */ |
| 1039 | static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void) |
| 1040 | { |
| 1041 | return tomoyo_domain()->ns; |
| 1042 | } |
| 1043 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1044 | #if defined(CONFIG_SLOB) |
| 1045 | |
| 1046 | /** |
| 1047 | * tomoyo_round2 - Round up to power of 2 for calculating memory usage. |
| 1048 | * |
| 1049 | * @size: Size to be rounded up. |
| 1050 | * |
| 1051 | * Returns @size. |
| 1052 | * |
| 1053 | * Since SLOB does not round up, this function simply returns @size. |
| 1054 | */ |
| 1055 | static inline int tomoyo_round2(size_t size) |
| 1056 | { |
| 1057 | return size; |
| 1058 | } |
| 1059 | |
| 1060 | #else |
| 1061 | |
| 1062 | /** |
| 1063 | * tomoyo_round2 - Round up to power of 2 for calculating memory usage. |
| 1064 | * |
| 1065 | * @size: Size to be rounded up. |
| 1066 | * |
| 1067 | * Returns rounded size. |
| 1068 | * |
| 1069 | * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of |
| 1070 | * (e.g.) 128 bytes. |
| 1071 | */ |
| 1072 | static inline int tomoyo_round2(size_t size) |
| 1073 | { |
| 1074 | #if PAGE_SIZE == 4096 |
| 1075 | size_t bsize = 32; |
| 1076 | #else |
| 1077 | size_t bsize = 64; |
| 1078 | #endif |
| 1079 | if (!size) |
| 1080 | return 0; |
| 1081 | while (size > bsize) |
| 1082 | bsize <<= 1; |
| 1083 | return bsize; |
| 1084 | } |
| 1085 | |
| 1086 | #endif |
| 1087 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1088 | /** |
| 1089 | * list_for_each_cookie - iterate over a list with cookie. |
| 1090 | * @pos: the &struct list_head to use as a loop cursor. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1091 | * @head: the head for your list. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1092 | */ |
Tetsuo Handa | 475e6fa | 2010-06-24 11:28:14 +0900 | [diff] [blame] | 1093 | #define list_for_each_cookie(pos, head) \ |
| 1094 | if (!pos) \ |
| 1095 | pos = srcu_dereference((head)->next, &tomoyo_ss); \ |
| 1096 | for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss)) |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1097 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1098 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ |