19590837bSKentaro Takeda /* 29590837bSKentaro Takeda * security/tomoyo/common.h 39590837bSKentaro Takeda * 476bb0895STetsuo Handa * Header file for TOMOYO. 59590837bSKentaro Takeda * 676bb0895STetsuo Handa * Copyright (C) 2005-2010 NTT DATA CORPORATION 79590837bSKentaro Takeda */ 89590837bSKentaro Takeda 99590837bSKentaro Takeda #ifndef _SECURITY_TOMOYO_COMMON_H 109590837bSKentaro Takeda #define _SECURITY_TOMOYO_COMMON_H 119590837bSKentaro Takeda 129590837bSKentaro Takeda #include <linux/ctype.h> 139590837bSKentaro Takeda #include <linux/string.h> 149590837bSKentaro Takeda #include <linux/mm.h> 159590837bSKentaro Takeda #include <linux/file.h> 169590837bSKentaro Takeda #include <linux/kmod.h> 179590837bSKentaro Takeda #include <linux/fs.h> 189590837bSKentaro Takeda #include <linux/sched.h> 199590837bSKentaro Takeda #include <linux/namei.h> 209590837bSKentaro Takeda #include <linux/mount.h> 219590837bSKentaro Takeda #include <linux/list.h> 2276bb0895STetsuo Handa #include <linux/cred.h> 2376bb0895STetsuo Handa struct linux_binprm; 249590837bSKentaro Takeda 2576bb0895STetsuo Handa /********** Constants definitions. **********/ 2676bb0895STetsuo Handa 2776bb0895STetsuo Handa /* 2876bb0895STetsuo Handa * TOMOYO uses this hash only when appending a string into the string 2976bb0895STetsuo Handa * table. Frequency of appending strings is very low. So we don't need 3076bb0895STetsuo Handa * large (e.g. 64k) hash size. 256 will be sufficient. 3176bb0895STetsuo Handa */ 3276bb0895STetsuo Handa #define TOMOYO_HASH_BITS 8 3376bb0895STetsuo Handa #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) 3476bb0895STetsuo Handa 3576bb0895STetsuo Handa /* 3676bb0895STetsuo Handa * This is the max length of a token. 3776bb0895STetsuo Handa * 3876bb0895STetsuo Handa * A token consists of only ASCII printable characters. 3976bb0895STetsuo Handa * Non printable characters in a token is represented in \ooo style 4076bb0895STetsuo Handa * octal string. Thus, \ itself is represented as \\. 4176bb0895STetsuo Handa */ 4276bb0895STetsuo Handa #define TOMOYO_MAX_PATHNAME_LEN 4000 4376bb0895STetsuo Handa 4476bb0895STetsuo Handa /* Profile number is an integer between 0 and 255. */ 4576bb0895STetsuo Handa #define TOMOYO_MAX_PROFILES 256 4676bb0895STetsuo Handa 4776bb0895STetsuo Handa /* Keywords for ACLs. */ 4876bb0895STetsuo Handa #define TOMOYO_KEYWORD_ALIAS "alias " 4976bb0895STetsuo Handa #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " 5076bb0895STetsuo Handa #define TOMOYO_KEYWORD_DELETE "delete " 5176bb0895STetsuo Handa #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " 5276bb0895STetsuo Handa #define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern " 5376bb0895STetsuo Handa #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " 5476bb0895STetsuo Handa #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " 5576bb0895STetsuo Handa #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " 5676bb0895STetsuo Handa #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " 5776bb0895STetsuo Handa #define TOMOYO_KEYWORD_SELECT "select " 5876bb0895STetsuo Handa #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " 5976bb0895STetsuo Handa #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" 6076bb0895STetsuo Handa /* A domain definition starts with <kernel>. */ 6176bb0895STetsuo Handa #define TOMOYO_ROOT_NAME "<kernel>" 6276bb0895STetsuo Handa #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) 6376bb0895STetsuo Handa 6476bb0895STetsuo Handa /* Index numbers for Access Controls. */ 65084da356STetsuo Handa enum tomoyo_mac_index { 66084da356STetsuo Handa TOMOYO_MAC_FOR_FILE, /* domain_policy.conf */ 67084da356STetsuo Handa TOMOYO_MAX_ACCEPT_ENTRY, 68084da356STetsuo Handa TOMOYO_VERBOSE, 69084da356STetsuo Handa TOMOYO_MAX_CONTROL_INDEX 70084da356STetsuo Handa }; 7176bb0895STetsuo Handa 7276bb0895STetsuo Handa /* Index numbers for Access Controls. */ 73084da356STetsuo Handa enum tomoyo_acl_entry_type_index { 747ef61233STetsuo Handa TOMOYO_TYPE_PATH_ACL, 757ef61233STetsuo Handa TOMOYO_TYPE_PATH2_ACL, 76084da356STetsuo Handa }; 7776bb0895STetsuo Handa 7876bb0895STetsuo Handa /* Index numbers for File Controls. */ 7976bb0895STetsuo Handa 8076bb0895STetsuo Handa /* 8176bb0895STetsuo Handa * TYPE_READ_WRITE_ACL is special. TYPE_READ_WRITE_ACL is automatically set 8276bb0895STetsuo Handa * if both TYPE_READ_ACL and TYPE_WRITE_ACL are set. Both TYPE_READ_ACL and 8376bb0895STetsuo Handa * TYPE_WRITE_ACL are automatically set if TYPE_READ_WRITE_ACL is set. 8476bb0895STetsuo Handa * TYPE_READ_WRITE_ACL is automatically cleared if either TYPE_READ_ACL or 8576bb0895STetsuo Handa * TYPE_WRITE_ACL is cleared. Both TYPE_READ_ACL and TYPE_WRITE_ACL are 8676bb0895STetsuo Handa * automatically cleared if TYPE_READ_WRITE_ACL is cleared. 8776bb0895STetsuo Handa */ 8876bb0895STetsuo Handa 89084da356STetsuo Handa enum tomoyo_path_acl_index { 907ef61233STetsuo Handa TOMOYO_TYPE_READ_WRITE, 917ef61233STetsuo Handa TOMOYO_TYPE_EXECUTE, 927ef61233STetsuo Handa TOMOYO_TYPE_READ, 937ef61233STetsuo Handa TOMOYO_TYPE_WRITE, 947ef61233STetsuo Handa TOMOYO_TYPE_CREATE, 957ef61233STetsuo Handa TOMOYO_TYPE_UNLINK, 967ef61233STetsuo Handa TOMOYO_TYPE_MKDIR, 977ef61233STetsuo Handa TOMOYO_TYPE_RMDIR, 987ef61233STetsuo Handa TOMOYO_TYPE_MKFIFO, 997ef61233STetsuo Handa TOMOYO_TYPE_MKSOCK, 1007ef61233STetsuo Handa TOMOYO_TYPE_MKBLOCK, 1017ef61233STetsuo Handa TOMOYO_TYPE_MKCHAR, 1027ef61233STetsuo Handa TOMOYO_TYPE_TRUNCATE, 1037ef61233STetsuo Handa TOMOYO_TYPE_SYMLINK, 1047ef61233STetsuo Handa TOMOYO_TYPE_REWRITE, 1057ef61233STetsuo Handa TOMOYO_TYPE_IOCTL, 1067ef61233STetsuo Handa TOMOYO_TYPE_CHMOD, 1077ef61233STetsuo Handa TOMOYO_TYPE_CHOWN, 1087ef61233STetsuo Handa TOMOYO_TYPE_CHGRP, 1097ef61233STetsuo Handa TOMOYO_TYPE_CHROOT, 1107ef61233STetsuo Handa TOMOYO_TYPE_MOUNT, 1117ef61233STetsuo Handa TOMOYO_TYPE_UMOUNT, 1127ef61233STetsuo Handa TOMOYO_MAX_PATH_OPERATION 113084da356STetsuo Handa }; 11476bb0895STetsuo Handa 115084da356STetsuo Handa enum tomoyo_path2_acl_index { 1167ef61233STetsuo Handa TOMOYO_TYPE_LINK, 1177ef61233STetsuo Handa TOMOYO_TYPE_RENAME, 1187ef61233STetsuo Handa TOMOYO_TYPE_PIVOT_ROOT, 1197ef61233STetsuo Handa TOMOYO_MAX_PATH2_OPERATION 120084da356STetsuo Handa }; 12176bb0895STetsuo Handa 122084da356STetsuo Handa enum tomoyo_securityfs_interface_index { 123084da356STetsuo Handa TOMOYO_DOMAINPOLICY, 124084da356STetsuo Handa TOMOYO_EXCEPTIONPOLICY, 125084da356STetsuo Handa TOMOYO_DOMAIN_STATUS, 126084da356STetsuo Handa TOMOYO_PROCESS_STATUS, 127084da356STetsuo Handa TOMOYO_MEMINFO, 128084da356STetsuo Handa TOMOYO_SELFDOMAIN, 129084da356STetsuo Handa TOMOYO_VERSION, 130084da356STetsuo Handa TOMOYO_PROFILE, 131084da356STetsuo Handa TOMOYO_MANAGER 132084da356STetsuo Handa }; 13376bb0895STetsuo Handa 13476bb0895STetsuo Handa /********** Structure definitions. **********/ 1359590837bSKentaro Takeda 136c3fa109aSTetsuo Handa /* 137c3fa109aSTetsuo Handa * tomoyo_page_buffer is a structure which is used for holding a pathname 138c3fa109aSTetsuo Handa * obtained from "struct dentry" and "struct vfsmount" pair. 139c3fa109aSTetsuo Handa * As of now, it is 4096 bytes. If users complain that 4096 bytes is too small 140c3fa109aSTetsuo Handa * (because TOMOYO escapes non ASCII printable characters using \ooo format), 141c3fa109aSTetsuo Handa * we will make the buffer larger. 142c3fa109aSTetsuo Handa */ 1439590837bSKentaro Takeda struct tomoyo_page_buffer { 1449590837bSKentaro Takeda char buffer[4096]; 1459590837bSKentaro Takeda }; 1469590837bSKentaro Takeda 147c3fa109aSTetsuo Handa /* 148c3fa109aSTetsuo Handa * tomoyo_path_info is a structure which is used for holding a string data 149c3fa109aSTetsuo Handa * used by TOMOYO. 150c3fa109aSTetsuo Handa * This structure has several fields for supporting pattern matching. 151c3fa109aSTetsuo Handa * 152c3fa109aSTetsuo Handa * (1) "name" is the '\0' terminated string data. 153c3fa109aSTetsuo Handa * (2) "hash" is full_name_hash(name, strlen(name)). 154c3fa109aSTetsuo Handa * This allows tomoyo_pathcmp() to compare by hash before actually compare 155c3fa109aSTetsuo Handa * using strcmp(). 156c3fa109aSTetsuo Handa * (3) "const_len" is the length of the initial segment of "name" which 157c3fa109aSTetsuo Handa * consists entirely of non wildcard characters. In other words, the length 158c3fa109aSTetsuo Handa * which we can compare two strings using strncmp(). 159c3fa109aSTetsuo Handa * (4) "is_dir" is a bool which is true if "name" ends with "/", 160c3fa109aSTetsuo Handa * false otherwise. 161c3fa109aSTetsuo Handa * TOMOYO distinguishes directory and non-directory. A directory ends with 162c3fa109aSTetsuo Handa * "/" and non-directory does not end with "/". 163c3fa109aSTetsuo Handa * (5) "is_patterned" is a bool which is true if "name" contains wildcard 164c3fa109aSTetsuo Handa * characters, false otherwise. This allows TOMOYO to use "hash" and 165c3fa109aSTetsuo Handa * strcmp() for string comparison if "is_patterned" is false. 166c3fa109aSTetsuo Handa */ 1679590837bSKentaro Takeda struct tomoyo_path_info { 1689590837bSKentaro Takeda const char *name; 1699590837bSKentaro Takeda u32 hash; /* = full_name_hash(name, strlen(name)) */ 1709590837bSKentaro Takeda u16 const_len; /* = tomoyo_const_part_length(name) */ 1719590837bSKentaro Takeda bool is_dir; /* = tomoyo_strendswith(name, "/") */ 1729590837bSKentaro Takeda bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 1739590837bSKentaro Takeda }; 1749590837bSKentaro Takeda 1759590837bSKentaro Takeda /* 17676bb0895STetsuo Handa * tomoyo_name_entry is a structure which is used for linking 17776bb0895STetsuo Handa * "struct tomoyo_path_info" into tomoyo_name_list . 1789590837bSKentaro Takeda */ 17976bb0895STetsuo Handa struct tomoyo_name_entry { 18076bb0895STetsuo Handa struct list_head list; 18176bb0895STetsuo Handa atomic_t users; 18276bb0895STetsuo Handa struct tomoyo_path_info entry; 18376bb0895STetsuo Handa }; 1849590837bSKentaro Takeda 185c3fa109aSTetsuo Handa /* 186c3fa109aSTetsuo Handa * tomoyo_path_info_with_data is a structure which is used for holding a 187c3fa109aSTetsuo Handa * pathname obtained from "struct dentry" and "struct vfsmount" pair. 188c3fa109aSTetsuo Handa * 189c3fa109aSTetsuo Handa * "struct tomoyo_path_info_with_data" consists of "struct tomoyo_path_info" 190c3fa109aSTetsuo Handa * and buffer for the pathname, while "struct tomoyo_page_buffer" consists of 191c3fa109aSTetsuo Handa * buffer for the pathname only. 192c3fa109aSTetsuo Handa * 193c3fa109aSTetsuo Handa * "struct tomoyo_path_info_with_data" is intended to allow TOMOYO to release 194c3fa109aSTetsuo Handa * both "struct tomoyo_path_info" and buffer for the pathname by single kfree() 195c3fa109aSTetsuo Handa * so that we don't need to return two pointers to the caller. If the caller 196c3fa109aSTetsuo Handa * puts "struct tomoyo_path_info" on stack memory, we will be able to remove 197c3fa109aSTetsuo Handa * "struct tomoyo_path_info_with_data". 198c3fa109aSTetsuo Handa */ 1999590837bSKentaro Takeda struct tomoyo_path_info_with_data { 2008e2d39a1STetsuo Handa /* Keep "head" first, for this pointer is passed to kfree(). */ 2019590837bSKentaro Takeda struct tomoyo_path_info head; 202a106cbfdSTetsuo Handa char barrier1[16]; /* Safeguard for overrun. */ 2039590837bSKentaro Takeda char body[TOMOYO_MAX_PATHNAME_LEN]; 2049590837bSKentaro Takeda char barrier2[16]; /* Safeguard for overrun. */ 2059590837bSKentaro Takeda }; 2069590837bSKentaro Takeda 2079590837bSKentaro Takeda /* 208c3fa109aSTetsuo Handa * tomoyo_acl_info is a structure which is used for holding 209c3fa109aSTetsuo Handa * 210c3fa109aSTetsuo Handa * (1) "list" which is linked to the ->acl_info_list of 211c3fa109aSTetsuo Handa * "struct tomoyo_domain_info" 212ea13ddbaSTetsuo Handa * (2) "type" which tells type of the entry (either 2137ef61233STetsuo Handa * "struct tomoyo_path_acl" or "struct tomoyo_path2_acl"). 2149590837bSKentaro Takeda * 2159590837bSKentaro Takeda * Packing "struct tomoyo_acl_info" allows 2167ef61233STetsuo Handa * "struct tomoyo_path_acl" to embed "u8" + "u16" and 2177ef61233STetsuo Handa * "struct tomoyo_path2_acl" to embed "u8" 2189590837bSKentaro Takeda * without enlarging their structure size. 2199590837bSKentaro Takeda */ 2209590837bSKentaro Takeda struct tomoyo_acl_info { 2219590837bSKentaro Takeda struct list_head list; 2229590837bSKentaro Takeda u8 type; 2239590837bSKentaro Takeda } __packed; 2249590837bSKentaro Takeda 225c3fa109aSTetsuo Handa /* 226c3fa109aSTetsuo Handa * tomoyo_domain_info is a structure which is used for holding permissions 227c3fa109aSTetsuo Handa * (e.g. "allow_read /lib/libc-2.5.so") given to each domain. 228c3fa109aSTetsuo Handa * It has following fields. 229c3fa109aSTetsuo Handa * 230c3fa109aSTetsuo Handa * (1) "list" which is linked to tomoyo_domain_list . 231c3fa109aSTetsuo Handa * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info". 232c3fa109aSTetsuo Handa * (3) "domainname" which holds the name of the domain. 233c3fa109aSTetsuo Handa * (4) "profile" which remembers profile number assigned to this domain. 234c3fa109aSTetsuo Handa * (5) "is_deleted" is a bool which is true if this domain is marked as 235c3fa109aSTetsuo Handa * "deleted", false otherwise. 236c3fa109aSTetsuo Handa * (6) "quota_warned" is a bool which is used for suppressing warning message 237c3fa109aSTetsuo Handa * when learning mode learned too much entries. 238ea13ddbaSTetsuo Handa * (7) "ignore_global_allow_read" is a bool which is true if this domain 239ea13ddbaSTetsuo Handa * should ignore "allow_read" directive in exception policy. 240ea13ddbaSTetsuo Handa * (8) "transition_failed" is a bool which is set to true when this domain was 241ea13ddbaSTetsuo Handa * unable to create a new domain at tomoyo_find_next_domain() because the 242ea13ddbaSTetsuo Handa * name of the domain to be created was too long or it could not allocate 243ea13ddbaSTetsuo Handa * memory. If set to true, more than one process continued execve() 244ea13ddbaSTetsuo Handa * without domain transition. 245ec8e6a4eSTetsuo Handa * (9) "users" is an atomic_t that holds how many "struct cred"->security 246ec8e6a4eSTetsuo Handa * are referring this "struct tomoyo_domain_info". If is_deleted == true 247ec8e6a4eSTetsuo Handa * and users == 0, this struct will be kfree()d upon next garbage 248ec8e6a4eSTetsuo Handa * collection. 249c3fa109aSTetsuo Handa * 250c3fa109aSTetsuo Handa * A domain's lifecycle is an analogy of files on / directory. 251c3fa109aSTetsuo Handa * Multiple domains with the same domainname cannot be created (as with 252c3fa109aSTetsuo Handa * creating files with the same filename fails with -EEXIST). 253c3fa109aSTetsuo Handa * If a process reached a domain, that process can reside in that domain after 254c3fa109aSTetsuo Handa * that domain is marked as "deleted" (as with a process can access an already 255c3fa109aSTetsuo Handa * open()ed file after that file was unlink()ed). 256c3fa109aSTetsuo Handa */ 2579590837bSKentaro Takeda struct tomoyo_domain_info { 2589590837bSKentaro Takeda struct list_head list; 2599590837bSKentaro Takeda struct list_head acl_info_list; 2609590837bSKentaro Takeda /* Name of this domain. Never NULL. */ 2619590837bSKentaro Takeda const struct tomoyo_path_info *domainname; 2629590837bSKentaro Takeda u8 profile; /* Profile number to use. */ 263a0558fc3STetsuo Handa bool is_deleted; /* Delete flag. */ 2649590837bSKentaro Takeda bool quota_warned; /* Quota warnning flag. */ 265ea13ddbaSTetsuo Handa bool ignore_global_allow_read; /* Ignore "allow_read" flag. */ 266ea13ddbaSTetsuo Handa bool transition_failed; /* Domain transition failed flag. */ 267ec8e6a4eSTetsuo Handa atomic_t users; /* Number of referring credentials. */ 2689590837bSKentaro Takeda }; 2699590837bSKentaro Takeda 2709590837bSKentaro Takeda /* 2717ef61233STetsuo Handa * tomoyo_path_acl is a structure which is used for holding an 272c3fa109aSTetsuo Handa * entry with one pathname operation (e.g. open(), mkdir()). 273c3fa109aSTetsuo Handa * It has following fields. 274c3fa109aSTetsuo Handa * 275c3fa109aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 276c3fa109aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 277c3fa109aSTetsuo Handa * (3) "filename" is the pathname. 278c3fa109aSTetsuo Handa * 279c3fa109aSTetsuo Handa * Directives held by this structure are "allow_read/write", "allow_execute", 280c3fa109aSTetsuo Handa * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir", 281c3fa109aSTetsuo Handa * "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock", 282937bf613STetsuo Handa * "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite", 283937bf613STetsuo Handa * "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot", "allow_mount" 284937bf613STetsuo Handa * and "allow_unmount". 2859590837bSKentaro Takeda */ 2867ef61233STetsuo Handa struct tomoyo_path_acl { 2877ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 288937bf613STetsuo Handa u8 perm_high; 2899590837bSKentaro Takeda u16 perm; 2909590837bSKentaro Takeda /* Pointer to single pathname. */ 2919590837bSKentaro Takeda const struct tomoyo_path_info *filename; 2929590837bSKentaro Takeda }; 2939590837bSKentaro Takeda 294c3fa109aSTetsuo Handa /* 2957ef61233STetsuo Handa * tomoyo_path2_acl is a structure which is used for holding an 296937bf613STetsuo Handa * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). 297c3fa109aSTetsuo Handa * It has following fields. 298c3fa109aSTetsuo Handa * 299c3fa109aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 300c3fa109aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 301c3fa109aSTetsuo Handa * (3) "filename1" is the source/old pathname. 302c3fa109aSTetsuo Handa * (4) "filename2" is the destination/new pathname. 303c3fa109aSTetsuo Handa * 304937bf613STetsuo Handa * Directives held by this structure are "allow_rename", "allow_link" and 305937bf613STetsuo Handa * "allow_pivot_root". 306c3fa109aSTetsuo Handa */ 3077ef61233STetsuo Handa struct tomoyo_path2_acl { 3087ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ 3099590837bSKentaro Takeda u8 perm; 3109590837bSKentaro Takeda /* Pointer to single pathname. */ 3119590837bSKentaro Takeda const struct tomoyo_path_info *filename1; 3129590837bSKentaro Takeda /* Pointer to single pathname. */ 3139590837bSKentaro Takeda const struct tomoyo_path_info *filename2; 3149590837bSKentaro Takeda }; 3159590837bSKentaro Takeda 316c3fa109aSTetsuo Handa /* 317c3fa109aSTetsuo Handa * tomoyo_io_buffer is a structure which is used for reading and modifying 318c3fa109aSTetsuo Handa * configuration via /sys/kernel/security/tomoyo/ interface. 319c3fa109aSTetsuo Handa * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as 320c3fa109aSTetsuo Handa * cursors. 321c3fa109aSTetsuo Handa * 322c3fa109aSTetsuo Handa * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of 323c3fa109aSTetsuo Handa * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info" 324c3fa109aSTetsuo Handa * entry has a list of "struct tomoyo_acl_info", we need two cursors when 325c3fa109aSTetsuo Handa * reading (one is for traversing tomoyo_domain_list and the other is for 326c3fa109aSTetsuo Handa * traversing "struct tomoyo_acl_info"->acl_info_list ). 327c3fa109aSTetsuo Handa * 328c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 329c3fa109aSTetsuo Handa * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the 330c3fa109aSTetsuo Handa * domain with the domainname specified by the rest of that line (NULL is set 331c3fa109aSTetsuo Handa * if seek failed). 332c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 333c3fa109aSTetsuo Handa * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that 334c3fa109aSTetsuo Handa * line (->write_var1 is set to NULL if a domain was deleted). 335c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 336c3fa109aSTetsuo Handa * neither "select " nor "delete ", an entry or a domain specified by that line 337c3fa109aSTetsuo Handa * is appended. 338c3fa109aSTetsuo Handa */ 3399590837bSKentaro Takeda struct tomoyo_io_buffer { 3409590837bSKentaro Takeda int (*read) (struct tomoyo_io_buffer *); 3419590837bSKentaro Takeda int (*write) (struct tomoyo_io_buffer *); 3429590837bSKentaro Takeda /* Exclusive lock for this structure. */ 3439590837bSKentaro Takeda struct mutex io_sem; 344fdb8ebb7STetsuo Handa /* Index returned by tomoyo_read_lock(). */ 345fdb8ebb7STetsuo Handa int reader_idx; 3469590837bSKentaro Takeda /* The position currently reading from. */ 3479590837bSKentaro Takeda struct list_head *read_var1; 3489590837bSKentaro Takeda /* Extra variables for reading. */ 3499590837bSKentaro Takeda struct list_head *read_var2; 3509590837bSKentaro Takeda /* The position currently writing to. */ 3519590837bSKentaro Takeda struct tomoyo_domain_info *write_var1; 3529590837bSKentaro Takeda /* The step for reading. */ 3539590837bSKentaro Takeda int read_step; 3549590837bSKentaro Takeda /* Buffer for reading. */ 3559590837bSKentaro Takeda char *read_buf; 3569590837bSKentaro Takeda /* EOF flag for reading. */ 3579590837bSKentaro Takeda bool read_eof; 3589590837bSKentaro Takeda /* Read domain ACL of specified PID? */ 3599590837bSKentaro Takeda bool read_single_domain; 3609590837bSKentaro Takeda /* Extra variable for reading. */ 3619590837bSKentaro Takeda u8 read_bit; 3629590837bSKentaro Takeda /* Bytes available for reading. */ 3639590837bSKentaro Takeda int read_avail; 3649590837bSKentaro Takeda /* Size of read buffer. */ 3659590837bSKentaro Takeda int readbuf_size; 3669590837bSKentaro Takeda /* Buffer for writing. */ 3679590837bSKentaro Takeda char *write_buf; 3689590837bSKentaro Takeda /* Bytes available for writing. */ 3699590837bSKentaro Takeda int write_avail; 3709590837bSKentaro Takeda /* Size of write buffer. */ 3719590837bSKentaro Takeda int writebuf_size; 3729590837bSKentaro Takeda }; 3739590837bSKentaro Takeda 37476bb0895STetsuo Handa /* 37576bb0895STetsuo Handa * tomoyo_globally_readable_file_entry is a structure which is used for holding 37676bb0895STetsuo Handa * "allow_read" entries. 37776bb0895STetsuo Handa * It has following fields. 37876bb0895STetsuo Handa * 37976bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_globally_readable_list . 38076bb0895STetsuo Handa * (2) "filename" is a pathname which is allowed to open(O_RDONLY). 38176bb0895STetsuo Handa * (3) "is_deleted" is a bool which is true if marked as deleted, false 38276bb0895STetsuo Handa * otherwise. 38376bb0895STetsuo Handa */ 38476bb0895STetsuo Handa struct tomoyo_globally_readable_file_entry { 38576bb0895STetsuo Handa struct list_head list; 38676bb0895STetsuo Handa const struct tomoyo_path_info *filename; 38776bb0895STetsuo Handa bool is_deleted; 38876bb0895STetsuo Handa }; 38976bb0895STetsuo Handa 39076bb0895STetsuo Handa /* 39176bb0895STetsuo Handa * tomoyo_pattern_entry is a structure which is used for holding 39276bb0895STetsuo Handa * "tomoyo_pattern_list" entries. 39376bb0895STetsuo Handa * It has following fields. 39476bb0895STetsuo Handa * 39576bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_pattern_list . 39676bb0895STetsuo Handa * (2) "pattern" is a pathname pattern which is used for converting pathnames 39776bb0895STetsuo Handa * to pathname patterns during learning mode. 39876bb0895STetsuo Handa * (3) "is_deleted" is a bool which is true if marked as deleted, false 39976bb0895STetsuo Handa * otherwise. 40076bb0895STetsuo Handa */ 40176bb0895STetsuo Handa struct tomoyo_pattern_entry { 40276bb0895STetsuo Handa struct list_head list; 40376bb0895STetsuo Handa const struct tomoyo_path_info *pattern; 40476bb0895STetsuo Handa bool is_deleted; 40576bb0895STetsuo Handa }; 40676bb0895STetsuo Handa 40776bb0895STetsuo Handa /* 40876bb0895STetsuo Handa * tomoyo_no_rewrite_entry is a structure which is used for holding 40976bb0895STetsuo Handa * "deny_rewrite" entries. 41076bb0895STetsuo Handa * It has following fields. 41176bb0895STetsuo Handa * 41276bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_no_rewrite_list . 41376bb0895STetsuo Handa * (2) "pattern" is a pathname which is by default not permitted to modify 41476bb0895STetsuo Handa * already existing content. 41576bb0895STetsuo Handa * (3) "is_deleted" is a bool which is true if marked as deleted, false 41676bb0895STetsuo Handa * otherwise. 41776bb0895STetsuo Handa */ 41876bb0895STetsuo Handa struct tomoyo_no_rewrite_entry { 41976bb0895STetsuo Handa struct list_head list; 42076bb0895STetsuo Handa const struct tomoyo_path_info *pattern; 42176bb0895STetsuo Handa bool is_deleted; 42276bb0895STetsuo Handa }; 42376bb0895STetsuo Handa 42476bb0895STetsuo Handa /* 42576bb0895STetsuo Handa * tomoyo_domain_initializer_entry is a structure which is used for holding 42676bb0895STetsuo Handa * "initialize_domain" and "no_initialize_domain" entries. 42776bb0895STetsuo Handa * It has following fields. 42876bb0895STetsuo Handa * 42976bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_domain_initializer_list . 43076bb0895STetsuo Handa * (2) "domainname" which is "a domainname" or "the last component of a 43176bb0895STetsuo Handa * domainname". This field is NULL if "from" clause is not specified. 43276bb0895STetsuo Handa * (3) "program" which is a program's pathname. 43376bb0895STetsuo Handa * (4) "is_deleted" is a bool which is true if marked as deleted, false 43476bb0895STetsuo Handa * otherwise. 43576bb0895STetsuo Handa * (5) "is_not" is a bool which is true if "no_initialize_domain", false 43676bb0895STetsuo Handa * otherwise. 43776bb0895STetsuo Handa * (6) "is_last_name" is a bool which is true if "domainname" is "the last 43876bb0895STetsuo Handa * component of a domainname", false otherwise. 43976bb0895STetsuo Handa */ 44076bb0895STetsuo Handa struct tomoyo_domain_initializer_entry { 44176bb0895STetsuo Handa struct list_head list; 44276bb0895STetsuo Handa const struct tomoyo_path_info *domainname; /* This may be NULL */ 44376bb0895STetsuo Handa const struct tomoyo_path_info *program; 44476bb0895STetsuo Handa bool is_deleted; 44576bb0895STetsuo Handa bool is_not; /* True if this entry is "no_initialize_domain". */ 44676bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 44776bb0895STetsuo Handa bool is_last_name; 44876bb0895STetsuo Handa }; 44976bb0895STetsuo Handa 45076bb0895STetsuo Handa /* 45176bb0895STetsuo Handa * tomoyo_domain_keeper_entry is a structure which is used for holding 45276bb0895STetsuo Handa * "keep_domain" and "no_keep_domain" entries. 45376bb0895STetsuo Handa * It has following fields. 45476bb0895STetsuo Handa * 45576bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_domain_keeper_list . 45676bb0895STetsuo Handa * (2) "domainname" which is "a domainname" or "the last component of a 45776bb0895STetsuo Handa * domainname". 45876bb0895STetsuo Handa * (3) "program" which is a program's pathname. 45976bb0895STetsuo Handa * This field is NULL if "from" clause is not specified. 46076bb0895STetsuo Handa * (4) "is_deleted" is a bool which is true if marked as deleted, false 46176bb0895STetsuo Handa * otherwise. 46276bb0895STetsuo Handa * (5) "is_not" is a bool which is true if "no_initialize_domain", false 46376bb0895STetsuo Handa * otherwise. 46476bb0895STetsuo Handa * (6) "is_last_name" is a bool which is true if "domainname" is "the last 46576bb0895STetsuo Handa * component of a domainname", false otherwise. 46676bb0895STetsuo Handa */ 46776bb0895STetsuo Handa struct tomoyo_domain_keeper_entry { 46876bb0895STetsuo Handa struct list_head list; 46976bb0895STetsuo Handa const struct tomoyo_path_info *domainname; 47076bb0895STetsuo Handa const struct tomoyo_path_info *program; /* This may be NULL */ 47176bb0895STetsuo Handa bool is_deleted; 47276bb0895STetsuo Handa bool is_not; /* True if this entry is "no_keep_domain". */ 47376bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 47476bb0895STetsuo Handa bool is_last_name; 47576bb0895STetsuo Handa }; 47676bb0895STetsuo Handa 47776bb0895STetsuo Handa /* 47876bb0895STetsuo Handa * tomoyo_alias_entry is a structure which is used for holding "alias" entries. 47976bb0895STetsuo Handa * It has following fields. 48076bb0895STetsuo Handa * 48176bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_alias_list . 48276bb0895STetsuo Handa * (2) "original_name" which is a dereferenced pathname. 48376bb0895STetsuo Handa * (3) "aliased_name" which is a symlink's pathname. 48476bb0895STetsuo Handa * (4) "is_deleted" is a bool which is true if marked as deleted, false 48576bb0895STetsuo Handa * otherwise. 48676bb0895STetsuo Handa */ 48776bb0895STetsuo Handa struct tomoyo_alias_entry { 48876bb0895STetsuo Handa struct list_head list; 48976bb0895STetsuo Handa const struct tomoyo_path_info *original_name; 49076bb0895STetsuo Handa const struct tomoyo_path_info *aliased_name; 49176bb0895STetsuo Handa bool is_deleted; 49276bb0895STetsuo Handa }; 49376bb0895STetsuo Handa 49476bb0895STetsuo Handa /* 49576bb0895STetsuo Handa * tomoyo_policy_manager_entry is a structure which is used for holding list of 49676bb0895STetsuo Handa * domainnames or programs which are permitted to modify configuration via 49776bb0895STetsuo Handa * /sys/kernel/security/tomoyo/ interface. 49876bb0895STetsuo Handa * It has following fields. 49976bb0895STetsuo Handa * 50076bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_policy_manager_list . 50176bb0895STetsuo Handa * (2) "manager" is a domainname or a program's pathname. 50276bb0895STetsuo Handa * (3) "is_domain" is a bool which is true if "manager" is a domainname, false 50376bb0895STetsuo Handa * otherwise. 50476bb0895STetsuo Handa * (4) "is_deleted" is a bool which is true if marked as deleted, false 50576bb0895STetsuo Handa * otherwise. 50676bb0895STetsuo Handa */ 50776bb0895STetsuo Handa struct tomoyo_policy_manager_entry { 50876bb0895STetsuo Handa struct list_head list; 50976bb0895STetsuo Handa /* A path to program or a domainname. */ 51076bb0895STetsuo Handa const struct tomoyo_path_info *manager; 51176bb0895STetsuo Handa bool is_domain; /* True if manager is a domainname. */ 51276bb0895STetsuo Handa bool is_deleted; /* True if this entry is deleted. */ 51376bb0895STetsuo Handa }; 51476bb0895STetsuo Handa 51576bb0895STetsuo Handa /********** Function prototypes. **********/ 51676bb0895STetsuo Handa 5179590837bSKentaro Takeda /* Check whether the domain has too many ACL entries to hold. */ 5189590837bSKentaro Takeda bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain); 5199590837bSKentaro Takeda /* Transactional sprintf() for policy dump. */ 5209590837bSKentaro Takeda bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) 5219590837bSKentaro Takeda __attribute__ ((format(printf, 2, 3))); 5229590837bSKentaro Takeda /* Check whether the domainname is correct. */ 5239590837bSKentaro Takeda bool tomoyo_is_correct_domain(const unsigned char *domainname, 5249590837bSKentaro Takeda const char *function); 5259590837bSKentaro Takeda /* Check whether the token is correct. */ 5269590837bSKentaro Takeda bool tomoyo_is_correct_path(const char *filename, const s8 start_type, 5279590837bSKentaro Takeda const s8 pattern_type, const s8 end_type, 5289590837bSKentaro Takeda const char *function); 5299590837bSKentaro Takeda /* Check whether the token can be a domainname. */ 5309590837bSKentaro Takeda bool tomoyo_is_domain_def(const unsigned char *buffer); 5319590837bSKentaro Takeda /* Check whether the given filename matches the given pattern. */ 5329590837bSKentaro Takeda bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 5339590837bSKentaro Takeda const struct tomoyo_path_info *pattern); 5349590837bSKentaro Takeda /* Read "alias" entry in exception policy. */ 5359590837bSKentaro Takeda bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head); 5369590837bSKentaro Takeda /* 5379590837bSKentaro Takeda * Read "initialize_domain" and "no_initialize_domain" entry 5389590837bSKentaro Takeda * in exception policy. 5399590837bSKentaro Takeda */ 5409590837bSKentaro Takeda bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head); 5419590837bSKentaro Takeda /* Read "keep_domain" and "no_keep_domain" entry in exception policy. */ 5429590837bSKentaro Takeda bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head); 5439590837bSKentaro Takeda /* Read "file_pattern" entry in exception policy. */ 5449590837bSKentaro Takeda bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head); 5459590837bSKentaro Takeda /* Read "allow_read" entry in exception policy. */ 5469590837bSKentaro Takeda bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head); 5479590837bSKentaro Takeda /* Read "deny_rewrite" entry in exception policy. */ 5489590837bSKentaro Takeda bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head); 5499590837bSKentaro Takeda /* Write domain policy violation warning message to console? */ 5509590837bSKentaro Takeda bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); 5519590837bSKentaro Takeda /* Convert double path operation to operation name. */ 5527ef61233STetsuo Handa const char *tomoyo_path22keyword(const u8 operation); 5539590837bSKentaro Takeda /* Get the last component of the given domainname. */ 5549590837bSKentaro Takeda const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); 5559590837bSKentaro Takeda /* Get warning message. */ 5569590837bSKentaro Takeda const char *tomoyo_get_msg(const bool is_enforce); 5579590837bSKentaro Takeda /* Convert single path operation to operation name. */ 5587ef61233STetsuo Handa const char *tomoyo_path2keyword(const u8 operation); 5599590837bSKentaro Takeda /* Create "alias" entry in exception policy. */ 5609590837bSKentaro Takeda int tomoyo_write_alias_policy(char *data, const bool is_delete); 5619590837bSKentaro Takeda /* 5629590837bSKentaro Takeda * Create "initialize_domain" and "no_initialize_domain" entry 5639590837bSKentaro Takeda * in exception policy. 5649590837bSKentaro Takeda */ 5659590837bSKentaro Takeda int tomoyo_write_domain_initializer_policy(char *data, const bool is_not, 5669590837bSKentaro Takeda const bool is_delete); 5679590837bSKentaro Takeda /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */ 5689590837bSKentaro Takeda int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, 5699590837bSKentaro Takeda const bool is_delete); 5709590837bSKentaro Takeda /* 5719590837bSKentaro Takeda * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", 5729590837bSKentaro Takeda * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", 5739590837bSKentaro Takeda * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", 5749590837bSKentaro Takeda * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and 5759590837bSKentaro Takeda * "allow_link" entry in domain policy. 5769590837bSKentaro Takeda */ 5779590837bSKentaro Takeda int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, 5789590837bSKentaro Takeda const bool is_delete); 5799590837bSKentaro Takeda /* Create "allow_read" entry in exception policy. */ 5809590837bSKentaro Takeda int tomoyo_write_globally_readable_policy(char *data, const bool is_delete); 5819590837bSKentaro Takeda /* Create "deny_rewrite" entry in exception policy. */ 5829590837bSKentaro Takeda int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); 5839590837bSKentaro Takeda /* Create "file_pattern" entry in exception policy. */ 5849590837bSKentaro Takeda int tomoyo_write_pattern_policy(char *data, const bool is_delete); 5859590837bSKentaro Takeda /* Find a domain by the given name. */ 5869590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 5879590837bSKentaro Takeda /* Find or create a domain by the given name. */ 5889590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * 5899590837bSKentaro Takeda domainname, 5909590837bSKentaro Takeda const u8 profile); 5919590837bSKentaro Takeda /* Check mode for specified functionality. */ 5929590837bSKentaro Takeda unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 5939590837bSKentaro Takeda const u8 index); 5949590837bSKentaro Takeda /* Fill in "struct tomoyo_path_info" members. */ 5959590837bSKentaro Takeda void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 5969590837bSKentaro Takeda /* Run policy loader when /sbin/init starts. */ 5979590837bSKentaro Takeda void tomoyo_load_policy(const char *filename); 5989590837bSKentaro Takeda 59976bb0895STetsuo Handa /* Convert binary string to ascii string. */ 60076bb0895STetsuo Handa int tomoyo_encode(char *buffer, int buflen, const char *str); 60176bb0895STetsuo Handa 60276bb0895STetsuo Handa /* Returns realpath(3) of the given pathname but ignores chroot'ed root. */ 60376bb0895STetsuo Handa int tomoyo_realpath_from_path2(struct path *path, char *newname, 60476bb0895STetsuo Handa int newname_len); 60576bb0895STetsuo Handa 60676bb0895STetsuo Handa /* 60776bb0895STetsuo Handa * Returns realpath(3) of the given pathname but ignores chroot'ed root. 60876bb0895STetsuo Handa * These functions use kzalloc(), so the caller must call kfree() 60976bb0895STetsuo Handa * if these functions didn't return NULL. 61076bb0895STetsuo Handa */ 61176bb0895STetsuo Handa char *tomoyo_realpath(const char *pathname); 61276bb0895STetsuo Handa /* 61376bb0895STetsuo Handa * Same with tomoyo_realpath() except that it doesn't follow the final symlink. 61476bb0895STetsuo Handa */ 61576bb0895STetsuo Handa char *tomoyo_realpath_nofollow(const char *pathname); 61676bb0895STetsuo Handa /* Same with tomoyo_realpath() except that the pathname is already solved. */ 61776bb0895STetsuo Handa char *tomoyo_realpath_from_path(struct path *path); 61876bb0895STetsuo Handa 61976bb0895STetsuo Handa /* Check memory quota. */ 62076bb0895STetsuo Handa bool tomoyo_memory_ok(void *ptr); 62176bb0895STetsuo Handa 62276bb0895STetsuo Handa /* 62376bb0895STetsuo Handa * Keep the given name on the RAM. 62476bb0895STetsuo Handa * The RAM is shared, so NEVER try to modify or kfree() the returned name. 62576bb0895STetsuo Handa */ 62676bb0895STetsuo Handa const struct tomoyo_path_info *tomoyo_get_name(const char *name); 62776bb0895STetsuo Handa 62876bb0895STetsuo Handa /* Check for memory usage. */ 62976bb0895STetsuo Handa int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); 63076bb0895STetsuo Handa 63176bb0895STetsuo Handa /* Set memory quota. */ 63276bb0895STetsuo Handa int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); 63376bb0895STetsuo Handa 63476bb0895STetsuo Handa /* Initialize realpath related code. */ 63576bb0895STetsuo Handa void __init tomoyo_realpath_init(void); 63676bb0895STetsuo Handa int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain, 63776bb0895STetsuo Handa const struct tomoyo_path_info *filename); 63876bb0895STetsuo Handa int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 63976bb0895STetsuo Handa struct path *path, const int flag); 6407ef61233STetsuo Handa int tomoyo_path_perm(struct tomoyo_domain_info *domain, const u8 operation, 6417ef61233STetsuo Handa struct path *path); 6427ef61233STetsuo Handa int tomoyo_path2_perm(struct tomoyo_domain_info *domain, const u8 operation, 6437ef61233STetsuo Handa struct path *path1, struct path *path2); 64476bb0895STetsuo Handa int tomoyo_check_rewrite_permission(struct tomoyo_domain_info *domain, 64576bb0895STetsuo Handa struct file *filp); 64676bb0895STetsuo Handa int tomoyo_find_next_domain(struct linux_binprm *bprm); 64776bb0895STetsuo Handa 648847b173eSTetsuo Handa /* Run garbage collector. */ 649847b173eSTetsuo Handa void tomoyo_run_gc(void); 650847b173eSTetsuo Handa 651847b173eSTetsuo Handa void tomoyo_memory_free(void *ptr); 652847b173eSTetsuo Handa 65376bb0895STetsuo Handa /********** External variable definitions. **********/ 65476bb0895STetsuo Handa 65576bb0895STetsuo Handa /* Lock for GC. */ 65676bb0895STetsuo Handa extern struct srcu_struct tomoyo_ss; 65776bb0895STetsuo Handa 65876bb0895STetsuo Handa /* The list for "struct tomoyo_domain_info". */ 65976bb0895STetsuo Handa extern struct list_head tomoyo_domain_list; 66076bb0895STetsuo Handa 661847b173eSTetsuo Handa extern struct list_head tomoyo_domain_initializer_list; 662847b173eSTetsuo Handa extern struct list_head tomoyo_domain_keeper_list; 663847b173eSTetsuo Handa extern struct list_head tomoyo_alias_list; 664847b173eSTetsuo Handa extern struct list_head tomoyo_globally_readable_list; 665847b173eSTetsuo Handa extern struct list_head tomoyo_pattern_list; 666847b173eSTetsuo Handa extern struct list_head tomoyo_no_rewrite_list; 667847b173eSTetsuo Handa extern struct list_head tomoyo_policy_manager_list; 668847b173eSTetsuo Handa extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 669847b173eSTetsuo Handa extern struct mutex tomoyo_name_list_lock; 670847b173eSTetsuo Handa 67176bb0895STetsuo Handa /* Lock for protecting policy. */ 67276bb0895STetsuo Handa extern struct mutex tomoyo_policy_lock; 67376bb0895STetsuo Handa 67476bb0895STetsuo Handa /* Has /sbin/init started? */ 67576bb0895STetsuo Handa extern bool tomoyo_policy_loaded; 67676bb0895STetsuo Handa 67776bb0895STetsuo Handa /* The kernel's domain. */ 67876bb0895STetsuo Handa extern struct tomoyo_domain_info tomoyo_kernel_domain; 67976bb0895STetsuo Handa 68076bb0895STetsuo Handa /********** Inlined functions. **********/ 68176bb0895STetsuo Handa 68276bb0895STetsuo Handa static inline int tomoyo_read_lock(void) 68376bb0895STetsuo Handa { 68476bb0895STetsuo Handa return srcu_read_lock(&tomoyo_ss); 68576bb0895STetsuo Handa } 68676bb0895STetsuo Handa 68776bb0895STetsuo Handa static inline void tomoyo_read_unlock(int idx) 68876bb0895STetsuo Handa { 68976bb0895STetsuo Handa srcu_read_unlock(&tomoyo_ss, idx); 69076bb0895STetsuo Handa } 69176bb0895STetsuo Handa 6929590837bSKentaro Takeda /* strcmp() for "struct tomoyo_path_info" structure. */ 6939590837bSKentaro Takeda static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, 6949590837bSKentaro Takeda const struct tomoyo_path_info *b) 6959590837bSKentaro Takeda { 6969590837bSKentaro Takeda return a->hash != b->hash || strcmp(a->name, b->name); 6979590837bSKentaro Takeda } 6989590837bSKentaro Takeda 6999590837bSKentaro Takeda /** 7009590837bSKentaro Takeda * tomoyo_is_valid - Check whether the character is a valid char. 7019590837bSKentaro Takeda * 7029590837bSKentaro Takeda * @c: The character to check. 7039590837bSKentaro Takeda * 7049590837bSKentaro Takeda * Returns true if @c is a valid character, false otherwise. 7059590837bSKentaro Takeda */ 7069590837bSKentaro Takeda static inline bool tomoyo_is_valid(const unsigned char c) 7079590837bSKentaro Takeda { 7089590837bSKentaro Takeda return c > ' ' && c < 127; 7099590837bSKentaro Takeda } 7109590837bSKentaro Takeda 7119590837bSKentaro Takeda /** 7129590837bSKentaro Takeda * tomoyo_is_invalid - Check whether the character is an invalid char. 7139590837bSKentaro Takeda * 7149590837bSKentaro Takeda * @c: The character to check. 7159590837bSKentaro Takeda * 7169590837bSKentaro Takeda * Returns true if @c is an invalid character, false otherwise. 7179590837bSKentaro Takeda */ 7189590837bSKentaro Takeda static inline bool tomoyo_is_invalid(const unsigned char c) 7199590837bSKentaro Takeda { 7209590837bSKentaro Takeda return c && (c <= ' ' || c >= 127); 7219590837bSKentaro Takeda } 7229590837bSKentaro Takeda 72376bb0895STetsuo Handa static inline void tomoyo_put_name(const struct tomoyo_path_info *name) 72476bb0895STetsuo Handa { 72576bb0895STetsuo Handa if (name) { 72676bb0895STetsuo Handa struct tomoyo_name_entry *ptr = 72776bb0895STetsuo Handa container_of(name, struct tomoyo_name_entry, entry); 72876bb0895STetsuo Handa atomic_dec(&ptr->users); 72976bb0895STetsuo Handa } 73076bb0895STetsuo Handa } 7319590837bSKentaro Takeda 73276bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_domain(void) 73376bb0895STetsuo Handa { 73476bb0895STetsuo Handa return current_cred()->security; 73576bb0895STetsuo Handa } 7369590837bSKentaro Takeda 73776bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct 73876bb0895STetsuo Handa *task) 73976bb0895STetsuo Handa { 74076bb0895STetsuo Handa return task_cred_xxx(task, security); 74176bb0895STetsuo Handa } 7429590837bSKentaro Takeda 7439590837bSKentaro Takeda /** 7449590837bSKentaro Takeda * list_for_each_cookie - iterate over a list with cookie. 7459590837bSKentaro Takeda * @pos: the &struct list_head to use as a loop cursor. 7469590837bSKentaro Takeda * @cookie: the &struct list_head to use as a cookie. 7479590837bSKentaro Takeda * @head: the head for your list. 7489590837bSKentaro Takeda * 749fdb8ebb7STetsuo Handa * Same with list_for_each_rcu() except that this primitive uses @cookie 7509590837bSKentaro Takeda * so that we can continue iteration. 7519590837bSKentaro Takeda * @cookie must be NULL when iteration starts, and @cookie will become 7529590837bSKentaro Takeda * NULL when iteration finishes. 7539590837bSKentaro Takeda */ 7549590837bSKentaro Takeda #define list_for_each_cookie(pos, cookie, head) \ 7559590837bSKentaro Takeda for (({ if (!cookie) \ 7569590837bSKentaro Takeda cookie = head; }), \ 757fdb8ebb7STetsuo Handa pos = rcu_dereference((cookie)->next); \ 7589590837bSKentaro Takeda prefetch(pos->next), pos != (head) || ((cookie) = NULL); \ 759fdb8ebb7STetsuo Handa (cookie) = pos, pos = rcu_dereference(pos->next)) 760fdb8ebb7STetsuo Handa 7619590837bSKentaro Takeda #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ 762