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 49a230f9e7STetsuo Handa enum tomoyo_policy_id { 50a230f9e7STetsuo Handa TOMOYO_ID_GROUP, 51a230f9e7STetsuo Handa TOMOYO_ID_PATH_GROUP, 52a230f9e7STetsuo Handa TOMOYO_ID_NUMBER_GROUP, 53a230f9e7STetsuo Handa TOMOYO_ID_DOMAIN_INITIALIZER, 54a230f9e7STetsuo Handa TOMOYO_ID_DOMAIN_KEEPER, 55a230f9e7STetsuo Handa TOMOYO_ID_AGGREGATOR, 56a230f9e7STetsuo Handa TOMOYO_ID_ALIAS, 57a230f9e7STetsuo Handa TOMOYO_ID_GLOBALLY_READABLE, 58a230f9e7STetsuo Handa TOMOYO_ID_PATTERN, 59a230f9e7STetsuo Handa TOMOYO_ID_NO_REWRITE, 60a230f9e7STetsuo Handa TOMOYO_ID_MANAGER, 61a230f9e7STetsuo Handa TOMOYO_ID_NAME, 62a230f9e7STetsuo Handa TOMOYO_ID_ACL, 63a230f9e7STetsuo Handa TOMOYO_ID_DOMAIN, 64a230f9e7STetsuo Handa TOMOYO_MAX_POLICY 65a230f9e7STetsuo Handa }; 66a230f9e7STetsuo Handa 67a230f9e7STetsuo Handa enum tomoyo_group_id { 68a230f9e7STetsuo Handa TOMOYO_PATH_GROUP, 69a230f9e7STetsuo Handa TOMOYO_NUMBER_GROUP, 70a230f9e7STetsuo Handa TOMOYO_MAX_GROUP 71a230f9e7STetsuo Handa }; 72a230f9e7STetsuo Handa 7376bb0895STetsuo Handa /* Keywords for ACLs. */ 741084307cSTetsuo Handa #define TOMOYO_KEYWORD_AGGREGATOR "aggregator " 7576bb0895STetsuo Handa #define TOMOYO_KEYWORD_ALIAS "alias " 762106ccd9STetsuo Handa #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount " 7776bb0895STetsuo Handa #define TOMOYO_KEYWORD_ALLOW_READ "allow_read " 7876bb0895STetsuo Handa #define TOMOYO_KEYWORD_DELETE "delete " 7976bb0895STetsuo Handa #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite " 8076bb0895STetsuo Handa #define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern " 8176bb0895STetsuo Handa #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain " 8276bb0895STetsuo Handa #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain " 8376bb0895STetsuo Handa #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain " 8476bb0895STetsuo Handa #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain " 857762fbffSTetsuo Handa #define TOMOYO_KEYWORD_PATH_GROUP "path_group " 864c3e9e2dSTetsuo Handa #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group " 8776bb0895STetsuo Handa #define TOMOYO_KEYWORD_SELECT "select " 8876bb0895STetsuo Handa #define TOMOYO_KEYWORD_USE_PROFILE "use_profile " 8976bb0895STetsuo Handa #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read" 909b244373STetsuo Handa #define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded" 919b244373STetsuo Handa #define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed" 9276bb0895STetsuo Handa /* A domain definition starts with <kernel>. */ 9376bb0895STetsuo Handa #define TOMOYO_ROOT_NAME "<kernel>" 9476bb0895STetsuo Handa #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1) 9576bb0895STetsuo Handa 964c3e9e2dSTetsuo Handa /* Value type definition. */ 974c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_INVALID 0 984c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_DECIMAL 1 994c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_OCTAL 2 1004c3e9e2dSTetsuo Handa #define TOMOYO_VALUE_TYPE_HEXADECIMAL 3 1014c3e9e2dSTetsuo Handa 10276bb0895STetsuo Handa /* Index numbers for Access Controls. */ 103084da356STetsuo Handa enum tomoyo_acl_entry_type_index { 1047ef61233STetsuo Handa TOMOYO_TYPE_PATH_ACL, 1057ef61233STetsuo Handa TOMOYO_TYPE_PATH2_ACL, 106a1f9bb6aSTetsuo Handa TOMOYO_TYPE_PATH_NUMBER_ACL, 10775093152STetsuo Handa TOMOYO_TYPE_MKDEV_ACL, 1082106ccd9STetsuo Handa TOMOYO_TYPE_MOUNT_ACL, 109084da356STetsuo Handa }; 11076bb0895STetsuo Handa 11176bb0895STetsuo Handa /* Index numbers for File Controls. */ 11276bb0895STetsuo Handa 11376bb0895STetsuo Handa /* 114a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically 115a1f9bb6aSTetsuo Handa * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set. 116a1f9bb6aSTetsuo Handa * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if 117a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is set. 118a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ 119a1f9bb6aSTetsuo Handa * or TOMOYO_TYPE_WRITE is cleared. 120a1f9bb6aSTetsuo Handa * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if 121a1f9bb6aSTetsuo Handa * TOMOYO_TYPE_READ_WRITE is cleared. 12276bb0895STetsuo Handa */ 12376bb0895STetsuo Handa 124084da356STetsuo Handa enum tomoyo_path_acl_index { 1257ef61233STetsuo Handa TOMOYO_TYPE_READ_WRITE, 1267ef61233STetsuo Handa TOMOYO_TYPE_EXECUTE, 1277ef61233STetsuo Handa TOMOYO_TYPE_READ, 1287ef61233STetsuo Handa TOMOYO_TYPE_WRITE, 1297ef61233STetsuo Handa TOMOYO_TYPE_UNLINK, 1307ef61233STetsuo Handa TOMOYO_TYPE_RMDIR, 1317ef61233STetsuo Handa TOMOYO_TYPE_TRUNCATE, 1327ef61233STetsuo Handa TOMOYO_TYPE_SYMLINK, 1337ef61233STetsuo Handa TOMOYO_TYPE_REWRITE, 1347ef61233STetsuo Handa TOMOYO_TYPE_CHROOT, 1357ef61233STetsuo Handa TOMOYO_TYPE_UMOUNT, 1367ef61233STetsuo Handa TOMOYO_MAX_PATH_OPERATION 137084da356STetsuo Handa }; 13876bb0895STetsuo Handa 139237ab459STetsuo Handa #define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE)) 140237ab459STetsuo Handa 14175093152STetsuo Handa enum tomoyo_mkdev_acl_index { 142a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKBLOCK, 143a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKCHAR, 14475093152STetsuo Handa TOMOYO_MAX_MKDEV_OPERATION 145a1f9bb6aSTetsuo Handa }; 146a1f9bb6aSTetsuo Handa 147084da356STetsuo Handa enum tomoyo_path2_acl_index { 1487ef61233STetsuo Handa TOMOYO_TYPE_LINK, 1497ef61233STetsuo Handa TOMOYO_TYPE_RENAME, 1507ef61233STetsuo Handa TOMOYO_TYPE_PIVOT_ROOT, 1517ef61233STetsuo Handa TOMOYO_MAX_PATH2_OPERATION 152084da356STetsuo Handa }; 15376bb0895STetsuo Handa 154a1f9bb6aSTetsuo Handa enum tomoyo_path_number_acl_index { 155a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CREATE, 156a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKDIR, 157a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKFIFO, 158a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKSOCK, 159a1f9bb6aSTetsuo Handa TOMOYO_TYPE_IOCTL, 160a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHMOD, 161a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHOWN, 162a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHGRP, 163a1f9bb6aSTetsuo Handa TOMOYO_MAX_PATH_NUMBER_OPERATION 164a1f9bb6aSTetsuo Handa }; 165a1f9bb6aSTetsuo Handa 166084da356STetsuo Handa enum tomoyo_securityfs_interface_index { 167084da356STetsuo Handa TOMOYO_DOMAINPOLICY, 168084da356STetsuo Handa TOMOYO_EXCEPTIONPOLICY, 169084da356STetsuo Handa TOMOYO_DOMAIN_STATUS, 170084da356STetsuo Handa TOMOYO_PROCESS_STATUS, 171084da356STetsuo Handa TOMOYO_MEMINFO, 172084da356STetsuo Handa TOMOYO_SELFDOMAIN, 173084da356STetsuo Handa TOMOYO_VERSION, 174084da356STetsuo Handa TOMOYO_PROFILE, 17517fcfbd9STetsuo Handa TOMOYO_QUERY, 176084da356STetsuo Handa TOMOYO_MANAGER 177084da356STetsuo Handa }; 17876bb0895STetsuo Handa 17957c2590fSTetsuo Handa enum tomoyo_mac_index { 18057c2590fSTetsuo Handa TOMOYO_MAC_FILE_EXECUTE, 18157c2590fSTetsuo Handa TOMOYO_MAC_FILE_OPEN, 18257c2590fSTetsuo Handa TOMOYO_MAC_FILE_CREATE, 18357c2590fSTetsuo Handa TOMOYO_MAC_FILE_UNLINK, 18457c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKDIR, 18557c2590fSTetsuo Handa TOMOYO_MAC_FILE_RMDIR, 18657c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKFIFO, 18757c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKSOCK, 18857c2590fSTetsuo Handa TOMOYO_MAC_FILE_TRUNCATE, 18957c2590fSTetsuo Handa TOMOYO_MAC_FILE_SYMLINK, 19057c2590fSTetsuo Handa TOMOYO_MAC_FILE_REWRITE, 19157c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKBLOCK, 19257c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKCHAR, 19357c2590fSTetsuo Handa TOMOYO_MAC_FILE_LINK, 19457c2590fSTetsuo Handa TOMOYO_MAC_FILE_RENAME, 19557c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHMOD, 19657c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHOWN, 19757c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHGRP, 19857c2590fSTetsuo Handa TOMOYO_MAC_FILE_IOCTL, 19957c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHROOT, 20057c2590fSTetsuo Handa TOMOYO_MAC_FILE_MOUNT, 20157c2590fSTetsuo Handa TOMOYO_MAC_FILE_UMOUNT, 20257c2590fSTetsuo Handa TOMOYO_MAC_FILE_PIVOT_ROOT, 20357c2590fSTetsuo Handa TOMOYO_MAX_MAC_INDEX 20457c2590fSTetsuo Handa }; 20557c2590fSTetsuo Handa 20657c2590fSTetsuo Handa enum tomoyo_mac_category_index { 20757c2590fSTetsuo Handa TOMOYO_MAC_CATEGORY_FILE, 20857c2590fSTetsuo Handa TOMOYO_MAX_MAC_CATEGORY_INDEX 20957c2590fSTetsuo Handa }; 21057c2590fSTetsuo Handa 21117fcfbd9STetsuo Handa #define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */ 21217fcfbd9STetsuo Handa 21376bb0895STetsuo Handa /********** Structure definitions. **********/ 2149590837bSKentaro Takeda 215c3fa109aSTetsuo Handa /* 21682e0f001STetsuo Handa * tomoyo_acl_head is a structure which is used for holding elements not in 21782e0f001STetsuo Handa * domain policy. 21882e0f001STetsuo Handa * It has following fields. 21982e0f001STetsuo Handa * 22082e0f001STetsuo Handa * (1) "list" which is linked to tomoyo_policy_list[] . 22182e0f001STetsuo Handa * (2) "is_deleted" is a bool which is true if marked as deleted, false 22282e0f001STetsuo Handa * otherwise. 22382e0f001STetsuo Handa */ 22482e0f001STetsuo Handa struct tomoyo_acl_head { 22582e0f001STetsuo Handa struct list_head list; 22682e0f001STetsuo Handa bool is_deleted; 22782e0f001STetsuo Handa } __packed; 22882e0f001STetsuo Handa 22982e0f001STetsuo Handa /* 230cb0abe6aSTetsuo Handa * tomoyo_request_info is a structure which is used for holding 231cb0abe6aSTetsuo Handa * 232cb0abe6aSTetsuo Handa * (1) Domain information of current process. 23317fcfbd9STetsuo Handa * (2) How many retries are made for this request. 23417fcfbd9STetsuo Handa * (3) Profile number used for this request. 23517fcfbd9STetsuo Handa * (4) Access control mode of the profile. 236cb0abe6aSTetsuo Handa */ 237cb0abe6aSTetsuo Handa struct tomoyo_request_info { 238cb0abe6aSTetsuo Handa struct tomoyo_domain_info *domain; 239cf6e9a64STetsuo Handa /* For holding parameters. */ 240cf6e9a64STetsuo Handa union { 241cf6e9a64STetsuo Handa struct { 242cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 243cf6e9a64STetsuo Handa u8 operation; 244cf6e9a64STetsuo Handa } path; 245cf6e9a64STetsuo Handa struct { 246cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename1; 247cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename2; 248cf6e9a64STetsuo Handa u8 operation; 249cf6e9a64STetsuo Handa } path2; 250cf6e9a64STetsuo Handa struct { 251cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 252cf6e9a64STetsuo Handa unsigned int mode; 253cf6e9a64STetsuo Handa unsigned int major; 254cf6e9a64STetsuo Handa unsigned int minor; 255cf6e9a64STetsuo Handa u8 operation; 256cf6e9a64STetsuo Handa } mkdev; 257cf6e9a64STetsuo Handa struct { 258cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 259cf6e9a64STetsuo Handa unsigned long number; 260cf6e9a64STetsuo Handa u8 operation; 261cf6e9a64STetsuo Handa } path_number; 262cf6e9a64STetsuo Handa struct { 263cf6e9a64STetsuo Handa const struct tomoyo_path_info *type; 264cf6e9a64STetsuo Handa const struct tomoyo_path_info *dir; 265cf6e9a64STetsuo Handa const struct tomoyo_path_info *dev; 266cf6e9a64STetsuo Handa unsigned long flags; 267cf6e9a64STetsuo Handa int need_dev; 268cf6e9a64STetsuo Handa } mount; 269cf6e9a64STetsuo Handa } param; 270cf6e9a64STetsuo Handa u8 param_type; 271cf6e9a64STetsuo Handa bool granted; 27217fcfbd9STetsuo Handa u8 retry; 27317fcfbd9STetsuo Handa u8 profile; 274cb0abe6aSTetsuo Handa u8 mode; /* One of tomoyo_mode_index . */ 27557c2590fSTetsuo Handa u8 type; 276cb0abe6aSTetsuo Handa }; 277cb0abe6aSTetsuo Handa 278cb0abe6aSTetsuo Handa /* 279c3fa109aSTetsuo Handa * tomoyo_path_info is a structure which is used for holding a string data 280c3fa109aSTetsuo Handa * used by TOMOYO. 281c3fa109aSTetsuo Handa * This structure has several fields for supporting pattern matching. 282c3fa109aSTetsuo Handa * 283c3fa109aSTetsuo Handa * (1) "name" is the '\0' terminated string data. 284c3fa109aSTetsuo Handa * (2) "hash" is full_name_hash(name, strlen(name)). 285c3fa109aSTetsuo Handa * This allows tomoyo_pathcmp() to compare by hash before actually compare 286c3fa109aSTetsuo Handa * using strcmp(). 287c3fa109aSTetsuo Handa * (3) "const_len" is the length of the initial segment of "name" which 288c3fa109aSTetsuo Handa * consists entirely of non wildcard characters. In other words, the length 289c3fa109aSTetsuo Handa * which we can compare two strings using strncmp(). 290c3fa109aSTetsuo Handa * (4) "is_dir" is a bool which is true if "name" ends with "/", 291c3fa109aSTetsuo Handa * false otherwise. 292c3fa109aSTetsuo Handa * TOMOYO distinguishes directory and non-directory. A directory ends with 293c3fa109aSTetsuo Handa * "/" and non-directory does not end with "/". 294c3fa109aSTetsuo Handa * (5) "is_patterned" is a bool which is true if "name" contains wildcard 295c3fa109aSTetsuo Handa * characters, false otherwise. This allows TOMOYO to use "hash" and 296c3fa109aSTetsuo Handa * strcmp() for string comparison if "is_patterned" is false. 297c3fa109aSTetsuo Handa */ 2989590837bSKentaro Takeda struct tomoyo_path_info { 2999590837bSKentaro Takeda const char *name; 3009590837bSKentaro Takeda u32 hash; /* = full_name_hash(name, strlen(name)) */ 3019590837bSKentaro Takeda u16 const_len; /* = tomoyo_const_part_length(name) */ 3029590837bSKentaro Takeda bool is_dir; /* = tomoyo_strendswith(name, "/") */ 3039590837bSKentaro Takeda bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 3049590837bSKentaro Takeda }; 3059590837bSKentaro Takeda 3069590837bSKentaro Takeda /* 30776bb0895STetsuo Handa * tomoyo_name_entry is a structure which is used for linking 30876bb0895STetsuo Handa * "struct tomoyo_path_info" into tomoyo_name_list . 3099590837bSKentaro Takeda */ 31076bb0895STetsuo Handa struct tomoyo_name_entry { 31176bb0895STetsuo Handa struct list_head list; 31276bb0895STetsuo Handa atomic_t users; 31376bb0895STetsuo Handa struct tomoyo_path_info entry; 31476bb0895STetsuo Handa }; 3159590837bSKentaro Takeda 3167762fbffSTetsuo Handa struct tomoyo_name_union { 3177762fbffSTetsuo Handa const struct tomoyo_path_info *filename; 318a98aa4deSTetsuo Handa struct tomoyo_group *group; 3197762fbffSTetsuo Handa u8 is_group; 3207762fbffSTetsuo Handa }; 3217762fbffSTetsuo Handa 3224c3e9e2dSTetsuo Handa struct tomoyo_number_union { 3234c3e9e2dSTetsuo Handa unsigned long values[2]; 324a98aa4deSTetsuo Handa struct tomoyo_group *group; 3254c3e9e2dSTetsuo Handa u8 min_type; 3264c3e9e2dSTetsuo Handa u8 max_type; 3274c3e9e2dSTetsuo Handa u8 is_group; 3284c3e9e2dSTetsuo Handa }; 3294c3e9e2dSTetsuo Handa 330a98aa4deSTetsuo Handa /* Structure for "path_group"/"number_group" directive. */ 331a98aa4deSTetsuo Handa struct tomoyo_group { 332a98aa4deSTetsuo Handa struct list_head list; 333a98aa4deSTetsuo Handa const struct tomoyo_path_info *group_name; 334a98aa4deSTetsuo Handa struct list_head member_list; 335a98aa4deSTetsuo Handa atomic_t users; 336a98aa4deSTetsuo Handa }; 337a98aa4deSTetsuo Handa 3387762fbffSTetsuo Handa /* Structure for "path_group" directive. */ 3397762fbffSTetsuo Handa struct tomoyo_path_group { 34082e0f001STetsuo Handa struct tomoyo_acl_head head; 3417762fbffSTetsuo Handa const struct tomoyo_path_info *member_name; 3427762fbffSTetsuo Handa }; 3437762fbffSTetsuo Handa 3444c3e9e2dSTetsuo Handa /* Structure for "number_group" directive. */ 345a98aa4deSTetsuo Handa struct tomoyo_number_group { 34682e0f001STetsuo Handa struct tomoyo_acl_head head; 3474c3e9e2dSTetsuo Handa struct tomoyo_number_union number; 3484c3e9e2dSTetsuo Handa }; 3494c3e9e2dSTetsuo Handa 3509590837bSKentaro Takeda /* 351c3fa109aSTetsuo Handa * tomoyo_acl_info is a structure which is used for holding 352c3fa109aSTetsuo Handa * 353c3fa109aSTetsuo Handa * (1) "list" which is linked to the ->acl_info_list of 354c3fa109aSTetsuo Handa * "struct tomoyo_domain_info" 355237ab459STetsuo Handa * (2) "is_deleted" is a bool which is true if this domain is marked as 356237ab459STetsuo Handa * "deleted", false otherwise. 357237ab459STetsuo Handa * (3) "type" which tells type of the entry. 3589590837bSKentaro Takeda * 3599590837bSKentaro Takeda * Packing "struct tomoyo_acl_info" allows 360237ab459STetsuo Handa * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl" 36175093152STetsuo Handa * "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed 362237ab459STetsuo Handa * "u8" without enlarging their structure size. 3639590837bSKentaro Takeda */ 3649590837bSKentaro Takeda struct tomoyo_acl_info { 3659590837bSKentaro Takeda struct list_head list; 366237ab459STetsuo Handa bool is_deleted; 367237ab459STetsuo Handa u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */ 3689590837bSKentaro Takeda } __packed; 3699590837bSKentaro Takeda 370c3fa109aSTetsuo Handa /* 371c3fa109aSTetsuo Handa * tomoyo_domain_info is a structure which is used for holding permissions 372c3fa109aSTetsuo Handa * (e.g. "allow_read /lib/libc-2.5.so") given to each domain. 373c3fa109aSTetsuo Handa * It has following fields. 374c3fa109aSTetsuo Handa * 375c3fa109aSTetsuo Handa * (1) "list" which is linked to tomoyo_domain_list . 376c3fa109aSTetsuo Handa * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info". 377c3fa109aSTetsuo Handa * (3) "domainname" which holds the name of the domain. 378c3fa109aSTetsuo Handa * (4) "profile" which remembers profile number assigned to this domain. 379c3fa109aSTetsuo Handa * (5) "is_deleted" is a bool which is true if this domain is marked as 380c3fa109aSTetsuo Handa * "deleted", false otherwise. 381c3fa109aSTetsuo Handa * (6) "quota_warned" is a bool which is used for suppressing warning message 382c3fa109aSTetsuo Handa * when learning mode learned too much entries. 383ea13ddbaSTetsuo Handa * (7) "ignore_global_allow_read" is a bool which is true if this domain 384ea13ddbaSTetsuo Handa * should ignore "allow_read" directive in exception policy. 385ea13ddbaSTetsuo Handa * (8) "transition_failed" is a bool which is set to true when this domain was 386ea13ddbaSTetsuo Handa * unable to create a new domain at tomoyo_find_next_domain() because the 387ea13ddbaSTetsuo Handa * name of the domain to be created was too long or it could not allocate 388ea13ddbaSTetsuo Handa * memory. If set to true, more than one process continued execve() 389ea13ddbaSTetsuo Handa * without domain transition. 390ec8e6a4eSTetsuo Handa * (9) "users" is an atomic_t that holds how many "struct cred"->security 391ec8e6a4eSTetsuo Handa * are referring this "struct tomoyo_domain_info". If is_deleted == true 392ec8e6a4eSTetsuo Handa * and users == 0, this struct will be kfree()d upon next garbage 393ec8e6a4eSTetsuo Handa * collection. 394c3fa109aSTetsuo Handa * 395c3fa109aSTetsuo Handa * A domain's lifecycle is an analogy of files on / directory. 396c3fa109aSTetsuo Handa * Multiple domains with the same domainname cannot be created (as with 397c3fa109aSTetsuo Handa * creating files with the same filename fails with -EEXIST). 398c3fa109aSTetsuo Handa * If a process reached a domain, that process can reside in that domain after 399c3fa109aSTetsuo Handa * that domain is marked as "deleted" (as with a process can access an already 400c3fa109aSTetsuo Handa * open()ed file after that file was unlink()ed). 401c3fa109aSTetsuo Handa */ 4029590837bSKentaro Takeda struct tomoyo_domain_info { 4039590837bSKentaro Takeda struct list_head list; 4049590837bSKentaro Takeda struct list_head acl_info_list; 4059590837bSKentaro Takeda /* Name of this domain. Never NULL. */ 4069590837bSKentaro Takeda const struct tomoyo_path_info *domainname; 4079590837bSKentaro Takeda u8 profile; /* Profile number to use. */ 408a0558fc3STetsuo Handa bool is_deleted; /* Delete flag. */ 4099590837bSKentaro Takeda bool quota_warned; /* Quota warnning flag. */ 410ea13ddbaSTetsuo Handa bool ignore_global_allow_read; /* Ignore "allow_read" flag. */ 411ea13ddbaSTetsuo Handa bool transition_failed; /* Domain transition failed flag. */ 412ec8e6a4eSTetsuo Handa atomic_t users; /* Number of referring credentials. */ 4139590837bSKentaro Takeda }; 4149590837bSKentaro Takeda 4159590837bSKentaro Takeda /* 4167ef61233STetsuo Handa * tomoyo_path_acl is a structure which is used for holding an 417c3fa109aSTetsuo Handa * entry with one pathname operation (e.g. open(), mkdir()). 418c3fa109aSTetsuo Handa * It has following fields. 419c3fa109aSTetsuo Handa * 420c3fa109aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 421c3fa109aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 4227762fbffSTetsuo Handa * (3) "name" is the pathname. 423c3fa109aSTetsuo Handa * 424c3fa109aSTetsuo Handa * Directives held by this structure are "allow_read/write", "allow_execute", 425a1f9bb6aSTetsuo Handa * "allow_read", "allow_write", "allow_unlink", "allow_rmdir", 4262106ccd9STetsuo Handa * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and 4272106ccd9STetsuo Handa * "allow_unmount". 4289590837bSKentaro Takeda */ 4297ef61233STetsuo Handa struct tomoyo_path_acl { 4307ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 4319590837bSKentaro Takeda u16 perm; 4327762fbffSTetsuo Handa struct tomoyo_name_union name; 4339590837bSKentaro Takeda }; 4349590837bSKentaro Takeda 435c3fa109aSTetsuo Handa /* 436a1f9bb6aSTetsuo Handa * tomoyo_path_number_acl is a structure which is used for holding an 437a1f9bb6aSTetsuo Handa * entry with one pathname and one number operation. 438a1f9bb6aSTetsuo Handa * It has following fields. 439a1f9bb6aSTetsuo Handa * 440a1f9bb6aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 441a1f9bb6aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 442a1f9bb6aSTetsuo Handa * (3) "name" is the pathname. 443a1f9bb6aSTetsuo Handa * (4) "number" is the numeric value. 444a1f9bb6aSTetsuo Handa * 445a1f9bb6aSTetsuo Handa * Directives held by this structure are "allow_create", "allow_mkdir", 446a1f9bb6aSTetsuo Handa * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown" 447a1f9bb6aSTetsuo Handa * and "allow_chgrp". 448a1f9bb6aSTetsuo Handa * 449a1f9bb6aSTetsuo Handa */ 450a1f9bb6aSTetsuo Handa struct tomoyo_path_number_acl { 451a1f9bb6aSTetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ 452a1f9bb6aSTetsuo Handa u8 perm; 453a1f9bb6aSTetsuo Handa struct tomoyo_name_union name; 454a1f9bb6aSTetsuo Handa struct tomoyo_number_union number; 455a1f9bb6aSTetsuo Handa }; 456a1f9bb6aSTetsuo Handa 457a1f9bb6aSTetsuo Handa /* 45875093152STetsuo Handa * tomoyo_mkdev_acl is a structure which is used for holding an 459a1f9bb6aSTetsuo Handa * entry with one pathname and three numbers operation. 460a1f9bb6aSTetsuo Handa * It has following fields. 461a1f9bb6aSTetsuo Handa * 462a1f9bb6aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 463a1f9bb6aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 464a1f9bb6aSTetsuo Handa * (3) "mode" is the create mode. 465a1f9bb6aSTetsuo Handa * (4) "major" is the major number of device node. 466a1f9bb6aSTetsuo Handa * (5) "minor" is the minor number of device node. 467a1f9bb6aSTetsuo Handa * 468a1f9bb6aSTetsuo Handa * Directives held by this structure are "allow_mkchar", "allow_mkblock". 469a1f9bb6aSTetsuo Handa * 470a1f9bb6aSTetsuo Handa */ 47175093152STetsuo Handa struct tomoyo_mkdev_acl { 47275093152STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ 473a1f9bb6aSTetsuo Handa u8 perm; 474a1f9bb6aSTetsuo Handa struct tomoyo_name_union name; 475a1f9bb6aSTetsuo Handa struct tomoyo_number_union mode; 476a1f9bb6aSTetsuo Handa struct tomoyo_number_union major; 477a1f9bb6aSTetsuo Handa struct tomoyo_number_union minor; 478a1f9bb6aSTetsuo Handa }; 479a1f9bb6aSTetsuo Handa 480a1f9bb6aSTetsuo Handa /* 4817ef61233STetsuo Handa * tomoyo_path2_acl is a structure which is used for holding an 482937bf613STetsuo Handa * entry with two pathnames operation (i.e. link(), rename() and pivot_root()). 483c3fa109aSTetsuo Handa * It has following fields. 484c3fa109aSTetsuo Handa * 485c3fa109aSTetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 486c3fa109aSTetsuo Handa * (2) "perm" which is a bitmask of permitted operations. 4877762fbffSTetsuo Handa * (3) "name1" is the source/old pathname. 4887762fbffSTetsuo Handa * (4) "name2" is the destination/new pathname. 489c3fa109aSTetsuo Handa * 490937bf613STetsuo Handa * Directives held by this structure are "allow_rename", "allow_link" and 491937bf613STetsuo Handa * "allow_pivot_root". 492c3fa109aSTetsuo Handa */ 4937ef61233STetsuo Handa struct tomoyo_path2_acl { 4947ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ 4959590837bSKentaro Takeda u8 perm; 4967762fbffSTetsuo Handa struct tomoyo_name_union name1; 4977762fbffSTetsuo Handa struct tomoyo_name_union name2; 4989590837bSKentaro Takeda }; 4999590837bSKentaro Takeda 500c3fa109aSTetsuo Handa /* 5012106ccd9STetsuo Handa * tomoyo_mount_acl is a structure which is used for holding an 5022106ccd9STetsuo Handa * entry for mount operation. 5032106ccd9STetsuo Handa * It has following fields. 5042106ccd9STetsuo Handa * 5052106ccd9STetsuo Handa * (1) "head" which is a "struct tomoyo_acl_info". 506237ab459STetsuo Handa * (2) "dev_name" is the device name. 507237ab459STetsuo Handa * (3) "dir_name" is the mount point. 508237ab459STetsuo Handa * (4) "fs_type" is the filesystem type. 5092106ccd9STetsuo Handa * (5) "flags" is the mount flags. 5102106ccd9STetsuo Handa * 511237ab459STetsuo Handa * Directive held by this structure is "allow_mount". 5122106ccd9STetsuo Handa */ 5132106ccd9STetsuo Handa struct tomoyo_mount_acl { 5142106ccd9STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ 5152106ccd9STetsuo Handa struct tomoyo_name_union dev_name; 5162106ccd9STetsuo Handa struct tomoyo_name_union dir_name; 5172106ccd9STetsuo Handa struct tomoyo_name_union fs_type; 5182106ccd9STetsuo Handa struct tomoyo_number_union flags; 5192106ccd9STetsuo Handa }; 5202106ccd9STetsuo Handa 5212106ccd9STetsuo Handa /* 522c3fa109aSTetsuo Handa * tomoyo_io_buffer is a structure which is used for reading and modifying 523c3fa109aSTetsuo Handa * configuration via /sys/kernel/security/tomoyo/ interface. 524c3fa109aSTetsuo Handa * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as 525c3fa109aSTetsuo Handa * cursors. 526c3fa109aSTetsuo Handa * 527c3fa109aSTetsuo Handa * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of 528c3fa109aSTetsuo Handa * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info" 529c3fa109aSTetsuo Handa * entry has a list of "struct tomoyo_acl_info", we need two cursors when 530c3fa109aSTetsuo Handa * reading (one is for traversing tomoyo_domain_list and the other is for 531c3fa109aSTetsuo Handa * traversing "struct tomoyo_acl_info"->acl_info_list ). 532c3fa109aSTetsuo Handa * 533c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 534c3fa109aSTetsuo Handa * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the 535c3fa109aSTetsuo Handa * domain with the domainname specified by the rest of that line (NULL is set 536c3fa109aSTetsuo Handa * if seek failed). 537c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 538c3fa109aSTetsuo Handa * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that 539c3fa109aSTetsuo Handa * line (->write_var1 is set to NULL if a domain was deleted). 540c3fa109aSTetsuo Handa * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with 541c3fa109aSTetsuo Handa * neither "select " nor "delete ", an entry or a domain specified by that line 542c3fa109aSTetsuo Handa * is appended. 543c3fa109aSTetsuo Handa */ 5449590837bSKentaro Takeda struct tomoyo_io_buffer { 5458fbe71f0STetsuo Handa void (*read) (struct tomoyo_io_buffer *); 5469590837bSKentaro Takeda int (*write) (struct tomoyo_io_buffer *); 54717fcfbd9STetsuo Handa int (*poll) (struct file *file, poll_table *wait); 5489590837bSKentaro Takeda /* Exclusive lock for this structure. */ 5499590837bSKentaro Takeda struct mutex io_sem; 550fdb8ebb7STetsuo Handa /* Index returned by tomoyo_read_lock(). */ 551fdb8ebb7STetsuo Handa int reader_idx; 5529590837bSKentaro Takeda /* The position currently reading from. */ 5539590837bSKentaro Takeda struct list_head *read_var1; 5549590837bSKentaro Takeda /* Extra variables for reading. */ 5559590837bSKentaro Takeda struct list_head *read_var2; 5569590837bSKentaro Takeda /* The position currently writing to. */ 5579590837bSKentaro Takeda struct tomoyo_domain_info *write_var1; 5589590837bSKentaro Takeda /* The step for reading. */ 5599590837bSKentaro Takeda int read_step; 5609590837bSKentaro Takeda /* Buffer for reading. */ 5619590837bSKentaro Takeda char *read_buf; 5629590837bSKentaro Takeda /* EOF flag for reading. */ 5639590837bSKentaro Takeda bool read_eof; 5649590837bSKentaro Takeda /* Read domain ACL of specified PID? */ 5659590837bSKentaro Takeda bool read_single_domain; 5669590837bSKentaro Takeda /* Extra variable for reading. */ 5679590837bSKentaro Takeda u8 read_bit; 5689590837bSKentaro Takeda /* Bytes available for reading. */ 5699590837bSKentaro Takeda int read_avail; 5709590837bSKentaro Takeda /* Size of read buffer. */ 5719590837bSKentaro Takeda int readbuf_size; 5729590837bSKentaro Takeda /* Buffer for writing. */ 5739590837bSKentaro Takeda char *write_buf; 5749590837bSKentaro Takeda /* Bytes available for writing. */ 5759590837bSKentaro Takeda int write_avail; 5769590837bSKentaro Takeda /* Size of write buffer. */ 5779590837bSKentaro Takeda int writebuf_size; 57817fcfbd9STetsuo Handa /* Type of this interface. */ 57917fcfbd9STetsuo Handa u8 type; 5809590837bSKentaro Takeda }; 5819590837bSKentaro Takeda 58276bb0895STetsuo Handa /* 58376bb0895STetsuo Handa * tomoyo_globally_readable_file_entry is a structure which is used for holding 58476bb0895STetsuo Handa * "allow_read" entries. 58576bb0895STetsuo Handa * It has following fields. 58676bb0895STetsuo Handa * 58782e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 58876bb0895STetsuo Handa * (2) "filename" is a pathname which is allowed to open(O_RDONLY). 58976bb0895STetsuo Handa */ 59076bb0895STetsuo Handa struct tomoyo_globally_readable_file_entry { 59182e0f001STetsuo Handa struct tomoyo_acl_head head; 59276bb0895STetsuo Handa const struct tomoyo_path_info *filename; 59376bb0895STetsuo Handa }; 59476bb0895STetsuo Handa 59576bb0895STetsuo Handa /* 59676bb0895STetsuo Handa * tomoyo_pattern_entry is a structure which is used for holding 597a230f9e7STetsuo Handa * "file_pattern" entries. 59876bb0895STetsuo Handa * It has following fields. 59976bb0895STetsuo Handa * 60082e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 60176bb0895STetsuo Handa * (2) "pattern" is a pathname pattern which is used for converting pathnames 60276bb0895STetsuo Handa * to pathname patterns during learning mode. 60376bb0895STetsuo Handa */ 60476bb0895STetsuo Handa struct tomoyo_pattern_entry { 60582e0f001STetsuo Handa struct tomoyo_acl_head head; 60676bb0895STetsuo Handa const struct tomoyo_path_info *pattern; 60776bb0895STetsuo Handa }; 60876bb0895STetsuo Handa 60976bb0895STetsuo Handa /* 61076bb0895STetsuo Handa * tomoyo_no_rewrite_entry is a structure which is used for holding 61176bb0895STetsuo Handa * "deny_rewrite" entries. 61276bb0895STetsuo Handa * It has following fields. 61376bb0895STetsuo Handa * 61482e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 61576bb0895STetsuo Handa * (2) "pattern" is a pathname which is by default not permitted to modify 61676bb0895STetsuo Handa * already existing content. 61776bb0895STetsuo Handa */ 61876bb0895STetsuo Handa struct tomoyo_no_rewrite_entry { 61982e0f001STetsuo Handa struct tomoyo_acl_head head; 62076bb0895STetsuo Handa const struct tomoyo_path_info *pattern; 62176bb0895STetsuo Handa }; 62276bb0895STetsuo Handa 62376bb0895STetsuo Handa /* 62476bb0895STetsuo Handa * tomoyo_domain_initializer_entry is a structure which is used for holding 62576bb0895STetsuo Handa * "initialize_domain" and "no_initialize_domain" entries. 62676bb0895STetsuo Handa * It has following fields. 62776bb0895STetsuo Handa * 62882e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 62982e0f001STetsuo Handa * (2) "is_not" is a bool which is true if "no_initialize_domain", false 63076bb0895STetsuo Handa * otherwise. 63182e0f001STetsuo Handa * (3) "is_last_name" is a bool which is true if "domainname" is "the last 63276bb0895STetsuo Handa * component of a domainname", false otherwise. 63382e0f001STetsuo Handa * (4) "domainname" which is "a domainname" or "the last component of a 63482e0f001STetsuo Handa * domainname". This field is NULL if "from" clause is not specified. 63582e0f001STetsuo Handa * (5) "program" which is a program's pathname. 63676bb0895STetsuo Handa */ 63776bb0895STetsuo Handa struct tomoyo_domain_initializer_entry { 63882e0f001STetsuo Handa struct tomoyo_acl_head head; 63976bb0895STetsuo Handa bool is_not; /* True if this entry is "no_initialize_domain". */ 64076bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 64176bb0895STetsuo Handa bool is_last_name; 64282e0f001STetsuo Handa const struct tomoyo_path_info *domainname; /* This may be NULL */ 64382e0f001STetsuo Handa const struct tomoyo_path_info *program; 64476bb0895STetsuo Handa }; 64576bb0895STetsuo Handa 64676bb0895STetsuo Handa /* 64776bb0895STetsuo Handa * tomoyo_domain_keeper_entry is a structure which is used for holding 64876bb0895STetsuo Handa * "keep_domain" and "no_keep_domain" entries. 64976bb0895STetsuo Handa * It has following fields. 65076bb0895STetsuo Handa * 65182e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 65282e0f001STetsuo Handa * (2) "is_not" is a bool which is true if "no_initialize_domain", false 65376bb0895STetsuo Handa * otherwise. 65482e0f001STetsuo Handa * (3) "is_last_name" is a bool which is true if "domainname" is "the last 65576bb0895STetsuo Handa * component of a domainname", false otherwise. 65682e0f001STetsuo Handa * (4) "domainname" which is "a domainname" or "the last component of a 65782e0f001STetsuo Handa * domainname". 65882e0f001STetsuo Handa * (5) "program" which is a program's pathname. 65982e0f001STetsuo Handa * This field is NULL if "from" clause is not specified. 66076bb0895STetsuo Handa */ 66176bb0895STetsuo Handa struct tomoyo_domain_keeper_entry { 66282e0f001STetsuo Handa struct tomoyo_acl_head head; 66376bb0895STetsuo Handa bool is_not; /* True if this entry is "no_keep_domain". */ 66476bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 66576bb0895STetsuo Handa bool is_last_name; 66682e0f001STetsuo Handa const struct tomoyo_path_info *domainname; 66782e0f001STetsuo Handa const struct tomoyo_path_info *program; /* This may be NULL */ 66876bb0895STetsuo Handa }; 66976bb0895STetsuo Handa 67076bb0895STetsuo Handa /* 6711084307cSTetsuo Handa * tomoyo_aggregator_entry is a structure which is used for holding 6721084307cSTetsuo Handa * "aggregator" entries. 6731084307cSTetsuo Handa * It has following fields. 6741084307cSTetsuo Handa * 67582e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 6761084307cSTetsuo Handa * (2) "original_name" which is originally requested name. 6771084307cSTetsuo Handa * (3) "aggregated_name" which is name to rewrite. 6781084307cSTetsuo Handa */ 6791084307cSTetsuo Handa struct tomoyo_aggregator_entry { 68082e0f001STetsuo Handa struct tomoyo_acl_head head; 6811084307cSTetsuo Handa const struct tomoyo_path_info *original_name; 6821084307cSTetsuo Handa const struct tomoyo_path_info *aggregated_name; 6831084307cSTetsuo Handa }; 6841084307cSTetsuo Handa 6851084307cSTetsuo Handa /* 68676bb0895STetsuo Handa * tomoyo_alias_entry is a structure which is used for holding "alias" entries. 68776bb0895STetsuo Handa * It has following fields. 68876bb0895STetsuo Handa * 68982e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 69076bb0895STetsuo Handa * (2) "original_name" which is a dereferenced pathname. 69176bb0895STetsuo Handa * (3) "aliased_name" which is a symlink's pathname. 69276bb0895STetsuo Handa */ 69376bb0895STetsuo Handa struct tomoyo_alias_entry { 69482e0f001STetsuo Handa struct tomoyo_acl_head head; 69576bb0895STetsuo Handa const struct tomoyo_path_info *original_name; 69676bb0895STetsuo Handa const struct tomoyo_path_info *aliased_name; 69776bb0895STetsuo Handa }; 69876bb0895STetsuo Handa 69976bb0895STetsuo Handa /* 70076bb0895STetsuo Handa * tomoyo_policy_manager_entry is a structure which is used for holding list of 70176bb0895STetsuo Handa * domainnames or programs which are permitted to modify configuration via 70276bb0895STetsuo Handa * /sys/kernel/security/tomoyo/ interface. 70376bb0895STetsuo Handa * It has following fields. 70476bb0895STetsuo Handa * 70582e0f001STetsuo Handa * (1) "head" is "struct tomoyo_acl_head". 70682e0f001STetsuo Handa * (2) "is_domain" is a bool which is true if "manager" is a domainname, false 70776bb0895STetsuo Handa * otherwise. 70882e0f001STetsuo Handa * (3) "manager" is a domainname or a program's pathname. 70976bb0895STetsuo Handa */ 71076bb0895STetsuo Handa struct tomoyo_policy_manager_entry { 71182e0f001STetsuo Handa struct tomoyo_acl_head head; 71282e0f001STetsuo Handa bool is_domain; /* True if manager is a domainname. */ 71376bb0895STetsuo Handa /* A path to program or a domainname. */ 71476bb0895STetsuo Handa const struct tomoyo_path_info *manager; 71576bb0895STetsuo Handa }; 71676bb0895STetsuo Handa 71757c2590fSTetsuo Handa struct tomoyo_preference { 71857c2590fSTetsuo Handa unsigned int learning_max_entry; 71957c2590fSTetsuo Handa bool enforcing_verbose; 72057c2590fSTetsuo Handa bool learning_verbose; 72157c2590fSTetsuo Handa bool permissive_verbose; 72257c2590fSTetsuo Handa }; 72357c2590fSTetsuo Handa 72457c2590fSTetsuo Handa struct tomoyo_profile { 72557c2590fSTetsuo Handa const struct tomoyo_path_info *comment; 72657c2590fSTetsuo Handa struct tomoyo_preference *learning; 72757c2590fSTetsuo Handa struct tomoyo_preference *permissive; 72857c2590fSTetsuo Handa struct tomoyo_preference *enforcing; 72957c2590fSTetsuo Handa struct tomoyo_preference preference; 73057c2590fSTetsuo Handa u8 default_config; 73157c2590fSTetsuo Handa u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; 73257c2590fSTetsuo Handa }; 73357c2590fSTetsuo Handa 73476bb0895STetsuo Handa /********** Function prototypes. **********/ 73576bb0895STetsuo Handa 73617fcfbd9STetsuo Handa extern asmlinkage long sys_getpid(void); 73717fcfbd9STetsuo Handa extern asmlinkage long sys_getppid(void); 73817fcfbd9STetsuo Handa 739c3ef1500STetsuo Handa /* Check whether the given string starts with the given keyword. */ 740c3ef1500STetsuo Handa bool tomoyo_str_starts(char **src, const char *find); 741c3ef1500STetsuo Handa /* Get tomoyo_realpath() of current process. */ 742c3ef1500STetsuo Handa const char *tomoyo_get_exe(void); 743c3ef1500STetsuo Handa /* Format string. */ 744c3ef1500STetsuo Handa void tomoyo_normalize_line(unsigned char *buffer); 745c3ef1500STetsuo Handa /* Print warning or error message on console. */ 746c3ef1500STetsuo Handa void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...) 747c3ef1500STetsuo Handa __attribute__ ((format(printf, 2, 3))); 748c3ef1500STetsuo Handa /* Check all profiles currently assigned to domains are defined. */ 749c3ef1500STetsuo Handa void tomoyo_check_profile(void); 750c3ef1500STetsuo Handa /* Open operation for /sys/kernel/security/tomoyo/ interface. */ 751c3ef1500STetsuo Handa int tomoyo_open_control(const u8 type, struct file *file); 752c3ef1500STetsuo Handa /* Close /sys/kernel/security/tomoyo/ interface. */ 753c3ef1500STetsuo Handa int tomoyo_close_control(struct file *file); 754c3ef1500STetsuo Handa /* Read operation for /sys/kernel/security/tomoyo/ interface. */ 755c3ef1500STetsuo Handa int tomoyo_read_control(struct file *file, char __user *buffer, 756c3ef1500STetsuo Handa const int buffer_len); 757c3ef1500STetsuo Handa /* Write operation for /sys/kernel/security/tomoyo/ interface. */ 758c3ef1500STetsuo Handa int tomoyo_write_control(struct file *file, const char __user *buffer, 759c3ef1500STetsuo Handa const int buffer_len); 760c3ef1500STetsuo Handa /* Check whether the domain has too many ACL entries to hold. */ 761c3ef1500STetsuo Handa bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); 762c3ef1500STetsuo Handa /* Print out of memory warning message. */ 763c3ef1500STetsuo Handa void tomoyo_warn_oom(const char *function); 7647762fbffSTetsuo Handa /* Check whether the given name matches the given name_union. */ 7657762fbffSTetsuo Handa bool tomoyo_compare_name_union(const struct tomoyo_path_info *name, 7667762fbffSTetsuo Handa const struct tomoyo_name_union *ptr); 7672106ccd9STetsuo Handa /* Check whether the given number matches the given number_union. */ 7682106ccd9STetsuo Handa bool tomoyo_compare_number_union(const unsigned long value, 7692106ccd9STetsuo Handa const struct tomoyo_number_union *ptr); 77057c2590fSTetsuo Handa int tomoyo_get_mode(const u8 profile, const u8 index); 7719590837bSKentaro Takeda /* Transactional sprintf() for policy dump. */ 7729590837bSKentaro Takeda bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) 7739590837bSKentaro Takeda __attribute__ ((format(printf, 2, 3))); 7749590837bSKentaro Takeda /* Check whether the domainname is correct. */ 77575093152STetsuo Handa bool tomoyo_correct_domain(const unsigned char *domainname); 7769590837bSKentaro Takeda /* Check whether the token is correct. */ 77775093152STetsuo Handa bool tomoyo_correct_path(const char *filename); 77875093152STetsuo Handa bool tomoyo_correct_word(const char *string); 7799590837bSKentaro Takeda /* Check whether the token can be a domainname. */ 78075093152STetsuo Handa bool tomoyo_domain_def(const unsigned char *buffer); 7817762fbffSTetsuo Handa bool tomoyo_parse_name_union(const char *filename, 7827762fbffSTetsuo Handa struct tomoyo_name_union *ptr); 7837762fbffSTetsuo Handa /* Check whether the given filename matches the given path_group. */ 7847762fbffSTetsuo Handa bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, 785a98aa4deSTetsuo Handa const struct tomoyo_group *group); 7864c3e9e2dSTetsuo Handa /* Check whether the given value matches the given number_group. */ 7874c3e9e2dSTetsuo Handa bool tomoyo_number_matches_group(const unsigned long min, 7884c3e9e2dSTetsuo Handa const unsigned long max, 789a98aa4deSTetsuo Handa const struct tomoyo_group *group); 7909590837bSKentaro Takeda /* Check whether the given filename matches the given pattern. */ 7919590837bSKentaro Takeda bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 7929590837bSKentaro Takeda const struct tomoyo_path_info *pattern); 7934c3e9e2dSTetsuo Handa 7944c3e9e2dSTetsuo Handa bool tomoyo_print_number_union(struct tomoyo_io_buffer *head, 7954c3e9e2dSTetsuo Handa const struct tomoyo_number_union *ptr); 7964c3e9e2dSTetsuo Handa bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num); 7974c3e9e2dSTetsuo Handa 7981084307cSTetsuo Handa /* Read "aggregator" entry in exception policy. */ 7991084307cSTetsuo Handa bool tomoyo_read_aggregator_policy(struct tomoyo_io_buffer *head); 8009590837bSKentaro Takeda /* Read "alias" entry in exception policy. */ 8019590837bSKentaro Takeda bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head); 8029590837bSKentaro Takeda /* 8039590837bSKentaro Takeda * Read "initialize_domain" and "no_initialize_domain" entry 8049590837bSKentaro Takeda * in exception policy. 8059590837bSKentaro Takeda */ 8069590837bSKentaro Takeda bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head); 8079590837bSKentaro Takeda /* Read "keep_domain" and "no_keep_domain" entry in exception policy. */ 8089590837bSKentaro Takeda bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head); 8099590837bSKentaro Takeda /* Read "file_pattern" entry in exception policy. */ 8109590837bSKentaro Takeda bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head); 8117762fbffSTetsuo Handa /* Read "path_group" entry in exception policy. */ 8127762fbffSTetsuo Handa bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head); 8134c3e9e2dSTetsuo Handa /* Read "number_group" entry in exception policy. */ 8144c3e9e2dSTetsuo Handa bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head); 8159590837bSKentaro Takeda /* Read "allow_read" entry in exception policy. */ 8169590837bSKentaro Takeda bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head); 8179590837bSKentaro Takeda /* Read "deny_rewrite" entry in exception policy. */ 8189590837bSKentaro Takeda bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head); 8197762fbffSTetsuo Handa /* Tokenize a line. */ 8207762fbffSTetsuo Handa bool tomoyo_tokenize(char *buffer, char *w[], size_t size); 8219590837bSKentaro Takeda /* Write domain policy violation warning message to console? */ 8229590837bSKentaro Takeda bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); 8239590837bSKentaro Takeda /* Get the last component of the given domainname. */ 8249590837bSKentaro Takeda const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain); 8252106ccd9STetsuo Handa /* Fill "struct tomoyo_request_info". */ 8262106ccd9STetsuo Handa int tomoyo_init_request_info(struct tomoyo_request_info *r, 82757c2590fSTetsuo Handa struct tomoyo_domain_info *domain, 82857c2590fSTetsuo Handa const u8 index); 8292106ccd9STetsuo Handa /* Check permission for mount operation. */ 8302106ccd9STetsuo Handa int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, 8312106ccd9STetsuo Handa unsigned long flags, void *data_page); 8321084307cSTetsuo Handa /* Create "aggregator" entry in exception policy. */ 8331084307cSTetsuo Handa int tomoyo_write_aggregator_policy(char *data, const bool is_delete); 8349590837bSKentaro Takeda /* Create "alias" entry in exception policy. */ 8359590837bSKentaro Takeda int tomoyo_write_alias_policy(char *data, const bool is_delete); 8369590837bSKentaro Takeda /* 8379590837bSKentaro Takeda * Create "initialize_domain" and "no_initialize_domain" entry 8389590837bSKentaro Takeda * in exception policy. 8399590837bSKentaro Takeda */ 8409590837bSKentaro Takeda int tomoyo_write_domain_initializer_policy(char *data, const bool is_not, 8419590837bSKentaro Takeda const bool is_delete); 8429590837bSKentaro Takeda /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */ 8439590837bSKentaro Takeda int tomoyo_write_domain_keeper_policy(char *data, const bool is_not, 8449590837bSKentaro Takeda const bool is_delete); 8459590837bSKentaro Takeda /* 8469590837bSKentaro Takeda * Create "allow_read/write", "allow_execute", "allow_read", "allow_write", 8479590837bSKentaro Takeda * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", 8489590837bSKentaro Takeda * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", 8499590837bSKentaro Takeda * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and 8509590837bSKentaro Takeda * "allow_link" entry in domain policy. 8519590837bSKentaro Takeda */ 8529590837bSKentaro Takeda int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, 8539590837bSKentaro Takeda const bool is_delete); 8549590837bSKentaro Takeda /* Create "allow_read" entry in exception policy. */ 8559590837bSKentaro Takeda int tomoyo_write_globally_readable_policy(char *data, const bool is_delete); 8562106ccd9STetsuo Handa /* Create "allow_mount" entry in domain policy. */ 8572106ccd9STetsuo Handa int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain, 8582106ccd9STetsuo Handa const bool is_delete); 8599590837bSKentaro Takeda /* Create "deny_rewrite" entry in exception policy. */ 8609590837bSKentaro Takeda int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete); 8619590837bSKentaro Takeda /* Create "file_pattern" entry in exception policy. */ 8629590837bSKentaro Takeda int tomoyo_write_pattern_policy(char *data, const bool is_delete); 8637762fbffSTetsuo Handa /* Create "path_group" entry in exception policy. */ 8647762fbffSTetsuo Handa int tomoyo_write_path_group_policy(char *data, const bool is_delete); 86517fcfbd9STetsuo Handa int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) 86617fcfbd9STetsuo Handa __attribute__ ((format(printf, 2, 3))); 8674c3e9e2dSTetsuo Handa /* Create "number_group" entry in exception policy. */ 8684c3e9e2dSTetsuo Handa int tomoyo_write_number_group_policy(char *data, const bool is_delete); 8699590837bSKentaro Takeda /* Find a domain by the given name. */ 8709590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 8719590837bSKentaro Takeda /* Find or create a domain by the given name. */ 8729590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char * 8739590837bSKentaro Takeda domainname, 8749590837bSKentaro Takeda const u8 profile); 87557c2590fSTetsuo Handa struct tomoyo_profile *tomoyo_profile(const u8 profile); 8767762fbffSTetsuo Handa /* Allocate memory for "struct tomoyo_path_group". */ 877a98aa4deSTetsuo Handa struct tomoyo_group *tomoyo_get_path_group(const char *group_name); 878a98aa4deSTetsuo Handa struct tomoyo_group *tomoyo_get_number_group(const char *group_name); 8797762fbffSTetsuo Handa 8809590837bSKentaro Takeda /* Check mode for specified functionality. */ 8819590837bSKentaro Takeda unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 8829590837bSKentaro Takeda const u8 index); 8839590837bSKentaro Takeda /* Fill in "struct tomoyo_path_info" members. */ 8849590837bSKentaro Takeda void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 8859590837bSKentaro Takeda /* Run policy loader when /sbin/init starts. */ 8869590837bSKentaro Takeda void tomoyo_load_policy(const char *filename); 8879590837bSKentaro Takeda 8884c3e9e2dSTetsuo Handa void tomoyo_put_number_union(struct tomoyo_number_union *ptr); 8894c3e9e2dSTetsuo Handa 89076bb0895STetsuo Handa /* Convert binary string to ascii string. */ 891c8c57e84STetsuo Handa char *tomoyo_encode(const char *str); 89276bb0895STetsuo Handa 89376bb0895STetsuo Handa /* 89476bb0895STetsuo Handa * Returns realpath(3) of the given pathname but ignores chroot'ed root. 89576bb0895STetsuo Handa * These functions use kzalloc(), so the caller must call kfree() 89676bb0895STetsuo Handa * if these functions didn't return NULL. 89776bb0895STetsuo Handa */ 89876bb0895STetsuo Handa char *tomoyo_realpath(const char *pathname); 89976bb0895STetsuo Handa /* 90076bb0895STetsuo Handa * Same with tomoyo_realpath() except that it doesn't follow the final symlink. 90176bb0895STetsuo Handa */ 90276bb0895STetsuo Handa char *tomoyo_realpath_nofollow(const char *pathname); 90376bb0895STetsuo Handa /* Same with tomoyo_realpath() except that the pathname is already solved. */ 90476bb0895STetsuo Handa char *tomoyo_realpath_from_path(struct path *path); 90517fcfbd9STetsuo Handa /* Get patterned pathname. */ 90617fcfbd9STetsuo Handa const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename); 90776bb0895STetsuo Handa 90876bb0895STetsuo Handa /* Check memory quota. */ 90976bb0895STetsuo Handa bool tomoyo_memory_ok(void *ptr); 9109e4b50e9STetsuo Handa void *tomoyo_commit_ok(void *data, const unsigned int size); 91176bb0895STetsuo Handa 91276bb0895STetsuo Handa /* 91376bb0895STetsuo Handa * Keep the given name on the RAM. 91476bb0895STetsuo Handa * The RAM is shared, so NEVER try to modify or kfree() the returned name. 91576bb0895STetsuo Handa */ 91676bb0895STetsuo Handa const struct tomoyo_path_info *tomoyo_get_name(const char *name); 91776bb0895STetsuo Handa 91876bb0895STetsuo Handa /* Check for memory usage. */ 9198fbe71f0STetsuo Handa void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); 92076bb0895STetsuo Handa 92176bb0895STetsuo Handa /* Set memory quota. */ 92276bb0895STetsuo Handa int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); 92376bb0895STetsuo Handa 924c3ef1500STetsuo Handa /* Initialize mm related code. */ 925c3ef1500STetsuo Handa void __init tomoyo_mm_init(void); 92605336deeSTetsuo Handa int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, 92776bb0895STetsuo Handa const struct tomoyo_path_info *filename); 92876bb0895STetsuo Handa int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 92976bb0895STetsuo Handa struct path *path, const int flag); 930a1f9bb6aSTetsuo Handa int tomoyo_path_number_perm(const u8 operation, struct path *path, 931a1f9bb6aSTetsuo Handa unsigned long number); 93275093152STetsuo Handa int tomoyo_mkdev_perm(const u8 operation, struct path *path, 933a1f9bb6aSTetsuo Handa const unsigned int mode, unsigned int dev); 93497d6931eSTetsuo Handa int tomoyo_path_perm(const u8 operation, struct path *path); 93597d6931eSTetsuo Handa int tomoyo_path2_perm(const u8 operation, struct path *path1, 93697d6931eSTetsuo Handa struct path *path2); 93776bb0895STetsuo Handa int tomoyo_find_next_domain(struct linux_binprm *bprm); 93876bb0895STetsuo Handa 939a1f9bb6aSTetsuo Handa void tomoyo_print_ulong(char *buffer, const int buffer_len, 940a1f9bb6aSTetsuo Handa const unsigned long value, const u8 type); 941a1f9bb6aSTetsuo Handa 9427762fbffSTetsuo Handa /* Drop refcount on tomoyo_name_union. */ 9437762fbffSTetsuo Handa void tomoyo_put_name_union(struct tomoyo_name_union *ptr); 9447762fbffSTetsuo Handa 945847b173eSTetsuo Handa /* Run garbage collector. */ 946847b173eSTetsuo Handa void tomoyo_run_gc(void); 947847b173eSTetsuo Handa 948847b173eSTetsuo Handa void tomoyo_memory_free(void *ptr); 949847b173eSTetsuo Handa 950237ab459STetsuo Handa int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, 951237ab459STetsuo Handa bool is_delete, struct tomoyo_domain_info *domain, 952237ab459STetsuo Handa bool (*check_duplicate) (const struct tomoyo_acl_info 953237ab459STetsuo Handa *, 954237ab459STetsuo Handa const struct tomoyo_acl_info 955237ab459STetsuo Handa *), 956237ab459STetsuo Handa bool (*merge_duplicate) (struct tomoyo_acl_info *, 957237ab459STetsuo Handa struct tomoyo_acl_info *, 958237ab459STetsuo Handa const bool)); 95936f5e1ffSTetsuo Handa int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, 96036f5e1ffSTetsuo Handa bool is_delete, struct list_head *list, 96136f5e1ffSTetsuo Handa bool (*check_duplicate) (const struct tomoyo_acl_head 96236f5e1ffSTetsuo Handa *, 96336f5e1ffSTetsuo Handa const struct tomoyo_acl_head 96436f5e1ffSTetsuo Handa *)); 96599a85259STetsuo Handa void tomoyo_check_acl(struct tomoyo_request_info *r, 96699a85259STetsuo Handa bool (*check_entry) (const struct tomoyo_request_info *, 96799a85259STetsuo Handa const struct tomoyo_acl_info *)); 968237ab459STetsuo Handa 96976bb0895STetsuo Handa /********** External variable definitions. **********/ 97076bb0895STetsuo Handa 97176bb0895STetsuo Handa /* Lock for GC. */ 97276bb0895STetsuo Handa extern struct srcu_struct tomoyo_ss; 97376bb0895STetsuo Handa 97476bb0895STetsuo Handa /* The list for "struct tomoyo_domain_info". */ 97576bb0895STetsuo Handa extern struct list_head tomoyo_domain_list; 97676bb0895STetsuo Handa 977a230f9e7STetsuo Handa extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY]; 978a230f9e7STetsuo Handa extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP]; 979847b173eSTetsuo Handa extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 980847b173eSTetsuo Handa 98176bb0895STetsuo Handa /* Lock for protecting policy. */ 98276bb0895STetsuo Handa extern struct mutex tomoyo_policy_lock; 98376bb0895STetsuo Handa 98476bb0895STetsuo Handa /* Has /sbin/init started? */ 98576bb0895STetsuo Handa extern bool tomoyo_policy_loaded; 98676bb0895STetsuo Handa 98776bb0895STetsuo Handa /* The kernel's domain. */ 98876bb0895STetsuo Handa extern struct tomoyo_domain_info tomoyo_kernel_domain; 98976bb0895STetsuo Handa 99071c28236STetsuo Handa extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; 99171c28236STetsuo Handa extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION]; 99271c28236STetsuo Handa extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION]; 99371c28236STetsuo Handa extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION]; 99471c28236STetsuo Handa 99517fcfbd9STetsuo Handa extern unsigned int tomoyo_quota_for_query; 99617fcfbd9STetsuo Handa extern unsigned int tomoyo_query_memory_size; 99717fcfbd9STetsuo Handa 99876bb0895STetsuo Handa /********** Inlined functions. **********/ 99976bb0895STetsuo Handa 100076bb0895STetsuo Handa static inline int tomoyo_read_lock(void) 100176bb0895STetsuo Handa { 100276bb0895STetsuo Handa return srcu_read_lock(&tomoyo_ss); 100376bb0895STetsuo Handa } 100476bb0895STetsuo Handa 100576bb0895STetsuo Handa static inline void tomoyo_read_unlock(int idx) 100676bb0895STetsuo Handa { 100776bb0895STetsuo Handa srcu_read_unlock(&tomoyo_ss, idx); 100876bb0895STetsuo Handa } 100976bb0895STetsuo Handa 10109590837bSKentaro Takeda /* strcmp() for "struct tomoyo_path_info" structure. */ 10119590837bSKentaro Takeda static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, 10129590837bSKentaro Takeda const struct tomoyo_path_info *b) 10139590837bSKentaro Takeda { 10149590837bSKentaro Takeda return a->hash != b->hash || strcmp(a->name, b->name); 10159590837bSKentaro Takeda } 10169590837bSKentaro Takeda 10179590837bSKentaro Takeda /** 101875093152STetsuo Handa * tomoyo_valid - Check whether the character is a valid char. 10199590837bSKentaro Takeda * 10209590837bSKentaro Takeda * @c: The character to check. 10219590837bSKentaro Takeda * 10229590837bSKentaro Takeda * Returns true if @c is a valid character, false otherwise. 10239590837bSKentaro Takeda */ 102475093152STetsuo Handa static inline bool tomoyo_valid(const unsigned char c) 10259590837bSKentaro Takeda { 10269590837bSKentaro Takeda return c > ' ' && c < 127; 10279590837bSKentaro Takeda } 10289590837bSKentaro Takeda 10299590837bSKentaro Takeda /** 103075093152STetsuo Handa * tomoyo_invalid - Check whether the character is an invalid char. 10319590837bSKentaro Takeda * 10329590837bSKentaro Takeda * @c: The character to check. 10339590837bSKentaro Takeda * 10349590837bSKentaro Takeda * Returns true if @c is an invalid character, false otherwise. 10359590837bSKentaro Takeda */ 103675093152STetsuo Handa static inline bool tomoyo_invalid(const unsigned char c) 10379590837bSKentaro Takeda { 10389590837bSKentaro Takeda return c && (c <= ' ' || c >= 127); 10399590837bSKentaro Takeda } 10409590837bSKentaro Takeda 104176bb0895STetsuo Handa static inline void tomoyo_put_name(const struct tomoyo_path_info *name) 104276bb0895STetsuo Handa { 104376bb0895STetsuo Handa if (name) { 104476bb0895STetsuo Handa struct tomoyo_name_entry *ptr = 104576bb0895STetsuo Handa container_of(name, struct tomoyo_name_entry, entry); 104676bb0895STetsuo Handa atomic_dec(&ptr->users); 104776bb0895STetsuo Handa } 104876bb0895STetsuo Handa } 10499590837bSKentaro Takeda 1050a98aa4deSTetsuo Handa static inline void tomoyo_put_group(struct tomoyo_group *group) 10514c3e9e2dSTetsuo Handa { 10524c3e9e2dSTetsuo Handa if (group) 10534c3e9e2dSTetsuo Handa atomic_dec(&group->users); 10544c3e9e2dSTetsuo Handa } 10554c3e9e2dSTetsuo Handa 105676bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_domain(void) 105776bb0895STetsuo Handa { 105876bb0895STetsuo Handa return current_cred()->security; 105976bb0895STetsuo Handa } 10609590837bSKentaro Takeda 106176bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct 106276bb0895STetsuo Handa *task) 106376bb0895STetsuo Handa { 106476bb0895STetsuo Handa return task_cred_xxx(task, security); 106576bb0895STetsuo Handa } 10669590837bSKentaro Takeda 106775093152STetsuo Handa static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1, 10687762fbffSTetsuo Handa const struct tomoyo_acl_info *p2) 10697762fbffSTetsuo Handa { 10707762fbffSTetsuo Handa return p1->type == p2->type; 10717762fbffSTetsuo Handa } 10727762fbffSTetsuo Handa 107375093152STetsuo Handa static inline bool tomoyo_same_name_union 10747762fbffSTetsuo Handa (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2) 10757762fbffSTetsuo Handa { 10767762fbffSTetsuo Handa return p1->filename == p2->filename && p1->group == p2->group && 10777762fbffSTetsuo Handa p1->is_group == p2->is_group; 10787762fbffSTetsuo Handa } 10797762fbffSTetsuo Handa 108075093152STetsuo Handa static inline bool tomoyo_same_number_union 10814c3e9e2dSTetsuo Handa (const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2) 10824c3e9e2dSTetsuo Handa { 10834c3e9e2dSTetsuo Handa return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1] 10844c3e9e2dSTetsuo Handa && p1->group == p2->group && p1->min_type == p2->min_type && 10854c3e9e2dSTetsuo Handa p1->max_type == p2->max_type && p1->is_group == p2->is_group; 10864c3e9e2dSTetsuo Handa } 10874c3e9e2dSTetsuo Handa 10889590837bSKentaro Takeda /** 10899590837bSKentaro Takeda * list_for_each_cookie - iterate over a list with cookie. 10909590837bSKentaro Takeda * @pos: the &struct list_head to use as a loop cursor. 10919590837bSKentaro Takeda * @cookie: the &struct list_head to use as a cookie. 10929590837bSKentaro Takeda * @head: the head for your list. 10939590837bSKentaro Takeda * 1094fdb8ebb7STetsuo Handa * Same with list_for_each_rcu() except that this primitive uses @cookie 10959590837bSKentaro Takeda * so that we can continue iteration. 10969590837bSKentaro Takeda * @cookie must be NULL when iteration starts, and @cookie will become 10979590837bSKentaro Takeda * NULL when iteration finishes. 10989590837bSKentaro Takeda */ 10999590837bSKentaro Takeda #define list_for_each_cookie(pos, cookie, head) \ 11009590837bSKentaro Takeda for (({ if (!cookie) \ 11019590837bSKentaro Takeda cookie = head; }), \ 1102fdb8ebb7STetsuo Handa pos = rcu_dereference((cookie)->next); \ 11039590837bSKentaro Takeda prefetch(pos->next), pos != (head) || ((cookie) = NULL); \ 1104fdb8ebb7STetsuo Handa (cookie) = pos, pos = rcu_dereference(pos->next)) 1105fdb8ebb7STetsuo Handa 11069590837bSKentaro Takeda #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ 1107