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> 2317fcfbd9STetsuo Handa #include <linux/poll.h> 2476bb0895STetsuo Handa struct linux_binprm; 259590837bSKentaro Takeda 2676bb0895STetsuo Handa /********** Constants definitions. **********/ 2776bb0895STetsuo Handa 2876bb0895STetsuo Handa /* 2976bb0895STetsuo Handa * TOMOYO uses this hash only when appending a string into the string 3076bb0895STetsuo Handa * table. Frequency of appending strings is very low. So we don't need 3176bb0895STetsuo Handa * large (e.g. 64k) hash size. 256 will be sufficient. 3276bb0895STetsuo Handa */ 3376bb0895STetsuo Handa #define TOMOYO_HASH_BITS 8 3476bb0895STetsuo Handa #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) 3576bb0895STetsuo Handa 36c8c57e84STetsuo Handa #define TOMOYO_EXEC_TMPSIZE 4096 3776bb0895STetsuo Handa 3876bb0895STetsuo Handa /* Profile number is an integer between 0 and 255. */ 3976bb0895STetsuo Handa #define TOMOYO_MAX_PROFILES 256 4076bb0895STetsuo Handa 41cb0abe6aSTetsuo Handa enum tomoyo_mode_index { 42cb0abe6aSTetsuo Handa TOMOYO_CONFIG_DISABLED, 43cb0abe6aSTetsuo Handa TOMOYO_CONFIG_LEARNING, 44cb0abe6aSTetsuo Handa TOMOYO_CONFIG_PERMISSIVE, 4557c2590fSTetsuo Handa TOMOYO_CONFIG_ENFORCING, 4657c2590fSTetsuo Handa TOMOYO_CONFIG_USE_DEFAULT = 255 47cb0abe6aSTetsuo Handa }; 48cb0abe6aSTetsuo Handa 4976bb0895STetsuo Handa /* Keywords for ACLs. */ 501084307cSTetsuo Handa #define TOMOYO_KEYWORD_AGGREGATOR "aggregator " 5176bb0895STetsuo Handa #define TOMOYO_KEYWORD_ALIAS "alias " 522106ccd9STetsuo Handa #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount " 5376bb0895STetsuo Handa #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " 5476bb0895STetsuo Handa #define TOMOYO_KEYWORD_DELETE "delete " 5576bb0895STetsuo Handa #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " 5676bb0895STetsuo Handa #define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern " 5776bb0895STetsuo Handa #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " 5876bb0895STetsuo Handa #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " 5976bb0895STetsuo Handa #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " 6076bb0895STetsuo Handa #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " 617762fbffSTetsuo Handa #define TOMOYO_KEYWORD_PATH_GROUP "path_group " 624c3e9e2dSTetsuo Handa #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group " 6376bb0895STetsuo Handa #define TOMOYO_KEYWORD_SELECT "select " 6476bb0895STetsuo Handa #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " 6576bb0895STetsuo Handa #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" 669b244373STetsuo Handa #define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded" 679b244373STetsuo Handa #define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed" 6876bb0895STetsuo Handa /* A domain definition starts with <kernel>. */ 6976bb0895STetsuo Handa #define TOMOYO_ROOT_NAME "<kernel>" 7076bb0895STetsuo Handa #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) 7176bb0895STetsuo Handa 724c3e9e2dSTetsuo Handa /* Value type definition. */ 734c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_INVALID 0 744c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_DECIMAL 1 754c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_OCTAL 2 764c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_HEXADECIMAL 3 774c3e9e2dSTetsuo Handa 7876bb0895STetsuo Handa /* Index numbers for Access Controls. */ 79084da356STetsuo Handa enum tomoyo_acl_entry_type_index { 807ef61233STetsuo Handa TOMOYO_TYPE_PATH_ACL, 817ef61233STetsuo Handa TOMOYO_TYPE_PATH2_ACL, 82a1f9bb6aSTetsuo Handa TOMOYO_TYPE_PATH_NUMBER_ACL, 83a1f9bb6aSTetsuo Handa TOMOYO_TYPE_PATH_NUMBER3_ACL, 842106ccd9STetsuo Handa TOMOYO_TYPE_MOUNT_ACL, 85084da356STetsuo Handa }; 8676bb0895STetsuo Handa 8776bb0895STetsuo Handa /* Index numbers for File Controls. */ 8876bb0895STetsuo Handa 8976bb0895STetsuo Handa /* 90a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically 91a1f9bb6aSTetsuo Handa * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set. 92a1f9bb6aSTetsuo Handa * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if 93a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is set. 94a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ 95a1f9bb6aSTetsuo Handa * or TOMOYO_TYPE_WRITE is cleared. 96a1f9bb6aSTetsuo Handa * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if 97a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is cleared. 9876bb0895STetsuo Handa */ 9976bb0895STetsuo Handa 100084da356STetsuo Handa enum tomoyo_path_acl_index { 1017ef61233STetsuo Handa TOMOYO_TYPE_READ_WRITE, 1027ef61233STetsuo Handa TOMOYO_TYPE_EXECUTE, 1037ef61233STetsuo Handa TOMOYO_TYPE_READ, 1047ef61233STetsuo Handa TOMOYO_TYPE_WRITE, 1057ef61233STetsuo Handa TOMOYO_TYPE_UNLINK, 1067ef61233STetsuo Handa TOMOYO_TYPE_RMDIR, 1077ef61233STetsuo Handa TOMOYO_TYPE_TRUNCATE, 1087ef61233STetsuo Handa TOMOYO_TYPE_SYMLINK, 1097ef61233STetsuo Handa TOMOYO_TYPE_REWRITE, 1107ef61233STetsuo Handa TOMOYO_TYPE_CHROOT, 1117ef61233STetsuo Handa TOMOYO_TYPE_UMOUNT, 1127ef61233STetsuo Handa TOMOYO_MAX_PATH_OPERATION 113084da356STetsuo Handa }; 11476bb0895STetsuo Handa 115237ab459STetsuo Handa #define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE)) 116237ab459STetsuo Handa 117a1f9bb6aSTetsuo Handa enum tomoyo_path_number3_acl_index { 118a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKBLOCK, 119a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKCHAR, 120a1f9bb6aSTetsuo Handa TOMOYO_MAX_PATH_NUMBER3_OPERATION 121a1f9bb6aSTetsuo Handa }; 122a1f9bb6aSTetsuo Handa 123084da356STetsuo Handa enum tomoyo_path2_acl_index { 1247ef61233STetsuo Handa TOMOYO_TYPE_LINK, 1257ef61233STetsuo Handa TOMOYO_TYPE_RENAME, 1267ef61233STetsuo Handa TOMOYO_TYPE_PIVOT_ROOT, 1277ef61233STetsuo Handa TOMOYO_MAX_PATH2_OPERATION 128084da356STetsuo Handa }; 12976bb0895STetsuo Handa 130a1f9bb6aSTetsuo Handa enum tomoyo_path_number_acl_index { 131a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CREATE, 132a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKDIR, 133a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKFIFO, 134a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKSOCK, 135a1f9bb6aSTetsuo Handa TOMOYO_TYPE_IOCTL, 136a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHMOD, 137a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHOWN, 138a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHGRP, 139a1f9bb6aSTetsuo Handa TOMOYO_MAX_PATH_NUMBER_OPERATION 140a1f9bb6aSTetsuo Handa }; 141a1f9bb6aSTetsuo Handa 142084da356STetsuo Handa enum tomoyo_securityfs_interface_index { 143084da356STetsuo Handa TOMOYO_DOMAINPOLICY, 144084da356STetsuo Handa TOMOYO_EXCEPTIONPOLICY, 145084da356STetsuo Handa TOMOYO_DOMAIN_STATUS, 146084da356STetsuo Handa TOMOYO_PROCESS_STATUS, 147084da356STetsuo Handa TOMOYO_MEMINFO, 148084da356STetsuo Handa TOMOYO_SELFDOMAIN, 149084da356STetsuo Handa TOMOYO_VERSION, 150084da356STetsuo Handa TOMOYO_PROFILE, 15117fcfbd9STetsuo Handa TOMOYO_QUERY, 152084da356STetsuo Handa TOMOYO_MANAGER 153084da356STetsuo Handa }; 15476bb0895STetsuo Handa 15557c2590fSTetsuo Handa enum tomoyo_mac_index { 15657c2590fSTetsuo Handa TOMOYO_MAC_FILE_EXECUTE, 15757c2590fSTetsuo Handa TOMOYO_MAC_FILE_OPEN, 15857c2590fSTetsuo Handa TOMOYO_MAC_FILE_CREATE, 15957c2590fSTetsuo Handa TOMOYO_MAC_FILE_UNLINK, 16057c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKDIR, 16157c2590fSTetsuo Handa TOMOYO_MAC_FILE_RMDIR, 16257c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKFIFO, 16357c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKSOCK, 16457c2590fSTetsuo Handa TOMOYO_MAC_FILE_TRUNCATE, 16557c2590fSTetsuo Handa TOMOYO_MAC_FILE_SYMLINK, 16657c2590fSTetsuo Handa TOMOYO_MAC_FILE_REWRITE, 16757c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKBLOCK, 16857c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKCHAR, 16957c2590fSTetsuo Handa TOMOYO_MAC_FILE_LINK, 17057c2590fSTetsuo Handa TOMOYO_MAC_FILE_RENAME, 17157c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHMOD, 17257c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHOWN, 17357c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHGRP, 17457c2590fSTetsuo Handa TOMOYO_MAC_FILE_IOCTL, 17557c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHROOT, 17657c2590fSTetsuo Handa TOMOYO_MAC_FILE_MOUNT, 17757c2590fSTetsuo Handa TOMOYO_MAC_FILE_UMOUNT, 17857c2590fSTetsuo Handa TOMOYO_MAC_FILE_PIVOT_ROOT, 17957c2590fSTetsuo Handa TOMOYO_MAX_MAC_INDEX 18057c2590fSTetsuo Handa }; 18157c2590fSTetsuo Handa 18257c2590fSTetsuo Handa enum tomoyo_mac_category_index { 18357c2590fSTetsuo Handa TOMOYO_MAC_CATEGORY_FILE, 18457c2590fSTetsuo Handa TOMOYO_MAX_MAC_CATEGORY_INDEX 18557c2590fSTetsuo Handa }; 18657c2590fSTetsuo Handa 18717fcfbd9STetsuo Handa #define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */ 18817fcfbd9STetsuo Handa 18976bb0895STetsuo Handa /********** Structure definitions. **********/ 1909590837bSKentaro Takeda 191c3fa109aSTetsuo Handa /* 19282e0f001STetsuo Handa * tomoyo_acl_head is a structure which is used for holding elements not in 19382e0f001STetsuo Handa * domain policy. 19482e0f001STetsuo Handa * It has following fields. 19582e0f001STetsuo Handa * 19682e0f001STetsuo Handa * (1) "list" which is linked to tomoyo_policy_list[] . 19782e0f001STetsuo Handa * (2) "is_deleted" is a bool which is true if marked as deleted, false 19882e0f001STetsuo Handa * otherwise. 19982e0f001STetsuo Handa */ 20082e0f001STetsuo Handa struct tomoyo_acl_head { 20182e0f001STetsuo Handa struct list_head list; 20282e0f001STetsuo Handa bool is_deleted; 20382e0f001STetsuo Handa } __packed; 20482e0f001STetsuo Handa 20582e0f001STetsuo Handa /* 206cb0abe6aSTetsuo Handa * tomoyo_request_info is a structure which is used for holding 207cb0abe6aSTetsuo Handa * 208cb0abe6aSTetsuo Handa * (1) Domain information of current process. 20917fcfbd9STetsuo Handa * (2) How many retries are made for this request. 21017fcfbd9STetsuo Handa * (3) Profile number used for this request. 21117fcfbd9STetsuo Handa * (4) Access control mode of the profile. 212cb0abe6aSTetsuo Handa */ 213cb0abe6aSTetsuo Handa struct tomoyo_request_info { 214cb0abe6aSTetsuo Handa struct tomoyo_domain_info *domain; 215cf6e9a64STetsuo Handa /* For holding parameters. */ 216cf6e9a64STetsuo Handa union { 217cf6e9a64STetsuo Handa struct { 218cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 219cf6e9a64STetsuo Handa u8 operation; 220cf6e9a64STetsuo Handa } path; 221cf6e9a64STetsuo Handa struct { 222cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename1; 223cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename2; 224cf6e9a64STetsuo Handa u8 operation; 225cf6e9a64STetsuo Handa } path2; 226cf6e9a64STetsuo Handa struct { 227cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 228cf6e9a64STetsuo Handa unsigned int mode; 229cf6e9a64STetsuo Handa unsigned int major; 230cf6e9a64STetsuo Handa unsigned int minor; 231cf6e9a64STetsuo Handa u8 operation; 232cf6e9a64STetsuo Handa } mkdev; 233cf6e9a64STetsuo Handa struct { 234cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 235cf6e9a64STetsuo Handa unsigned long number; 236cf6e9a64STetsuo Handa u8 operation; 237cf6e9a64STetsuo Handa } path_number; 238cf6e9a64STetsuo Handa struct { 239cf6e9a64STetsuo Handa const struct tomoyo_path_info *type; 240cf6e9a64STetsuo Handa const struct tomoyo_path_info *dir; 241cf6e9a64STetsuo Handa const struct tomoyo_path_info *dev; 242cf6e9a64STetsuo Handa unsigned long flags; 243cf6e9a64STetsuo Handa int need_dev; 244cf6e9a64STetsuo Handa } mount; 245cf6e9a64STetsuo Handa } param; 246cf6e9a64STetsuo Handa u8 param_type; 247cf6e9a64STetsuo Handa bool granted; 24817fcfbd9STetsuo Handa u8 retry; 24917fcfbd9STetsuo Handa u8 profile; 250cb0abe6aSTetsuo Handa u8 mode; /* One of tomoyo_mode_index . */ 25157c2590fSTetsuo Handa u8 type; 252cb0abe6aSTetsuo Handa }; 253cb0abe6aSTetsuo Handa 254cb0abe6aSTetsuo Handa /* 255c3fa109aSTetsuo Handa * tomoyo_path_info is a structure which is used for holding a string data 256c3fa109aSTetsuo Handa * used by TOMOYO. 257c3fa109aSTetsuo Handa * This structure has several fields for supporting pattern matching. 258c3fa109aSTetsuo Handa * 259c3fa109aSTetsuo Handa * (1) "name" is the '\0' terminated string data. 260c3fa109aSTetsuo Handa * (2) "hash" is full_name_hash(name, strlen(name)). 261c3fa109aSTetsuo Handa * This allows tomoyo_pathcmp() to compare by hash before actually compare 262c3fa109aSTetsuo Handa * using strcmp(). 263c3fa109aSTetsuo Handa * (3) "const_len" is the length of the initial segment of "name" which 264c3fa109aSTetsuo Handa * consists entirely of non wildcard characters. In other words, the length 265c3fa109aSTetsuo Handa * which we can compare two strings using strncmp(). 266c3fa109aSTetsuo Handa * (4) "is_dir" is a bool which is true if "name" ends with "/", 267c3fa109aSTetsuo Handa * false otherwise. 268c3fa109aSTetsuo Handa * TOMOYO distinguishes directory and non-directory. A directory ends with 269c3fa109aSTetsuo Handa * "/" and non-directory does not end with "/". 270c3fa109aSTetsuo Handa * (5) "is_patterned" is a bool which is true if "name" contains wildcard 271c3fa109aSTetsuo Handa * characters, false otherwise. This allows TOMOYO to use "hash" and 272c3fa109aSTetsuo Handa * strcmp() for string comparison if "is_patterned" is false. 273c3fa109aSTetsuo Handa */ 2749590837bSKentaro Takeda struct tomoyo_path_info { 2759590837bSKentaro Takeda const char *name; 2769590837bSKentaro Takeda u32 hash; /* = full_name_hash(name, strlen(name)) */ 2779590837bSKentaro Takeda u16 const_len; /* = tomoyo_const_part_length(name) */ 2789590837bSKentaro Takeda bool is_dir; /* = tomoyo_strendswith(name, "/") */ 2799590837bSKentaro Takeda bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 2809590837bSKentaro Takeda }; 2819590837bSKentaro Takeda 2829590837bSKentaro Takeda /* 28376bb0895STetsuo Handa * tomoyo_name_entry is a structure which is used for linking 28476bb0895STetsuo Handa * "struct tomoyo_path_info" into tomoyo_name_list . 2859590837bSKentaro Takeda */ 28676bb0895STetsuo Handa struct tomoyo_name_entry { 28776bb0895STetsuo Handa struct list_head list; 28876bb0895STetsuo Handa atomic_t users; 28976bb0895STetsuo Handa struct tomoyo_path_info entry; 29076bb0895STetsuo Handa }; 2919590837bSKentaro Takeda 2927762fbffSTetsuo Handa struct tomoyo_name_union { 2937762fbffSTetsuo Handa const struct tomoyo_path_info *filename; 2947762fbffSTetsuo Handa struct tomoyo_path_group *group; 2957762fbffSTetsuo Handa u8 is_group; 2967762fbffSTetsuo Handa }; 2977762fbffSTetsuo Handa 2984c3e9e2dSTetsuo Handa struct tomoyo_number_union { 2994c3e9e2dSTetsuo Handa unsigned long values[2]; 3004c3e9e2dSTetsuo Handa struct tomoyo_number_group *group; 3014c3e9e2dSTetsuo Handa u8 min_type; 3024c3e9e2dSTetsuo Handa u8 max_type; 3034c3e9e2dSTetsuo Handa u8 is_group; 3044c3e9e2dSTetsuo Handa }; 3054c3e9e2dSTetsuo Handa 3067762fbffSTetsuo Handa /* Structure for "path_group" directive. */ 3077762fbffSTetsuo Handa struct tomoyo_path_group { 3087762fbffSTetsuo Handa struct list_head list; 3097762fbffSTetsuo Handa const struct tomoyo_path_info *group_name; 3107762fbffSTetsuo Handa struct list_head member_list; 3117762fbffSTetsuo Handa atomic_t users; 3127762fbffSTetsuo Handa }; 3137762fbffSTetsuo Handa 3144c3e9e2dSTetsuo Handa /* Structure for "number_group" directive. */ 3154c3e9e2dSTetsuo Handa struct tomoyo_number_group { 3164c3e9e2dSTetsuo Handa struct list_head list; 3174c3e9e2dSTetsuo Handa const struct tomoyo_path_info *group_name; 3184c3e9e2dSTetsuo Handa struct list_head member_list; 3194c3e9e2dSTetsuo Handa atomic_t users; 3204c3e9e2dSTetsuo Handa }; 3214c3e9e2dSTetsuo Handa 3227762fbffSTetsuo Handa /* Structure for "path_group" directive. */ 3237762fbffSTetsuo Handa struct tomoyo_path_group_member { 32482e0f001STetsuo Handa struct tomoyo_acl_head head; 3257762fbffSTetsuo Handa const struct tomoyo_path_info *member_name; 3267762fbffSTetsuo Handa }; 3277762fbffSTetsuo Handa 3284c3e9e2dSTetsuo Handa /* Structure for "number_group" directive. */ 3294c3e9e2dSTetsuo Handa struct tomoyo_number_group_member { 33082e0f001STetsuo Handa struct tomoyo_acl_head head; 3314c3e9e2dSTetsuo Handa struct tomoyo_number_union number; 3324c3e9e2dSTetsuo Handa }; 3334c3e9e2dSTetsuo Handa 3349590837bSKentaro Takeda /* 335c3fa109aSTetsuo Handa * tomoyo_acl_info is a structure which is used for holding 336c3fa109aSTetsuo Handa * 337c3fa109aSTetsuo Handa * (1) "list" which is linked to the ->acl_info_list of 338c3fa109aSTetsuo Handa * "struct tomoyo_domain_info" 339237ab459STetsuo Handa * (2) "is_deleted" is a bool which is true if this domain is marked as 340237ab459STetsuo Handa * "deleted", false otherwise. 341237ab459STetsuo Handa * (3) "type" which tells type of the entry. 3429590837bSKentaro Takeda * 3439590837bSKentaro Takeda * Packing "struct tomoyo_acl_info" allows 344237ab459STetsuo Handa * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl" 345237ab459STetsuo Handa * "struct tomoyo_path_number_acl" "struct tomoyo_path_number3_acl" to embed 346237ab459STetsuo Handa * "u8" without enlarging their structure size. 3479590837bSKentaro Takeda */ 3489590837bSKentaro Takeda struct tomoyo_acl_info { 3499590837bSKentaro Takeda struct list_head list; 350237ab459STetsuo Handa bool is_deleted; 351237ab459STetsuo Handa u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */ 3529590837bSKentaro Takeda } __packed; 3539590837bSKentaro Takeda 354c3fa109aSTetsuo Handa /* 355c3fa109aSTetsuo Handa * tomoyo_domain_info is a structure which is used for holding permissions 356c3fa109aSTetsuo Handa * (e.g. "allow_read /lib/libc-2.5.so") given to each domain. 357c3fa109aSTetsuo Handa * It has following fields. 358c3fa109aSTetsuo Handa * 359c3fa109aSTetsuo Handa * (1) "list" which is linked to tomoyo_domain_list . 360c3fa109aSTetsuo Handa * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info". 361c3fa109aSTetsuo Handa * (3) "domainname" which holds the name of the domain. 362c3fa109aSTetsuo Handa * (4) "profile" which remembers profile number assigned to this domain. 363c3fa109aSTetsuo Handa * (5) "is_deleted" is a bool which is true if this domain is marked as 364c3fa109aSTetsuo Handa * "deleted", false otherwise. 365c3fa109aSTetsuo Handa * (6) "quota_warned" is a bool which is used for suppressing warning message 366c3fa109aSTetsuo Handa * when learning mode learned too much entries. 367ea13ddbaSTetsuo Handa * (7) "ignore_global_allow_read" is a bool which is true if this domain 368ea13ddbaSTetsuo Handa * should ignore "allow_read" directive in exception policy. 369ea13ddbaSTetsuo Handa * (8) "transition_failed" is a bool which is set to true when this domain was 370ea13ddbaSTetsuo Handa * unable to create a new domain at tomoyo_find_next_domain() because the 371ea13ddbaSTetsuo Handa * name of the domain to be created was too long or it could not allocate 372ea13ddbaSTetsuo Handa * memory. If set to true, more than one process continued execve() 373ea13ddbaSTetsuo Handa * without domain transition. 374ec8e6a4eSTetsuo Handa * (9) "users" is an atomic_t that holds how many "struct cred"->security 375ec8e6a4eSTetsuo Handa * are referring this "struct tomoyo_domain_info". If is_deleted == true 376ec8e6a4eSTetsuo Handa * and users == 0, this struct will be kfree()d upon next garbage 377ec8e6a4eSTetsuo Handa * collection. 378c3fa109aSTetsuo Handa * 379c3fa109aSTetsuo Handa * A domain's lifecycle is an analogy of files on / directory. 380c3fa109aSTetsuo Handa * Multiple domains with the same domainname cannot be created (as with 381c3fa109aSTetsuo Handa * creating files with the same filename fails with -EEXIST). 382c3fa109aSTetsuo Handa * If a process reached a domain, that process can reside in that domain after 383c3fa109aSTetsuo Handa * that domain is marked as "deleted" (as with a process can access an already 384c3fa109aSTetsuo Handa * open()ed file after that file was unlink()ed). 385c3fa109aSTetsuo Handa */ 3869590837bSKentaro Takeda struct tomoyo_domain_info { 3879590837bSKentaro Takeda struct list_head list; 3889590837bSKentaro Takeda struct list_head acl_info_list; 3899590837bSKentaro Takeda /* Name of this domain. Never NULL. */ 3909590837bSKentaro Takeda const struct tomoyo_path_info *domainname; 3919590837bSKentaro Takeda u8 profile; /* Profile number to use. */ 392a0558fc3STetsuo Handa bool is_deleted; /* Delete flag. */ 3939590837bSKentaro Takeda bool quota_warned; /* Quota warnning flag. */ 394ea13ddbaSTetsuo Handa bool ignore_global_allow_read; /* Ignore "allow_read" flag. */ 395ea13ddbaSTetsuo Handa bool transition_failed; /* Domain transition failed flag. */ 396ec8e6a4eSTetsuo Handa atomic_t users; /* Number of referring credentials. */ 3979590837bSKentaro Takeda }; 3989590837bSKentaro Takeda 3999590837bSKentaro Takeda /* 4007ef61233STetsuo Handa * tomoyo_path_acl is a structure which is used for holding an 401c3fa109aSTetsuo Handa * entry with one pathname operation (e.g. open(), mkdir()). 402c3fa109aSTetsuo Handa * It has following fields. 403c3fa109aSTetsuo Handa * 404c3fa109aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 405c3fa109aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 4067762fbffSTetsuo Handa * (3) "name" is the pathname. 407c3fa109aSTetsuo Handa * 408c3fa109aSTetsuo Handa * Directives held by this structure are "allow_read/write", "allow_execute", 409a1f9bb6aSTetsuo Handa * "allow_read", "allow_write", "allow_unlink", "allow_rmdir", 4102106ccd9STetsuo Handa * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and 4112106ccd9STetsuo Handa * "allow_unmount". 4129590837bSKentaro Takeda */ 4137ef61233STetsuo Handa struct tomoyo_path_acl { 4147ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 4159590837bSKentaro Takeda u16 perm; 4167762fbffSTetsuo Handa struct tomoyo_name_union name; 4179590837bSKentaro Takeda }; 4189590837bSKentaro Takeda 419c3fa109aSTetsuo Handa /* 420a1f9bb6aSTetsuo Handa * tomoyo_path_number_acl is a structure which is used for holding an 421a1f9bb6aSTetsuo Handa * entry with one pathname and one number operation. 422a1f9bb6aSTetsuo Handa * It has following fields. 423a1f9bb6aSTetsuo Handa * 424a1f9bb6aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 425a1f9bb6aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 426a1f9bb6aSTetsuo Handa * (3) "name" is the pathname. 427a1f9bb6aSTetsuo Handa * (4) "number" is the numeric value. 428a1f9bb6aSTetsuo Handa * 429a1f9bb6aSTetsuo Handa * Directives held by this structure are "allow_create", "allow_mkdir", 430a1f9bb6aSTetsuo Handa * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown" 431a1f9bb6aSTetsuo Handa * and "allow_chgrp". 432a1f9bb6aSTetsuo Handa * 433a1f9bb6aSTetsuo Handa */ 434a1f9bb6aSTetsuo Handa struct tomoyo_path_number_acl { 435a1f9bb6aSTetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ 436a1f9bb6aSTetsuo Handa u8 perm; 437a1f9bb6aSTetsuo Handa struct tomoyo_name_union name; 438a1f9bb6aSTetsuo Handa struct tomoyo_number_union number; 439a1f9bb6aSTetsuo Handa }; 440a1f9bb6aSTetsuo Handa 441a1f9bb6aSTetsuo Handa /* 442a1f9bb6aSTetsuo Handa * tomoyo_path_number3_acl is a structure which is used for holding an 443a1f9bb6aSTetsuo Handa * entry with one pathname and three numbers operation. 444a1f9bb6aSTetsuo Handa * It has following fields. 445a1f9bb6aSTetsuo Handa * 446a1f9bb6aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 447a1f9bb6aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 448a1f9bb6aSTetsuo Handa * (3) "mode" is the create mode. 449a1f9bb6aSTetsuo Handa * (4) "major" is the major number of device node. 450a1f9bb6aSTetsuo Handa * (5) "minor" is the minor number of device node. 451a1f9bb6aSTetsuo Handa * 452a1f9bb6aSTetsuo Handa * Directives held by this structure are "allow_mkchar", "allow_mkblock". 453a1f9bb6aSTetsuo Handa * 454a1f9bb6aSTetsuo Handa */ 455a1f9bb6aSTetsuo Handa struct tomoyo_path_number3_acl { 456a1f9bb6aSTetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER3_ACL */ 457a1f9bb6aSTetsuo Handa u8 perm; 458a1f9bb6aSTetsuo Handa struct tomoyo_name_union name; 459a1f9bb6aSTetsuo Handa struct tomoyo_number_union mode; 460a1f9bb6aSTetsuo Handa struct tomoyo_number_union major; 461a1f9bb6aSTetsuo Handa struct tomoyo_number_union minor; 462a1f9bb6aSTetsuo Handa }; 463a1f9bb6aSTetsuo Handa 464a1f9bb6aSTetsuo Handa /* 4657ef61233STetsuo Handa * tomoyo_path2_acl is a structure which is used for holding an 466937bf613STetsuo Handa * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). 467c3fa109aSTetsuo Handa * It has following fields. 468c3fa109aSTetsuo Handa * 469c3fa109aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 470c3fa109aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 4717762fbffSTetsuo Handa * (3) "name1" is the source/old pathname. 4727762fbffSTetsuo Handa * (4) "name2" is the destination/new pathname. 473c3fa109aSTetsuo Handa * 474937bf613STetsuo Handa * Directives held by this structure are "allow_rename", "allow_link" and 475937bf613STetsuo Handa * "allow_pivot_root". 476c3fa109aSTetsuo Handa */ 4777ef61233STetsuo Handa struct tomoyo_path2_acl { 4787ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ 4799590837bSKentaro Takeda u8 perm; 4807762fbffSTetsuo Handa struct tomoyo_name_union name1; 4817762fbffSTetsuo Handa struct tomoyo_name_union name2; 4829590837bSKentaro Takeda }; 4839590837bSKentaro Takeda 484c3fa109aSTetsuo Handa /* 4852106ccd9STetsuo Handa * tomoyo_mount_acl is a structure which is used for holding an 4862106ccd9STetsuo Handa * entry for mount operation. 4872106ccd9STetsuo Handa * It has following fields. 4882106ccd9STetsuo Handa * 4892106ccd9STetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 490237ab459STetsuo Handa * (2) "dev_name" is the device name. 491237ab459STetsuo Handa * (3) "dir_name" is the mount point. 492237ab459STetsuo Handa * (4) "fs_type" is the filesystem type. 4932106ccd9STetsuo Handa * (5) "flags" is the mount flags. 4942106ccd9STetsuo Handa * 495237ab459STetsuo Handa * Directive held by this structure is "allow_mount". 4962106ccd9STetsuo Handa */ 4972106ccd9STetsuo Handa struct tomoyo_mount_acl { 4982106ccd9STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ 4992106ccd9STetsuo Handa struct tomoyo_name_union dev_name; 5002106ccd9STetsuo Handa struct tomoyo_name_union dir_name; 5012106ccd9STetsuo Handa struct tomoyo_name_union fs_type; 5022106ccd9STetsuo Handa struct tomoyo_number_union flags; 5032106ccd9STetsuo Handa }; 5042106ccd9STetsuo Handa 5052106ccd9STetsuo Handa /* 506c3fa109aSTetsuo Handa * tomoyo_io_buffer is a structure which is used for reading and modifying 507c3fa109aSTetsuo Handa * configuration via /sys/kernel/security/tomoyo/ interface. 508c3fa109aSTetsuo Handa * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as 509c3fa109aSTetsuo Handa * cursors. 510c3fa109aSTetsuo Handa * 511c3fa109aSTetsuo Handa * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of 512c3fa109aSTetsuo Handa * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info" 513c3fa109aSTetsuo Handa * entry has a list of "struct tomoyo_acl_info", we need two cursors when 514c3fa109aSTetsuo Handa * reading (one is for traversing tomoyo_domain_list and the other is for 515c3fa109aSTetsuo Handa * traversing "struct tomoyo_acl_info"->acl_info_list ). 516c3fa109aSTetsuo Handa * 517c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 518c3fa109aSTetsuo Handa * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the 519c3fa109aSTetsuo Handa * domain with the domainname specified by the rest of that line (NULL is set 520c3fa109aSTetsuo Handa * if seek failed). 521c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 522c3fa109aSTetsuo Handa * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that 523c3fa109aSTetsuo Handa * line (->write_var1 is set to NULL if a domain was deleted). 524c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 525c3fa109aSTetsuo Handa * neither "select " nor "delete ", an entry or a domain specified by that line 526c3fa109aSTetsuo Handa * is appended. 527c3fa109aSTetsuo Handa */ 5289590837bSKentaro Takeda struct tomoyo_io_buffer { 5299590837bSKentaro Takeda int (*read) (struct tomoyo_io_buffer *); 5309590837bSKentaro Takeda int (*write) (struct tomoyo_io_buffer *); 53117fcfbd9STetsuo Handa int (*poll) (struct file *file, poll_table *wait); 5329590837bSKentaro Takeda /* Exclusive lock for this structure. */ 5339590837bSKentaro Takeda struct mutex io_sem; 534fdb8ebb7STetsuo Handa /* Index returned by tomoyo_read_lock(). */ 535fdb8ebb7STetsuo Handa int reader_idx; 5369590837bSKentaro Takeda /* The position currently reading from. */ 5379590837bSKentaro Takeda struct list_head *read_var1; 5389590837bSKentaro Takeda /* Extra variables for reading. */ 5399590837bSKentaro Takeda struct list_head *read_var2; 5409590837bSKentaro Takeda /* The position currently writing to. */ 5419590837bSKentaro Takeda struct tomoyo_domain_info *write_var1; 5429590837bSKentaro Takeda /* The step for reading. */ 5439590837bSKentaro Takeda int read_step; 5449590837bSKentaro Takeda /* Buffer for reading. */ 5459590837bSKentaro Takeda char *read_buf; 5469590837bSKentaro Takeda /* EOF flag for reading. */ 5479590837bSKentaro Takeda bool read_eof; 5489590837bSKentaro Takeda /* Read domain ACL of specified PID? */ 5499590837bSKentaro Takeda bool read_single_domain; 5509590837bSKentaro Takeda /* Extra variable for reading. */ 5519590837bSKentaro Takeda u8 read_bit; 5529590837bSKentaro Takeda /* Bytes available for reading. */ 5539590837bSKentaro Takeda int read_avail; 5549590837bSKentaro Takeda /* Size of read buffer. */ 5559590837bSKentaro Takeda int readbuf_size; 5569590837bSKentaro Takeda /* Buffer for writing. */ 5579590837bSKentaro Takeda char *write_buf; 5589590837bSKentaro Takeda /* Bytes available for writing. */ 5599590837bSKentaro Takeda int write_avail; 5609590837bSKentaro Takeda /* Size of write buffer. */ 5619590837bSKentaro Takeda int writebuf_size; 56217fcfbd9STetsuo Handa /* Type of this interface. */ 56317fcfbd9STetsuo Handa u8 type; 5649590837bSKentaro Takeda }; 5659590837bSKentaro Takeda 56676bb0895STetsuo Handa /* 56776bb0895STetsuo Handa * tomoyo_globally_readable_file_entry is a structure which is used for holding 56876bb0895STetsuo Handa * "allow_read" entries. 56976bb0895STetsuo Handa * It has following fields. 57076bb0895STetsuo Handa * 57182e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 57276bb0895STetsuo Handa * (2) "filename" is a pathname which is allowed to open(O_RDONLY). 57376bb0895STetsuo Handa */ 57476bb0895STetsuo Handa struct tomoyo_globally_readable_file_entry { 57582e0f001STetsuo Handa struct tomoyo_acl_head head; 57676bb0895STetsuo Handa const struct tomoyo_path_info *filename; 57776bb0895STetsuo Handa }; 57876bb0895STetsuo Handa 57976bb0895STetsuo Handa /* 58076bb0895STetsuo Handa * tomoyo_pattern_entry is a structure which is used for holding 58176bb0895STetsuo Handa * "tomoyo_pattern_list" entries. 58276bb0895STetsuo Handa * It has following fields. 58376bb0895STetsuo Handa * 58482e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 58576bb0895STetsuo Handa * (2) "pattern" is a pathname pattern which is used for converting pathnames 58676bb0895STetsuo Handa * to pathname patterns during learning mode. 58776bb0895STetsuo Handa */ 58876bb0895STetsuo Handa struct tomoyo_pattern_entry { 58982e0f001STetsuo Handa struct tomoyo_acl_head head; 59076bb0895STetsuo Handa const struct tomoyo_path_info *pattern; 59176bb0895STetsuo Handa }; 59276bb0895STetsuo Handa 59376bb0895STetsuo Handa /* 59476bb0895STetsuo Handa * tomoyo_no_rewrite_entry is a structure which is used for holding 59576bb0895STetsuo Handa * "deny_rewrite" entries. 59676bb0895STetsuo Handa * It has following fields. 59776bb0895STetsuo Handa * 59882e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 59976bb0895STetsuo Handa * (2) "pattern" is a pathname which is by default not permitted to modify 60076bb0895STetsuo Handa * already existing content. 60176bb0895STetsuo Handa */ 60276bb0895STetsuo Handa struct tomoyo_no_rewrite_entry { 60382e0f001STetsuo Handa struct tomoyo_acl_head head; 60476bb0895STetsuo Handa const struct tomoyo_path_info *pattern; 60576bb0895STetsuo Handa }; 60676bb0895STetsuo Handa 60776bb0895STetsuo Handa /* 60876bb0895STetsuo Handa * tomoyo_domain_initializer_entry is a structure which is used for holding 60976bb0895STetsuo Handa * "initialize_domain" and "no_initialize_domain" entries. 61076bb0895STetsuo Handa * It has following fields. 61176bb0895STetsuo Handa * 61282e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 61382e0f001STetsuo Handa * (2) "is_not" is a bool which is true if "no_initialize_domain", false 61476bb0895STetsuo Handa * otherwise. 61582e0f001STetsuo Handa * (3) "is_last_name" is a bool which is true if "domainname" is "the last 61676bb0895STetsuo Handa * component of a domainname", false otherwise. 61782e0f001STetsuo Handa * (4) "domainname" which is "a domainname" or "the last component of a 61882e0f001STetsuo Handa * domainname". This field is NULL if "from" clause is not specified. 61982e0f001STetsuo Handa * (5) "program" which is a program's pathname. 62076bb0895STetsuo Handa */ 62176bb0895STetsuo Handa struct tomoyo_domain_initializer_entry { 62282e0f001STetsuo Handa struct tomoyo_acl_head head; 62376bb0895STetsuo Handa bool is_not; /* True if this entry is "no_initialize_domain". */ 62476bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 62576bb0895STetsuo Handa bool is_last_name; 62682e0f001STetsuo Handa const struct tomoyo_path_info *domainname; /* This may be NULL */ 62782e0f001STetsuo Handa const struct tomoyo_path_info *program; 62876bb0895STetsuo Handa }; 62976bb0895STetsuo Handa 63076bb0895STetsuo Handa /* 63176bb0895STetsuo Handa * tomoyo_domain_keeper_entry is a structure which is used for holding 63276bb0895STetsuo Handa * "keep_domain" and "no_keep_domain" entries. 63376bb0895STetsuo Handa * It has following fields. 63476bb0895STetsuo Handa * 63582e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 63682e0f001STetsuo Handa * (2) "is_not" is a bool which is true if "no_initialize_domain", false 63776bb0895STetsuo Handa * otherwise. 63882e0f001STetsuo Handa * (3) "is_last_name" is a bool which is true if "domainname" is "the last 63976bb0895STetsuo Handa * component of a domainname", false otherwise. 64082e0f001STetsuo Handa * (4) "domainname" which is "a domainname" or "the last component of a 64182e0f001STetsuo Handa * domainname". 64282e0f001STetsuo Handa * (5) "program" which is a program's pathname. 64382e0f001STetsuo Handa * This field is NULL if "from" clause is not specified. 64476bb0895STetsuo Handa */ 64576bb0895STetsuo Handa struct tomoyo_domain_keeper_entry { 64682e0f001STetsuo Handa struct tomoyo_acl_head head; 64776bb0895STetsuo Handa bool is_not; /* True if this entry is "no_keep_domain". */ 64876bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 64976bb0895STetsuo Handa bool is_last_name; 65082e0f001STetsuo Handa const struct tomoyo_path_info *domainname; 65182e0f001STetsuo Handa const struct tomoyo_path_info *program; /* This may be NULL */ 65276bb0895STetsuo Handa }; 65376bb0895STetsuo Handa 65476bb0895STetsuo Handa /* 6551084307cSTetsuo Handa * tomoyo_aggregator_entry is a structure which is used for holding 6561084307cSTetsuo Handa * "aggregator" entries. 6571084307cSTetsuo Handa * It has following fields. 6581084307cSTetsuo Handa * 65982e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 6601084307cSTetsuo Handa * (2) "original_name" which is originally requested name. 6611084307cSTetsuo Handa * (3) "aggregated_name" which is name to rewrite. 6621084307cSTetsuo Handa */ 6631084307cSTetsuo Handa struct tomoyo_aggregator_entry { 66482e0f001STetsuo Handa struct tomoyo_acl_head head; 6651084307cSTetsuo Handa const struct tomoyo_path_info *original_name; 6661084307cSTetsuo Handa const struct tomoyo_path_info *aggregated_name; 6671084307cSTetsuo Handa }; 6681084307cSTetsuo Handa 6691084307cSTetsuo Handa /* 67076bb0895STetsuo Handa * tomoyo_alias_entry is a structure which is used for holding "alias" entries. 67176bb0895STetsuo Handa * It has following fields. 67276bb0895STetsuo Handa * 67382e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 67476bb0895STetsuo Handa * (2) "original_name" which is a dereferenced pathname. 67576bb0895STetsuo Handa * (3) "aliased_name" which is a symlink's pathname. 67676bb0895STetsuo Handa */ 67776bb0895STetsuo Handa struct tomoyo_alias_entry { 67882e0f001STetsuo Handa struct tomoyo_acl_head head; 67976bb0895STetsuo Handa const struct tomoyo_path_info *original_name; 68076bb0895STetsuo Handa const struct tomoyo_path_info *aliased_name; 68176bb0895STetsuo Handa }; 68276bb0895STetsuo Handa 68376bb0895STetsuo Handa /* 68476bb0895STetsuo Handa * tomoyo_policy_manager_entry is a structure which is used for holding list of 68576bb0895STetsuo Handa * domainnames or programs which are permitted to modify configuration via 68676bb0895STetsuo Handa * /sys/kernel/security/tomoyo/ interface. 68776bb0895STetsuo Handa * It has following fields. 68876bb0895STetsuo Handa * 68982e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 69082e0f001STetsuo Handa * (2) "is_domain" is a bool which is true if "manager" is a domainname, false 69176bb0895STetsuo Handa * otherwise. 69282e0f001STetsuo Handa * (3) "manager" is a domainname or a program's pathname. 69376bb0895STetsuo Handa */ 69476bb0895STetsuo Handa struct tomoyo_policy_manager_entry { 69582e0f001STetsuo Handa struct tomoyo_acl_head head; 69682e0f001STetsuo Handa bool is_domain; /* True if manager is a domainname. */ 69776bb0895STetsuo Handa /* A path to program or a domainname. */ 69876bb0895STetsuo Handa const struct tomoyo_path_info *manager; 69976bb0895STetsuo Handa }; 70076bb0895STetsuo Handa 70157c2590fSTetsuo Handa struct tomoyo_preference { 70257c2590fSTetsuo Handa unsigned int learning_max_entry; 70357c2590fSTetsuo Handa bool enforcing_verbose; 70457c2590fSTetsuo Handa bool learning_verbose; 70557c2590fSTetsuo Handa bool permissive_verbose; 70657c2590fSTetsuo Handa }; 70757c2590fSTetsuo Handa 70857c2590fSTetsuo Handa struct tomoyo_profile { 70957c2590fSTetsuo Handa const struct tomoyo_path_info *comment; 71057c2590fSTetsuo Handa struct tomoyo_preference *learning; 71157c2590fSTetsuo Handa struct tomoyo_preference *permissive; 71257c2590fSTetsuo Handa struct tomoyo_preference *enforcing; 71357c2590fSTetsuo Handa struct tomoyo_preference preference; 71457c2590fSTetsuo Handa u8 default_config; 71557c2590fSTetsuo Handa u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; 71657c2590fSTetsuo Handa }; 71757c2590fSTetsuo Handa 71876bb0895STetsuo Handa /********** Function prototypes. **********/ 71976bb0895STetsuo Handa 72017fcfbd9STetsuo Handa extern asmlinkage long sys_getpid(void); 72117fcfbd9STetsuo Handa extern asmlinkage long sys_getppid(void); 72217fcfbd9STetsuo Handa 723c3ef1500STetsuo Handa /* Check whether the given string starts with the given keyword. */ 724c3ef1500STetsuo Handa bool tomoyo_str_starts(char **src, const char *find); 725c3ef1500STetsuo Handa /* Get tomoyo_realpath() of current process. */ 726c3ef1500STetsuo Handa const char *tomoyo_get_exe(void); 727c3ef1500STetsuo Handa /* Format string. */ 728c3ef1500STetsuo Handa void tomoyo_normalize_line(unsigned char *buffer); 729c3ef1500STetsuo Handa /* Print warning or error message on console. */ 730c3ef1500STetsuo Handa void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...) 731c3ef1500STetsuo Handa __attribute__ ((format(printf, 2, 3))); 732c3ef1500STetsuo Handa /* Check all profiles currently assigned to domains are defined. */ 733c3ef1500STetsuo Handa void tomoyo_check_profile(void); 734c3ef1500STetsuo Handa /* Open operation for /sys/kernel/security/tomoyo/ interface. */ 735c3ef1500STetsuo Handa int tomoyo_open_control(const u8 type, struct file *file); 736c3ef1500STetsuo Handa /* Close /sys/kernel/security/tomoyo/ interface. */ 737c3ef1500STetsuo Handa int tomoyo_close_control(struct file *file); 738c3ef1500STetsuo Handa /* Read operation for /sys/kernel/security/tomoyo/ interface. */ 739c3ef1500STetsuo Handa int tomoyo_read_control(struct file *file, char __user *buffer, 740c3ef1500STetsuo Handa const int buffer_len); 741c3ef1500STetsuo Handa /* Write operation for /sys/kernel/security/tomoyo/ interface. */ 742c3ef1500STetsuo Handa int tomoyo_write_control(struct file *file, const char __user *buffer, 743c3ef1500STetsuo Handa const int buffer_len); 744c3ef1500STetsuo Handa /* Check whether the domain has too many ACL entries to hold. */ 745c3ef1500STetsuo Handa bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); 746c3ef1500STetsuo Handa /* Print out of memory warning message. */ 747c3ef1500STetsuo Handa void tomoyo_warn_oom(const char *function); 7487762fbffSTetsuo Handa /* Check whether the given name matches the given name_union. */ 7497762fbffSTetsuo Handa bool tomoyo_compare_name_union(const struct tomoyo_path_info *name, 7507762fbffSTetsuo Handa const struct tomoyo_name_union *ptr); 7512106ccd9STetsuo Handa /* Check whether the given number matches the given number_union. */ 7522106ccd9STetsuo Handa bool tomoyo_compare_number_union(const unsigned long value, 7532106ccd9STetsuo Handa const struct tomoyo_number_union *ptr); 75457c2590fSTetsuo Handa int tomoyo_get_mode(const u8 profile, const u8 index); 7559590837bSKentaro Takeda /* Transactional sprintf() for policy dump. */ 7569590837bSKentaro Takeda bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) 7579590837bSKentaro Takeda __attribute__ ((format(printf, 2, 3))); 7589590837bSKentaro Takeda /* Check whether the domainname is correct. */ 75917080008STetsuo Handa bool tomoyo_is_correct_domain(const unsigned char *domainname); 7609590837bSKentaro Takeda /* Check whether the token is correct. */ 7613f629636STetsuo Handa bool tomoyo_is_correct_path(const char *filename); 7623f629636STetsuo Handa bool tomoyo_is_correct_word(const char *string); 7639590837bSKentaro Takeda /* Check whether the token can be a domainname. */ 7649590837bSKentaro Takeda bool tomoyo_is_domain_def(const unsigned char *buffer); 7657762fbffSTetsuo Handa bool tomoyo_parse_name_union(const char *filename, 7667762fbffSTetsuo Handa struct tomoyo_name_union *ptr); 7677762fbffSTetsuo Handa /* Check whether the given filename matches the given path_group. */ 7687762fbffSTetsuo Handa bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, 7693f629636STetsuo Handa const struct tomoyo_path_group *group); 7704c3e9e2dSTetsuo Handa /* Check whether the given value matches the given number_group. */ 7714c3e9e2dSTetsuo Handa bool tomoyo_number_matches_group(const unsigned long min, 7724c3e9e2dSTetsuo Handa const unsigned long max, 7734c3e9e2dSTetsuo Handa const struct tomoyo_number_group *group); 7749590837bSKentaro Takeda /* Check whether the given filename matches the given pattern. */ 7759590837bSKentaro Takeda bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 7769590837bSKentaro Takeda const struct tomoyo_path_info *pattern); 7774c3e9e2dSTetsuo Handa 7784c3e9e2dSTetsuo Handa bool tomoyo_print_number_union(struct tomoyo_io_buffer *head, 7794c3e9e2dSTetsuo Handa const struct tomoyo_number_union *ptr); 7804c3e9e2dSTetsuo Handa bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num); 7814c3e9e2dSTetsuo Handa 7821084307cSTetsuo Handa /* Read "aggregator" entry in exception policy. */ 7831084307cSTetsuo Handa bool tomoyo_read_aggregator_policy(struct tomoyo_io_buffer *head); 7849590837bSKentaro Takeda /* Read "alias" entry in exception policy. */ 7859590837bSKentaro Takeda bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head); 7869590837bSKentaro Takeda /* 7879590837bSKentaro Takeda * Read "initialize_domain" and "no_initialize_domain" entry 7889590837bSKentaro Takeda * in exception policy. 7899590837bSKentaro Takeda */ 7909590837bSKentaro Takeda bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head); 7919590837bSKentaro Takeda /* Read "keep_domain" and "no_keep_domain" entry in exception policy. */ 7929590837bSKentaro Takeda bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head); 7939590837bSKentaro Takeda /* Read "file_pattern" entry in exception policy. */ 7949590837bSKentaro Takeda bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head); 7957762fbffSTetsuo Handa /* Read "path_group" entry in exception policy. */ 7967762fbffSTetsuo Handa bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head); 7974c3e9e2dSTetsuo Handa /* Read "number_group" entry in exception policy. */ 7984c3e9e2dSTetsuo Handa bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head); 7999590837bSKentaro Takeda /* Read "allow_read" entry in exception policy. */ 8009590837bSKentaro Takeda bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head); 8019590837bSKentaro Takeda /* Read "deny_rewrite" entry in exception policy. */ 8029590837bSKentaro Takeda bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head); 8037762fbffSTetsuo Handa /* Tokenize a line. */ 8047762fbffSTetsuo Handa bool tomoyo_tokenize(char *buffer, char *w[], size_t size); 8059590837bSKentaro Takeda /* Write domain policy violation warning message to console? */ 8069590837bSKentaro Takeda bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); 8079590837bSKentaro Takeda /* Convert double path operation to operation name. */ 8087ef61233STetsuo Handa const char *tomoyo_path22keyword(const u8 operation); 809a1f9bb6aSTetsuo Handa const char *tomoyo_path_number2keyword(const u8 operation); 810a1f9bb6aSTetsuo Handa const char *tomoyo_path_number32keyword(const u8 operation); 8119590837bSKentaro Takeda /* Get the last component of the given domainname. */ 8129590837bSKentaro Takeda const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); 8139590837bSKentaro Takeda /* Convert single path operation to operation name. */ 8147ef61233STetsuo Handa const char *tomoyo_path2keyword(const u8 operation); 8152106ccd9STetsuo Handa /* Fill "struct tomoyo_request_info". */ 8162106ccd9STetsuo Handa int tomoyo_init_request_info(struct tomoyo_request_info *r, 81757c2590fSTetsuo Handa struct tomoyo_domain_info *domain, 81857c2590fSTetsuo Handa const u8 index); 8192106ccd9STetsuo Handa /* Check permission for mount operation. */ 8202106ccd9STetsuo Handa int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, 8212106ccd9STetsuo Handa unsigned long flags, void *data_page); 8221084307cSTetsuo Handa /* Create "aggregator" entry in exception policy. */ 8231084307cSTetsuo Handa int tomoyo_write_aggregator_policy(char *data, const bool is_delete); 8249590837bSKentaro Takeda /* Create "alias" entry in exception policy. */ 8259590837bSKentaro Takeda int tomoyo_write_alias_policy(char *data, const bool is_delete); 8269590837bSKentaro Takeda /* 8279590837bSKentaro Takeda * Create "initialize_domain" and "no_initialize_domain" entry 8289590837bSKentaro Takeda * in exception policy. 8299590837bSKentaro Takeda */ 8309590837bSKentaro Takeda int tomoyo_write_domain_initializer_policy(char *data, const bool is_not, 8319590837bSKentaro Takeda const bool is_delete); 8329590837bSKentaro Takeda /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */ 8339590837bSKentaro Takeda int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, 8349590837bSKentaro Takeda const bool is_delete); 8359590837bSKentaro Takeda /* 8369590837bSKentaro Takeda * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", 8379590837bSKentaro Takeda * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", 8389590837bSKentaro Takeda * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", 8399590837bSKentaro Takeda * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and 8409590837bSKentaro Takeda * "allow_link" entry in domain policy. 8419590837bSKentaro Takeda */ 8429590837bSKentaro Takeda int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, 8439590837bSKentaro Takeda const bool is_delete); 8449590837bSKentaro Takeda /* Create "allow_read" entry in exception policy. */ 8459590837bSKentaro Takeda int tomoyo_write_globally_readable_policy(char *data, const bool is_delete); 8462106ccd9STetsuo Handa /* Create "allow_mount" entry in domain policy. */ 8472106ccd9STetsuo Handa int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain, 8482106ccd9STetsuo Handa const bool is_delete); 8499590837bSKentaro Takeda /* Create "deny_rewrite" entry in exception policy. */ 8509590837bSKentaro Takeda int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); 8519590837bSKentaro Takeda /* Create "file_pattern" entry in exception policy. */ 8529590837bSKentaro Takeda int tomoyo_write_pattern_policy(char *data, const bool is_delete); 8537762fbffSTetsuo Handa /* Create "path_group" entry in exception policy. */ 8547762fbffSTetsuo Handa int tomoyo_write_path_group_policy(char *data, const bool is_delete); 85517fcfbd9STetsuo Handa int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) 85617fcfbd9STetsuo Handa __attribute__ ((format(printf, 2, 3))); 8574c3e9e2dSTetsuo Handa /* Create "number_group" entry in exception policy. */ 8584c3e9e2dSTetsuo Handa int tomoyo_write_number_group_policy(char *data, const bool is_delete); 8599590837bSKentaro Takeda /* Find a domain by the given name. */ 8609590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 8619590837bSKentaro Takeda /* Find or create a domain by the given name. */ 8629590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * 8639590837bSKentaro Takeda domainname, 8649590837bSKentaro Takeda const u8 profile); 86557c2590fSTetsuo Handa struct tomoyo_profile *tomoyo_profile(const u8 profile); 8667762fbffSTetsuo Handa /* Allocate memory for "struct tomoyo_path_group". */ 8677762fbffSTetsuo Handa struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name); 8684c3e9e2dSTetsuo Handa struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name); 8697762fbffSTetsuo Handa 8709590837bSKentaro Takeda /* Check mode for specified functionality. */ 8719590837bSKentaro Takeda unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 8729590837bSKentaro Takeda const u8 index); 8739590837bSKentaro Takeda /* Fill in "struct tomoyo_path_info" members. */ 8749590837bSKentaro Takeda void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 8759590837bSKentaro Takeda /* Run policy loader when /sbin/init starts. */ 8769590837bSKentaro Takeda void tomoyo_load_policy(const char *filename); 8779590837bSKentaro Takeda 8784c3e9e2dSTetsuo Handa void tomoyo_put_number_union(struct tomoyo_number_union *ptr); 8794c3e9e2dSTetsuo Handa 88076bb0895STetsuo Handa /* Convert binary string to ascii string. */ 881c8c57e84STetsuo Handa char *tomoyo_encode(const char *str); 88276bb0895STetsuo Handa 88376bb0895STetsuo Handa /* 88476bb0895STetsuo Handa * Returns realpath(3) of the given pathname but ignores chroot'ed root. 88576bb0895STetsuo Handa * These functions use kzalloc(), so the caller must call kfree() 88676bb0895STetsuo Handa * if these functions didn't return NULL. 88776bb0895STetsuo Handa */ 88876bb0895STetsuo Handa char *tomoyo_realpath(const char *pathname); 88976bb0895STetsuo Handa /* 89076bb0895STetsuo Handa * Same with tomoyo_realpath() except that it doesn't follow the final symlink. 89176bb0895STetsuo Handa */ 89276bb0895STetsuo Handa char *tomoyo_realpath_nofollow(const char *pathname); 89376bb0895STetsuo Handa /* Same with tomoyo_realpath() except that the pathname is already solved. */ 89476bb0895STetsuo Handa char *tomoyo_realpath_from_path(struct path *path); 89517fcfbd9STetsuo Handa /* Get patterned pathname. */ 89617fcfbd9STetsuo Handa const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename); 89776bb0895STetsuo Handa 89876bb0895STetsuo Handa /* Check memory quota. */ 89976bb0895STetsuo Handa bool tomoyo_memory_ok(void *ptr); 9009e4b50e9STetsuo Handa void *tomoyo_commit_ok(void *data, const unsigned int size); 90176bb0895STetsuo Handa 90276bb0895STetsuo Handa /* 90376bb0895STetsuo Handa * Keep the given name on the RAM. 90476bb0895STetsuo Handa * The RAM is shared, so NEVER try to modify or kfree() the returned name. 90576bb0895STetsuo Handa */ 90676bb0895STetsuo Handa const struct tomoyo_path_info *tomoyo_get_name(const char *name); 90776bb0895STetsuo Handa 90876bb0895STetsuo Handa /* Check for memory usage. */ 90976bb0895STetsuo Handa int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); 91076bb0895STetsuo Handa 91176bb0895STetsuo Handa /* Set memory quota. */ 91276bb0895STetsuo Handa int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); 91376bb0895STetsuo Handa 914c3ef1500STetsuo Handa /* Initialize mm related code. */ 915c3ef1500STetsuo Handa void __init tomoyo_mm_init(void); 91605336deeSTetsuo Handa int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, 91776bb0895STetsuo Handa const struct tomoyo_path_info *filename); 91876bb0895STetsuo Handa int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 91976bb0895STetsuo Handa struct path *path, const int flag); 920a1f9bb6aSTetsuo Handa int tomoyo_path_number_perm(const u8 operation, struct path *path, 921a1f9bb6aSTetsuo Handa unsigned long number); 922a1f9bb6aSTetsuo Handa int tomoyo_path_number3_perm(const u8 operation, struct path *path, 923a1f9bb6aSTetsuo Handa const unsigned int mode, unsigned int dev); 92497d6931eSTetsuo Handa int tomoyo_path_perm(const u8 operation, struct path *path); 92597d6931eSTetsuo Handa int tomoyo_path2_perm(const u8 operation, struct path *path1, 92697d6931eSTetsuo Handa struct path *path2); 92776bb0895STetsuo Handa int tomoyo_find_next_domain(struct linux_binprm *bprm); 92876bb0895STetsuo Handa 929a1f9bb6aSTetsuo Handa void tomoyo_print_ulong(char *buffer, const int buffer_len, 930a1f9bb6aSTetsuo Handa const unsigned long value, const u8 type); 931a1f9bb6aSTetsuo Handa 9327762fbffSTetsuo Handa /* Drop refcount on tomoyo_name_union. */ 9337762fbffSTetsuo Handa void tomoyo_put_name_union(struct tomoyo_name_union *ptr); 9347762fbffSTetsuo Handa 935847b173eSTetsuo Handa /* Run garbage collector. */ 936847b173eSTetsuo Handa void tomoyo_run_gc(void); 937847b173eSTetsuo Handa 938847b173eSTetsuo Handa void tomoyo_memory_free(void *ptr); 939847b173eSTetsuo Handa 940237ab459STetsuo Handa int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, 941237ab459STetsuo Handa bool is_delete, struct tomoyo_domain_info *domain, 942237ab459STetsuo Handa bool (*check_duplicate) (const struct tomoyo_acl_info 943237ab459STetsuo Handa *, 944237ab459STetsuo Handa const struct tomoyo_acl_info 945237ab459STetsuo Handa *), 946237ab459STetsuo Handa bool (*merge_duplicate) (struct tomoyo_acl_info *, 947237ab459STetsuo Handa struct tomoyo_acl_info *, 948237ab459STetsuo Handa const bool)); 94936f5e1ffSTetsuo Handa int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, 95036f5e1ffSTetsuo Handa bool is_delete, struct list_head *list, 95136f5e1ffSTetsuo Handa bool (*check_duplicate) (const struct tomoyo_acl_head 95236f5e1ffSTetsuo Handa *, 95336f5e1ffSTetsuo Handa const struct tomoyo_acl_head 95436f5e1ffSTetsuo Handa *)); 95599a85259STetsuo Handa void tomoyo_check_acl(struct tomoyo_request_info *r, 95699a85259STetsuo Handa bool (*check_entry) (const struct tomoyo_request_info *, 95799a85259STetsuo Handa const struct tomoyo_acl_info *)); 958237ab459STetsuo Handa 95976bb0895STetsuo Handa /********** External variable definitions. **********/ 96076bb0895STetsuo Handa 96176bb0895STetsuo Handa /* Lock for GC. */ 96276bb0895STetsuo Handa extern struct srcu_struct tomoyo_ss; 96376bb0895STetsuo Handa 96476bb0895STetsuo Handa /* The list for "struct tomoyo_domain_info". */ 96576bb0895STetsuo Handa extern struct list_head tomoyo_domain_list; 96676bb0895STetsuo Handa 9677762fbffSTetsuo Handa extern struct list_head tomoyo_path_group_list; 9684c3e9e2dSTetsuo Handa extern struct list_head tomoyo_number_group_list; 969847b173eSTetsuo Handa extern struct list_head tomoyo_domain_initializer_list; 970847b173eSTetsuo Handa extern struct list_head tomoyo_domain_keeper_list; 9711084307cSTetsuo Handa extern struct list_head tomoyo_aggregator_list; 972847b173eSTetsuo Handa extern struct list_head tomoyo_alias_list; 973847b173eSTetsuo Handa extern struct list_head tomoyo_globally_readable_list; 974847b173eSTetsuo Handa extern struct list_head tomoyo_pattern_list; 975847b173eSTetsuo Handa extern struct list_head tomoyo_no_rewrite_list; 976847b173eSTetsuo Handa extern struct list_head tomoyo_policy_manager_list; 977847b173eSTetsuo Handa extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 978847b173eSTetsuo Handa 97976bb0895STetsuo Handa /* Lock for protecting policy. */ 98076bb0895STetsuo Handa extern struct mutex tomoyo_policy_lock; 98176bb0895STetsuo Handa 98276bb0895STetsuo Handa /* Has /sbin/init started? */ 98376bb0895STetsuo Handa extern bool tomoyo_policy_loaded; 98476bb0895STetsuo Handa 98576bb0895STetsuo Handa /* The kernel's domain. */ 98676bb0895STetsuo Handa extern struct tomoyo_domain_info tomoyo_kernel_domain; 98776bb0895STetsuo Handa 98817fcfbd9STetsuo Handa extern unsigned int tomoyo_quota_for_query; 98917fcfbd9STetsuo Handa extern unsigned int tomoyo_query_memory_size; 99017fcfbd9STetsuo Handa 99176bb0895STetsuo Handa /********** Inlined functions. **********/ 99276bb0895STetsuo Handa 99376bb0895STetsuo Handa static inline int tomoyo_read_lock(void) 99476bb0895STetsuo Handa { 99576bb0895STetsuo Handa return srcu_read_lock(&tomoyo_ss); 99676bb0895STetsuo Handa } 99776bb0895STetsuo Handa 99876bb0895STetsuo Handa static inline void tomoyo_read_unlock(int idx) 99976bb0895STetsuo Handa { 100076bb0895STetsuo Handa srcu_read_unlock(&tomoyo_ss, idx); 100176bb0895STetsuo Handa } 100276bb0895STetsuo Handa 10039590837bSKentaro Takeda /* strcmp() for "struct tomoyo_path_info" structure. */ 10049590837bSKentaro Takeda static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, 10059590837bSKentaro Takeda const struct tomoyo_path_info *b) 10069590837bSKentaro Takeda { 10079590837bSKentaro Takeda return a->hash != b->hash || strcmp(a->name, b->name); 10089590837bSKentaro Takeda } 10099590837bSKentaro Takeda 10109590837bSKentaro Takeda /** 10119590837bSKentaro Takeda * tomoyo_is_valid - Check whether the character is a valid char. 10129590837bSKentaro Takeda * 10139590837bSKentaro Takeda * @c: The character to check. 10149590837bSKentaro Takeda * 10159590837bSKentaro Takeda * Returns true if @c is a valid character, false otherwise. 10169590837bSKentaro Takeda */ 10179590837bSKentaro Takeda static inline bool tomoyo_is_valid(const unsigned char c) 10189590837bSKentaro Takeda { 10199590837bSKentaro Takeda return c > ' ' && c < 127; 10209590837bSKentaro Takeda } 10219590837bSKentaro Takeda 10229590837bSKentaro Takeda /** 10239590837bSKentaro Takeda * tomoyo_is_invalid - Check whether the character is an invalid char. 10249590837bSKentaro Takeda * 10259590837bSKentaro Takeda * @c: The character to check. 10269590837bSKentaro Takeda * 10279590837bSKentaro Takeda * Returns true if @c is an invalid character, false otherwise. 10289590837bSKentaro Takeda */ 10299590837bSKentaro Takeda static inline bool tomoyo_is_invalid(const unsigned char c) 10309590837bSKentaro Takeda { 10319590837bSKentaro Takeda return c && (c <= ' ' || c >= 127); 10329590837bSKentaro Takeda } 10339590837bSKentaro Takeda 103476bb0895STetsuo Handa static inline void tomoyo_put_name(const struct tomoyo_path_info *name) 103576bb0895STetsuo Handa { 103676bb0895STetsuo Handa if (name) { 103776bb0895STetsuo Handa struct tomoyo_name_entry *ptr = 103876bb0895STetsuo Handa container_of(name, struct tomoyo_name_entry, entry); 103976bb0895STetsuo Handa atomic_dec(&ptr->users); 104076bb0895STetsuo Handa } 104176bb0895STetsuo Handa } 10429590837bSKentaro Takeda 10437762fbffSTetsuo Handa static inline void tomoyo_put_path_group(struct tomoyo_path_group *group) 10447762fbffSTetsuo Handa { 10457762fbffSTetsuo Handa if (group) 10467762fbffSTetsuo Handa atomic_dec(&group->users); 10477762fbffSTetsuo Handa } 10487762fbffSTetsuo Handa 10494c3e9e2dSTetsuo Handa static inline void tomoyo_put_number_group(struct tomoyo_number_group *group) 10504c3e9e2dSTetsuo Handa { 10514c3e9e2dSTetsuo Handa if (group) 10524c3e9e2dSTetsuo Handa atomic_dec(&group->users); 10534c3e9e2dSTetsuo Handa } 10544c3e9e2dSTetsuo Handa 105576bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_domain(void) 105676bb0895STetsuo Handa { 105776bb0895STetsuo Handa return current_cred()->security; 105876bb0895STetsuo Handa } 10599590837bSKentaro Takeda 106076bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct 106176bb0895STetsuo Handa *task) 106276bb0895STetsuo Handa { 106376bb0895STetsuo Handa return task_cred_xxx(task, security); 106476bb0895STetsuo Handa } 10659590837bSKentaro Takeda 10667762fbffSTetsuo Handa static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1, 10677762fbffSTetsuo Handa const struct tomoyo_acl_info *p2) 10687762fbffSTetsuo Handa { 10697762fbffSTetsuo Handa return p1->type == p2->type; 10707762fbffSTetsuo Handa } 10717762fbffSTetsuo Handa 10727762fbffSTetsuo Handa static inline bool tomoyo_is_same_name_union 10737762fbffSTetsuo Handa (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) 10747762fbffSTetsuo Handa { 10757762fbffSTetsuo Handa return p1->filename == p2->filename && p1->group == p2->group && 10767762fbffSTetsuo Handa p1->is_group == p2->is_group; 10777762fbffSTetsuo Handa } 10787762fbffSTetsuo Handa 10794c3e9e2dSTetsuo Handa static inline bool tomoyo_is_same_number_union 10804c3e9e2dSTetsuo Handa (const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2) 10814c3e9e2dSTetsuo Handa { 10824c3e9e2dSTetsuo Handa return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1] 10834c3e9e2dSTetsuo Handa && p1->group == p2->group && p1->min_type == p2->min_type && 10844c3e9e2dSTetsuo Handa p1->max_type == p2->max_type && p1->is_group == p2->is_group; 10854c3e9e2dSTetsuo Handa } 10864c3e9e2dSTetsuo Handa 10879590837bSKentaro Takeda /** 10889590837bSKentaro Takeda * list_for_each_cookie - iterate over a list with cookie. 10899590837bSKentaro Takeda * @pos: the &struct list_head to use as a loop cursor. 10909590837bSKentaro Takeda * @cookie: the &struct list_head to use as a cookie. 10919590837bSKentaro Takeda * @head: the head for your list. 10929590837bSKentaro Takeda * 1093fdb8ebb7STetsuo Handa * Same with list_for_each_rcu() except that this primitive uses @cookie 10949590837bSKentaro Takeda * so that we can continue iteration. 10959590837bSKentaro Takeda * @cookie must be NULL when iteration starts, and @cookie will become 10969590837bSKentaro Takeda * NULL when iteration finishes. 10979590837bSKentaro Takeda */ 10989590837bSKentaro Takeda #define list_for_each_cookie(pos, cookie, head) \ 10999590837bSKentaro Takeda for (({ if (!cookie) \ 11009590837bSKentaro Takeda cookie = head; }), \ 1101fdb8ebb7STetsuo Handa pos = rcu_dereference((cookie)->next); \ 11029590837bSKentaro Takeda prefetch(pos->next), pos != (head) || ((cookie) = NULL); \ 1103fdb8ebb7STetsuo Handa (cookie) = pos, pos = rcu_dereference(pos->next)) 1104fdb8ebb7STetsuo Handa 11059590837bSKentaro Takeda #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ 1106