Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1 | /* |
| 2 | * security/tomoyo/common.h |
| 3 | * |
| 4 | * Common functions for TOMOYO. |
| 5 | * |
| 6 | * Copyright (C) 2005-2009 NTT DATA CORPORATION |
| 7 | * |
Tetsuo Handa | 39826a1 | 2009-04-08 22:31:28 +0900 | [diff] [blame] | 8 | * Version: 2.2.0 2009/04/01 |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 9 | * |
| 10 | */ |
| 11 | |
| 12 | #ifndef _SECURITY_TOMOYO_COMMON_H |
| 13 | #define _SECURITY_TOMOYO_COMMON_H |
| 14 | |
| 15 | #include <linux/ctype.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/mm.h> |
| 18 | #include <linux/file.h> |
| 19 | #include <linux/kmod.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/namei.h> |
| 23 | #include <linux/mount.h> |
| 24 | #include <linux/list.h> |
| 25 | |
| 26 | struct dentry; |
| 27 | struct vfsmount; |
| 28 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 29 | /* |
| 30 | * tomoyo_page_buffer is a structure which is used for holding a pathname |
| 31 | * obtained from "struct dentry" and "struct vfsmount" pair. |
| 32 | * As of now, it is 4096 bytes. If users complain that 4096 bytes is too small |
| 33 | * (because TOMOYO escapes non ASCII printable characters using \ooo format), |
| 34 | * we will make the buffer larger. |
| 35 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 36 | struct tomoyo_page_buffer { |
| 37 | char buffer[4096]; |
| 38 | }; |
| 39 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 40 | /* |
| 41 | * tomoyo_path_info is a structure which is used for holding a string data |
| 42 | * used by TOMOYO. |
| 43 | * This structure has several fields for supporting pattern matching. |
| 44 | * |
| 45 | * (1) "name" is the '\0' terminated string data. |
| 46 | * (2) "hash" is full_name_hash(name, strlen(name)). |
| 47 | * This allows tomoyo_pathcmp() to compare by hash before actually compare |
| 48 | * using strcmp(). |
| 49 | * (3) "const_len" is the length of the initial segment of "name" which |
| 50 | * consists entirely of non wildcard characters. In other words, the length |
| 51 | * which we can compare two strings using strncmp(). |
| 52 | * (4) "is_dir" is a bool which is true if "name" ends with "/", |
| 53 | * false otherwise. |
| 54 | * TOMOYO distinguishes directory and non-directory. A directory ends with |
| 55 | * "/" and non-directory does not end with "/". |
| 56 | * (5) "is_patterned" is a bool which is true if "name" contains wildcard |
| 57 | * characters, false otherwise. This allows TOMOYO to use "hash" and |
| 58 | * strcmp() for string comparison if "is_patterned" is false. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 59 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 60 | struct tomoyo_path_info { |
| 61 | const char *name; |
| 62 | u32 hash; /* = full_name_hash(name, strlen(name)) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 63 | u16 const_len; /* = tomoyo_const_part_length(name) */ |
| 64 | bool is_dir; /* = tomoyo_strendswith(name, "/") */ |
| 65 | bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * This is the max length of a token. |
| 70 | * |
| 71 | * A token consists of only ASCII printable characters. |
| 72 | * Non printable characters in a token is represented in \ooo style |
| 73 | * octal string. Thus, \ itself is represented as \\. |
| 74 | */ |
| 75 | #define TOMOYO_MAX_PATHNAME_LEN 4000 |
| 76 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 77 | /* |
| 78 | * tomoyo_path_info_with_data is a structure which is used for holding a |
| 79 | * pathname obtained from "struct dentry" and "struct vfsmount" pair. |
| 80 | * |
| 81 | * "struct tomoyo_path_info_with_data" consists of "struct tomoyo_path_info" |
| 82 | * and buffer for the pathname, while "struct tomoyo_page_buffer" consists of |
| 83 | * buffer for the pathname only. |
| 84 | * |
| 85 | * "struct tomoyo_path_info_with_data" is intended to allow TOMOYO to release |
| 86 | * both "struct tomoyo_path_info" and buffer for the pathname by single kfree() |
| 87 | * so that we don't need to return two pointers to the caller. If the caller |
| 88 | * puts "struct tomoyo_path_info" on stack memory, we will be able to remove |
| 89 | * "struct tomoyo_path_info_with_data". |
| 90 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 91 | struct tomoyo_path_info_with_data { |
Tetsuo Handa | 8e2d39a | 2010-01-26 20:45:27 +0900 | [diff] [blame] | 92 | /* Keep "head" first, for this pointer is passed to kfree(). */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 93 | struct tomoyo_path_info head; |
Tetsuo Handa | a106cbf | 2009-03-27 13:12:16 +0900 | [diff] [blame] | 94 | char barrier1[16]; /* Safeguard for overrun. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 95 | char body[TOMOYO_MAX_PATHNAME_LEN]; |
| 96 | char barrier2[16]; /* Safeguard for overrun. */ |
| 97 | }; |
| 98 | |
| 99 | /* |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 100 | * tomoyo_acl_info is a structure which is used for holding |
| 101 | * |
| 102 | * (1) "list" which is linked to the ->acl_info_list of |
| 103 | * "struct tomoyo_domain_info" |
Tetsuo Handa | ea13ddb | 2010-02-03 06:43:06 +0900 | [diff] [blame^] | 104 | * (2) "type" which tells type of the entry (either |
| 105 | * "struct tomoyo_single_path_acl_record" or |
| 106 | * "struct tomoyo_double_path_acl_record"). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 107 | * |
| 108 | * Packing "struct tomoyo_acl_info" allows |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 109 | * "struct tomoyo_single_path_acl_record" to embed "u8" + "u16" and |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 110 | * "struct tomoyo_double_path_acl_record" to embed "u8" |
| 111 | * without enlarging their structure size. |
| 112 | */ |
| 113 | struct tomoyo_acl_info { |
| 114 | struct list_head list; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 115 | u8 type; |
| 116 | } __packed; |
| 117 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 118 | /* |
| 119 | * tomoyo_domain_info is a structure which is used for holding permissions |
| 120 | * (e.g. "allow_read /lib/libc-2.5.so") given to each domain. |
| 121 | * It has following fields. |
| 122 | * |
| 123 | * (1) "list" which is linked to tomoyo_domain_list . |
| 124 | * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info". |
| 125 | * (3) "domainname" which holds the name of the domain. |
| 126 | * (4) "profile" which remembers profile number assigned to this domain. |
| 127 | * (5) "is_deleted" is a bool which is true if this domain is marked as |
| 128 | * "deleted", false otherwise. |
| 129 | * (6) "quota_warned" is a bool which is used for suppressing warning message |
| 130 | * when learning mode learned too much entries. |
Tetsuo Handa | ea13ddb | 2010-02-03 06:43:06 +0900 | [diff] [blame^] | 131 | * (7) "ignore_global_allow_read" is a bool which is true if this domain |
| 132 | * should ignore "allow_read" directive in exception policy. |
| 133 | * (8) "transition_failed" is a bool which is set to true when this domain was |
| 134 | * unable to create a new domain at tomoyo_find_next_domain() because the |
| 135 | * name of the domain to be created was too long or it could not allocate |
| 136 | * memory. If set to true, more than one process continued execve() |
| 137 | * without domain transition. |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 138 | * |
| 139 | * A domain's lifecycle is an analogy of files on / directory. |
| 140 | * Multiple domains with the same domainname cannot be created (as with |
| 141 | * creating files with the same filename fails with -EEXIST). |
| 142 | * If a process reached a domain, that process can reside in that domain after |
| 143 | * that domain is marked as "deleted" (as with a process can access an already |
| 144 | * open()ed file after that file was unlink()ed). |
| 145 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 146 | struct tomoyo_domain_info { |
| 147 | struct list_head list; |
| 148 | struct list_head acl_info_list; |
| 149 | /* Name of this domain. Never NULL. */ |
| 150 | const struct tomoyo_path_info *domainname; |
| 151 | u8 profile; /* Profile number to use. */ |
Tetsuo Handa | a0558fc | 2009-04-06 20:49:14 +0900 | [diff] [blame] | 152 | bool is_deleted; /* Delete flag. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 153 | bool quota_warned; /* Quota warnning flag. */ |
Tetsuo Handa | ea13ddb | 2010-02-03 06:43:06 +0900 | [diff] [blame^] | 154 | bool ignore_global_allow_read; /* Ignore "allow_read" flag. */ |
| 155 | bool transition_failed; /* Domain transition failed flag. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | /* Profile number is an integer between 0 and 255. */ |
| 159 | #define TOMOYO_MAX_PROFILES 256 |
| 160 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 161 | /* |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 162 | * tomoyo_single_path_acl_record is a structure which is used for holding an |
| 163 | * entry with one pathname operation (e.g. open(), mkdir()). |
| 164 | * It has following fields. |
| 165 | * |
| 166 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 167 | * (2) "perm" which is a bitmask of permitted operations. |
| 168 | * (3) "filename" is the pathname. |
| 169 | * |
| 170 | * Directives held by this structure are "allow_read/write", "allow_execute", |
| 171 | * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir", |
| 172 | * "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock", |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 173 | * "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite", |
| 174 | * "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot", "allow_mount" |
| 175 | * and "allow_unmount". |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 176 | */ |
| 177 | struct tomoyo_single_path_acl_record { |
| 178 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_SINGLE_PATH_ACL */ |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 179 | u8 perm_high; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 180 | u16 perm; |
| 181 | /* Pointer to single pathname. */ |
| 182 | const struct tomoyo_path_info *filename; |
| 183 | }; |
| 184 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 185 | /* |
| 186 | * tomoyo_double_path_acl_record is a structure which is used for holding an |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 187 | * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 188 | * It has following fields. |
| 189 | * |
| 190 | * (1) "head" which is a "struct tomoyo_acl_info". |
| 191 | * (2) "perm" which is a bitmask of permitted operations. |
| 192 | * (3) "filename1" is the source/old pathname. |
| 193 | * (4) "filename2" is the destination/new pathname. |
| 194 | * |
Tetsuo Handa | 937bf61 | 2009-12-02 21:09:48 +0900 | [diff] [blame] | 195 | * Directives held by this structure are "allow_rename", "allow_link" and |
| 196 | * "allow_pivot_root". |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 197 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 198 | struct tomoyo_double_path_acl_record { |
| 199 | struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_DOUBLE_PATH_ACL */ |
| 200 | u8 perm; |
| 201 | /* Pointer to single pathname. */ |
| 202 | const struct tomoyo_path_info *filename1; |
| 203 | /* Pointer to single pathname. */ |
| 204 | const struct tomoyo_path_info *filename2; |
| 205 | }; |
| 206 | |
| 207 | /* Keywords for ACLs. */ |
| 208 | #define TOMOYO_KEYWORD_ALIAS "alias " |
| 209 | #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " |
| 210 | #define TOMOYO_KEYWORD_DELETE "delete " |
| 211 | #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " |
| 212 | #define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern " |
| 213 | #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " |
| 214 | #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " |
| 215 | #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " |
| 216 | #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " |
| 217 | #define TOMOYO_KEYWORD_SELECT "select " |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 218 | #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " |
| 219 | #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" |
| 220 | /* A domain definition starts with <kernel>. */ |
| 221 | #define TOMOYO_ROOT_NAME "<kernel>" |
| 222 | #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) |
| 223 | |
| 224 | /* Index numbers for Access Controls. */ |
| 225 | #define TOMOYO_MAC_FOR_FILE 0 /* domain_policy.conf */ |
| 226 | #define TOMOYO_MAX_ACCEPT_ENTRY 1 |
| 227 | #define TOMOYO_VERBOSE 2 |
| 228 | #define TOMOYO_MAX_CONTROL_INDEX 3 |
| 229 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 230 | /* |
| 231 | * tomoyo_io_buffer is a structure which is used for reading and modifying |
| 232 | * configuration via /sys/kernel/security/tomoyo/ interface. |
| 233 | * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as |
| 234 | * cursors. |
| 235 | * |
| 236 | * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of |
| 237 | * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info" |
| 238 | * entry has a list of "struct tomoyo_acl_info", we need two cursors when |
| 239 | * reading (one is for traversing tomoyo_domain_list and the other is for |
| 240 | * traversing "struct tomoyo_acl_info"->acl_info_list ). |
| 241 | * |
| 242 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with |
| 243 | * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the |
| 244 | * domain with the domainname specified by the rest of that line (NULL is set |
| 245 | * if seek failed). |
| 246 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with |
| 247 | * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that |
| 248 | * line (->write_var1 is set to NULL if a domain was deleted). |
| 249 | * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with |
| 250 | * neither "select " nor "delete ", an entry or a domain specified by that line |
| 251 | * is appended. |
| 252 | */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 253 | struct tomoyo_io_buffer { |
| 254 | int (*read) (struct tomoyo_io_buffer *); |
| 255 | int (*write) (struct tomoyo_io_buffer *); |
| 256 | /* Exclusive lock for this structure. */ |
| 257 | struct mutex io_sem; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 258 | /* Index returned by tomoyo_read_lock(). */ |
| 259 | int reader_idx; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 260 | /* The position currently reading from. */ |
| 261 | struct list_head *read_var1; |
| 262 | /* Extra variables for reading. */ |
| 263 | struct list_head *read_var2; |
| 264 | /* The position currently writing to. */ |
| 265 | struct tomoyo_domain_info *write_var1; |
| 266 | /* The step for reading. */ |
| 267 | int read_step; |
| 268 | /* Buffer for reading. */ |
| 269 | char *read_buf; |
| 270 | /* EOF flag for reading. */ |
| 271 | bool read_eof; |
| 272 | /* Read domain ACL of specified PID? */ |
| 273 | bool read_single_domain; |
| 274 | /* Extra variable for reading. */ |
| 275 | u8 read_bit; |
| 276 | /* Bytes available for reading. */ |
| 277 | int read_avail; |
| 278 | /* Size of read buffer. */ |
| 279 | int readbuf_size; |
| 280 | /* Buffer for writing. */ |
| 281 | char *write_buf; |
| 282 | /* Bytes available for writing. */ |
| 283 | int write_avail; |
| 284 | /* Size of write buffer. */ |
| 285 | int writebuf_size; |
| 286 | }; |
| 287 | |
| 288 | /* Check whether the domain has too many ACL entries to hold. */ |
| 289 | bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain); |
| 290 | /* Transactional sprintf() for policy dump. */ |
| 291 | bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) |
| 292 | __attribute__ ((format(printf, 2, 3))); |
| 293 | /* Check whether the domainname is correct. */ |
| 294 | bool tomoyo_is_correct_domain(const unsigned char *domainname, |
| 295 | const char *function); |
| 296 | /* Check whether the token is correct. */ |
| 297 | bool tomoyo_is_correct_path(const char *filename, const s8 start_type, |
| 298 | const s8 pattern_type, const s8 end_type, |
| 299 | const char *function); |
| 300 | /* Check whether the token can be a domainname. */ |
| 301 | bool tomoyo_is_domain_def(const unsigned char *buffer); |
| 302 | /* Check whether the given filename matches the given pattern. */ |
| 303 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, |
| 304 | const struct tomoyo_path_info *pattern); |
| 305 | /* Read "alias" entry in exception policy. */ |
| 306 | bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head); |
| 307 | /* |
| 308 | * Read "initialize_domain" and "no_initialize_domain" entry |
| 309 | * in exception policy. |
| 310 | */ |
| 311 | bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head); |
| 312 | /* Read "keep_domain" and "no_keep_domain" entry in exception policy. */ |
| 313 | bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head); |
| 314 | /* Read "file_pattern" entry in exception policy. */ |
| 315 | bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head); |
| 316 | /* Read "allow_read" entry in exception policy. */ |
| 317 | bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head); |
| 318 | /* Read "deny_rewrite" entry in exception policy. */ |
| 319 | bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head); |
| 320 | /* Write domain policy violation warning message to console? */ |
| 321 | bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); |
| 322 | /* Convert double path operation to operation name. */ |
| 323 | const char *tomoyo_dp2keyword(const u8 operation); |
| 324 | /* Get the last component of the given domainname. */ |
| 325 | const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); |
| 326 | /* Get warning message. */ |
| 327 | const char *tomoyo_get_msg(const bool is_enforce); |
| 328 | /* Convert single path operation to operation name. */ |
| 329 | const char *tomoyo_sp2keyword(const u8 operation); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 330 | /* Create "alias" entry in exception policy. */ |
| 331 | int tomoyo_write_alias_policy(char *data, const bool is_delete); |
| 332 | /* |
| 333 | * Create "initialize_domain" and "no_initialize_domain" entry |
| 334 | * in exception policy. |
| 335 | */ |
| 336 | int tomoyo_write_domain_initializer_policy(char *data, const bool is_not, |
| 337 | const bool is_delete); |
| 338 | /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */ |
| 339 | int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, |
| 340 | const bool is_delete); |
| 341 | /* |
| 342 | * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", |
| 343 | * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", |
| 344 | * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", |
| 345 | * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and |
| 346 | * "allow_link" entry in domain policy. |
| 347 | */ |
| 348 | int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, |
| 349 | const bool is_delete); |
| 350 | /* Create "allow_read" entry in exception policy. */ |
| 351 | int tomoyo_write_globally_readable_policy(char *data, const bool is_delete); |
| 352 | /* Create "deny_rewrite" entry in exception policy. */ |
| 353 | int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); |
| 354 | /* Create "file_pattern" entry in exception policy. */ |
| 355 | int tomoyo_write_pattern_policy(char *data, const bool is_delete); |
| 356 | /* Find a domain by the given name. */ |
| 357 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); |
| 358 | /* Find or create a domain by the given name. */ |
| 359 | struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * |
| 360 | domainname, |
| 361 | const u8 profile); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 362 | /* Check mode for specified functionality. */ |
| 363 | unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, |
| 364 | const u8 index); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 365 | /* Fill in "struct tomoyo_path_info" members. */ |
| 366 | void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); |
| 367 | /* Run policy loader when /sbin/init starts. */ |
| 368 | void tomoyo_load_policy(const char *filename); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 369 | |
| 370 | /* strcmp() for "struct tomoyo_path_info" structure. */ |
| 371 | static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, |
| 372 | const struct tomoyo_path_info *b) |
| 373 | { |
| 374 | return a->hash != b->hash || strcmp(a->name, b->name); |
| 375 | } |
| 376 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 377 | /** |
| 378 | * tomoyo_is_valid - Check whether the character is a valid char. |
| 379 | * |
| 380 | * @c: The character to check. |
| 381 | * |
| 382 | * Returns true if @c is a valid character, false otherwise. |
| 383 | */ |
| 384 | static inline bool tomoyo_is_valid(const unsigned char c) |
| 385 | { |
| 386 | return c > ' ' && c < 127; |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * tomoyo_is_invalid - Check whether the character is an invalid char. |
| 391 | * |
| 392 | * @c: The character to check. |
| 393 | * |
| 394 | * Returns true if @c is an invalid character, false otherwise. |
| 395 | */ |
| 396 | static inline bool tomoyo_is_invalid(const unsigned char c) |
| 397 | { |
| 398 | return c && (c <= ' ' || c >= 127); |
| 399 | } |
| 400 | |
| 401 | /* The list for "struct tomoyo_domain_info". */ |
| 402 | extern struct list_head tomoyo_domain_list; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 403 | |
Tetsuo Handa | f737d95 | 2010-01-03 21:16:32 +0900 | [diff] [blame] | 404 | /* Lock for protecting policy. */ |
| 405 | extern struct mutex tomoyo_policy_lock; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 406 | |
| 407 | /* Has /sbin/init started? */ |
| 408 | extern bool tomoyo_policy_loaded; |
| 409 | |
| 410 | /* The kernel's domain. */ |
| 411 | extern struct tomoyo_domain_info tomoyo_kernel_domain; |
| 412 | |
| 413 | /** |
| 414 | * list_for_each_cookie - iterate over a list with cookie. |
| 415 | * @pos: the &struct list_head to use as a loop cursor. |
| 416 | * @cookie: the &struct list_head to use as a cookie. |
| 417 | * @head: the head for your list. |
| 418 | * |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 419 | * Same with list_for_each_rcu() except that this primitive uses @cookie |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 420 | * so that we can continue iteration. |
| 421 | * @cookie must be NULL when iteration starts, and @cookie will become |
| 422 | * NULL when iteration finishes. |
| 423 | */ |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 424 | #define list_for_each_cookie(pos, cookie, head) \ |
| 425 | for (({ if (!cookie) \ |
| 426 | cookie = head; }), \ |
| 427 | pos = rcu_dereference((cookie)->next); \ |
| 428 | prefetch(pos->next), pos != (head) || ((cookie) = NULL); \ |
| 429 | (cookie) = pos, pos = rcu_dereference(pos->next)) |
| 430 | |
| 431 | extern struct srcu_struct tomoyo_ss; |
| 432 | |
| 433 | static inline int tomoyo_read_lock(void) |
| 434 | { |
| 435 | return srcu_read_lock(&tomoyo_ss); |
| 436 | } |
| 437 | |
| 438 | static inline void tomoyo_read_unlock(int idx) |
| 439 | { |
| 440 | srcu_read_unlock(&tomoyo_ss, idx); |
| 441 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 442 | |
| 443 | #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ |