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