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 47cb0abe6aSTetsuo Handa enum tomoyo_mode_index { 48cb0abe6aSTetsuo Handa TOMOYO_CONFIG_DISABLED, 49cb0abe6aSTetsuo Handa TOMOYO_CONFIG_LEARNING, 50cb0abe6aSTetsuo Handa TOMOYO_CONFIG_PERMISSIVE, 51cb0abe6aSTetsuo Handa TOMOYO_CONFIG_ENFORCING 52cb0abe6aSTetsuo Handa }; 53cb0abe6aSTetsuo Handa 5476bb0895STetsuo Handa /* Keywords for ACLs. */ 5576bb0895STetsuo Handa #define TOMOYO_KEYWORD_ALIAS "alias " 562106ccd9STetsuo Handa #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount " 5776bb0895STetsuo Handa #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " 5876bb0895STetsuo Handa #define TOMOYO_KEYWORD_DELETE "delete " 5976bb0895STetsuo Handa #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " 6076bb0895STetsuo Handa #define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern " 6176bb0895STetsuo Handa #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " 6276bb0895STetsuo Handa #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " 6376bb0895STetsuo Handa #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " 6476bb0895STetsuo Handa #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " 657762fbffSTetsuo Handa #define TOMOYO_KEYWORD_PATH_GROUP "path_group " 664c3e9e2dSTetsuo Handa #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group " 6776bb0895STetsuo Handa #define TOMOYO_KEYWORD_SELECT "select " 6876bb0895STetsuo Handa #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " 6976bb0895STetsuo Handa #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" 7076bb0895STetsuo Handa /* A domain definition starts with <kernel>. */ 7176bb0895STetsuo Handa #define TOMOYO_ROOT_NAME "<kernel>" 7276bb0895STetsuo Handa #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) 7376bb0895STetsuo Handa 744c3e9e2dSTetsuo Handa /* Value type definition. */ 754c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_INVALID 0 764c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_DECIMAL 1 774c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_OCTAL 2 784c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_HEXADECIMAL 3 794c3e9e2dSTetsuo Handa 8076bb0895STetsuo Handa /* Index numbers for Access Controls. */ 81084da356STetsuo Handa enum tomoyo_mac_index { 82084da356STetsuo Handa TOMOYO_MAC_FOR_FILE, /* domain_policy.conf */ 83084da356STetsuo Handa TOMOYO_MAX_ACCEPT_ENTRY, 84084da356STetsuo Handa TOMOYO_VERBOSE, 85084da356STetsuo Handa TOMOYO_MAX_CONTROL_INDEX 86084da356STetsuo Handa }; 8776bb0895STetsuo Handa 8876bb0895STetsuo Handa /* Index numbers for Access Controls. */ 89084da356STetsuo Handa enum tomoyo_acl_entry_type_index { 907ef61233STetsuo Handa TOMOYO_TYPE_PATH_ACL, 917ef61233STetsuo Handa TOMOYO_TYPE_PATH2_ACL, 92a1f9bb6aSTetsuo Handa TOMOYO_TYPE_PATH_NUMBER_ACL, 93a1f9bb6aSTetsuo Handa TOMOYO_TYPE_PATH_NUMBER3_ACL, 942106ccd9STetsuo Handa TOMOYO_TYPE_MOUNT_ACL, 95084da356STetsuo Handa }; 9676bb0895STetsuo Handa 9776bb0895STetsuo Handa /* Index numbers for File Controls. */ 9876bb0895STetsuo Handa 9976bb0895STetsuo Handa /* 100a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically 101a1f9bb6aSTetsuo Handa * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set. 102a1f9bb6aSTetsuo Handa * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if 103a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is set. 104a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ 105a1f9bb6aSTetsuo Handa * or TOMOYO_TYPE_WRITE is cleared. 106a1f9bb6aSTetsuo Handa * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if 107a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is cleared. 10876bb0895STetsuo Handa */ 10976bb0895STetsuo Handa 110084da356STetsuo Handa enum tomoyo_path_acl_index { 1117ef61233STetsuo Handa TOMOYO_TYPE_READ_WRITE, 1127ef61233STetsuo Handa TOMOYO_TYPE_EXECUTE, 1137ef61233STetsuo Handa TOMOYO_TYPE_READ, 1147ef61233STetsuo Handa TOMOYO_TYPE_WRITE, 1157ef61233STetsuo Handa TOMOYO_TYPE_UNLINK, 1167ef61233STetsuo Handa TOMOYO_TYPE_RMDIR, 1177ef61233STetsuo Handa TOMOYO_TYPE_TRUNCATE, 1187ef61233STetsuo Handa TOMOYO_TYPE_SYMLINK, 1197ef61233STetsuo Handa TOMOYO_TYPE_REWRITE, 1207ef61233STetsuo Handa TOMOYO_TYPE_CHROOT, 1217ef61233STetsuo Handa TOMOYO_TYPE_UMOUNT, 1227ef61233STetsuo Handa TOMOYO_MAX_PATH_OPERATION 123084da356STetsuo Handa }; 12476bb0895STetsuo Handa 125a1f9bb6aSTetsuo Handa enum tomoyo_path_number3_acl_index { 126a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKBLOCK, 127a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKCHAR, 128a1f9bb6aSTetsuo Handa TOMOYO_MAX_PATH_NUMBER3_OPERATION 129a1f9bb6aSTetsuo Handa }; 130a1f9bb6aSTetsuo Handa 131084da356STetsuo Handa enum tomoyo_path2_acl_index { 1327ef61233STetsuo Handa TOMOYO_TYPE_LINK, 1337ef61233STetsuo Handa TOMOYO_TYPE_RENAME, 1347ef61233STetsuo Handa TOMOYO_TYPE_PIVOT_ROOT, 1357ef61233STetsuo Handa TOMOYO_MAX_PATH2_OPERATION 136084da356STetsuo Handa }; 13776bb0895STetsuo Handa 138a1f9bb6aSTetsuo Handa enum tomoyo_path_number_acl_index { 139a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CREATE, 140a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKDIR, 141a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKFIFO, 142a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKSOCK, 143a1f9bb6aSTetsuo Handa TOMOYO_TYPE_IOCTL, 144a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHMOD, 145a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHOWN, 146a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHGRP, 147a1f9bb6aSTetsuo Handa TOMOYO_MAX_PATH_NUMBER_OPERATION 148a1f9bb6aSTetsuo Handa }; 149a1f9bb6aSTetsuo Handa 150084da356STetsuo Handa enum tomoyo_securityfs_interface_index { 151084da356STetsuo Handa TOMOYO_DOMAINPOLICY, 152084da356STetsuo Handa TOMOYO_EXCEPTIONPOLICY, 153084da356STetsuo Handa TOMOYO_DOMAIN_STATUS, 154084da356STetsuo Handa TOMOYO_PROCESS_STATUS, 155084da356STetsuo Handa TOMOYO_MEMINFO, 156084da356STetsuo Handa TOMOYO_SELFDOMAIN, 157084da356STetsuo Handa TOMOYO_VERSION, 158084da356STetsuo Handa TOMOYO_PROFILE, 159084da356STetsuo Handa TOMOYO_MANAGER 160084da356STetsuo Handa }; 16176bb0895STetsuo Handa 16276bb0895STetsuo Handa /********** Structure definitions. **********/ 1639590837bSKentaro Takeda 164c3fa109aSTetsuo Handa /* 165c3fa109aSTetsuo Handa * tomoyo_page_buffer is a structure which is used for holding a pathname 166c3fa109aSTetsuo Handa * obtained from "struct dentry" and "struct vfsmount" pair. 167c3fa109aSTetsuo Handa * As of now, it is 4096 bytes. If users complain that 4096 bytes is too small 168c3fa109aSTetsuo Handa * (because TOMOYO escapes non ASCII printable characters using \ooo format), 169c3fa109aSTetsuo Handa * we will make the buffer larger. 170c3fa109aSTetsuo Handa */ 1719590837bSKentaro Takeda struct tomoyo_page_buffer { 1729590837bSKentaro Takeda char buffer[4096]; 1739590837bSKentaro Takeda }; 1749590837bSKentaro Takeda 175c3fa109aSTetsuo Handa /* 176cb0abe6aSTetsuo Handa * tomoyo_request_info is a structure which is used for holding 177cb0abe6aSTetsuo Handa * 178cb0abe6aSTetsuo Handa * (1) Domain information of current process. 179cb0abe6aSTetsuo Handa * (2) Access control mode of the profile. 180cb0abe6aSTetsuo Handa */ 181cb0abe6aSTetsuo Handa struct tomoyo_request_info { 182cb0abe6aSTetsuo Handa struct tomoyo_domain_info *domain; 183cb0abe6aSTetsuo Handa u8 mode; /* One of tomoyo_mode_index . */ 184cb0abe6aSTetsuo Handa }; 185cb0abe6aSTetsuo Handa 186cb0abe6aSTetsuo Handa /* 187c3fa109aSTetsuo Handa * tomoyo_path_info is a structure which is used for holding a string data 188c3fa109aSTetsuo Handa * used by TOMOYO. 189c3fa109aSTetsuo Handa * This structure has several fields for supporting pattern matching. 190c3fa109aSTetsuo Handa * 191c3fa109aSTetsuo Handa * (1) "name" is the '\0' terminated string data. 192c3fa109aSTetsuo Handa * (2) "hash" is full_name_hash(name, strlen(name)). 193c3fa109aSTetsuo Handa * This allows tomoyo_pathcmp() to compare by hash before actually compare 194c3fa109aSTetsuo Handa * using strcmp(). 195c3fa109aSTetsuo Handa * (3) "const_len" is the length of the initial segment of "name" which 196c3fa109aSTetsuo Handa * consists entirely of non wildcard characters. In other words, the length 197c3fa109aSTetsuo Handa * which we can compare two strings using strncmp(). 198c3fa109aSTetsuo Handa * (4) "is_dir" is a bool which is true if "name" ends with "/", 199c3fa109aSTetsuo Handa * false otherwise. 200c3fa109aSTetsuo Handa * TOMOYO distinguishes directory and non-directory. A directory ends with 201c3fa109aSTetsuo Handa * "/" and non-directory does not end with "/". 202c3fa109aSTetsuo Handa * (5) "is_patterned" is a bool which is true if "name" contains wildcard 203c3fa109aSTetsuo Handa * characters, false otherwise. This allows TOMOYO to use "hash" and 204c3fa109aSTetsuo Handa * strcmp() for string comparison if "is_patterned" is false. 205c3fa109aSTetsuo Handa */ 2069590837bSKentaro Takeda struct tomoyo_path_info { 2079590837bSKentaro Takeda const char *name; 2089590837bSKentaro Takeda u32 hash; /* = full_name_hash(name, strlen(name)) */ 2099590837bSKentaro Takeda u16 const_len; /* = tomoyo_const_part_length(name) */ 2109590837bSKentaro Takeda bool is_dir; /* = tomoyo_strendswith(name, "/") */ 2119590837bSKentaro Takeda bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 2129590837bSKentaro Takeda }; 2139590837bSKentaro Takeda 2149590837bSKentaro Takeda /* 21576bb0895STetsuo Handa * tomoyo_name_entry is a structure which is used for linking 21676bb0895STetsuo Handa * "struct tomoyo_path_info" into tomoyo_name_list . 2179590837bSKentaro Takeda */ 21876bb0895STetsuo Handa struct tomoyo_name_entry { 21976bb0895STetsuo Handa struct list_head list; 22076bb0895STetsuo Handa atomic_t users; 22176bb0895STetsuo Handa struct tomoyo_path_info entry; 22276bb0895STetsuo Handa }; 2239590837bSKentaro Takeda 224c3fa109aSTetsuo Handa /* 225c3fa109aSTetsuo Handa * tomoyo_path_info_with_data is a structure which is used for holding a 226c3fa109aSTetsuo Handa * pathname obtained from "struct dentry" and "struct vfsmount" pair. 227c3fa109aSTetsuo Handa * 228c3fa109aSTetsuo Handa * "struct tomoyo_path_info_with_data" consists of "struct tomoyo_path_info" 229c3fa109aSTetsuo Handa * and buffer for the pathname, while "struct tomoyo_page_buffer" consists of 230c3fa109aSTetsuo Handa * buffer for the pathname only. 231c3fa109aSTetsuo Handa * 232c3fa109aSTetsuo Handa * "struct tomoyo_path_info_with_data" is intended to allow TOMOYO to release 233c3fa109aSTetsuo Handa * both "struct tomoyo_path_info" and buffer for the pathname by single kfree() 234c3fa109aSTetsuo Handa * so that we don't need to return two pointers to the caller. If the caller 235c3fa109aSTetsuo Handa * puts "struct tomoyo_path_info" on stack memory, we will be able to remove 236c3fa109aSTetsuo Handa * "struct tomoyo_path_info_with_data". 237c3fa109aSTetsuo Handa */ 2389590837bSKentaro Takeda struct tomoyo_path_info_with_data { 2398e2d39a1STetsuo Handa /* Keep "head" first, for this pointer is passed to kfree(). */ 2409590837bSKentaro Takeda struct tomoyo_path_info head; 241a106cbfdSTetsuo Handa char barrier1[16]; /* Safeguard for overrun. */ 2429590837bSKentaro Takeda char body[TOMOYO_MAX_PATHNAME_LEN]; 2439590837bSKentaro Takeda char barrier2[16]; /* Safeguard for overrun. */ 2449590837bSKentaro Takeda }; 2459590837bSKentaro Takeda 2467762fbffSTetsuo Handa struct tomoyo_name_union { 2477762fbffSTetsuo Handa const struct tomoyo_path_info *filename; 2487762fbffSTetsuo Handa struct tomoyo_path_group *group; 2497762fbffSTetsuo Handa u8 is_group; 2507762fbffSTetsuo Handa }; 2517762fbffSTetsuo Handa 2524c3e9e2dSTetsuo Handa struct tomoyo_number_union { 2534c3e9e2dSTetsuo Handa unsigned long values[2]; 2544c3e9e2dSTetsuo Handa struct tomoyo_number_group *group; 2554c3e9e2dSTetsuo Handa u8 min_type; 2564c3e9e2dSTetsuo Handa u8 max_type; 2574c3e9e2dSTetsuo Handa u8 is_group; 2584c3e9e2dSTetsuo Handa }; 2594c3e9e2dSTetsuo Handa 2607762fbffSTetsuo Handa /* Structure for "path_group" directive. */ 2617762fbffSTetsuo Handa struct tomoyo_path_group { 2627762fbffSTetsuo Handa struct list_head list; 2637762fbffSTetsuo Handa const struct tomoyo_path_info *group_name; 2647762fbffSTetsuo Handa struct list_head member_list; 2657762fbffSTetsuo Handa atomic_t users; 2667762fbffSTetsuo Handa }; 2677762fbffSTetsuo Handa 2684c3e9e2dSTetsuo Handa /* Structure for "number_group" directive. */ 2694c3e9e2dSTetsuo Handa struct tomoyo_number_group { 2704c3e9e2dSTetsuo Handa struct list_head list; 2714c3e9e2dSTetsuo Handa const struct tomoyo_path_info *group_name; 2724c3e9e2dSTetsuo Handa struct list_head member_list; 2734c3e9e2dSTetsuo Handa atomic_t users; 2744c3e9e2dSTetsuo Handa }; 2754c3e9e2dSTetsuo Handa 2767762fbffSTetsuo Handa /* Structure for "path_group" directive. */ 2777762fbffSTetsuo Handa struct tomoyo_path_group_member { 2787762fbffSTetsuo Handa struct list_head list; 2797762fbffSTetsuo Handa bool is_deleted; 2807762fbffSTetsuo Handa const struct tomoyo_path_info *member_name; 2817762fbffSTetsuo Handa }; 2827762fbffSTetsuo Handa 2834c3e9e2dSTetsuo Handa /* Structure for "number_group" directive. */ 2844c3e9e2dSTetsuo Handa struct tomoyo_number_group_member { 2854c3e9e2dSTetsuo Handa struct list_head list; 2864c3e9e2dSTetsuo Handa bool is_deleted; 2874c3e9e2dSTetsuo Handa struct tomoyo_number_union number; 2884c3e9e2dSTetsuo Handa }; 2894c3e9e2dSTetsuo Handa 2909590837bSKentaro Takeda /* 291c3fa109aSTetsuo Handa * tomoyo_acl_info is a structure which is used for holding 292c3fa109aSTetsuo Handa * 293c3fa109aSTetsuo Handa * (1) "list" which is linked to the ->acl_info_list of 294c3fa109aSTetsuo Handa * "struct tomoyo_domain_info" 295ea13ddbaSTetsuo Handa * (2) "type" which tells type of the entry (either 2967ef61233STetsuo Handa * "struct tomoyo_path_acl" or "struct tomoyo_path2_acl"). 2979590837bSKentaro Takeda * 2989590837bSKentaro Takeda * Packing "struct tomoyo_acl_info" allows 2997ef61233STetsuo Handa * "struct tomoyo_path_acl" to embed "u8" + "u16" and 3007ef61233STetsuo Handa * "struct tomoyo_path2_acl" to embed "u8" 3019590837bSKentaro Takeda * without enlarging their structure size. 3029590837bSKentaro Takeda */ 3039590837bSKentaro Takeda struct tomoyo_acl_info { 3049590837bSKentaro Takeda struct list_head list; 3059590837bSKentaro Takeda u8 type; 3069590837bSKentaro Takeda } __packed; 3079590837bSKentaro Takeda 308c3fa109aSTetsuo Handa /* 309c3fa109aSTetsuo Handa * tomoyo_domain_info is a structure which is used for holding permissions 310c3fa109aSTetsuo Handa * (e.g. "allow_read /lib/libc-2.5.so") given to each domain. 311c3fa109aSTetsuo Handa * It has following fields. 312c3fa109aSTetsuo Handa * 313c3fa109aSTetsuo Handa * (1) "list" which is linked to tomoyo_domain_list . 314c3fa109aSTetsuo Handa * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info". 315c3fa109aSTetsuo Handa * (3) "domainname" which holds the name of the domain. 316c3fa109aSTetsuo Handa * (4) "profile" which remembers profile number assigned to this domain. 317c3fa109aSTetsuo Handa * (5) "is_deleted" is a bool which is true if this domain is marked as 318c3fa109aSTetsuo Handa * "deleted", false otherwise. 319c3fa109aSTetsuo Handa * (6) "quota_warned" is a bool which is used for suppressing warning message 320c3fa109aSTetsuo Handa * when learning mode learned too much entries. 321ea13ddbaSTetsuo Handa * (7) "ignore_global_allow_read" is a bool which is true if this domain 322ea13ddbaSTetsuo Handa * should ignore "allow_read" directive in exception policy. 323ea13ddbaSTetsuo Handa * (8) "transition_failed" is a bool which is set to true when this domain was 324ea13ddbaSTetsuo Handa * unable to create a new domain at tomoyo_find_next_domain() because the 325ea13ddbaSTetsuo Handa * name of the domain to be created was too long or it could not allocate 326ea13ddbaSTetsuo Handa * memory. If set to true, more than one process continued execve() 327ea13ddbaSTetsuo Handa * without domain transition. 328ec8e6a4eSTetsuo Handa * (9) "users" is an atomic_t that holds how many "struct cred"->security 329ec8e6a4eSTetsuo Handa * are referring this "struct tomoyo_domain_info". If is_deleted == true 330ec8e6a4eSTetsuo Handa * and users == 0, this struct will be kfree()d upon next garbage 331ec8e6a4eSTetsuo Handa * collection. 332c3fa109aSTetsuo Handa * 333c3fa109aSTetsuo Handa * A domain's lifecycle is an analogy of files on / directory. 334c3fa109aSTetsuo Handa * Multiple domains with the same domainname cannot be created (as with 335c3fa109aSTetsuo Handa * creating files with the same filename fails with -EEXIST). 336c3fa109aSTetsuo Handa * If a process reached a domain, that process can reside in that domain after 337c3fa109aSTetsuo Handa * that domain is marked as "deleted" (as with a process can access an already 338c3fa109aSTetsuo Handa * open()ed file after that file was unlink()ed). 339c3fa109aSTetsuo Handa */ 3409590837bSKentaro Takeda struct tomoyo_domain_info { 3419590837bSKentaro Takeda struct list_head list; 3429590837bSKentaro Takeda struct list_head acl_info_list; 3439590837bSKentaro Takeda /* Name of this domain. Never NULL. */ 3449590837bSKentaro Takeda const struct tomoyo_path_info *domainname; 3459590837bSKentaro Takeda u8 profile; /* Profile number to use. */ 346a0558fc3STetsuo Handa bool is_deleted; /* Delete flag. */ 3479590837bSKentaro Takeda bool quota_warned; /* Quota warnning flag. */ 348ea13ddbaSTetsuo Handa bool ignore_global_allow_read; /* Ignore "allow_read" flag. */ 349ea13ddbaSTetsuo Handa bool transition_failed; /* Domain transition failed flag. */ 350ec8e6a4eSTetsuo Handa atomic_t users; /* Number of referring credentials. */ 3519590837bSKentaro Takeda }; 3529590837bSKentaro Takeda 3539590837bSKentaro Takeda /* 3547ef61233STetsuo Handa * tomoyo_path_acl is a structure which is used for holding an 355c3fa109aSTetsuo Handa * entry with one pathname operation (e.g. open(), mkdir()). 356c3fa109aSTetsuo Handa * It has following fields. 357c3fa109aSTetsuo Handa * 358c3fa109aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 359c3fa109aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 3607762fbffSTetsuo Handa * (3) "name" is the pathname. 361c3fa109aSTetsuo Handa * 362c3fa109aSTetsuo Handa * Directives held by this structure are "allow_read/write", "allow_execute", 363a1f9bb6aSTetsuo Handa * "allow_read", "allow_write", "allow_unlink", "allow_rmdir", 3642106ccd9STetsuo Handa * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and 3652106ccd9STetsuo Handa * "allow_unmount". 3669590837bSKentaro Takeda */ 3677ef61233STetsuo Handa struct tomoyo_path_acl { 3687ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 3699590837bSKentaro Takeda u16 perm; 3707762fbffSTetsuo Handa struct tomoyo_name_union name; 3719590837bSKentaro Takeda }; 3729590837bSKentaro Takeda 373c3fa109aSTetsuo Handa /* 374a1f9bb6aSTetsuo Handa * tomoyo_path_number_acl is a structure which is used for holding an 375a1f9bb6aSTetsuo Handa * entry with one pathname and one number operation. 376a1f9bb6aSTetsuo Handa * It has following fields. 377a1f9bb6aSTetsuo Handa * 378a1f9bb6aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 379a1f9bb6aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 380a1f9bb6aSTetsuo Handa * (3) "name" is the pathname. 381a1f9bb6aSTetsuo Handa * (4) "number" is the numeric value. 382a1f9bb6aSTetsuo Handa * 383a1f9bb6aSTetsuo Handa * Directives held by this structure are "allow_create", "allow_mkdir", 384a1f9bb6aSTetsuo Handa * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown" 385a1f9bb6aSTetsuo Handa * and "allow_chgrp". 386a1f9bb6aSTetsuo Handa * 387a1f9bb6aSTetsuo Handa */ 388a1f9bb6aSTetsuo Handa struct tomoyo_path_number_acl { 389a1f9bb6aSTetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ 390a1f9bb6aSTetsuo Handa u8 perm; 391a1f9bb6aSTetsuo Handa struct tomoyo_name_union name; 392a1f9bb6aSTetsuo Handa struct tomoyo_number_union number; 393a1f9bb6aSTetsuo Handa }; 394a1f9bb6aSTetsuo Handa 395a1f9bb6aSTetsuo Handa /* 396a1f9bb6aSTetsuo Handa * tomoyo_path_number3_acl is a structure which is used for holding an 397a1f9bb6aSTetsuo Handa * entry with one pathname and three numbers operation. 398a1f9bb6aSTetsuo Handa * It has following fields. 399a1f9bb6aSTetsuo Handa * 400a1f9bb6aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 401a1f9bb6aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 402a1f9bb6aSTetsuo Handa * (3) "mode" is the create mode. 403a1f9bb6aSTetsuo Handa * (4) "major" is the major number of device node. 404a1f9bb6aSTetsuo Handa * (5) "minor" is the minor number of device node. 405a1f9bb6aSTetsuo Handa * 406a1f9bb6aSTetsuo Handa * Directives held by this structure are "allow_mkchar", "allow_mkblock". 407a1f9bb6aSTetsuo Handa * 408a1f9bb6aSTetsuo Handa */ 409a1f9bb6aSTetsuo Handa struct tomoyo_path_number3_acl { 410a1f9bb6aSTetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER3_ACL */ 411a1f9bb6aSTetsuo Handa u8 perm; 412a1f9bb6aSTetsuo Handa struct tomoyo_name_union name; 413a1f9bb6aSTetsuo Handa struct tomoyo_number_union mode; 414a1f9bb6aSTetsuo Handa struct tomoyo_number_union major; 415a1f9bb6aSTetsuo Handa struct tomoyo_number_union minor; 416a1f9bb6aSTetsuo Handa }; 417a1f9bb6aSTetsuo Handa 418a1f9bb6aSTetsuo Handa /* 4197ef61233STetsuo Handa * tomoyo_path2_acl is a structure which is used for holding an 420937bf613STetsuo Handa * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). 421c3fa109aSTetsuo Handa * It has following fields. 422c3fa109aSTetsuo Handa * 423c3fa109aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 424c3fa109aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 4257762fbffSTetsuo Handa * (3) "name1" is the source/old pathname. 4267762fbffSTetsuo Handa * (4) "name2" is the destination/new pathname. 427c3fa109aSTetsuo Handa * 428937bf613STetsuo Handa * Directives held by this structure are "allow_rename", "allow_link" and 429937bf613STetsuo Handa * "allow_pivot_root". 430c3fa109aSTetsuo Handa */ 4317ef61233STetsuo Handa struct tomoyo_path2_acl { 4327ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ 4339590837bSKentaro Takeda u8 perm; 4347762fbffSTetsuo Handa struct tomoyo_name_union name1; 4357762fbffSTetsuo Handa struct tomoyo_name_union name2; 4369590837bSKentaro Takeda }; 4379590837bSKentaro Takeda 438c3fa109aSTetsuo Handa /* 4392106ccd9STetsuo Handa * tomoyo_mount_acl is a structure which is used for holding an 4402106ccd9STetsuo Handa * entry for mount operation. 4412106ccd9STetsuo Handa * It has following fields. 4422106ccd9STetsuo Handa * 4432106ccd9STetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 4442106ccd9STetsuo Handa * (2) "is_deleted" is boolean. 4452106ccd9STetsuo Handa * (3) "dev_name" is the device name. 4462106ccd9STetsuo Handa * (4) "dir_name" is the mount point. 4472106ccd9STetsuo Handa * (5) "flags" is the mount flags. 4482106ccd9STetsuo Handa * 4492106ccd9STetsuo Handa * Directives held by this structure are "allow_rename", "allow_link" and 4502106ccd9STetsuo Handa * "allow_pivot_root". 4512106ccd9STetsuo Handa */ 4522106ccd9STetsuo Handa struct tomoyo_mount_acl { 4532106ccd9STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ 4542106ccd9STetsuo Handa bool is_deleted; 4552106ccd9STetsuo Handa struct tomoyo_name_union dev_name; 4562106ccd9STetsuo Handa struct tomoyo_name_union dir_name; 4572106ccd9STetsuo Handa struct tomoyo_name_union fs_type; 4582106ccd9STetsuo Handa struct tomoyo_number_union flags; 4592106ccd9STetsuo Handa }; 4602106ccd9STetsuo Handa 4612106ccd9STetsuo Handa /* 462c3fa109aSTetsuo Handa * tomoyo_io_buffer is a structure which is used for reading and modifying 463c3fa109aSTetsuo Handa * configuration via /sys/kernel/security/tomoyo/ interface. 464c3fa109aSTetsuo Handa * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as 465c3fa109aSTetsuo Handa * cursors. 466c3fa109aSTetsuo Handa * 467c3fa109aSTetsuo Handa * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of 468c3fa109aSTetsuo Handa * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info" 469c3fa109aSTetsuo Handa * entry has a list of "struct tomoyo_acl_info", we need two cursors when 470c3fa109aSTetsuo Handa * reading (one is for traversing tomoyo_domain_list and the other is for 471c3fa109aSTetsuo Handa * traversing "struct tomoyo_acl_info"->acl_info_list ). 472c3fa109aSTetsuo Handa * 473c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 474c3fa109aSTetsuo Handa * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the 475c3fa109aSTetsuo Handa * domain with the domainname specified by the rest of that line (NULL is set 476c3fa109aSTetsuo Handa * if seek failed). 477c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 478c3fa109aSTetsuo Handa * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that 479c3fa109aSTetsuo Handa * line (->write_var1 is set to NULL if a domain was deleted). 480c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 481c3fa109aSTetsuo Handa * neither "select " nor "delete ", an entry or a domain specified by that line 482c3fa109aSTetsuo Handa * is appended. 483c3fa109aSTetsuo Handa */ 4849590837bSKentaro Takeda struct tomoyo_io_buffer { 4859590837bSKentaro Takeda int (*read) (struct tomoyo_io_buffer *); 4869590837bSKentaro Takeda int (*write) (struct tomoyo_io_buffer *); 4879590837bSKentaro Takeda /* Exclusive lock for this structure. */ 4889590837bSKentaro Takeda struct mutex io_sem; 489fdb8ebb7STetsuo Handa /* Index returned by tomoyo_read_lock(). */ 490fdb8ebb7STetsuo Handa int reader_idx; 4919590837bSKentaro Takeda /* The position currently reading from. */ 4929590837bSKentaro Takeda struct list_head *read_var1; 4939590837bSKentaro Takeda /* Extra variables for reading. */ 4949590837bSKentaro Takeda struct list_head *read_var2; 4959590837bSKentaro Takeda /* The position currently writing to. */ 4969590837bSKentaro Takeda struct tomoyo_domain_info *write_var1; 4979590837bSKentaro Takeda /* The step for reading. */ 4989590837bSKentaro Takeda int read_step; 4999590837bSKentaro Takeda /* Buffer for reading. */ 5009590837bSKentaro Takeda char *read_buf; 5019590837bSKentaro Takeda /* EOF flag for reading. */ 5029590837bSKentaro Takeda bool read_eof; 5039590837bSKentaro Takeda /* Read domain ACL of specified PID? */ 5049590837bSKentaro Takeda bool read_single_domain; 5059590837bSKentaro Takeda /* Extra variable for reading. */ 5069590837bSKentaro Takeda u8 read_bit; 5079590837bSKentaro Takeda /* Bytes available for reading. */ 5089590837bSKentaro Takeda int read_avail; 5099590837bSKentaro Takeda /* Size of read buffer. */ 5109590837bSKentaro Takeda int readbuf_size; 5119590837bSKentaro Takeda /* Buffer for writing. */ 5129590837bSKentaro Takeda char *write_buf; 5139590837bSKentaro Takeda /* Bytes available for writing. */ 5149590837bSKentaro Takeda int write_avail; 5159590837bSKentaro Takeda /* Size of write buffer. */ 5169590837bSKentaro Takeda int writebuf_size; 5179590837bSKentaro Takeda }; 5189590837bSKentaro Takeda 51976bb0895STetsuo Handa /* 52076bb0895STetsuo Handa * tomoyo_globally_readable_file_entry is a structure which is used for holding 52176bb0895STetsuo Handa * "allow_read" entries. 52276bb0895STetsuo Handa * It has following fields. 52376bb0895STetsuo Handa * 52476bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_globally_readable_list . 52576bb0895STetsuo Handa * (2) "filename" is a pathname which is allowed to open(O_RDONLY). 52676bb0895STetsuo Handa * (3) "is_deleted" is a bool which is true if marked as deleted, false 52776bb0895STetsuo Handa * otherwise. 52876bb0895STetsuo Handa */ 52976bb0895STetsuo Handa struct tomoyo_globally_readable_file_entry { 53076bb0895STetsuo Handa struct list_head list; 53176bb0895STetsuo Handa const struct tomoyo_path_info *filename; 53276bb0895STetsuo Handa bool is_deleted; 53376bb0895STetsuo Handa }; 53476bb0895STetsuo Handa 53576bb0895STetsuo Handa /* 53676bb0895STetsuo Handa * tomoyo_pattern_entry is a structure which is used for holding 53776bb0895STetsuo Handa * "tomoyo_pattern_list" entries. 53876bb0895STetsuo Handa * It has following fields. 53976bb0895STetsuo Handa * 54076bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_pattern_list . 54176bb0895STetsuo Handa * (2) "pattern" is a pathname pattern which is used for converting pathnames 54276bb0895STetsuo Handa * to pathname patterns during learning mode. 54376bb0895STetsuo Handa * (3) "is_deleted" is a bool which is true if marked as deleted, false 54476bb0895STetsuo Handa * otherwise. 54576bb0895STetsuo Handa */ 54676bb0895STetsuo Handa struct tomoyo_pattern_entry { 54776bb0895STetsuo Handa struct list_head list; 54876bb0895STetsuo Handa const struct tomoyo_path_info *pattern; 54976bb0895STetsuo Handa bool is_deleted; 55076bb0895STetsuo Handa }; 55176bb0895STetsuo Handa 55276bb0895STetsuo Handa /* 55376bb0895STetsuo Handa * tomoyo_no_rewrite_entry is a structure which is used for holding 55476bb0895STetsuo Handa * "deny_rewrite" entries. 55576bb0895STetsuo Handa * It has following fields. 55676bb0895STetsuo Handa * 55776bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_no_rewrite_list . 55876bb0895STetsuo Handa * (2) "pattern" is a pathname which is by default not permitted to modify 55976bb0895STetsuo Handa * already existing content. 56076bb0895STetsuo Handa * (3) "is_deleted" is a bool which is true if marked as deleted, false 56176bb0895STetsuo Handa * otherwise. 56276bb0895STetsuo Handa */ 56376bb0895STetsuo Handa struct tomoyo_no_rewrite_entry { 56476bb0895STetsuo Handa struct list_head list; 56576bb0895STetsuo Handa const struct tomoyo_path_info *pattern; 56676bb0895STetsuo Handa bool is_deleted; 56776bb0895STetsuo Handa }; 56876bb0895STetsuo Handa 56976bb0895STetsuo Handa /* 57076bb0895STetsuo Handa * tomoyo_domain_initializer_entry is a structure which is used for holding 57176bb0895STetsuo Handa * "initialize_domain" and "no_initialize_domain" entries. 57276bb0895STetsuo Handa * It has following fields. 57376bb0895STetsuo Handa * 57476bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_domain_initializer_list . 57576bb0895STetsuo Handa * (2) "domainname" which is "a domainname" or "the last component of a 57676bb0895STetsuo Handa * domainname". This field is NULL if "from" clause is not specified. 57776bb0895STetsuo Handa * (3) "program" which is a program's pathname. 57876bb0895STetsuo Handa * (4) "is_deleted" is a bool which is true if marked as deleted, false 57976bb0895STetsuo Handa * otherwise. 58076bb0895STetsuo Handa * (5) "is_not" is a bool which is true if "no_initialize_domain", false 58176bb0895STetsuo Handa * otherwise. 58276bb0895STetsuo Handa * (6) "is_last_name" is a bool which is true if "domainname" is "the last 58376bb0895STetsuo Handa * component of a domainname", false otherwise. 58476bb0895STetsuo Handa */ 58576bb0895STetsuo Handa struct tomoyo_domain_initializer_entry { 58676bb0895STetsuo Handa struct list_head list; 58776bb0895STetsuo Handa const struct tomoyo_path_info *domainname; /* This may be NULL */ 58876bb0895STetsuo Handa const struct tomoyo_path_info *program; 58976bb0895STetsuo Handa bool is_deleted; 59076bb0895STetsuo Handa bool is_not; /* True if this entry is "no_initialize_domain". */ 59176bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 59276bb0895STetsuo Handa bool is_last_name; 59376bb0895STetsuo Handa }; 59476bb0895STetsuo Handa 59576bb0895STetsuo Handa /* 59676bb0895STetsuo Handa * tomoyo_domain_keeper_entry is a structure which is used for holding 59776bb0895STetsuo Handa * "keep_domain" and "no_keep_domain" entries. 59876bb0895STetsuo Handa * It has following fields. 59976bb0895STetsuo Handa * 60076bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_domain_keeper_list . 60176bb0895STetsuo Handa * (2) "domainname" which is "a domainname" or "the last component of a 60276bb0895STetsuo Handa * domainname". 60376bb0895STetsuo Handa * (3) "program" which is a program's pathname. 60476bb0895STetsuo Handa * This field is NULL if "from" clause is not specified. 60576bb0895STetsuo Handa * (4) "is_deleted" is a bool which is true if marked as deleted, false 60676bb0895STetsuo Handa * otherwise. 60776bb0895STetsuo Handa * (5) "is_not" is a bool which is true if "no_initialize_domain", false 60876bb0895STetsuo Handa * otherwise. 60976bb0895STetsuo Handa * (6) "is_last_name" is a bool which is true if "domainname" is "the last 61076bb0895STetsuo Handa * component of a domainname", false otherwise. 61176bb0895STetsuo Handa */ 61276bb0895STetsuo Handa struct tomoyo_domain_keeper_entry { 61376bb0895STetsuo Handa struct list_head list; 61476bb0895STetsuo Handa const struct tomoyo_path_info *domainname; 61576bb0895STetsuo Handa const struct tomoyo_path_info *program; /* This may be NULL */ 61676bb0895STetsuo Handa bool is_deleted; 61776bb0895STetsuo Handa bool is_not; /* True if this entry is "no_keep_domain". */ 61876bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 61976bb0895STetsuo Handa bool is_last_name; 62076bb0895STetsuo Handa }; 62176bb0895STetsuo Handa 62276bb0895STetsuo Handa /* 62376bb0895STetsuo Handa * tomoyo_alias_entry is a structure which is used for holding "alias" entries. 62476bb0895STetsuo Handa * It has following fields. 62576bb0895STetsuo Handa * 62676bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_alias_list . 62776bb0895STetsuo Handa * (2) "original_name" which is a dereferenced pathname. 62876bb0895STetsuo Handa * (3) "aliased_name" which is a symlink's pathname. 62976bb0895STetsuo Handa * (4) "is_deleted" is a bool which is true if marked as deleted, false 63076bb0895STetsuo Handa * otherwise. 63176bb0895STetsuo Handa */ 63276bb0895STetsuo Handa struct tomoyo_alias_entry { 63376bb0895STetsuo Handa struct list_head list; 63476bb0895STetsuo Handa const struct tomoyo_path_info *original_name; 63576bb0895STetsuo Handa const struct tomoyo_path_info *aliased_name; 63676bb0895STetsuo Handa bool is_deleted; 63776bb0895STetsuo Handa }; 63876bb0895STetsuo Handa 63976bb0895STetsuo Handa /* 64076bb0895STetsuo Handa * tomoyo_policy_manager_entry is a structure which is used for holding list of 64176bb0895STetsuo Handa * domainnames or programs which are permitted to modify configuration via 64276bb0895STetsuo Handa * /sys/kernel/security/tomoyo/ interface. 64376bb0895STetsuo Handa * It has following fields. 64476bb0895STetsuo Handa * 64576bb0895STetsuo Handa * (1) "list" which is linked to tomoyo_policy_manager_list . 64676bb0895STetsuo Handa * (2) "manager" is a domainname or a program's pathname. 64776bb0895STetsuo Handa * (3) "is_domain" is a bool which is true if "manager" is a domainname, false 64876bb0895STetsuo Handa * otherwise. 64976bb0895STetsuo Handa * (4) "is_deleted" is a bool which is true if marked as deleted, false 65076bb0895STetsuo Handa * otherwise. 65176bb0895STetsuo Handa */ 65276bb0895STetsuo Handa struct tomoyo_policy_manager_entry { 65376bb0895STetsuo Handa struct list_head list; 65476bb0895STetsuo Handa /* A path to program or a domainname. */ 65576bb0895STetsuo Handa const struct tomoyo_path_info *manager; 65676bb0895STetsuo Handa bool is_domain; /* True if manager is a domainname. */ 65776bb0895STetsuo Handa bool is_deleted; /* True if this entry is deleted. */ 65876bb0895STetsuo Handa }; 65976bb0895STetsuo Handa 66076bb0895STetsuo Handa /********** Function prototypes. **********/ 66176bb0895STetsuo Handa 6627762fbffSTetsuo Handa /* Check whether the given name matches the given name_union. */ 6637762fbffSTetsuo Handa bool tomoyo_compare_name_union(const struct tomoyo_path_info *name, 6647762fbffSTetsuo Handa const struct tomoyo_name_union *ptr); 6652106ccd9STetsuo Handa /* Check whether the given number matches the given number_union. */ 6662106ccd9STetsuo Handa bool tomoyo_compare_number_union(const unsigned long value, 6672106ccd9STetsuo Handa const struct tomoyo_number_union *ptr); 6689590837bSKentaro Takeda /* Check whether the domain has too many ACL entries to hold. */ 669cb0abe6aSTetsuo Handa bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); 6709590837bSKentaro Takeda /* Transactional sprintf() for policy dump. */ 6719590837bSKentaro Takeda bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) 6729590837bSKentaro Takeda __attribute__ ((format(printf, 2, 3))); 6739590837bSKentaro Takeda /* Check whether the domainname is correct. */ 67417080008STetsuo Handa bool tomoyo_is_correct_domain(const unsigned char *domainname); 6759590837bSKentaro Takeda /* Check whether the token is correct. */ 6769590837bSKentaro Takeda bool tomoyo_is_correct_path(const char *filename, const s8 start_type, 67717080008STetsuo Handa const s8 pattern_type, const s8 end_type); 6789590837bSKentaro Takeda /* Check whether the token can be a domainname. */ 6799590837bSKentaro Takeda bool tomoyo_is_domain_def(const unsigned char *buffer); 6807762fbffSTetsuo Handa bool tomoyo_parse_name_union(const char *filename, 6817762fbffSTetsuo Handa struct tomoyo_name_union *ptr); 6827762fbffSTetsuo Handa /* Check whether the given filename matches the given path_group. */ 6837762fbffSTetsuo Handa bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, 6847762fbffSTetsuo Handa const struct tomoyo_path_group *group, 6857762fbffSTetsuo Handa const bool may_use_pattern); 6864c3e9e2dSTetsuo Handa /* Check whether the given value matches the given number_group. */ 6874c3e9e2dSTetsuo Handa bool tomoyo_number_matches_group(const unsigned long min, 6884c3e9e2dSTetsuo Handa const unsigned long max, 6894c3e9e2dSTetsuo Handa const struct tomoyo_number_group *group); 6909590837bSKentaro Takeda /* Check whether the given filename matches the given pattern. */ 6919590837bSKentaro Takeda bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 6929590837bSKentaro Takeda const struct tomoyo_path_info *pattern); 6934c3e9e2dSTetsuo Handa 6944c3e9e2dSTetsuo Handa bool tomoyo_print_number_union(struct tomoyo_io_buffer *head, 6954c3e9e2dSTetsuo Handa const struct tomoyo_number_union *ptr); 6964c3e9e2dSTetsuo Handa bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num); 6974c3e9e2dSTetsuo Handa 6989590837bSKentaro Takeda /* Read "alias" entry in exception policy. */ 6999590837bSKentaro Takeda bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head); 7009590837bSKentaro Takeda /* 7019590837bSKentaro Takeda * Read "initialize_domain" and "no_initialize_domain" entry 7029590837bSKentaro Takeda * in exception policy. 7039590837bSKentaro Takeda */ 7049590837bSKentaro Takeda bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head); 7059590837bSKentaro Takeda /* Read "keep_domain" and "no_keep_domain" entry in exception policy. */ 7069590837bSKentaro Takeda bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head); 7079590837bSKentaro Takeda /* Read "file_pattern" entry in exception policy. */ 7089590837bSKentaro Takeda bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head); 7097762fbffSTetsuo Handa /* Read "path_group" entry in exception policy. */ 7107762fbffSTetsuo Handa bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head); 7114c3e9e2dSTetsuo Handa /* Read "number_group" entry in exception policy. */ 7124c3e9e2dSTetsuo Handa bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head); 7139590837bSKentaro Takeda /* Read "allow_read" entry in exception policy. */ 7149590837bSKentaro Takeda bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head); 7159590837bSKentaro Takeda /* Read "deny_rewrite" entry in exception policy. */ 7169590837bSKentaro Takeda bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head); 7177762fbffSTetsuo Handa /* Tokenize a line. */ 7187762fbffSTetsuo Handa bool tomoyo_tokenize(char *buffer, char *w[], size_t size); 7199590837bSKentaro Takeda /* Write domain policy violation warning message to console? */ 7209590837bSKentaro Takeda bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); 7219590837bSKentaro Takeda /* Convert double path operation to operation name. */ 7227ef61233STetsuo Handa const char *tomoyo_path22keyword(const u8 operation); 723a1f9bb6aSTetsuo Handa const char *tomoyo_path_number2keyword(const u8 operation); 724a1f9bb6aSTetsuo Handa const char *tomoyo_path_number32keyword(const u8 operation); 7259590837bSKentaro Takeda /* Get the last component of the given domainname. */ 7269590837bSKentaro Takeda const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); 7279590837bSKentaro Takeda /* Convert single path operation to operation name. */ 7287ef61233STetsuo Handa const char *tomoyo_path2keyword(const u8 operation); 7292106ccd9STetsuo Handa /* Fill "struct tomoyo_request_info". */ 7302106ccd9STetsuo Handa int tomoyo_init_request_info(struct tomoyo_request_info *r, 7312106ccd9STetsuo Handa struct tomoyo_domain_info *domain); 7322106ccd9STetsuo Handa /* Check permission for mount operation. */ 7332106ccd9STetsuo Handa int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, 7342106ccd9STetsuo Handa unsigned long flags, void *data_page); 7359590837bSKentaro Takeda /* Create "alias" entry in exception policy. */ 7369590837bSKentaro Takeda int tomoyo_write_alias_policy(char *data, const bool is_delete); 7379590837bSKentaro Takeda /* 7389590837bSKentaro Takeda * Create "initialize_domain" and "no_initialize_domain" entry 7399590837bSKentaro Takeda * in exception policy. 7409590837bSKentaro Takeda */ 7419590837bSKentaro Takeda int tomoyo_write_domain_initializer_policy(char *data, const bool is_not, 7429590837bSKentaro Takeda const bool is_delete); 7439590837bSKentaro Takeda /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */ 7449590837bSKentaro Takeda int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, 7459590837bSKentaro Takeda const bool is_delete); 7469590837bSKentaro Takeda /* 7479590837bSKentaro Takeda * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", 7489590837bSKentaro Takeda * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", 7499590837bSKentaro Takeda * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", 7509590837bSKentaro Takeda * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and 7519590837bSKentaro Takeda * "allow_link" entry in domain policy. 7529590837bSKentaro Takeda */ 7539590837bSKentaro Takeda int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, 7549590837bSKentaro Takeda const bool is_delete); 7559590837bSKentaro Takeda /* Create "allow_read" entry in exception policy. */ 7569590837bSKentaro Takeda int tomoyo_write_globally_readable_policy(char *data, const bool is_delete); 7572106ccd9STetsuo Handa /* Create "allow_mount" entry in domain policy. */ 7582106ccd9STetsuo Handa int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain, 7592106ccd9STetsuo Handa const bool is_delete); 7609590837bSKentaro Takeda /* Create "deny_rewrite" entry in exception policy. */ 7619590837bSKentaro Takeda int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); 7629590837bSKentaro Takeda /* Create "file_pattern" entry in exception policy. */ 7639590837bSKentaro Takeda int tomoyo_write_pattern_policy(char *data, const bool is_delete); 7647762fbffSTetsuo Handa /* Create "path_group" entry in exception policy. */ 7657762fbffSTetsuo Handa int tomoyo_write_path_group_policy(char *data, const bool is_delete); 7664c3e9e2dSTetsuo Handa /* Create "number_group" entry in exception policy. */ 7674c3e9e2dSTetsuo Handa int tomoyo_write_number_group_policy(char *data, const bool is_delete); 7689590837bSKentaro Takeda /* Find a domain by the given name. */ 7699590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 7709590837bSKentaro Takeda /* Find or create a domain by the given name. */ 7719590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * 7729590837bSKentaro Takeda domainname, 7739590837bSKentaro Takeda const u8 profile); 7742106ccd9STetsuo Handa /* Get patterned pathname. */ 7752106ccd9STetsuo Handa const struct tomoyo_path_info * 7762106ccd9STetsuo Handa tomoyo_get_file_pattern(const struct tomoyo_path_info *filename); 7777762fbffSTetsuo Handa /* Allocate memory for "struct tomoyo_path_group". */ 7787762fbffSTetsuo Handa struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name); 7794c3e9e2dSTetsuo Handa struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name); 7807762fbffSTetsuo Handa 7819590837bSKentaro Takeda /* Check mode for specified functionality. */ 7829590837bSKentaro Takeda unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 7839590837bSKentaro Takeda const u8 index); 7849590837bSKentaro Takeda /* Fill in "struct tomoyo_path_info" members. */ 7859590837bSKentaro Takeda void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 7869590837bSKentaro Takeda /* Run policy loader when /sbin/init starts. */ 7879590837bSKentaro Takeda void tomoyo_load_policy(const char *filename); 7889590837bSKentaro Takeda 7894c3e9e2dSTetsuo Handa void tomoyo_put_number_union(struct tomoyo_number_union *ptr); 7904c3e9e2dSTetsuo Handa 79176bb0895STetsuo Handa /* Convert binary string to ascii string. */ 79276bb0895STetsuo Handa int tomoyo_encode(char *buffer, int buflen, const char *str); 79376bb0895STetsuo Handa 79476bb0895STetsuo Handa /* Returns realpath(3) of the given pathname but ignores chroot'ed root. */ 79576bb0895STetsuo Handa int tomoyo_realpath_from_path2(struct path *path, char *newname, 79676bb0895STetsuo Handa int newname_len); 79776bb0895STetsuo Handa 79876bb0895STetsuo Handa /* 79976bb0895STetsuo Handa * Returns realpath(3) of the given pathname but ignores chroot'ed root. 80076bb0895STetsuo Handa * These functions use kzalloc(), so the caller must call kfree() 80176bb0895STetsuo Handa * if these functions didn't return NULL. 80276bb0895STetsuo Handa */ 80376bb0895STetsuo Handa char *tomoyo_realpath(const char *pathname); 80476bb0895STetsuo Handa /* 80576bb0895STetsuo Handa * Same with tomoyo_realpath() except that it doesn't follow the final symlink. 80676bb0895STetsuo Handa */ 80776bb0895STetsuo Handa char *tomoyo_realpath_nofollow(const char *pathname); 80876bb0895STetsuo Handa /* Same with tomoyo_realpath() except that the pathname is already solved. */ 80976bb0895STetsuo Handa char *tomoyo_realpath_from_path(struct path *path); 81076bb0895STetsuo Handa 81176bb0895STetsuo Handa /* Check memory quota. */ 81276bb0895STetsuo Handa bool tomoyo_memory_ok(void *ptr); 8139e4b50e9STetsuo Handa void *tomoyo_commit_ok(void *data, const unsigned int size); 81476bb0895STetsuo Handa 81576bb0895STetsuo Handa /* 81676bb0895STetsuo Handa * Keep the given name on the RAM. 81776bb0895STetsuo Handa * The RAM is shared, so NEVER try to modify or kfree() the returned name. 81876bb0895STetsuo Handa */ 81976bb0895STetsuo Handa const struct tomoyo_path_info *tomoyo_get_name(const char *name); 82076bb0895STetsuo Handa 82176bb0895STetsuo Handa /* Check for memory usage. */ 82276bb0895STetsuo Handa int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); 82376bb0895STetsuo Handa 82476bb0895STetsuo Handa /* Set memory quota. */ 82576bb0895STetsuo Handa int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); 82676bb0895STetsuo Handa 82776bb0895STetsuo Handa /* Initialize realpath related code. */ 82876bb0895STetsuo Handa void __init tomoyo_realpath_init(void); 82976bb0895STetsuo Handa int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain, 83076bb0895STetsuo Handa const struct tomoyo_path_info *filename); 83176bb0895STetsuo Handa int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 83276bb0895STetsuo Handa struct path *path, const int flag); 833a1f9bb6aSTetsuo Handa int tomoyo_path_number_perm(const u8 operation, struct path *path, 834a1f9bb6aSTetsuo Handa unsigned long number); 835a1f9bb6aSTetsuo Handa int tomoyo_path_number3_perm(const u8 operation, struct path *path, 836a1f9bb6aSTetsuo Handa const unsigned int mode, unsigned int dev); 83797d6931eSTetsuo Handa int tomoyo_path_perm(const u8 operation, struct path *path); 83897d6931eSTetsuo Handa int tomoyo_path2_perm(const u8 operation, struct path *path1, 83997d6931eSTetsuo Handa struct path *path2); 84076bb0895STetsuo Handa int tomoyo_find_next_domain(struct linux_binprm *bprm); 84176bb0895STetsuo Handa 842a1f9bb6aSTetsuo Handa void tomoyo_print_ulong(char *buffer, const int buffer_len, 843a1f9bb6aSTetsuo Handa const unsigned long value, const u8 type); 844a1f9bb6aSTetsuo Handa 8457762fbffSTetsuo Handa /* Drop refcount on tomoyo_name_union. */ 8467762fbffSTetsuo Handa void tomoyo_put_name_union(struct tomoyo_name_union *ptr); 8477762fbffSTetsuo Handa 848847b173eSTetsuo Handa /* Run garbage collector. */ 849847b173eSTetsuo Handa void tomoyo_run_gc(void); 850847b173eSTetsuo Handa 851847b173eSTetsuo Handa void tomoyo_memory_free(void *ptr); 852847b173eSTetsuo Handa 85376bb0895STetsuo Handa /********** External variable definitions. **********/ 85476bb0895STetsuo Handa 85576bb0895STetsuo Handa /* Lock for GC. */ 85676bb0895STetsuo Handa extern struct srcu_struct tomoyo_ss; 85776bb0895STetsuo Handa 85876bb0895STetsuo Handa /* The list for "struct tomoyo_domain_info". */ 85976bb0895STetsuo Handa extern struct list_head tomoyo_domain_list; 86076bb0895STetsuo Handa 8617762fbffSTetsuo Handa extern struct list_head tomoyo_path_group_list; 8624c3e9e2dSTetsuo Handa extern struct list_head tomoyo_number_group_list; 863847b173eSTetsuo Handa extern struct list_head tomoyo_domain_initializer_list; 864847b173eSTetsuo Handa extern struct list_head tomoyo_domain_keeper_list; 865847b173eSTetsuo Handa extern struct list_head tomoyo_alias_list; 866847b173eSTetsuo Handa extern struct list_head tomoyo_globally_readable_list; 867847b173eSTetsuo Handa extern struct list_head tomoyo_pattern_list; 868847b173eSTetsuo Handa extern struct list_head tomoyo_no_rewrite_list; 869847b173eSTetsuo Handa extern struct list_head tomoyo_policy_manager_list; 870847b173eSTetsuo Handa extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 871847b173eSTetsuo Handa 87276bb0895STetsuo Handa /* Lock for protecting policy. */ 87376bb0895STetsuo Handa extern struct mutex tomoyo_policy_lock; 87476bb0895STetsuo Handa 87576bb0895STetsuo Handa /* Has /sbin/init started? */ 87676bb0895STetsuo Handa extern bool tomoyo_policy_loaded; 87776bb0895STetsuo Handa 87876bb0895STetsuo Handa /* The kernel's domain. */ 87976bb0895STetsuo Handa extern struct tomoyo_domain_info tomoyo_kernel_domain; 88076bb0895STetsuo Handa 88176bb0895STetsuo Handa /********** Inlined functions. **********/ 88276bb0895STetsuo Handa 88376bb0895STetsuo Handa static inline int tomoyo_read_lock(void) 88476bb0895STetsuo Handa { 88576bb0895STetsuo Handa return srcu_read_lock(&tomoyo_ss); 88676bb0895STetsuo Handa } 88776bb0895STetsuo Handa 88876bb0895STetsuo Handa static inline void tomoyo_read_unlock(int idx) 88976bb0895STetsuo Handa { 89076bb0895STetsuo Handa srcu_read_unlock(&tomoyo_ss, idx); 89176bb0895STetsuo Handa } 89276bb0895STetsuo Handa 8939590837bSKentaro Takeda /* strcmp() for "struct tomoyo_path_info" structure. */ 8949590837bSKentaro Takeda static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, 8959590837bSKentaro Takeda const struct tomoyo_path_info *b) 8969590837bSKentaro Takeda { 8979590837bSKentaro Takeda return a->hash != b->hash || strcmp(a->name, b->name); 8989590837bSKentaro Takeda } 8999590837bSKentaro Takeda 9009590837bSKentaro Takeda /** 9019590837bSKentaro Takeda * tomoyo_is_valid - Check whether the character is a valid char. 9029590837bSKentaro Takeda * 9039590837bSKentaro Takeda * @c: The character to check. 9049590837bSKentaro Takeda * 9059590837bSKentaro Takeda * Returns true if @c is a valid character, false otherwise. 9069590837bSKentaro Takeda */ 9079590837bSKentaro Takeda static inline bool tomoyo_is_valid(const unsigned char c) 9089590837bSKentaro Takeda { 9099590837bSKentaro Takeda return c > ' ' && c < 127; 9109590837bSKentaro Takeda } 9119590837bSKentaro Takeda 9129590837bSKentaro Takeda /** 9139590837bSKentaro Takeda * tomoyo_is_invalid - Check whether the character is an invalid char. 9149590837bSKentaro Takeda * 9159590837bSKentaro Takeda * @c: The character to check. 9169590837bSKentaro Takeda * 9179590837bSKentaro Takeda * Returns true if @c is an invalid character, false otherwise. 9189590837bSKentaro Takeda */ 9199590837bSKentaro Takeda static inline bool tomoyo_is_invalid(const unsigned char c) 9209590837bSKentaro Takeda { 9219590837bSKentaro Takeda return c && (c <= ' ' || c >= 127); 9229590837bSKentaro Takeda } 9239590837bSKentaro Takeda 92476bb0895STetsuo Handa static inline void tomoyo_put_name(const struct tomoyo_path_info *name) 92576bb0895STetsuo Handa { 92676bb0895STetsuo Handa if (name) { 92776bb0895STetsuo Handa struct tomoyo_name_entry *ptr = 92876bb0895STetsuo Handa container_of(name, struct tomoyo_name_entry, entry); 92976bb0895STetsuo Handa atomic_dec(&ptr->users); 93076bb0895STetsuo Handa } 93176bb0895STetsuo Handa } 9329590837bSKentaro Takeda 9337762fbffSTetsuo Handa static inline void tomoyo_put_path_group(struct tomoyo_path_group *group) 9347762fbffSTetsuo Handa { 9357762fbffSTetsuo Handa if (group) 9367762fbffSTetsuo Handa atomic_dec(&group->users); 9377762fbffSTetsuo Handa } 9387762fbffSTetsuo Handa 9394c3e9e2dSTetsuo Handa static inline void tomoyo_put_number_group(struct tomoyo_number_group *group) 9404c3e9e2dSTetsuo Handa { 9414c3e9e2dSTetsuo Handa if (group) 9424c3e9e2dSTetsuo Handa atomic_dec(&group->users); 9434c3e9e2dSTetsuo Handa } 9444c3e9e2dSTetsuo Handa 94576bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_domain(void) 94676bb0895STetsuo Handa { 94776bb0895STetsuo Handa return current_cred()->security; 94876bb0895STetsuo Handa } 9499590837bSKentaro Takeda 95076bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct 95176bb0895STetsuo Handa *task) 95276bb0895STetsuo Handa { 95376bb0895STetsuo Handa return task_cred_xxx(task, security); 95476bb0895STetsuo Handa } 9559590837bSKentaro Takeda 9567762fbffSTetsuo Handa static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1, 9577762fbffSTetsuo Handa const struct tomoyo_acl_info *p2) 9587762fbffSTetsuo Handa { 9597762fbffSTetsuo Handa return p1->type == p2->type; 9607762fbffSTetsuo Handa } 9617762fbffSTetsuo Handa 9627762fbffSTetsuo Handa static inline bool tomoyo_is_same_name_union 9637762fbffSTetsuo Handa (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) 9647762fbffSTetsuo Handa { 9657762fbffSTetsuo Handa return p1->filename == p2->filename && p1->group == p2->group && 9667762fbffSTetsuo Handa p1->is_group == p2->is_group; 9677762fbffSTetsuo Handa } 9687762fbffSTetsuo Handa 9694c3e9e2dSTetsuo Handa static inline bool tomoyo_is_same_number_union 9704c3e9e2dSTetsuo Handa (const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2) 9714c3e9e2dSTetsuo Handa { 9724c3e9e2dSTetsuo Handa return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1] 9734c3e9e2dSTetsuo Handa && p1->group == p2->group && p1->min_type == p2->min_type && 9744c3e9e2dSTetsuo Handa p1->max_type == p2->max_type && p1->is_group == p2->is_group; 9754c3e9e2dSTetsuo Handa } 9764c3e9e2dSTetsuo Handa 9777762fbffSTetsuo Handa static inline bool tomoyo_is_same_path_acl(const struct tomoyo_path_acl *p1, 9787762fbffSTetsuo Handa const struct tomoyo_path_acl *p2) 9797762fbffSTetsuo Handa { 9807762fbffSTetsuo Handa return tomoyo_is_same_acl_head(&p1->head, &p2->head) && 9817762fbffSTetsuo Handa tomoyo_is_same_name_union(&p1->name, &p2->name); 9827762fbffSTetsuo Handa } 9837762fbffSTetsuo Handa 984a1f9bb6aSTetsuo Handa static inline bool tomoyo_is_same_path_number3_acl 985a1f9bb6aSTetsuo Handa (const struct tomoyo_path_number3_acl *p1, 986a1f9bb6aSTetsuo Handa const struct tomoyo_path_number3_acl *p2) 987a1f9bb6aSTetsuo Handa { 988a1f9bb6aSTetsuo Handa return tomoyo_is_same_acl_head(&p1->head, &p2->head) 989a1f9bb6aSTetsuo Handa && tomoyo_is_same_name_union(&p1->name, &p2->name) 990a1f9bb6aSTetsuo Handa && tomoyo_is_same_number_union(&p1->mode, &p2->mode) 991a1f9bb6aSTetsuo Handa && tomoyo_is_same_number_union(&p1->major, &p2->major) 992a1f9bb6aSTetsuo Handa && tomoyo_is_same_number_union(&p1->minor, &p2->minor); 993a1f9bb6aSTetsuo Handa } 994a1f9bb6aSTetsuo Handa 995a1f9bb6aSTetsuo Handa 9967762fbffSTetsuo Handa static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1, 9977762fbffSTetsuo Handa const struct tomoyo_path2_acl *p2) 9987762fbffSTetsuo Handa { 9997762fbffSTetsuo Handa return tomoyo_is_same_acl_head(&p1->head, &p2->head) && 10007762fbffSTetsuo Handa tomoyo_is_same_name_union(&p1->name1, &p2->name1) && 10017762fbffSTetsuo Handa tomoyo_is_same_name_union(&p1->name2, &p2->name2); 10027762fbffSTetsuo Handa } 10037762fbffSTetsuo Handa 1004a1f9bb6aSTetsuo Handa static inline bool tomoyo_is_same_path_number_acl 1005a1f9bb6aSTetsuo Handa (const struct tomoyo_path_number_acl *p1, 1006a1f9bb6aSTetsuo Handa const struct tomoyo_path_number_acl *p2) 1007a1f9bb6aSTetsuo Handa { 1008a1f9bb6aSTetsuo Handa return tomoyo_is_same_acl_head(&p1->head, &p2->head) 1009a1f9bb6aSTetsuo Handa && tomoyo_is_same_name_union(&p1->name, &p2->name) 1010a1f9bb6aSTetsuo Handa && tomoyo_is_same_number_union(&p1->number, &p2->number); 1011a1f9bb6aSTetsuo Handa } 1012a1f9bb6aSTetsuo Handa 10132106ccd9STetsuo Handa static inline bool tomoyo_is_same_mount_acl(const struct tomoyo_mount_acl *p1, 10142106ccd9STetsuo Handa const struct tomoyo_mount_acl *p2) 10152106ccd9STetsuo Handa { 10162106ccd9STetsuo Handa return tomoyo_is_same_acl_head(&p1->head, &p2->head) && 10172106ccd9STetsuo Handa tomoyo_is_same_name_union(&p1->dev_name, &p2->dev_name) && 10182106ccd9STetsuo Handa tomoyo_is_same_name_union(&p1->dir_name, &p2->dir_name) && 10192106ccd9STetsuo Handa tomoyo_is_same_name_union(&p1->fs_type, &p2->fs_type) && 10202106ccd9STetsuo Handa tomoyo_is_same_number_union(&p1->flags, &p2->flags); 10212106ccd9STetsuo Handa } 10222106ccd9STetsuo Handa 10239e4b50e9STetsuo Handa static inline bool tomoyo_is_same_domain_initializer_entry 10249e4b50e9STetsuo Handa (const struct tomoyo_domain_initializer_entry *p1, 10259e4b50e9STetsuo Handa const struct tomoyo_domain_initializer_entry *p2) 10269e4b50e9STetsuo Handa { 10279e4b50e9STetsuo Handa return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name 10289e4b50e9STetsuo Handa && p1->domainname == p2->domainname 10299e4b50e9STetsuo Handa && p1->program == p2->program; 10309e4b50e9STetsuo Handa } 10319e4b50e9STetsuo Handa 10329e4b50e9STetsuo Handa static inline bool tomoyo_is_same_domain_keeper_entry 10339e4b50e9STetsuo Handa (const struct tomoyo_domain_keeper_entry *p1, 10349e4b50e9STetsuo Handa const struct tomoyo_domain_keeper_entry *p2) 10359e4b50e9STetsuo Handa { 10369e4b50e9STetsuo Handa return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name 10379e4b50e9STetsuo Handa && p1->domainname == p2->domainname 10389e4b50e9STetsuo Handa && p1->program == p2->program; 10399e4b50e9STetsuo Handa } 10409e4b50e9STetsuo Handa 10419e4b50e9STetsuo Handa static inline bool tomoyo_is_same_alias_entry 10429e4b50e9STetsuo Handa (const struct tomoyo_alias_entry *p1, const struct tomoyo_alias_entry *p2) 10439e4b50e9STetsuo Handa { 10449e4b50e9STetsuo Handa return p1->original_name == p2->original_name && 10459e4b50e9STetsuo Handa p1->aliased_name == p2->aliased_name; 10469e4b50e9STetsuo Handa } 10479e4b50e9STetsuo Handa 10489590837bSKentaro Takeda /** 10499590837bSKentaro Takeda * list_for_each_cookie - iterate over a list with cookie. 10509590837bSKentaro Takeda * @pos: the &struct list_head to use as a loop cursor. 10519590837bSKentaro Takeda * @cookie: the &struct list_head to use as a cookie. 10529590837bSKentaro Takeda * @head: the head for your list. 10539590837bSKentaro Takeda * 1054fdb8ebb7STetsuo Handa * Same with list_for_each_rcu() except that this primitive uses @cookie 10559590837bSKentaro Takeda * so that we can continue iteration. 10569590837bSKentaro Takeda * @cookie must be NULL when iteration starts, and @cookie will become 10579590837bSKentaro Takeda * NULL when iteration finishes. 10589590837bSKentaro Takeda */ 10599590837bSKentaro Takeda #define list_for_each_cookie(pos, cookie, head) \ 10609590837bSKentaro Takeda for (({ if (!cookie) \ 10619590837bSKentaro Takeda cookie = head; }), \ 1062fdb8ebb7STetsuo Handa pos = rcu_dereference((cookie)->next); \ 10639590837bSKentaro Takeda prefetch(pos->next), pos != (head) || ((cookie) = NULL); \ 1064fdb8ebb7STetsuo Handa (cookie) = pos, pos = rcu_dereference(pos->next)) 1065fdb8ebb7STetsuo Handa 10669590837bSKentaro Takeda #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ 1067