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