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 4132997144STetsuo Handa /* Group number is an integer between 0 and 255. */ 4232997144STetsuo Handa #define TOMOYO_MAX_ACL_GROUPS 256 4332997144STetsuo Handa 44b5bc60b4STetsuo Handa /* Index numbers for operation mode. */ 45cb0abe6aSTetsuo Handa enum tomoyo_mode_index { 46cb0abe6aSTetsuo Handa TOMOYO_CONFIG_DISABLED, 47cb0abe6aSTetsuo Handa TOMOYO_CONFIG_LEARNING, 48cb0abe6aSTetsuo Handa TOMOYO_CONFIG_PERMISSIVE, 4957c2590fSTetsuo Handa TOMOYO_CONFIG_ENFORCING, 50eadd99ccSTetsuo Handa TOMOYO_CONFIG_MAX_MODE, 51eadd99ccSTetsuo Handa TOMOYO_CONFIG_WANT_REJECT_LOG = 64, 52eadd99ccSTetsuo Handa TOMOYO_CONFIG_WANT_GRANT_LOG = 128, 53eadd99ccSTetsuo Handa TOMOYO_CONFIG_USE_DEFAULT = 255, 54cb0abe6aSTetsuo Handa }; 55cb0abe6aSTetsuo Handa 56b5bc60b4STetsuo Handa /* Index numbers for entry type. */ 57a230f9e7STetsuo Handa enum tomoyo_policy_id { 58a230f9e7STetsuo Handa TOMOYO_ID_GROUP, 59a230f9e7STetsuo Handa TOMOYO_ID_PATH_GROUP, 60a230f9e7STetsuo Handa TOMOYO_ID_NUMBER_GROUP, 615448ec4fSTetsuo Handa TOMOYO_ID_TRANSITION_CONTROL, 62a230f9e7STetsuo Handa TOMOYO_ID_AGGREGATOR, 63a230f9e7STetsuo Handa TOMOYO_ID_MANAGER, 64a230f9e7STetsuo Handa TOMOYO_ID_NAME, 65a230f9e7STetsuo Handa TOMOYO_ID_ACL, 66a230f9e7STetsuo Handa TOMOYO_ID_DOMAIN, 67a230f9e7STetsuo Handa TOMOYO_MAX_POLICY 68a230f9e7STetsuo Handa }; 69a230f9e7STetsuo Handa 702c47ab93STetsuo Handa /* Index numbers for domain's attributes. */ 712c47ab93STetsuo Handa enum tomoyo_domain_info_flags_index { 722c47ab93STetsuo Handa /* Quota warnning flag. */ 732c47ab93STetsuo Handa TOMOYO_DIF_QUOTA_WARNED, 742c47ab93STetsuo Handa /* 752c47ab93STetsuo Handa * This domain was unable to create a new domain at 762c47ab93STetsuo Handa * tomoyo_find_next_domain() because the name of the domain to be 772c47ab93STetsuo Handa * created was too long or it could not allocate memory. 782c47ab93STetsuo Handa * More than one process continued execve() without domain transition. 792c47ab93STetsuo Handa */ 802c47ab93STetsuo Handa TOMOYO_DIF_TRANSITION_FAILED, 812c47ab93STetsuo Handa TOMOYO_MAX_DOMAIN_INFO_FLAGS 822c47ab93STetsuo Handa }; 832c47ab93STetsuo Handa 84b5bc60b4STetsuo Handa /* Index numbers for group entries. */ 85a230f9e7STetsuo Handa enum tomoyo_group_id { 86a230f9e7STetsuo Handa TOMOYO_PATH_GROUP, 87a230f9e7STetsuo Handa TOMOYO_NUMBER_GROUP, 88a230f9e7STetsuo Handa TOMOYO_MAX_GROUP 89a230f9e7STetsuo Handa }; 90a230f9e7STetsuo Handa 91b5bc60b4STetsuo Handa /* Index numbers for type of numeric values. */ 92b5bc60b4STetsuo Handa enum tomoyo_value_type { 93b5bc60b4STetsuo Handa TOMOYO_VALUE_TYPE_INVALID, 94b5bc60b4STetsuo Handa TOMOYO_VALUE_TYPE_DECIMAL, 95b5bc60b4STetsuo Handa TOMOYO_VALUE_TYPE_OCTAL, 96b5bc60b4STetsuo Handa TOMOYO_VALUE_TYPE_HEXADECIMAL, 97b5bc60b4STetsuo Handa }; 984c3e9e2dSTetsuo Handa 99b5bc60b4STetsuo Handa /* Index numbers for domain transition control keywords. */ 1005448ec4fSTetsuo Handa enum tomoyo_transition_type { 1015448ec4fSTetsuo Handa /* Do not change this order, */ 102bd03a3e4STetsuo Handa TOMOYO_TRANSITION_CONTROL_NO_RESET, 103bd03a3e4STetsuo Handa TOMOYO_TRANSITION_CONTROL_RESET, 1045448ec4fSTetsuo Handa TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, 1055448ec4fSTetsuo Handa TOMOYO_TRANSITION_CONTROL_INITIALIZE, 1065448ec4fSTetsuo Handa TOMOYO_TRANSITION_CONTROL_NO_KEEP, 1075448ec4fSTetsuo Handa TOMOYO_TRANSITION_CONTROL_KEEP, 1085448ec4fSTetsuo Handa TOMOYO_MAX_TRANSITION_TYPE 1095448ec4fSTetsuo Handa }; 1105448ec4fSTetsuo Handa 11176bb0895STetsuo Handa /* Index numbers for Access Controls. */ 112084da356STetsuo Handa enum tomoyo_acl_entry_type_index { 1137ef61233STetsuo Handa TOMOYO_TYPE_PATH_ACL, 1147ef61233STetsuo Handa TOMOYO_TYPE_PATH2_ACL, 115a1f9bb6aSTetsuo Handa TOMOYO_TYPE_PATH_NUMBER_ACL, 11675093152STetsuo Handa TOMOYO_TYPE_MKDEV_ACL, 1172106ccd9STetsuo Handa TOMOYO_TYPE_MOUNT_ACL, 118084da356STetsuo Handa }; 11976bb0895STetsuo Handa 120b5bc60b4STetsuo Handa /* Index numbers for access controls with one pathname. */ 121084da356STetsuo Handa enum tomoyo_path_acl_index { 1227ef61233STetsuo Handa TOMOYO_TYPE_EXECUTE, 1237ef61233STetsuo Handa TOMOYO_TYPE_READ, 1247ef61233STetsuo Handa TOMOYO_TYPE_WRITE, 1257c75964fSTetsuo Handa TOMOYO_TYPE_APPEND, 1267ef61233STetsuo Handa TOMOYO_TYPE_UNLINK, 1277c75964fSTetsuo Handa TOMOYO_TYPE_GETATTR, 1287ef61233STetsuo Handa TOMOYO_TYPE_RMDIR, 1297ef61233STetsuo Handa TOMOYO_TYPE_TRUNCATE, 1307ef61233STetsuo Handa TOMOYO_TYPE_SYMLINK, 1317ef61233STetsuo Handa TOMOYO_TYPE_CHROOT, 1327ef61233STetsuo Handa TOMOYO_TYPE_UMOUNT, 1337ef61233STetsuo Handa TOMOYO_MAX_PATH_OPERATION 134084da356STetsuo Handa }; 13576bb0895STetsuo Handa 136eadd99ccSTetsuo Handa enum tomoyo_memory_stat_type { 137eadd99ccSTetsuo Handa TOMOYO_MEMORY_POLICY, 138eadd99ccSTetsuo Handa TOMOYO_MEMORY_AUDIT, 139eadd99ccSTetsuo Handa TOMOYO_MEMORY_QUERY, 140eadd99ccSTetsuo Handa TOMOYO_MAX_MEMORY_STAT 141eadd99ccSTetsuo Handa }; 142eadd99ccSTetsuo Handa 14375093152STetsuo Handa enum tomoyo_mkdev_acl_index { 144a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKBLOCK, 145a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKCHAR, 14675093152STetsuo Handa TOMOYO_MAX_MKDEV_OPERATION 147a1f9bb6aSTetsuo Handa }; 148a1f9bb6aSTetsuo Handa 149b5bc60b4STetsuo Handa /* Index numbers for access controls with two pathnames. */ 150084da356STetsuo Handa enum tomoyo_path2_acl_index { 1517ef61233STetsuo Handa TOMOYO_TYPE_LINK, 1527ef61233STetsuo Handa TOMOYO_TYPE_RENAME, 1537ef61233STetsuo Handa TOMOYO_TYPE_PIVOT_ROOT, 1547ef61233STetsuo Handa TOMOYO_MAX_PATH2_OPERATION 155084da356STetsuo Handa }; 15676bb0895STetsuo Handa 157b5bc60b4STetsuo Handa /* Index numbers for access controls with one pathname and one number. */ 158a1f9bb6aSTetsuo Handa enum tomoyo_path_number_acl_index { 159a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CREATE, 160a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKDIR, 161a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKFIFO, 162a1f9bb6aSTetsuo Handa TOMOYO_TYPE_MKSOCK, 163a1f9bb6aSTetsuo Handa TOMOYO_TYPE_IOCTL, 164a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHMOD, 165a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHOWN, 166a1f9bb6aSTetsuo Handa TOMOYO_TYPE_CHGRP, 167a1f9bb6aSTetsuo Handa TOMOYO_MAX_PATH_NUMBER_OPERATION 168a1f9bb6aSTetsuo Handa }; 169a1f9bb6aSTetsuo Handa 170b5bc60b4STetsuo Handa /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */ 171084da356STetsuo Handa enum tomoyo_securityfs_interface_index { 172084da356STetsuo Handa TOMOYO_DOMAINPOLICY, 173084da356STetsuo Handa TOMOYO_EXCEPTIONPOLICY, 174084da356STetsuo Handa TOMOYO_DOMAIN_STATUS, 175084da356STetsuo Handa TOMOYO_PROCESS_STATUS, 176084da356STetsuo Handa TOMOYO_MEMINFO, 177084da356STetsuo Handa TOMOYO_SELFDOMAIN, 178eadd99ccSTetsuo Handa TOMOYO_AUDIT, 179084da356STetsuo Handa TOMOYO_VERSION, 180084da356STetsuo Handa TOMOYO_PROFILE, 18117fcfbd9STetsuo Handa TOMOYO_QUERY, 182084da356STetsuo Handa TOMOYO_MANAGER 183084da356STetsuo Handa }; 18476bb0895STetsuo Handa 185b5bc60b4STetsuo Handa /* Index numbers for special mount operations. */ 186b5bc60b4STetsuo Handa enum tomoyo_special_mount { 187b5bc60b4STetsuo Handa TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */ 188b5bc60b4STetsuo Handa TOMOYO_MOUNT_MOVE, /* mount --move /old /new */ 189b5bc60b4STetsuo Handa TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */ 190b5bc60b4STetsuo Handa TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */ 191b5bc60b4STetsuo Handa TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */ 192b5bc60b4STetsuo Handa TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */ 193b5bc60b4STetsuo Handa TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */ 194b5bc60b4STetsuo Handa TOMOYO_MAX_SPECIAL_MOUNT 195b5bc60b4STetsuo Handa }; 196b5bc60b4STetsuo Handa 197b5bc60b4STetsuo Handa /* Index numbers for functionality. */ 19857c2590fSTetsuo Handa enum tomoyo_mac_index { 19957c2590fSTetsuo Handa TOMOYO_MAC_FILE_EXECUTE, 20057c2590fSTetsuo Handa TOMOYO_MAC_FILE_OPEN, 20157c2590fSTetsuo Handa TOMOYO_MAC_FILE_CREATE, 20257c2590fSTetsuo Handa TOMOYO_MAC_FILE_UNLINK, 2037c75964fSTetsuo Handa TOMOYO_MAC_FILE_GETATTR, 20457c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKDIR, 20557c2590fSTetsuo Handa TOMOYO_MAC_FILE_RMDIR, 20657c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKFIFO, 20757c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKSOCK, 20857c2590fSTetsuo Handa TOMOYO_MAC_FILE_TRUNCATE, 20957c2590fSTetsuo Handa TOMOYO_MAC_FILE_SYMLINK, 21057c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKBLOCK, 21157c2590fSTetsuo Handa TOMOYO_MAC_FILE_MKCHAR, 21257c2590fSTetsuo Handa TOMOYO_MAC_FILE_LINK, 21357c2590fSTetsuo Handa TOMOYO_MAC_FILE_RENAME, 21457c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHMOD, 21557c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHOWN, 21657c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHGRP, 21757c2590fSTetsuo Handa TOMOYO_MAC_FILE_IOCTL, 21857c2590fSTetsuo Handa TOMOYO_MAC_FILE_CHROOT, 21957c2590fSTetsuo Handa TOMOYO_MAC_FILE_MOUNT, 22057c2590fSTetsuo Handa TOMOYO_MAC_FILE_UMOUNT, 22157c2590fSTetsuo Handa TOMOYO_MAC_FILE_PIVOT_ROOT, 22257c2590fSTetsuo Handa TOMOYO_MAX_MAC_INDEX 22357c2590fSTetsuo Handa }; 22457c2590fSTetsuo Handa 225b5bc60b4STetsuo Handa /* Index numbers for category of functionality. */ 22657c2590fSTetsuo Handa enum tomoyo_mac_category_index { 22757c2590fSTetsuo Handa TOMOYO_MAC_CATEGORY_FILE, 22857c2590fSTetsuo Handa TOMOYO_MAX_MAC_CATEGORY_INDEX 22957c2590fSTetsuo Handa }; 23057c2590fSTetsuo Handa 231b5bc60b4STetsuo Handa /* 232b5bc60b4STetsuo Handa * Retry this request. Returned by tomoyo_supervisor() if policy violation has 233b5bc60b4STetsuo Handa * occurred in enforcing mode and the userspace daemon decided to retry. 234b5bc60b4STetsuo Handa * 235b5bc60b4STetsuo Handa * We must choose a positive value in order to distinguish "granted" (which is 236b5bc60b4STetsuo Handa * 0) and "rejected" (which is a negative value) and "retry". 237b5bc60b4STetsuo Handa */ 238b5bc60b4STetsuo Handa #define TOMOYO_RETRY_REQUEST 1 23917fcfbd9STetsuo Handa 240d5ca1725STetsuo Handa /* Index numbers for profile's PREFERENCE values. */ 241d5ca1725STetsuo Handa enum tomoyo_pref_index { 242eadd99ccSTetsuo Handa TOMOYO_PREF_MAX_AUDIT_LOG, 243d5ca1725STetsuo Handa TOMOYO_PREF_MAX_LEARNING_ENTRY, 244d5ca1725STetsuo Handa TOMOYO_MAX_PREF 245d5ca1725STetsuo Handa }; 246d5ca1725STetsuo Handa 24776bb0895STetsuo Handa /********** Structure definitions. **********/ 2489590837bSKentaro Takeda 249b5bc60b4STetsuo Handa /* Common header for holding ACL entries. */ 25082e0f001STetsuo Handa struct tomoyo_acl_head { 25182e0f001STetsuo Handa struct list_head list; 25282e0f001STetsuo Handa bool is_deleted; 25382e0f001STetsuo Handa } __packed; 25482e0f001STetsuo Handa 2550df7e8b8STetsuo Handa /* Common header for shared entries. */ 2560df7e8b8STetsuo Handa struct tomoyo_shared_acl_head { 2570df7e8b8STetsuo Handa struct list_head list; 2580df7e8b8STetsuo Handa atomic_t users; 2590df7e8b8STetsuo Handa } __packed; 2600df7e8b8STetsuo Handa 261bd03a3e4STetsuo Handa struct tomoyo_policy_namespace; 262bd03a3e4STetsuo Handa 263b5bc60b4STetsuo Handa /* Structure for request info. */ 264cb0abe6aSTetsuo Handa struct tomoyo_request_info { 265cb0abe6aSTetsuo Handa struct tomoyo_domain_info *domain; 266cf6e9a64STetsuo Handa /* For holding parameters. */ 267cf6e9a64STetsuo Handa union { 268cf6e9a64STetsuo Handa struct { 269cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 270484ca79cSTetsuo Handa /* For using wildcards at tomoyo_find_next_domain(). */ 271484ca79cSTetsuo Handa const struct tomoyo_path_info *matched_path; 272b5bc60b4STetsuo Handa /* One of values in "enum tomoyo_path_acl_index". */ 273cf6e9a64STetsuo Handa u8 operation; 274cf6e9a64STetsuo Handa } path; 275cf6e9a64STetsuo Handa struct { 276cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename1; 277cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename2; 278b5bc60b4STetsuo Handa /* One of values in "enum tomoyo_path2_acl_index". */ 279cf6e9a64STetsuo Handa u8 operation; 280cf6e9a64STetsuo Handa } path2; 281cf6e9a64STetsuo Handa struct { 282cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 283cf6e9a64STetsuo Handa unsigned int mode; 284cf6e9a64STetsuo Handa unsigned int major; 285cf6e9a64STetsuo Handa unsigned int minor; 286b5bc60b4STetsuo Handa /* One of values in "enum tomoyo_mkdev_acl_index". */ 287cf6e9a64STetsuo Handa u8 operation; 288cf6e9a64STetsuo Handa } mkdev; 289cf6e9a64STetsuo Handa struct { 290cf6e9a64STetsuo Handa const struct tomoyo_path_info *filename; 291cf6e9a64STetsuo Handa unsigned long number; 292b5bc60b4STetsuo Handa /* 293b5bc60b4STetsuo Handa * One of values in 294b5bc60b4STetsuo Handa * "enum tomoyo_path_number_acl_index". 295b5bc60b4STetsuo Handa */ 296cf6e9a64STetsuo Handa u8 operation; 297cf6e9a64STetsuo Handa } path_number; 298cf6e9a64STetsuo Handa struct { 299cf6e9a64STetsuo Handa const struct tomoyo_path_info *type; 300cf6e9a64STetsuo Handa const struct tomoyo_path_info *dir; 301cf6e9a64STetsuo Handa const struct tomoyo_path_info *dev; 302cf6e9a64STetsuo Handa unsigned long flags; 303cf6e9a64STetsuo Handa int need_dev; 304cf6e9a64STetsuo Handa } mount; 305cf6e9a64STetsuo Handa } param; 306cf6e9a64STetsuo Handa u8 param_type; 307cf6e9a64STetsuo Handa bool granted; 30817fcfbd9STetsuo Handa u8 retry; 30917fcfbd9STetsuo Handa u8 profile; 310cb0abe6aSTetsuo Handa u8 mode; /* One of tomoyo_mode_index . */ 31157c2590fSTetsuo Handa u8 type; 312cb0abe6aSTetsuo Handa }; 313cb0abe6aSTetsuo Handa 314b5bc60b4STetsuo Handa /* Structure for holding a token. */ 3159590837bSKentaro Takeda struct tomoyo_path_info { 3169590837bSKentaro Takeda const char *name; 3179590837bSKentaro Takeda u32 hash; /* = full_name_hash(name, strlen(name)) */ 3189590837bSKentaro Takeda u16 const_len; /* = tomoyo_const_part_length(name) */ 3199590837bSKentaro Takeda bool is_dir; /* = tomoyo_strendswith(name, "/") */ 3209590837bSKentaro Takeda bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 3219590837bSKentaro Takeda }; 3229590837bSKentaro Takeda 323b5bc60b4STetsuo Handa /* Structure for holding string data. */ 324e2bf6907STetsuo Handa struct tomoyo_name { 3250df7e8b8STetsuo Handa struct tomoyo_shared_acl_head head; 32676bb0895STetsuo Handa struct tomoyo_path_info entry; 32776bb0895STetsuo Handa }; 3289590837bSKentaro Takeda 329b5bc60b4STetsuo Handa /* Structure for holding a word. */ 3307762fbffSTetsuo Handa struct tomoyo_name_union { 331b5bc60b4STetsuo Handa /* Either @filename or @group is NULL. */ 3327762fbffSTetsuo Handa const struct tomoyo_path_info *filename; 333a98aa4deSTetsuo Handa struct tomoyo_group *group; 3347762fbffSTetsuo Handa }; 3357762fbffSTetsuo Handa 336b5bc60b4STetsuo Handa /* Structure for holding a number. */ 3374c3e9e2dSTetsuo Handa struct tomoyo_number_union { 3384c3e9e2dSTetsuo Handa unsigned long values[2]; 339b5bc60b4STetsuo Handa struct tomoyo_group *group; /* Maybe NULL. */ 340b5bc60b4STetsuo Handa /* One of values in "enum tomoyo_value_type". */ 3410df7e8b8STetsuo Handa u8 value_type[2]; 3424c3e9e2dSTetsuo Handa }; 3434c3e9e2dSTetsuo Handa 344a98aa4deSTetsuo Handa /* Structure for "path_group"/"number_group" directive. */ 345a98aa4deSTetsuo Handa struct tomoyo_group { 3460df7e8b8STetsuo Handa struct tomoyo_shared_acl_head head; 347a98aa4deSTetsuo Handa const struct tomoyo_path_info *group_name; 348a98aa4deSTetsuo Handa struct list_head member_list; 349a98aa4deSTetsuo Handa }; 350a98aa4deSTetsuo Handa 3517762fbffSTetsuo Handa /* Structure for "path_group" directive. */ 3527762fbffSTetsuo Handa struct tomoyo_path_group { 35382e0f001STetsuo Handa struct tomoyo_acl_head head; 3547762fbffSTetsuo Handa const struct tomoyo_path_info *member_name; 3557762fbffSTetsuo Handa }; 3567762fbffSTetsuo Handa 3574c3e9e2dSTetsuo Handa /* Structure for "number_group" directive. */ 358a98aa4deSTetsuo Handa struct tomoyo_number_group { 35982e0f001STetsuo Handa struct tomoyo_acl_head head; 3604c3e9e2dSTetsuo Handa struct tomoyo_number_union number; 3614c3e9e2dSTetsuo Handa }; 3624c3e9e2dSTetsuo Handa 363b5bc60b4STetsuo Handa /* Common header for individual entries. */ 3649590837bSKentaro Takeda struct tomoyo_acl_info { 3659590837bSKentaro Takeda struct list_head list; 366237ab459STetsuo Handa bool is_deleted; 367b5bc60b4STetsuo Handa u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */ 3689590837bSKentaro Takeda } __packed; 3699590837bSKentaro Takeda 370b5bc60b4STetsuo Handa /* Structure for domain information. */ 3719590837bSKentaro Takeda struct tomoyo_domain_info { 3729590837bSKentaro Takeda struct list_head list; 3739590837bSKentaro Takeda struct list_head acl_info_list; 3749590837bSKentaro Takeda /* Name of this domain. Never NULL. */ 3759590837bSKentaro Takeda const struct tomoyo_path_info *domainname; 376bd03a3e4STetsuo Handa /* Namespace for this domain. Never NULL. */ 377bd03a3e4STetsuo Handa struct tomoyo_policy_namespace *ns; 3789590837bSKentaro Takeda u8 profile; /* Profile number to use. */ 37932997144STetsuo Handa u8 group; /* Group number to use. */ 380a0558fc3STetsuo Handa bool is_deleted; /* Delete flag. */ 3812c47ab93STetsuo Handa bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS]; 382ec8e6a4eSTetsuo Handa atomic_t users; /* Number of referring credentials. */ 3839590837bSKentaro Takeda }; 3849590837bSKentaro Takeda 3859590837bSKentaro Takeda /* 386b5bc60b4STetsuo Handa * Structure for "file execute", "file read", "file write", "file append", 387b5bc60b4STetsuo Handa * "file unlink", "file getattr", "file rmdir", "file truncate", 388b5bc60b4STetsuo Handa * "file symlink", "file chroot" and "file unmount" directive. 3899590837bSKentaro Takeda */ 3907ef61233STetsuo Handa struct tomoyo_path_acl { 3917ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 392b5bc60b4STetsuo Handa u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */ 3937762fbffSTetsuo Handa struct tomoyo_name_union name; 3949590837bSKentaro Takeda }; 3959590837bSKentaro Takeda 396c3fa109aSTetsuo Handa /* 397b5bc60b4STetsuo Handa * Structure for "file create", "file mkdir", "file mkfifo", "file mksock", 398b5bc60b4STetsuo Handa * "file ioctl", "file chmod", "file chown" and "file chgrp" directive. 399a1f9bb6aSTetsuo Handa */ 400a1f9bb6aSTetsuo Handa struct tomoyo_path_number_acl { 401a1f9bb6aSTetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ 402b5bc60b4STetsuo Handa /* Bitmask of values in "enum tomoyo_path_number_acl_index". */ 403a1f9bb6aSTetsuo Handa u8 perm; 404a1f9bb6aSTetsuo Handa struct tomoyo_name_union name; 405a1f9bb6aSTetsuo Handa struct tomoyo_number_union number; 406a1f9bb6aSTetsuo Handa }; 407a1f9bb6aSTetsuo Handa 408b5bc60b4STetsuo Handa /* Structure for "file mkblock" and "file mkchar" directive. */ 40975093152STetsuo Handa struct tomoyo_mkdev_acl { 41075093152STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ 411b5bc60b4STetsuo Handa u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */ 412a1f9bb6aSTetsuo Handa struct tomoyo_name_union name; 413a1f9bb6aSTetsuo Handa struct tomoyo_number_union mode; 414a1f9bb6aSTetsuo Handa struct tomoyo_number_union major; 415a1f9bb6aSTetsuo Handa struct tomoyo_number_union minor; 416a1f9bb6aSTetsuo Handa }; 417a1f9bb6aSTetsuo Handa 418a1f9bb6aSTetsuo Handa /* 419b5bc60b4STetsuo Handa * Structure for "file rename", "file link" and "file pivot_root" directive. 420c3fa109aSTetsuo Handa */ 4217ef61233STetsuo Handa struct tomoyo_path2_acl { 4227ef61233STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ 423b5bc60b4STetsuo Handa u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */ 4247762fbffSTetsuo Handa struct tomoyo_name_union name1; 4257762fbffSTetsuo Handa struct tomoyo_name_union name2; 4269590837bSKentaro Takeda }; 4279590837bSKentaro Takeda 428b5bc60b4STetsuo Handa /* Structure for "file mount" directive. */ 4292106ccd9STetsuo Handa struct tomoyo_mount_acl { 4302106ccd9STetsuo Handa struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ 4312106ccd9STetsuo Handa struct tomoyo_name_union dev_name; 4322106ccd9STetsuo Handa struct tomoyo_name_union dir_name; 4332106ccd9STetsuo Handa struct tomoyo_name_union fs_type; 4342106ccd9STetsuo Handa struct tomoyo_number_union flags; 4352106ccd9STetsuo Handa }; 4362106ccd9STetsuo Handa 437a238cf5bSTetsuo Handa /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */ 438a238cf5bSTetsuo Handa struct tomoyo_acl_param { 439a238cf5bSTetsuo Handa char *data; 440a238cf5bSTetsuo Handa struct list_head *list; 441bd03a3e4STetsuo Handa struct tomoyo_policy_namespace *ns; 442a238cf5bSTetsuo Handa bool is_delete; 443a238cf5bSTetsuo Handa }; 444a238cf5bSTetsuo Handa 4450d2171d7STetsuo Handa #define TOMOYO_MAX_IO_READ_QUEUE 64 446f23571e8STetsuo Handa 4472106ccd9STetsuo Handa /* 448f23571e8STetsuo Handa * Structure for reading/writing policy via /sys/kernel/security/tomoyo 449f23571e8STetsuo Handa * interfaces. 450c3fa109aSTetsuo Handa */ 4519590837bSKentaro Takeda struct tomoyo_io_buffer { 4528fbe71f0STetsuo Handa void (*read) (struct tomoyo_io_buffer *); 4539590837bSKentaro Takeda int (*write) (struct tomoyo_io_buffer *); 45417fcfbd9STetsuo Handa int (*poll) (struct file *file, poll_table *wait); 4559590837bSKentaro Takeda /* Exclusive lock for this structure. */ 4569590837bSKentaro Takeda struct mutex io_sem; 457f23571e8STetsuo Handa char __user *read_user_buf; 4582c47ab93STetsuo Handa size_t read_user_buf_avail; 459f23571e8STetsuo Handa struct { 460bd03a3e4STetsuo Handa struct list_head *ns; 461f23571e8STetsuo Handa struct list_head *domain; 462f23571e8STetsuo Handa struct list_head *group; 463f23571e8STetsuo Handa struct list_head *acl; 4642c47ab93STetsuo Handa size_t avail; 4652c47ab93STetsuo Handa unsigned int step; 4662c47ab93STetsuo Handa unsigned int query_index; 467f23571e8STetsuo Handa u16 index; 46832997144STetsuo Handa u8 acl_group_index; 469f23571e8STetsuo Handa u8 bit; 470f23571e8STetsuo Handa u8 w_pos; 471f23571e8STetsuo Handa bool eof; 472f23571e8STetsuo Handa bool print_this_domain_only; 473bd03a3e4STetsuo Handa bool print_transition_related_only; 474f23571e8STetsuo Handa const char *w[TOMOYO_MAX_IO_READ_QUEUE]; 475f23571e8STetsuo Handa } r; 4760df7e8b8STetsuo Handa struct { 477bd03a3e4STetsuo Handa struct tomoyo_policy_namespace *ns; 4789590837bSKentaro Takeda /* The position currently writing to. */ 4790df7e8b8STetsuo Handa struct tomoyo_domain_info *domain; 4800df7e8b8STetsuo Handa /* Bytes available for writing. */ 4812c47ab93STetsuo Handa size_t avail; 482bd03a3e4STetsuo Handa bool is_delete; 4830df7e8b8STetsuo Handa } w; 4849590837bSKentaro Takeda /* Buffer for reading. */ 4859590837bSKentaro Takeda char *read_buf; 4869590837bSKentaro Takeda /* Size of read buffer. */ 4872c47ab93STetsuo Handa size_t readbuf_size; 4889590837bSKentaro Takeda /* Buffer for writing. */ 4899590837bSKentaro Takeda char *write_buf; 4909590837bSKentaro Takeda /* Size of write buffer. */ 4912c47ab93STetsuo Handa size_t writebuf_size; 49217fcfbd9STetsuo Handa /* Type of this interface. */ 4932c47ab93STetsuo Handa enum tomoyo_securityfs_interface_index type; 4942e503bbbSTetsuo Handa /* Users counter protected by tomoyo_io_buffer_list_lock. */ 4952e503bbbSTetsuo Handa u8 users; 4962e503bbbSTetsuo Handa /* List for telling GC not to kfree() elements. */ 4972e503bbbSTetsuo Handa struct list_head list; 4989590837bSKentaro Takeda }; 4999590837bSKentaro Takeda 50076bb0895STetsuo Handa /* 501b5bc60b4STetsuo Handa * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/ 502b5bc60b4STetsuo Handa * "no_keep_domain" keyword. 50376bb0895STetsuo Handa */ 5045448ec4fSTetsuo Handa struct tomoyo_transition_control { 50582e0f001STetsuo Handa struct tomoyo_acl_head head; 5065448ec4fSTetsuo Handa u8 type; /* One of values in "enum tomoyo_transition_type". */ 50776bb0895STetsuo Handa /* True if the domainname is tomoyo_get_last_name(). */ 50876bb0895STetsuo Handa bool is_last_name; 5095448ec4fSTetsuo Handa const struct tomoyo_path_info *domainname; /* Maybe NULL */ 5105448ec4fSTetsuo Handa const struct tomoyo_path_info *program; /* Maybe NULL */ 51176bb0895STetsuo Handa }; 51276bb0895STetsuo Handa 513b5bc60b4STetsuo Handa /* Structure for "aggregator" keyword. */ 514e2bf6907STetsuo Handa struct tomoyo_aggregator { 51582e0f001STetsuo Handa struct tomoyo_acl_head head; 5161084307cSTetsuo Handa const struct tomoyo_path_info *original_name; 5171084307cSTetsuo Handa const struct tomoyo_path_info *aggregated_name; 5181084307cSTetsuo Handa }; 5191084307cSTetsuo Handa 520b5bc60b4STetsuo Handa /* Structure for policy manager. */ 521e2bf6907STetsuo Handa struct tomoyo_manager { 52282e0f001STetsuo Handa struct tomoyo_acl_head head; 52382e0f001STetsuo Handa bool is_domain; /* True if manager is a domainname. */ 52476bb0895STetsuo Handa /* A path to program or a domainname. */ 52576bb0895STetsuo Handa const struct tomoyo_path_info *manager; 52676bb0895STetsuo Handa }; 52776bb0895STetsuo Handa 52857c2590fSTetsuo Handa struct tomoyo_preference { 52957c2590fSTetsuo Handa unsigned int learning_max_entry; 53057c2590fSTetsuo Handa bool enforcing_verbose; 53157c2590fSTetsuo Handa bool learning_verbose; 53257c2590fSTetsuo Handa bool permissive_verbose; 53357c2590fSTetsuo Handa }; 53457c2590fSTetsuo Handa 535b5bc60b4STetsuo Handa /* Structure for /sys/kernel/security/tomnoyo/profile interface. */ 53657c2590fSTetsuo Handa struct tomoyo_profile { 53757c2590fSTetsuo Handa const struct tomoyo_path_info *comment; 53857c2590fSTetsuo Handa struct tomoyo_preference *learning; 53957c2590fSTetsuo Handa struct tomoyo_preference *permissive; 54057c2590fSTetsuo Handa struct tomoyo_preference *enforcing; 54157c2590fSTetsuo Handa struct tomoyo_preference preference; 54257c2590fSTetsuo Handa u8 default_config; 54357c2590fSTetsuo Handa u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; 544d5ca1725STetsuo Handa unsigned int pref[TOMOYO_MAX_PREF]; 54557c2590fSTetsuo Handa }; 54657c2590fSTetsuo Handa 547eadd99ccSTetsuo Handa /* Structure for representing YYYY/MM/DD hh/mm/ss. */ 548eadd99ccSTetsuo Handa struct tomoyo_time { 549eadd99ccSTetsuo Handa u16 year; 550eadd99ccSTetsuo Handa u8 month; 551eadd99ccSTetsuo Handa u8 day; 552eadd99ccSTetsuo Handa u8 hour; 553eadd99ccSTetsuo Handa u8 min; 554eadd99ccSTetsuo Handa u8 sec; 555eadd99ccSTetsuo Handa }; 556eadd99ccSTetsuo Handa 557bd03a3e4STetsuo Handa /* Structure for policy namespace. */ 558bd03a3e4STetsuo Handa struct tomoyo_policy_namespace { 559bd03a3e4STetsuo Handa /* Profile table. Memory is allocated as needed. */ 560bd03a3e4STetsuo Handa struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES]; 561bd03a3e4STetsuo Handa /* List of "struct tomoyo_group". */ 562bd03a3e4STetsuo Handa struct list_head group_list[TOMOYO_MAX_GROUP]; 563bd03a3e4STetsuo Handa /* List of policy. */ 564bd03a3e4STetsuo Handa struct list_head policy_list[TOMOYO_MAX_POLICY]; 565bd03a3e4STetsuo Handa /* The global ACL referred by "use_group" keyword. */ 566bd03a3e4STetsuo Handa struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS]; 567bd03a3e4STetsuo Handa /* List for connecting to tomoyo_namespace_list list. */ 568bd03a3e4STetsuo Handa struct list_head namespace_list; 569bd03a3e4STetsuo Handa /* Profile version. Currently only 20100903 is defined. */ 570bd03a3e4STetsuo Handa unsigned int profile_version; 571bd03a3e4STetsuo Handa /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */ 572bd03a3e4STetsuo Handa const char *name; 573bd03a3e4STetsuo Handa }; 574bd03a3e4STetsuo Handa 57576bb0895STetsuo Handa /********** Function prototypes. **********/ 57676bb0895STetsuo Handa 577bd03a3e4STetsuo Handa void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns); 578c3ef1500STetsuo Handa bool tomoyo_str_starts(char **src, const char *find); 579c3ef1500STetsuo Handa const char *tomoyo_get_exe(void); 580c3ef1500STetsuo Handa void tomoyo_normalize_line(unsigned char *buffer); 581c3ef1500STetsuo Handa void tomoyo_check_profile(void); 582c3ef1500STetsuo Handa int tomoyo_open_control(const u8 type, struct file *file); 5830df7e8b8STetsuo Handa int tomoyo_close_control(struct tomoyo_io_buffer *head); 5840849e3baSTetsuo Handa int tomoyo_poll_control(struct file *file, poll_table *wait); 5852c47ab93STetsuo Handa ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, 586c3ef1500STetsuo Handa const int buffer_len); 5872c47ab93STetsuo Handa ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head, 5880df7e8b8STetsuo Handa const char __user *buffer, const int buffer_len); 589c3ef1500STetsuo Handa bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); 590c3ef1500STetsuo Handa void tomoyo_warn_oom(const char *function); 591484ca79cSTetsuo Handa const struct tomoyo_path_info * 592484ca79cSTetsuo Handa tomoyo_compare_name_union(const struct tomoyo_path_info *name, 5937762fbffSTetsuo Handa const struct tomoyo_name_union *ptr); 5942106ccd9STetsuo Handa bool tomoyo_compare_number_union(const unsigned long value, 5952106ccd9STetsuo Handa const struct tomoyo_number_union *ptr); 596bd03a3e4STetsuo Handa int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile, 597bd03a3e4STetsuo Handa const u8 index); 598f23571e8STetsuo Handa void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) 5999590837bSKentaro Takeda __attribute__ ((format(printf, 2, 3))); 60075093152STetsuo Handa bool tomoyo_correct_domain(const unsigned char *domainname); 60175093152STetsuo Handa bool tomoyo_correct_path(const char *filename); 60275093152STetsuo Handa bool tomoyo_correct_word(const char *string); 60375093152STetsuo Handa bool tomoyo_domain_def(const unsigned char *buffer); 604a238cf5bSTetsuo Handa bool tomoyo_parse_name_union(struct tomoyo_acl_param *param, 6057762fbffSTetsuo Handa struct tomoyo_name_union *ptr); 606484ca79cSTetsuo Handa const struct tomoyo_path_info * 607484ca79cSTetsuo Handa tomoyo_path_matches_group(const struct tomoyo_path_info *pathname, 608a98aa4deSTetsuo Handa const struct tomoyo_group *group); 6094c3e9e2dSTetsuo Handa bool tomoyo_number_matches_group(const unsigned long min, 6104c3e9e2dSTetsuo Handa const unsigned long max, 611a98aa4deSTetsuo Handa const struct tomoyo_group *group); 6129590837bSKentaro Takeda bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 6139590837bSKentaro Takeda const struct tomoyo_path_info *pattern); 614a238cf5bSTetsuo Handa bool tomoyo_parse_number_union(struct tomoyo_acl_param *param, 615a238cf5bSTetsuo Handa struct tomoyo_number_union *ptr); 6167762fbffSTetsuo Handa bool tomoyo_tokenize(char *buffer, char *w[], size_t size); 6179590837bSKentaro Takeda bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain); 6182106ccd9STetsuo Handa int tomoyo_init_request_info(struct tomoyo_request_info *r, 61957c2590fSTetsuo Handa struct tomoyo_domain_info *domain, 62057c2590fSTetsuo Handa const u8 index); 621b5bc60b4STetsuo Handa int tomoyo_mount_permission(char *dev_name, struct path *path, 622b5bc60b4STetsuo Handa const char *type, unsigned long flags, 623b5bc60b4STetsuo Handa void *data_page); 624a238cf5bSTetsuo Handa int tomoyo_write_aggregator(struct tomoyo_acl_param *param); 625a238cf5bSTetsuo Handa int tomoyo_write_transition_control(struct tomoyo_acl_param *param, 6265448ec4fSTetsuo Handa const u8 type); 627a238cf5bSTetsuo Handa int tomoyo_write_file(struct tomoyo_acl_param *param); 628a238cf5bSTetsuo Handa int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type); 62917fcfbd9STetsuo Handa int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) 63017fcfbd9STetsuo Handa __attribute__ ((format(printf, 2, 3))); 6319590837bSKentaro Takeda struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 632e2bf6907STetsuo Handa struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, 633bd03a3e4STetsuo Handa const bool transit); 634bd03a3e4STetsuo Handa struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns, 6359590837bSKentaro Takeda const u8 profile); 636bd03a3e4STetsuo Handa struct tomoyo_policy_namespace *tomoyo_assign_namespace 637bd03a3e4STetsuo Handa (const char *domainname); 638a238cf5bSTetsuo Handa struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param, 639a238cf5bSTetsuo Handa const u8 idx); 6409590837bSKentaro Takeda unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 6419590837bSKentaro Takeda const u8 index); 6429590837bSKentaro Takeda void tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 6439590837bSKentaro Takeda void tomoyo_load_policy(const char *filename); 6444c3e9e2dSTetsuo Handa void tomoyo_put_number_union(struct tomoyo_number_union *ptr); 645c8c57e84STetsuo Handa char *tomoyo_encode(const char *str); 64676bb0895STetsuo Handa char *tomoyo_realpath_nofollow(const char *pathname); 64776bb0895STetsuo Handa char *tomoyo_realpath_from_path(struct path *path); 64876bb0895STetsuo Handa bool tomoyo_memory_ok(void *ptr); 6499e4b50e9STetsuo Handa void *tomoyo_commit_ok(void *data, const unsigned int size); 65076bb0895STetsuo Handa const struct tomoyo_path_info *tomoyo_get_name(const char *name); 6518fbe71f0STetsuo Handa void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head); 65276bb0895STetsuo Handa int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head); 653c3ef1500STetsuo Handa void __init tomoyo_mm_init(void); 65405336deeSTetsuo Handa int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, 65576bb0895STetsuo Handa const struct tomoyo_path_info *filename); 65676bb0895STetsuo Handa int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 65776bb0895STetsuo Handa struct path *path, const int flag); 658a1f9bb6aSTetsuo Handa int tomoyo_path_number_perm(const u8 operation, struct path *path, 659a1f9bb6aSTetsuo Handa unsigned long number); 66075093152STetsuo Handa int tomoyo_mkdev_perm(const u8 operation, struct path *path, 661a1f9bb6aSTetsuo Handa const unsigned int mode, unsigned int dev); 66297d6931eSTetsuo Handa int tomoyo_path_perm(const u8 operation, struct path *path); 66397d6931eSTetsuo Handa int tomoyo_path2_perm(const u8 operation, struct path *path1, 66497d6931eSTetsuo Handa struct path *path2); 66576bb0895STetsuo Handa int tomoyo_find_next_domain(struct linux_binprm *bprm); 666a1f9bb6aSTetsuo Handa void tomoyo_print_ulong(char *buffer, const int buffer_len, 667a1f9bb6aSTetsuo Handa const unsigned long value, const u8 type); 6687762fbffSTetsuo Handa void tomoyo_put_name_union(struct tomoyo_name_union *ptr); 6692e503bbbSTetsuo Handa void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register); 670847b173eSTetsuo Handa void tomoyo_memory_free(void *ptr); 671237ab459STetsuo Handa int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, 672a238cf5bSTetsuo Handa struct tomoyo_acl_param *param, 673237ab459STetsuo Handa bool (*check_duplicate) (const struct tomoyo_acl_info 674237ab459STetsuo Handa *, 675237ab459STetsuo Handa const struct tomoyo_acl_info 676237ab459STetsuo Handa *), 677237ab459STetsuo Handa bool (*merge_duplicate) (struct tomoyo_acl_info *, 678237ab459STetsuo Handa struct tomoyo_acl_info *, 679237ab459STetsuo Handa const bool)); 68036f5e1ffSTetsuo Handa int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, 681a238cf5bSTetsuo Handa struct tomoyo_acl_param *param, 68236f5e1ffSTetsuo Handa bool (*check_duplicate) (const struct tomoyo_acl_head 68336f5e1ffSTetsuo Handa *, 68436f5e1ffSTetsuo Handa const struct tomoyo_acl_head 68536f5e1ffSTetsuo Handa *)); 68699a85259STetsuo Handa void tomoyo_check_acl(struct tomoyo_request_info *r, 687484ca79cSTetsuo Handa bool (*check_entry) (struct tomoyo_request_info *, 68899a85259STetsuo Handa const struct tomoyo_acl_info *)); 689a238cf5bSTetsuo Handa char *tomoyo_read_token(struct tomoyo_acl_param *param); 690a238cf5bSTetsuo Handa bool tomoyo_permstr(const char *string, const char *keyword); 691237ab459STetsuo Handa 692eadd99ccSTetsuo Handa const char *tomoyo_yesno(const unsigned int value); 693bd03a3e4STetsuo Handa void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...) 694bd03a3e4STetsuo Handa __attribute__ ((format(printf, 2, 3))); 695eadd99ccSTetsuo Handa void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt, 696eadd99ccSTetsuo Handa va_list args); 697eadd99ccSTetsuo Handa void tomoyo_read_log(struct tomoyo_io_buffer *head); 698eadd99ccSTetsuo Handa int tomoyo_poll_log(struct file *file, poll_table *wait); 699eadd99ccSTetsuo Handa char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt, 700eadd99ccSTetsuo Handa va_list args); 701eadd99ccSTetsuo Handa 70276bb0895STetsuo Handa /********** External variable definitions. **********/ 70376bb0895STetsuo Handa 70476bb0895STetsuo Handa /* Lock for GC. */ 70576bb0895STetsuo Handa extern struct srcu_struct tomoyo_ss; 70676bb0895STetsuo Handa 70776bb0895STetsuo Handa /* The list for "struct tomoyo_domain_info". */ 70876bb0895STetsuo Handa extern struct list_head tomoyo_domain_list; 70976bb0895STetsuo Handa 710847b173eSTetsuo Handa extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 711847b173eSTetsuo Handa 71276bb0895STetsuo Handa /* Lock for protecting policy. */ 71376bb0895STetsuo Handa extern struct mutex tomoyo_policy_lock; 71476bb0895STetsuo Handa 71576bb0895STetsuo Handa /* Has /sbin/init started? */ 71676bb0895STetsuo Handa extern bool tomoyo_policy_loaded; 71776bb0895STetsuo Handa 71876bb0895STetsuo Handa /* The kernel's domain. */ 71976bb0895STetsuo Handa extern struct tomoyo_domain_info tomoyo_kernel_domain; 720bd03a3e4STetsuo Handa extern struct tomoyo_policy_namespace tomoyo_kernel_namespace; 721bd03a3e4STetsuo Handa extern struct list_head tomoyo_namespace_list; 72276bb0895STetsuo Handa 7232c47ab93STetsuo Handa extern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX + 7242c47ab93STetsuo Handa TOMOYO_MAX_MAC_CATEGORY_INDEX]; 7252c47ab93STetsuo Handa extern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; 7262c47ab93STetsuo Handa extern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX]; 7272c47ab93STetsuo Handa 72871c28236STetsuo Handa 7290d2171d7STetsuo Handa extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION]; 7300d2171d7STetsuo Handa extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION]; 7310d2171d7STetsuo Handa extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION]; 7320d2171d7STetsuo Handa 7332c47ab93STetsuo Handa extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS]; 734eadd99ccSTetsuo Handa extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE]; 735eadd99ccSTetsuo Handa extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT]; 736eadd99ccSTetsuo Handa extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT]; 73717fcfbd9STetsuo Handa 73876bb0895STetsuo Handa /********** Inlined functions. **********/ 73976bb0895STetsuo Handa 740b5bc60b4STetsuo Handa /** 741b5bc60b4STetsuo Handa * tomoyo_read_lock - Take lock for protecting policy. 742b5bc60b4STetsuo Handa * 743b5bc60b4STetsuo Handa * Returns index number for tomoyo_read_unlock(). 744b5bc60b4STetsuo Handa */ 74576bb0895STetsuo Handa static inline int tomoyo_read_lock(void) 74676bb0895STetsuo Handa { 74776bb0895STetsuo Handa return srcu_read_lock(&tomoyo_ss); 74876bb0895STetsuo Handa } 74976bb0895STetsuo Handa 750b5bc60b4STetsuo Handa /** 751b5bc60b4STetsuo Handa * tomoyo_read_unlock - Release lock for protecting policy. 752b5bc60b4STetsuo Handa * 753b5bc60b4STetsuo Handa * @idx: Index number returned by tomoyo_read_lock(). 754b5bc60b4STetsuo Handa * 755b5bc60b4STetsuo Handa * Returns nothing. 756b5bc60b4STetsuo Handa */ 75776bb0895STetsuo Handa static inline void tomoyo_read_unlock(int idx) 75876bb0895STetsuo Handa { 75976bb0895STetsuo Handa srcu_read_unlock(&tomoyo_ss, idx); 76076bb0895STetsuo Handa } 76176bb0895STetsuo Handa 762b5bc60b4STetsuo Handa /** 763b5bc60b4STetsuo Handa * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure. 764b5bc60b4STetsuo Handa * 765b5bc60b4STetsuo Handa * @a: Pointer to "struct tomoyo_path_info". 766b5bc60b4STetsuo Handa * @b: Pointer to "struct tomoyo_path_info". 767b5bc60b4STetsuo Handa * 768b5bc60b4STetsuo Handa * Returns true if @a == @b, false otherwise. 769b5bc60b4STetsuo Handa */ 7709590837bSKentaro Takeda static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, 7719590837bSKentaro Takeda const struct tomoyo_path_info *b) 7729590837bSKentaro Takeda { 7739590837bSKentaro Takeda return a->hash != b->hash || strcmp(a->name, b->name); 7749590837bSKentaro Takeda } 7759590837bSKentaro Takeda 7769590837bSKentaro Takeda /** 777b5bc60b4STetsuo Handa * tomoyo_put_name - Drop reference on "struct tomoyo_name". 778b5bc60b4STetsuo Handa * 779b5bc60b4STetsuo Handa * @name: Pointer to "struct tomoyo_path_info". Maybe NULL. 780b5bc60b4STetsuo Handa * 781b5bc60b4STetsuo Handa * Returns nothing. 782b5bc60b4STetsuo Handa */ 78376bb0895STetsuo Handa static inline void tomoyo_put_name(const struct tomoyo_path_info *name) 78476bb0895STetsuo Handa { 78576bb0895STetsuo Handa if (name) { 786e2bf6907STetsuo Handa struct tomoyo_name *ptr = 787e2bf6907STetsuo Handa container_of(name, typeof(*ptr), entry); 7880df7e8b8STetsuo Handa atomic_dec(&ptr->head.users); 78976bb0895STetsuo Handa } 79076bb0895STetsuo Handa } 7919590837bSKentaro Takeda 792b5bc60b4STetsuo Handa /** 793b5bc60b4STetsuo Handa * tomoyo_put_group - Drop reference on "struct tomoyo_group". 794b5bc60b4STetsuo Handa * 795b5bc60b4STetsuo Handa * @group: Pointer to "struct tomoyo_group". Maybe NULL. 796b5bc60b4STetsuo Handa * 797b5bc60b4STetsuo Handa * Returns nothing. 798b5bc60b4STetsuo Handa */ 799a98aa4deSTetsuo Handa static inline void tomoyo_put_group(struct tomoyo_group *group) 8004c3e9e2dSTetsuo Handa { 8014c3e9e2dSTetsuo Handa if (group) 8020df7e8b8STetsuo Handa atomic_dec(&group->head.users); 8034c3e9e2dSTetsuo Handa } 8044c3e9e2dSTetsuo Handa 805b5bc60b4STetsuo Handa /** 806b5bc60b4STetsuo Handa * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread. 807b5bc60b4STetsuo Handa * 808b5bc60b4STetsuo Handa * Returns pointer to "struct tomoyo_domain_info" for current thread. 809b5bc60b4STetsuo Handa */ 81076bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_domain(void) 81176bb0895STetsuo Handa { 81276bb0895STetsuo Handa return current_cred()->security; 81376bb0895STetsuo Handa } 8149590837bSKentaro Takeda 815b5bc60b4STetsuo Handa /** 816b5bc60b4STetsuo Handa * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread. 817b5bc60b4STetsuo Handa * 818b5bc60b4STetsuo Handa * @task: Pointer to "struct task_struct". 819b5bc60b4STetsuo Handa * 820b5bc60b4STetsuo Handa * Returns pointer to "struct tomoyo_security" for specified thread. 821b5bc60b4STetsuo Handa */ 82276bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct 82376bb0895STetsuo Handa *task) 82476bb0895STetsuo Handa { 82576bb0895STetsuo Handa return task_cred_xxx(task, security); 82676bb0895STetsuo Handa } 8279590837bSKentaro Takeda 828b5bc60b4STetsuo Handa /** 829b5bc60b4STetsuo Handa * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry. 830b5bc60b4STetsuo Handa * 831b5bc60b4STetsuo Handa * @a: Pointer to "struct tomoyo_name_union". 832b5bc60b4STetsuo Handa * @b: Pointer to "struct tomoyo_name_union". 833b5bc60b4STetsuo Handa * 834b5bc60b4STetsuo Handa * Returns true if @a == @b, false otherwise. 835b5bc60b4STetsuo Handa */ 83675093152STetsuo Handa static inline bool tomoyo_same_name_union 837b5bc60b4STetsuo Handa (const struct tomoyo_name_union *a, const struct tomoyo_name_union *b) 8387762fbffSTetsuo Handa { 8390df7e8b8STetsuo Handa return a->filename == b->filename && a->group == b->group; 8407762fbffSTetsuo Handa } 8417762fbffSTetsuo Handa 842b5bc60b4STetsuo Handa /** 843b5bc60b4STetsuo Handa * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry. 844b5bc60b4STetsuo Handa * 845b5bc60b4STetsuo Handa * @a: Pointer to "struct tomoyo_number_union". 846b5bc60b4STetsuo Handa * @b: Pointer to "struct tomoyo_number_union". 847b5bc60b4STetsuo Handa * 848b5bc60b4STetsuo Handa * Returns true if @a == @b, false otherwise. 849b5bc60b4STetsuo Handa */ 85075093152STetsuo Handa static inline bool tomoyo_same_number_union 851b5bc60b4STetsuo Handa (const struct tomoyo_number_union *a, const struct tomoyo_number_union *b) 8524c3e9e2dSTetsuo Handa { 853b5bc60b4STetsuo Handa return a->values[0] == b->values[0] && a->values[1] == b->values[1] && 8540df7e8b8STetsuo Handa a->group == b->group && a->value_type[0] == b->value_type[0] && 8550df7e8b8STetsuo Handa a->value_type[1] == b->value_type[1]; 8564c3e9e2dSTetsuo Handa } 8574c3e9e2dSTetsuo Handa 858bd03a3e4STetsuo Handa /** 859bd03a3e4STetsuo Handa * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread. 860bd03a3e4STetsuo Handa * 861bd03a3e4STetsuo Handa * Returns pointer to "struct tomoyo_policy_namespace" for current thread. 862bd03a3e4STetsuo Handa */ 863bd03a3e4STetsuo Handa static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void) 864bd03a3e4STetsuo Handa { 865bd03a3e4STetsuo Handa return tomoyo_domain()->ns; 866bd03a3e4STetsuo Handa } 867bd03a3e4STetsuo Handa 868eadd99ccSTetsuo Handa #if defined(CONFIG_SLOB) 869eadd99ccSTetsuo Handa 870eadd99ccSTetsuo Handa /** 871eadd99ccSTetsuo Handa * tomoyo_round2 - Round up to power of 2 for calculating memory usage. 872eadd99ccSTetsuo Handa * 873eadd99ccSTetsuo Handa * @size: Size to be rounded up. 874eadd99ccSTetsuo Handa * 875eadd99ccSTetsuo Handa * Returns @size. 876eadd99ccSTetsuo Handa * 877eadd99ccSTetsuo Handa * Since SLOB does not round up, this function simply returns @size. 878eadd99ccSTetsuo Handa */ 879eadd99ccSTetsuo Handa static inline int tomoyo_round2(size_t size) 880eadd99ccSTetsuo Handa { 881eadd99ccSTetsuo Handa return size; 882eadd99ccSTetsuo Handa } 883eadd99ccSTetsuo Handa 884eadd99ccSTetsuo Handa #else 885eadd99ccSTetsuo Handa 886eadd99ccSTetsuo Handa /** 887eadd99ccSTetsuo Handa * tomoyo_round2 - Round up to power of 2 for calculating memory usage. 888eadd99ccSTetsuo Handa * 889eadd99ccSTetsuo Handa * @size: Size to be rounded up. 890eadd99ccSTetsuo Handa * 891eadd99ccSTetsuo Handa * Returns rounded size. 892eadd99ccSTetsuo Handa * 893eadd99ccSTetsuo Handa * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of 894eadd99ccSTetsuo Handa * (e.g.) 128 bytes. 895eadd99ccSTetsuo Handa */ 896eadd99ccSTetsuo Handa static inline int tomoyo_round2(size_t size) 897eadd99ccSTetsuo Handa { 898eadd99ccSTetsuo Handa #if PAGE_SIZE == 4096 899eadd99ccSTetsuo Handa size_t bsize = 32; 900eadd99ccSTetsuo Handa #else 901eadd99ccSTetsuo Handa size_t bsize = 64; 902eadd99ccSTetsuo Handa #endif 903eadd99ccSTetsuo Handa if (!size) 904eadd99ccSTetsuo Handa return 0; 905eadd99ccSTetsuo Handa while (size > bsize) 906eadd99ccSTetsuo Handa bsize <<= 1; 907eadd99ccSTetsuo Handa return bsize; 908eadd99ccSTetsuo Handa } 909eadd99ccSTetsuo Handa 910eadd99ccSTetsuo Handa #endif 911eadd99ccSTetsuo Handa 9129590837bSKentaro Takeda /** 9139590837bSKentaro Takeda * list_for_each_cookie - iterate over a list with cookie. 9149590837bSKentaro Takeda * @pos: the &struct list_head to use as a loop cursor. 9159590837bSKentaro Takeda * @head: the head for your list. 9169590837bSKentaro Takeda */ 917475e6fa3STetsuo Handa #define list_for_each_cookie(pos, head) \ 918475e6fa3STetsuo Handa if (!pos) \ 919475e6fa3STetsuo Handa pos = srcu_dereference((head)->next, &tomoyo_ss); \ 920475e6fa3STetsuo Handa for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss)) 921fdb8ebb7STetsuo Handa 9229590837bSKentaro Takeda #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ 923