18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * security/tomoyo/common.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Header file for TOMOYO. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 2005-2011 NTT DATA CORPORATION 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _SECURITY_TOMOYO_COMMON_H 118c2ecf20Sopenharmony_ci#define _SECURITY_TOMOYO_COMMON_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define pr_fmt(fmt) fmt 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/ctype.h> 168c2ecf20Sopenharmony_ci#include <linux/string.h> 178c2ecf20Sopenharmony_ci#include <linux/mm.h> 188c2ecf20Sopenharmony_ci#include <linux/file.h> 198c2ecf20Sopenharmony_ci#include <linux/kmod.h> 208c2ecf20Sopenharmony_ci#include <linux/fs.h> 218c2ecf20Sopenharmony_ci#include <linux/sched.h> 228c2ecf20Sopenharmony_ci#include <linux/namei.h> 238c2ecf20Sopenharmony_ci#include <linux/mount.h> 248c2ecf20Sopenharmony_ci#include <linux/list.h> 258c2ecf20Sopenharmony_ci#include <linux/cred.h> 268c2ecf20Sopenharmony_ci#include <linux/poll.h> 278c2ecf20Sopenharmony_ci#include <linux/binfmts.h> 288c2ecf20Sopenharmony_ci#include <linux/highmem.h> 298c2ecf20Sopenharmony_ci#include <linux/net.h> 308c2ecf20Sopenharmony_ci#include <linux/inet.h> 318c2ecf20Sopenharmony_ci#include <linux/in.h> 328c2ecf20Sopenharmony_ci#include <linux/in6.h> 338c2ecf20Sopenharmony_ci#include <linux/un.h> 348c2ecf20Sopenharmony_ci#include <linux/lsm_hooks.h> 358c2ecf20Sopenharmony_ci#include <net/sock.h> 368c2ecf20Sopenharmony_ci#include <net/af_unix.h> 378c2ecf20Sopenharmony_ci#include <net/ip.h> 388c2ecf20Sopenharmony_ci#include <net/ipv6.h> 398c2ecf20Sopenharmony_ci#include <net/udp.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/********** Constants definitions. **********/ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* 448c2ecf20Sopenharmony_ci * TOMOYO uses this hash only when appending a string into the string 458c2ecf20Sopenharmony_ci * table. Frequency of appending strings is very low. So we don't need 468c2ecf20Sopenharmony_ci * large (e.g. 64k) hash size. 256 will be sufficient. 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_ci#define TOMOYO_HASH_BITS 8 498c2ecf20Sopenharmony_ci#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* 528c2ecf20Sopenharmony_ci * TOMOYO checks only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET. 538c2ecf20Sopenharmony_ci * Therefore, we don't need SOCK_MAX. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci#define TOMOYO_SOCK_MAX 6 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define TOMOYO_EXEC_TMPSIZE 4096 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* Garbage collector is trying to kfree() this element. */ 608c2ecf20Sopenharmony_ci#define TOMOYO_GC_IN_PROGRESS -1 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* Profile number is an integer between 0 and 255. */ 638c2ecf20Sopenharmony_ci#define TOMOYO_MAX_PROFILES 256 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* Group number is an integer between 0 and 255. */ 668c2ecf20Sopenharmony_ci#define TOMOYO_MAX_ACL_GROUPS 256 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* Index numbers for "struct tomoyo_condition". */ 698c2ecf20Sopenharmony_cienum tomoyo_conditions_index { 708c2ecf20Sopenharmony_ci TOMOYO_TASK_UID, /* current_uid() */ 718c2ecf20Sopenharmony_ci TOMOYO_TASK_EUID, /* current_euid() */ 728c2ecf20Sopenharmony_ci TOMOYO_TASK_SUID, /* current_suid() */ 738c2ecf20Sopenharmony_ci TOMOYO_TASK_FSUID, /* current_fsuid() */ 748c2ecf20Sopenharmony_ci TOMOYO_TASK_GID, /* current_gid() */ 758c2ecf20Sopenharmony_ci TOMOYO_TASK_EGID, /* current_egid() */ 768c2ecf20Sopenharmony_ci TOMOYO_TASK_SGID, /* current_sgid() */ 778c2ecf20Sopenharmony_ci TOMOYO_TASK_FSGID, /* current_fsgid() */ 788c2ecf20Sopenharmony_ci TOMOYO_TASK_PID, /* sys_getpid() */ 798c2ecf20Sopenharmony_ci TOMOYO_TASK_PPID, /* sys_getppid() */ 808c2ecf20Sopenharmony_ci TOMOYO_EXEC_ARGC, /* "struct linux_binprm *"->argc */ 818c2ecf20Sopenharmony_ci TOMOYO_EXEC_ENVC, /* "struct linux_binprm *"->envc */ 828c2ecf20Sopenharmony_ci TOMOYO_TYPE_IS_SOCKET, /* S_IFSOCK */ 838c2ecf20Sopenharmony_ci TOMOYO_TYPE_IS_SYMLINK, /* S_IFLNK */ 848c2ecf20Sopenharmony_ci TOMOYO_TYPE_IS_FILE, /* S_IFREG */ 858c2ecf20Sopenharmony_ci TOMOYO_TYPE_IS_BLOCK_DEV, /* S_IFBLK */ 868c2ecf20Sopenharmony_ci TOMOYO_TYPE_IS_DIRECTORY, /* S_IFDIR */ 878c2ecf20Sopenharmony_ci TOMOYO_TYPE_IS_CHAR_DEV, /* S_IFCHR */ 888c2ecf20Sopenharmony_ci TOMOYO_TYPE_IS_FIFO, /* S_IFIFO */ 898c2ecf20Sopenharmony_ci TOMOYO_MODE_SETUID, /* S_ISUID */ 908c2ecf20Sopenharmony_ci TOMOYO_MODE_SETGID, /* S_ISGID */ 918c2ecf20Sopenharmony_ci TOMOYO_MODE_STICKY, /* S_ISVTX */ 928c2ecf20Sopenharmony_ci TOMOYO_MODE_OWNER_READ, /* S_IRUSR */ 938c2ecf20Sopenharmony_ci TOMOYO_MODE_OWNER_WRITE, /* S_IWUSR */ 948c2ecf20Sopenharmony_ci TOMOYO_MODE_OWNER_EXECUTE, /* S_IXUSR */ 958c2ecf20Sopenharmony_ci TOMOYO_MODE_GROUP_READ, /* S_IRGRP */ 968c2ecf20Sopenharmony_ci TOMOYO_MODE_GROUP_WRITE, /* S_IWGRP */ 978c2ecf20Sopenharmony_ci TOMOYO_MODE_GROUP_EXECUTE, /* S_IXGRP */ 988c2ecf20Sopenharmony_ci TOMOYO_MODE_OTHERS_READ, /* S_IROTH */ 998c2ecf20Sopenharmony_ci TOMOYO_MODE_OTHERS_WRITE, /* S_IWOTH */ 1008c2ecf20Sopenharmony_ci TOMOYO_MODE_OTHERS_EXECUTE, /* S_IXOTH */ 1018c2ecf20Sopenharmony_ci TOMOYO_EXEC_REALPATH, 1028c2ecf20Sopenharmony_ci TOMOYO_SYMLINK_TARGET, 1038c2ecf20Sopenharmony_ci TOMOYO_PATH1_UID, 1048c2ecf20Sopenharmony_ci TOMOYO_PATH1_GID, 1058c2ecf20Sopenharmony_ci TOMOYO_PATH1_INO, 1068c2ecf20Sopenharmony_ci TOMOYO_PATH1_MAJOR, 1078c2ecf20Sopenharmony_ci TOMOYO_PATH1_MINOR, 1088c2ecf20Sopenharmony_ci TOMOYO_PATH1_PERM, 1098c2ecf20Sopenharmony_ci TOMOYO_PATH1_TYPE, 1108c2ecf20Sopenharmony_ci TOMOYO_PATH1_DEV_MAJOR, 1118c2ecf20Sopenharmony_ci TOMOYO_PATH1_DEV_MINOR, 1128c2ecf20Sopenharmony_ci TOMOYO_PATH2_UID, 1138c2ecf20Sopenharmony_ci TOMOYO_PATH2_GID, 1148c2ecf20Sopenharmony_ci TOMOYO_PATH2_INO, 1158c2ecf20Sopenharmony_ci TOMOYO_PATH2_MAJOR, 1168c2ecf20Sopenharmony_ci TOMOYO_PATH2_MINOR, 1178c2ecf20Sopenharmony_ci TOMOYO_PATH2_PERM, 1188c2ecf20Sopenharmony_ci TOMOYO_PATH2_TYPE, 1198c2ecf20Sopenharmony_ci TOMOYO_PATH2_DEV_MAJOR, 1208c2ecf20Sopenharmony_ci TOMOYO_PATH2_DEV_MINOR, 1218c2ecf20Sopenharmony_ci TOMOYO_PATH1_PARENT_UID, 1228c2ecf20Sopenharmony_ci TOMOYO_PATH1_PARENT_GID, 1238c2ecf20Sopenharmony_ci TOMOYO_PATH1_PARENT_INO, 1248c2ecf20Sopenharmony_ci TOMOYO_PATH1_PARENT_PERM, 1258c2ecf20Sopenharmony_ci TOMOYO_PATH2_PARENT_UID, 1268c2ecf20Sopenharmony_ci TOMOYO_PATH2_PARENT_GID, 1278c2ecf20Sopenharmony_ci TOMOYO_PATH2_PARENT_INO, 1288c2ecf20Sopenharmony_ci TOMOYO_PATH2_PARENT_PERM, 1298c2ecf20Sopenharmony_ci TOMOYO_MAX_CONDITION_KEYWORD, 1308c2ecf20Sopenharmony_ci TOMOYO_NUMBER_UNION, 1318c2ecf20Sopenharmony_ci TOMOYO_NAME_UNION, 1328c2ecf20Sopenharmony_ci TOMOYO_ARGV_ENTRY, 1338c2ecf20Sopenharmony_ci TOMOYO_ENVP_ENTRY, 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci/* Index numbers for stat(). */ 1388c2ecf20Sopenharmony_cienum tomoyo_path_stat_index { 1398c2ecf20Sopenharmony_ci /* Do not change this order. */ 1408c2ecf20Sopenharmony_ci TOMOYO_PATH1, 1418c2ecf20Sopenharmony_ci TOMOYO_PATH1_PARENT, 1428c2ecf20Sopenharmony_ci TOMOYO_PATH2, 1438c2ecf20Sopenharmony_ci TOMOYO_PATH2_PARENT, 1448c2ecf20Sopenharmony_ci TOMOYO_MAX_PATH_STAT 1458c2ecf20Sopenharmony_ci}; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/* Index numbers for operation mode. */ 1488c2ecf20Sopenharmony_cienum tomoyo_mode_index { 1498c2ecf20Sopenharmony_ci TOMOYO_CONFIG_DISABLED, 1508c2ecf20Sopenharmony_ci TOMOYO_CONFIG_LEARNING, 1518c2ecf20Sopenharmony_ci TOMOYO_CONFIG_PERMISSIVE, 1528c2ecf20Sopenharmony_ci TOMOYO_CONFIG_ENFORCING, 1538c2ecf20Sopenharmony_ci TOMOYO_CONFIG_MAX_MODE, 1548c2ecf20Sopenharmony_ci TOMOYO_CONFIG_WANT_REJECT_LOG = 64, 1558c2ecf20Sopenharmony_ci TOMOYO_CONFIG_WANT_GRANT_LOG = 128, 1568c2ecf20Sopenharmony_ci TOMOYO_CONFIG_USE_DEFAULT = 255, 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci/* Index numbers for entry type. */ 1608c2ecf20Sopenharmony_cienum tomoyo_policy_id { 1618c2ecf20Sopenharmony_ci TOMOYO_ID_GROUP, 1628c2ecf20Sopenharmony_ci TOMOYO_ID_ADDRESS_GROUP, 1638c2ecf20Sopenharmony_ci TOMOYO_ID_PATH_GROUP, 1648c2ecf20Sopenharmony_ci TOMOYO_ID_NUMBER_GROUP, 1658c2ecf20Sopenharmony_ci TOMOYO_ID_TRANSITION_CONTROL, 1668c2ecf20Sopenharmony_ci TOMOYO_ID_AGGREGATOR, 1678c2ecf20Sopenharmony_ci TOMOYO_ID_MANAGER, 1688c2ecf20Sopenharmony_ci TOMOYO_ID_CONDITION, 1698c2ecf20Sopenharmony_ci TOMOYO_ID_NAME, 1708c2ecf20Sopenharmony_ci TOMOYO_ID_ACL, 1718c2ecf20Sopenharmony_ci TOMOYO_ID_DOMAIN, 1728c2ecf20Sopenharmony_ci TOMOYO_MAX_POLICY 1738c2ecf20Sopenharmony_ci}; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci/* Index numbers for domain's attributes. */ 1768c2ecf20Sopenharmony_cienum tomoyo_domain_info_flags_index { 1778c2ecf20Sopenharmony_ci /* Quota warnning flag. */ 1788c2ecf20Sopenharmony_ci TOMOYO_DIF_QUOTA_WARNED, 1798c2ecf20Sopenharmony_ci /* 1808c2ecf20Sopenharmony_ci * This domain was unable to create a new domain at 1818c2ecf20Sopenharmony_ci * tomoyo_find_next_domain() because the name of the domain to be 1828c2ecf20Sopenharmony_ci * created was too long or it could not allocate memory. 1838c2ecf20Sopenharmony_ci * More than one process continued execve() without domain transition. 1848c2ecf20Sopenharmony_ci */ 1858c2ecf20Sopenharmony_ci TOMOYO_DIF_TRANSITION_FAILED, 1868c2ecf20Sopenharmony_ci TOMOYO_MAX_DOMAIN_INFO_FLAGS 1878c2ecf20Sopenharmony_ci}; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* Index numbers for audit type. */ 1908c2ecf20Sopenharmony_cienum tomoyo_grant_log { 1918c2ecf20Sopenharmony_ci /* Follow profile's configuration. */ 1928c2ecf20Sopenharmony_ci TOMOYO_GRANTLOG_AUTO, 1938c2ecf20Sopenharmony_ci /* Do not generate grant log. */ 1948c2ecf20Sopenharmony_ci TOMOYO_GRANTLOG_NO, 1958c2ecf20Sopenharmony_ci /* Generate grant_log. */ 1968c2ecf20Sopenharmony_ci TOMOYO_GRANTLOG_YES, 1978c2ecf20Sopenharmony_ci}; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci/* Index numbers for group entries. */ 2008c2ecf20Sopenharmony_cienum tomoyo_group_id { 2018c2ecf20Sopenharmony_ci TOMOYO_PATH_GROUP, 2028c2ecf20Sopenharmony_ci TOMOYO_NUMBER_GROUP, 2038c2ecf20Sopenharmony_ci TOMOYO_ADDRESS_GROUP, 2048c2ecf20Sopenharmony_ci TOMOYO_MAX_GROUP 2058c2ecf20Sopenharmony_ci}; 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci/* Index numbers for type of numeric values. */ 2088c2ecf20Sopenharmony_cienum tomoyo_value_type { 2098c2ecf20Sopenharmony_ci TOMOYO_VALUE_TYPE_INVALID, 2108c2ecf20Sopenharmony_ci TOMOYO_VALUE_TYPE_DECIMAL, 2118c2ecf20Sopenharmony_ci TOMOYO_VALUE_TYPE_OCTAL, 2128c2ecf20Sopenharmony_ci TOMOYO_VALUE_TYPE_HEXADECIMAL, 2138c2ecf20Sopenharmony_ci}; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci/* Index numbers for domain transition control keywords. */ 2168c2ecf20Sopenharmony_cienum tomoyo_transition_type { 2178c2ecf20Sopenharmony_ci /* Do not change this order, */ 2188c2ecf20Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_NO_RESET, 2198c2ecf20Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_RESET, 2208c2ecf20Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, 2218c2ecf20Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_INITIALIZE, 2228c2ecf20Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_NO_KEEP, 2238c2ecf20Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_KEEP, 2248c2ecf20Sopenharmony_ci TOMOYO_MAX_TRANSITION_TYPE 2258c2ecf20Sopenharmony_ci}; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci/* Index numbers for Access Controls. */ 2288c2ecf20Sopenharmony_cienum tomoyo_acl_entry_type_index { 2298c2ecf20Sopenharmony_ci TOMOYO_TYPE_PATH_ACL, 2308c2ecf20Sopenharmony_ci TOMOYO_TYPE_PATH2_ACL, 2318c2ecf20Sopenharmony_ci TOMOYO_TYPE_PATH_NUMBER_ACL, 2328c2ecf20Sopenharmony_ci TOMOYO_TYPE_MKDEV_ACL, 2338c2ecf20Sopenharmony_ci TOMOYO_TYPE_MOUNT_ACL, 2348c2ecf20Sopenharmony_ci TOMOYO_TYPE_INET_ACL, 2358c2ecf20Sopenharmony_ci TOMOYO_TYPE_UNIX_ACL, 2368c2ecf20Sopenharmony_ci TOMOYO_TYPE_ENV_ACL, 2378c2ecf20Sopenharmony_ci TOMOYO_TYPE_MANUAL_TASK_ACL, 2388c2ecf20Sopenharmony_ci}; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci/* Index numbers for access controls with one pathname. */ 2418c2ecf20Sopenharmony_cienum tomoyo_path_acl_index { 2428c2ecf20Sopenharmony_ci TOMOYO_TYPE_EXECUTE, 2438c2ecf20Sopenharmony_ci TOMOYO_TYPE_READ, 2448c2ecf20Sopenharmony_ci TOMOYO_TYPE_WRITE, 2458c2ecf20Sopenharmony_ci TOMOYO_TYPE_APPEND, 2468c2ecf20Sopenharmony_ci TOMOYO_TYPE_UNLINK, 2478c2ecf20Sopenharmony_ci TOMOYO_TYPE_GETATTR, 2488c2ecf20Sopenharmony_ci TOMOYO_TYPE_RMDIR, 2498c2ecf20Sopenharmony_ci TOMOYO_TYPE_TRUNCATE, 2508c2ecf20Sopenharmony_ci TOMOYO_TYPE_SYMLINK, 2518c2ecf20Sopenharmony_ci TOMOYO_TYPE_CHROOT, 2528c2ecf20Sopenharmony_ci TOMOYO_TYPE_UMOUNT, 2538c2ecf20Sopenharmony_ci TOMOYO_MAX_PATH_OPERATION 2548c2ecf20Sopenharmony_ci}; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci/* Index numbers for /sys/kernel/security/tomoyo/stat interface. */ 2578c2ecf20Sopenharmony_cienum tomoyo_memory_stat_type { 2588c2ecf20Sopenharmony_ci TOMOYO_MEMORY_POLICY, 2598c2ecf20Sopenharmony_ci TOMOYO_MEMORY_AUDIT, 2608c2ecf20Sopenharmony_ci TOMOYO_MEMORY_QUERY, 2618c2ecf20Sopenharmony_ci TOMOYO_MAX_MEMORY_STAT 2628c2ecf20Sopenharmony_ci}; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cienum tomoyo_mkdev_acl_index { 2658c2ecf20Sopenharmony_ci TOMOYO_TYPE_MKBLOCK, 2668c2ecf20Sopenharmony_ci TOMOYO_TYPE_MKCHAR, 2678c2ecf20Sopenharmony_ci TOMOYO_MAX_MKDEV_OPERATION 2688c2ecf20Sopenharmony_ci}; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci/* Index numbers for socket operations. */ 2718c2ecf20Sopenharmony_cienum tomoyo_network_acl_index { 2728c2ecf20Sopenharmony_ci TOMOYO_NETWORK_BIND, /* bind() operation. */ 2738c2ecf20Sopenharmony_ci TOMOYO_NETWORK_LISTEN, /* listen() operation. */ 2748c2ecf20Sopenharmony_ci TOMOYO_NETWORK_CONNECT, /* connect() operation. */ 2758c2ecf20Sopenharmony_ci TOMOYO_NETWORK_SEND, /* send() operation. */ 2768c2ecf20Sopenharmony_ci TOMOYO_MAX_NETWORK_OPERATION 2778c2ecf20Sopenharmony_ci}; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci/* Index numbers for access controls with two pathnames. */ 2808c2ecf20Sopenharmony_cienum tomoyo_path2_acl_index { 2818c2ecf20Sopenharmony_ci TOMOYO_TYPE_LINK, 2828c2ecf20Sopenharmony_ci TOMOYO_TYPE_RENAME, 2838c2ecf20Sopenharmony_ci TOMOYO_TYPE_PIVOT_ROOT, 2848c2ecf20Sopenharmony_ci TOMOYO_MAX_PATH2_OPERATION 2858c2ecf20Sopenharmony_ci}; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci/* Index numbers for access controls with one pathname and one number. */ 2888c2ecf20Sopenharmony_cienum tomoyo_path_number_acl_index { 2898c2ecf20Sopenharmony_ci TOMOYO_TYPE_CREATE, 2908c2ecf20Sopenharmony_ci TOMOYO_TYPE_MKDIR, 2918c2ecf20Sopenharmony_ci TOMOYO_TYPE_MKFIFO, 2928c2ecf20Sopenharmony_ci TOMOYO_TYPE_MKSOCK, 2938c2ecf20Sopenharmony_ci TOMOYO_TYPE_IOCTL, 2948c2ecf20Sopenharmony_ci TOMOYO_TYPE_CHMOD, 2958c2ecf20Sopenharmony_ci TOMOYO_TYPE_CHOWN, 2968c2ecf20Sopenharmony_ci TOMOYO_TYPE_CHGRP, 2978c2ecf20Sopenharmony_ci TOMOYO_MAX_PATH_NUMBER_OPERATION 2988c2ecf20Sopenharmony_ci}; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */ 3018c2ecf20Sopenharmony_cienum tomoyo_securityfs_interface_index { 3028c2ecf20Sopenharmony_ci TOMOYO_DOMAINPOLICY, 3038c2ecf20Sopenharmony_ci TOMOYO_EXCEPTIONPOLICY, 3048c2ecf20Sopenharmony_ci TOMOYO_PROCESS_STATUS, 3058c2ecf20Sopenharmony_ci TOMOYO_STAT, 3068c2ecf20Sopenharmony_ci TOMOYO_AUDIT, 3078c2ecf20Sopenharmony_ci TOMOYO_VERSION, 3088c2ecf20Sopenharmony_ci TOMOYO_PROFILE, 3098c2ecf20Sopenharmony_ci TOMOYO_QUERY, 3108c2ecf20Sopenharmony_ci TOMOYO_MANAGER 3118c2ecf20Sopenharmony_ci}; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci/* Index numbers for special mount operations. */ 3148c2ecf20Sopenharmony_cienum tomoyo_special_mount { 3158c2ecf20Sopenharmony_ci TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */ 3168c2ecf20Sopenharmony_ci TOMOYO_MOUNT_MOVE, /* mount --move /old /new */ 3178c2ecf20Sopenharmony_ci TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */ 3188c2ecf20Sopenharmony_ci TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */ 3198c2ecf20Sopenharmony_ci TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */ 3208c2ecf20Sopenharmony_ci TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */ 3218c2ecf20Sopenharmony_ci TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */ 3228c2ecf20Sopenharmony_ci TOMOYO_MAX_SPECIAL_MOUNT 3238c2ecf20Sopenharmony_ci}; 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci/* Index numbers for functionality. */ 3268c2ecf20Sopenharmony_cienum tomoyo_mac_index { 3278c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_EXECUTE, 3288c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_OPEN, 3298c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_CREATE, 3308c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_UNLINK, 3318c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_GETATTR, 3328c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_MKDIR, 3338c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_RMDIR, 3348c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_MKFIFO, 3358c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_MKSOCK, 3368c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_TRUNCATE, 3378c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_SYMLINK, 3388c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_MKBLOCK, 3398c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_MKCHAR, 3408c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_LINK, 3418c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_RENAME, 3428c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_CHMOD, 3438c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_CHOWN, 3448c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_CHGRP, 3458c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_IOCTL, 3468c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_CHROOT, 3478c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_MOUNT, 3488c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_UMOUNT, 3498c2ecf20Sopenharmony_ci TOMOYO_MAC_FILE_PIVOT_ROOT, 3508c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_STREAM_BIND, 3518c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_STREAM_LISTEN, 3528c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_STREAM_CONNECT, 3538c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_DGRAM_BIND, 3548c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_DGRAM_SEND, 3558c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_RAW_BIND, 3568c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_RAW_SEND, 3578c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_STREAM_BIND, 3588c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_STREAM_LISTEN, 3598c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_STREAM_CONNECT, 3608c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_DGRAM_BIND, 3618c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_DGRAM_SEND, 3628c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_BIND, 3638c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_LISTEN, 3648c2ecf20Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_CONNECT, 3658c2ecf20Sopenharmony_ci TOMOYO_MAC_ENVIRON, 3668c2ecf20Sopenharmony_ci TOMOYO_MAX_MAC_INDEX 3678c2ecf20Sopenharmony_ci}; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci/* Index numbers for category of functionality. */ 3708c2ecf20Sopenharmony_cienum tomoyo_mac_category_index { 3718c2ecf20Sopenharmony_ci TOMOYO_MAC_CATEGORY_FILE, 3728c2ecf20Sopenharmony_ci TOMOYO_MAC_CATEGORY_NETWORK, 3738c2ecf20Sopenharmony_ci TOMOYO_MAC_CATEGORY_MISC, 3748c2ecf20Sopenharmony_ci TOMOYO_MAX_MAC_CATEGORY_INDEX 3758c2ecf20Sopenharmony_ci}; 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci/* 3788c2ecf20Sopenharmony_ci * Retry this request. Returned by tomoyo_supervisor() if policy violation has 3798c2ecf20Sopenharmony_ci * occurred in enforcing mode and the userspace daemon decided to retry. 3808c2ecf20Sopenharmony_ci * 3818c2ecf20Sopenharmony_ci * We must choose a positive value in order to distinguish "granted" (which is 3828c2ecf20Sopenharmony_ci * 0) and "rejected" (which is a negative value) and "retry". 3838c2ecf20Sopenharmony_ci */ 3848c2ecf20Sopenharmony_ci#define TOMOYO_RETRY_REQUEST 1 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci/* Index numbers for /sys/kernel/security/tomoyo/stat interface. */ 3878c2ecf20Sopenharmony_cienum tomoyo_policy_stat_type { 3888c2ecf20Sopenharmony_ci /* Do not change this order. */ 3898c2ecf20Sopenharmony_ci TOMOYO_STAT_POLICY_UPDATES, 3908c2ecf20Sopenharmony_ci TOMOYO_STAT_POLICY_LEARNING, /* == TOMOYO_CONFIG_LEARNING */ 3918c2ecf20Sopenharmony_ci TOMOYO_STAT_POLICY_PERMISSIVE, /* == TOMOYO_CONFIG_PERMISSIVE */ 3928c2ecf20Sopenharmony_ci TOMOYO_STAT_POLICY_ENFORCING, /* == TOMOYO_CONFIG_ENFORCING */ 3938c2ecf20Sopenharmony_ci TOMOYO_MAX_POLICY_STAT 3948c2ecf20Sopenharmony_ci}; 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci/* Index numbers for profile's PREFERENCE values. */ 3978c2ecf20Sopenharmony_cienum tomoyo_pref_index { 3988c2ecf20Sopenharmony_ci TOMOYO_PREF_MAX_AUDIT_LOG, 3998c2ecf20Sopenharmony_ci TOMOYO_PREF_MAX_LEARNING_ENTRY, 4008c2ecf20Sopenharmony_ci TOMOYO_MAX_PREF 4018c2ecf20Sopenharmony_ci}; 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci/********** Structure definitions. **********/ 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci/* Common header for holding ACL entries. */ 4068c2ecf20Sopenharmony_cistruct tomoyo_acl_head { 4078c2ecf20Sopenharmony_ci struct list_head list; 4088c2ecf20Sopenharmony_ci s8 is_deleted; /* true or false or TOMOYO_GC_IN_PROGRESS */ 4098c2ecf20Sopenharmony_ci} __packed; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci/* Common header for shared entries. */ 4128c2ecf20Sopenharmony_cistruct tomoyo_shared_acl_head { 4138c2ecf20Sopenharmony_ci struct list_head list; 4148c2ecf20Sopenharmony_ci atomic_t users; 4158c2ecf20Sopenharmony_ci} __packed; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cistruct tomoyo_policy_namespace; 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci/* Structure for request info. */ 4208c2ecf20Sopenharmony_cistruct tomoyo_request_info { 4218c2ecf20Sopenharmony_ci /* 4228c2ecf20Sopenharmony_ci * For holding parameters specific to operations which deal files. 4238c2ecf20Sopenharmony_ci * NULL if not dealing files. 4248c2ecf20Sopenharmony_ci */ 4258c2ecf20Sopenharmony_ci struct tomoyo_obj_info *obj; 4268c2ecf20Sopenharmony_ci /* 4278c2ecf20Sopenharmony_ci * For holding parameters specific to execve() request. 4288c2ecf20Sopenharmony_ci * NULL if not dealing execve(). 4298c2ecf20Sopenharmony_ci */ 4308c2ecf20Sopenharmony_ci struct tomoyo_execve *ee; 4318c2ecf20Sopenharmony_ci struct tomoyo_domain_info *domain; 4328c2ecf20Sopenharmony_ci /* For holding parameters. */ 4338c2ecf20Sopenharmony_ci union { 4348c2ecf20Sopenharmony_ci struct { 4358c2ecf20Sopenharmony_ci const struct tomoyo_path_info *filename; 4368c2ecf20Sopenharmony_ci /* For using wildcards at tomoyo_find_next_domain(). */ 4378c2ecf20Sopenharmony_ci const struct tomoyo_path_info *matched_path; 4388c2ecf20Sopenharmony_ci /* One of values in "enum tomoyo_path_acl_index". */ 4398c2ecf20Sopenharmony_ci u8 operation; 4408c2ecf20Sopenharmony_ci } path; 4418c2ecf20Sopenharmony_ci struct { 4428c2ecf20Sopenharmony_ci const struct tomoyo_path_info *filename1; 4438c2ecf20Sopenharmony_ci const struct tomoyo_path_info *filename2; 4448c2ecf20Sopenharmony_ci /* One of values in "enum tomoyo_path2_acl_index". */ 4458c2ecf20Sopenharmony_ci u8 operation; 4468c2ecf20Sopenharmony_ci } path2; 4478c2ecf20Sopenharmony_ci struct { 4488c2ecf20Sopenharmony_ci const struct tomoyo_path_info *filename; 4498c2ecf20Sopenharmony_ci unsigned int mode; 4508c2ecf20Sopenharmony_ci unsigned int major; 4518c2ecf20Sopenharmony_ci unsigned int minor; 4528c2ecf20Sopenharmony_ci /* One of values in "enum tomoyo_mkdev_acl_index". */ 4538c2ecf20Sopenharmony_ci u8 operation; 4548c2ecf20Sopenharmony_ci } mkdev; 4558c2ecf20Sopenharmony_ci struct { 4568c2ecf20Sopenharmony_ci const struct tomoyo_path_info *filename; 4578c2ecf20Sopenharmony_ci unsigned long number; 4588c2ecf20Sopenharmony_ci /* 4598c2ecf20Sopenharmony_ci * One of values in 4608c2ecf20Sopenharmony_ci * "enum tomoyo_path_number_acl_index". 4618c2ecf20Sopenharmony_ci */ 4628c2ecf20Sopenharmony_ci u8 operation; 4638c2ecf20Sopenharmony_ci } path_number; 4648c2ecf20Sopenharmony_ci struct { 4658c2ecf20Sopenharmony_ci const struct tomoyo_path_info *name; 4668c2ecf20Sopenharmony_ci } environ; 4678c2ecf20Sopenharmony_ci struct { 4688c2ecf20Sopenharmony_ci const __be32 *address; 4698c2ecf20Sopenharmony_ci u16 port; 4708c2ecf20Sopenharmony_ci /* One of values smaller than TOMOYO_SOCK_MAX. */ 4718c2ecf20Sopenharmony_ci u8 protocol; 4728c2ecf20Sopenharmony_ci /* One of values in "enum tomoyo_network_acl_index". */ 4738c2ecf20Sopenharmony_ci u8 operation; 4748c2ecf20Sopenharmony_ci bool is_ipv6; 4758c2ecf20Sopenharmony_ci } inet_network; 4768c2ecf20Sopenharmony_ci struct { 4778c2ecf20Sopenharmony_ci const struct tomoyo_path_info *address; 4788c2ecf20Sopenharmony_ci /* One of values smaller than TOMOYO_SOCK_MAX. */ 4798c2ecf20Sopenharmony_ci u8 protocol; 4808c2ecf20Sopenharmony_ci /* One of values in "enum tomoyo_network_acl_index". */ 4818c2ecf20Sopenharmony_ci u8 operation; 4828c2ecf20Sopenharmony_ci } unix_network; 4838c2ecf20Sopenharmony_ci struct { 4848c2ecf20Sopenharmony_ci const struct tomoyo_path_info *type; 4858c2ecf20Sopenharmony_ci const struct tomoyo_path_info *dir; 4868c2ecf20Sopenharmony_ci const struct tomoyo_path_info *dev; 4878c2ecf20Sopenharmony_ci unsigned long flags; 4888c2ecf20Sopenharmony_ci int need_dev; 4898c2ecf20Sopenharmony_ci } mount; 4908c2ecf20Sopenharmony_ci struct { 4918c2ecf20Sopenharmony_ci const struct tomoyo_path_info *domainname; 4928c2ecf20Sopenharmony_ci } task; 4938c2ecf20Sopenharmony_ci } param; 4948c2ecf20Sopenharmony_ci struct tomoyo_acl_info *matched_acl; 4958c2ecf20Sopenharmony_ci u8 param_type; 4968c2ecf20Sopenharmony_ci bool granted; 4978c2ecf20Sopenharmony_ci u8 retry; 4988c2ecf20Sopenharmony_ci u8 profile; 4998c2ecf20Sopenharmony_ci u8 mode; /* One of tomoyo_mode_index . */ 5008c2ecf20Sopenharmony_ci u8 type; 5018c2ecf20Sopenharmony_ci}; 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci/* Structure for holding a token. */ 5048c2ecf20Sopenharmony_cistruct tomoyo_path_info { 5058c2ecf20Sopenharmony_ci const char *name; 5068c2ecf20Sopenharmony_ci u32 hash; /* = full_name_hash(name, strlen(name)) */ 5078c2ecf20Sopenharmony_ci u16 const_len; /* = tomoyo_const_part_length(name) */ 5088c2ecf20Sopenharmony_ci bool is_dir; /* = tomoyo_strendswith(name, "/") */ 5098c2ecf20Sopenharmony_ci bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 5108c2ecf20Sopenharmony_ci}; 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci/* Structure for holding string data. */ 5138c2ecf20Sopenharmony_cistruct tomoyo_name { 5148c2ecf20Sopenharmony_ci struct tomoyo_shared_acl_head head; 5158c2ecf20Sopenharmony_ci struct tomoyo_path_info entry; 5168c2ecf20Sopenharmony_ci}; 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci/* Structure for holding a word. */ 5198c2ecf20Sopenharmony_cistruct tomoyo_name_union { 5208c2ecf20Sopenharmony_ci /* Either @filename or @group is NULL. */ 5218c2ecf20Sopenharmony_ci const struct tomoyo_path_info *filename; 5228c2ecf20Sopenharmony_ci struct tomoyo_group *group; 5238c2ecf20Sopenharmony_ci}; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci/* Structure for holding a number. */ 5268c2ecf20Sopenharmony_cistruct tomoyo_number_union { 5278c2ecf20Sopenharmony_ci unsigned long values[2]; 5288c2ecf20Sopenharmony_ci struct tomoyo_group *group; /* Maybe NULL. */ 5298c2ecf20Sopenharmony_ci /* One of values in "enum tomoyo_value_type". */ 5308c2ecf20Sopenharmony_ci u8 value_type[2]; 5318c2ecf20Sopenharmony_ci}; 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci/* Structure for holding an IP address. */ 5348c2ecf20Sopenharmony_cistruct tomoyo_ipaddr_union { 5358c2ecf20Sopenharmony_ci struct in6_addr ip[2]; /* Big endian. */ 5368c2ecf20Sopenharmony_ci struct tomoyo_group *group; /* Pointer to address group. */ 5378c2ecf20Sopenharmony_ci bool is_ipv6; /* Valid only if @group == NULL. */ 5388c2ecf20Sopenharmony_ci}; 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci/* Structure for "path_group"/"number_group"/"address_group" directive. */ 5418c2ecf20Sopenharmony_cistruct tomoyo_group { 5428c2ecf20Sopenharmony_ci struct tomoyo_shared_acl_head head; 5438c2ecf20Sopenharmony_ci const struct tomoyo_path_info *group_name; 5448c2ecf20Sopenharmony_ci struct list_head member_list; 5458c2ecf20Sopenharmony_ci}; 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci/* Structure for "path_group" directive. */ 5488c2ecf20Sopenharmony_cistruct tomoyo_path_group { 5498c2ecf20Sopenharmony_ci struct tomoyo_acl_head head; 5508c2ecf20Sopenharmony_ci const struct tomoyo_path_info *member_name; 5518c2ecf20Sopenharmony_ci}; 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci/* Structure for "number_group" directive. */ 5548c2ecf20Sopenharmony_cistruct tomoyo_number_group { 5558c2ecf20Sopenharmony_ci struct tomoyo_acl_head head; 5568c2ecf20Sopenharmony_ci struct tomoyo_number_union number; 5578c2ecf20Sopenharmony_ci}; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci/* Structure for "address_group" directive. */ 5608c2ecf20Sopenharmony_cistruct tomoyo_address_group { 5618c2ecf20Sopenharmony_ci struct tomoyo_acl_head head; 5628c2ecf20Sopenharmony_ci /* Structure for holding an IP address. */ 5638c2ecf20Sopenharmony_ci struct tomoyo_ipaddr_union address; 5648c2ecf20Sopenharmony_ci}; 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci/* Subset of "struct stat". Used by conditional ACL and audit logs. */ 5678c2ecf20Sopenharmony_cistruct tomoyo_mini_stat { 5688c2ecf20Sopenharmony_ci kuid_t uid; 5698c2ecf20Sopenharmony_ci kgid_t gid; 5708c2ecf20Sopenharmony_ci ino_t ino; 5718c2ecf20Sopenharmony_ci umode_t mode; 5728c2ecf20Sopenharmony_ci dev_t dev; 5738c2ecf20Sopenharmony_ci dev_t rdev; 5748c2ecf20Sopenharmony_ci}; 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci/* Structure for dumping argv[] and envp[] of "struct linux_binprm". */ 5778c2ecf20Sopenharmony_cistruct tomoyo_page_dump { 5788c2ecf20Sopenharmony_ci struct page *page; /* Previously dumped page. */ 5798c2ecf20Sopenharmony_ci char *data; /* Contents of "page". Size is PAGE_SIZE. */ 5808c2ecf20Sopenharmony_ci}; 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci/* Structure for attribute checks in addition to pathname checks. */ 5838c2ecf20Sopenharmony_cistruct tomoyo_obj_info { 5848c2ecf20Sopenharmony_ci /* 5858c2ecf20Sopenharmony_ci * True if tomoyo_get_attributes() was already called, false otherwise. 5868c2ecf20Sopenharmony_ci */ 5878c2ecf20Sopenharmony_ci bool validate_done; 5888c2ecf20Sopenharmony_ci /* True if @stat[] is valid. */ 5898c2ecf20Sopenharmony_ci bool stat_valid[TOMOYO_MAX_PATH_STAT]; 5908c2ecf20Sopenharmony_ci /* First pathname. Initialized with { NULL, NULL } if no path. */ 5918c2ecf20Sopenharmony_ci struct path path1; 5928c2ecf20Sopenharmony_ci /* Second pathname. Initialized with { NULL, NULL } if no path. */ 5938c2ecf20Sopenharmony_ci struct path path2; 5948c2ecf20Sopenharmony_ci /* 5958c2ecf20Sopenharmony_ci * Information on @path1, @path1's parent directory, @path2, @path2's 5968c2ecf20Sopenharmony_ci * parent directory. 5978c2ecf20Sopenharmony_ci */ 5988c2ecf20Sopenharmony_ci struct tomoyo_mini_stat stat[TOMOYO_MAX_PATH_STAT]; 5998c2ecf20Sopenharmony_ci /* 6008c2ecf20Sopenharmony_ci * Content of symbolic link to be created. NULL for operations other 6018c2ecf20Sopenharmony_ci * than symlink(). 6028c2ecf20Sopenharmony_ci */ 6038c2ecf20Sopenharmony_ci struct tomoyo_path_info *symlink_target; 6048c2ecf20Sopenharmony_ci}; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci/* Structure for argv[]. */ 6078c2ecf20Sopenharmony_cistruct tomoyo_argv { 6088c2ecf20Sopenharmony_ci unsigned long index; 6098c2ecf20Sopenharmony_ci const struct tomoyo_path_info *value; 6108c2ecf20Sopenharmony_ci bool is_not; 6118c2ecf20Sopenharmony_ci}; 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci/* Structure for envp[]. */ 6148c2ecf20Sopenharmony_cistruct tomoyo_envp { 6158c2ecf20Sopenharmony_ci const struct tomoyo_path_info *name; 6168c2ecf20Sopenharmony_ci const struct tomoyo_path_info *value; 6178c2ecf20Sopenharmony_ci bool is_not; 6188c2ecf20Sopenharmony_ci}; 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci/* Structure for execve() operation. */ 6218c2ecf20Sopenharmony_cistruct tomoyo_execve { 6228c2ecf20Sopenharmony_ci struct tomoyo_request_info r; 6238c2ecf20Sopenharmony_ci struct tomoyo_obj_info obj; 6248c2ecf20Sopenharmony_ci struct linux_binprm *bprm; 6258c2ecf20Sopenharmony_ci const struct tomoyo_path_info *transition; 6268c2ecf20Sopenharmony_ci /* For dumping argv[] and envp[]. */ 6278c2ecf20Sopenharmony_ci struct tomoyo_page_dump dump; 6288c2ecf20Sopenharmony_ci /* For temporary use. */ 6298c2ecf20Sopenharmony_ci char *tmp; /* Size is TOMOYO_EXEC_TMPSIZE bytes */ 6308c2ecf20Sopenharmony_ci}; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci/* Structure for entries which follows "struct tomoyo_condition". */ 6338c2ecf20Sopenharmony_cistruct tomoyo_condition_element { 6348c2ecf20Sopenharmony_ci /* 6358c2ecf20Sopenharmony_ci * Left hand operand. A "struct tomoyo_argv" for TOMOYO_ARGV_ENTRY, a 6368c2ecf20Sopenharmony_ci * "struct tomoyo_envp" for TOMOYO_ENVP_ENTRY is attached to the tail 6378c2ecf20Sopenharmony_ci * of the array of this struct. 6388c2ecf20Sopenharmony_ci */ 6398c2ecf20Sopenharmony_ci u8 left; 6408c2ecf20Sopenharmony_ci /* 6418c2ecf20Sopenharmony_ci * Right hand operand. A "struct tomoyo_number_union" for 6428c2ecf20Sopenharmony_ci * TOMOYO_NUMBER_UNION, a "struct tomoyo_name_union" for 6438c2ecf20Sopenharmony_ci * TOMOYO_NAME_UNION is attached to the tail of the array of this 6448c2ecf20Sopenharmony_ci * struct. 6458c2ecf20Sopenharmony_ci */ 6468c2ecf20Sopenharmony_ci u8 right; 6478c2ecf20Sopenharmony_ci /* Equation operator. True if equals or overlaps, false otherwise. */ 6488c2ecf20Sopenharmony_ci bool equals; 6498c2ecf20Sopenharmony_ci}; 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci/* Structure for optional arguments. */ 6528c2ecf20Sopenharmony_cistruct tomoyo_condition { 6538c2ecf20Sopenharmony_ci struct tomoyo_shared_acl_head head; 6548c2ecf20Sopenharmony_ci u32 size; /* Memory size allocated for this entry. */ 6558c2ecf20Sopenharmony_ci u16 condc; /* Number of conditions in this struct. */ 6568c2ecf20Sopenharmony_ci u16 numbers_count; /* Number of "struct tomoyo_number_union values". */ 6578c2ecf20Sopenharmony_ci u16 names_count; /* Number of "struct tomoyo_name_union names". */ 6588c2ecf20Sopenharmony_ci u16 argc; /* Number of "struct tomoyo_argv". */ 6598c2ecf20Sopenharmony_ci u16 envc; /* Number of "struct tomoyo_envp". */ 6608c2ecf20Sopenharmony_ci u8 grant_log; /* One of values in "enum tomoyo_grant_log". */ 6618c2ecf20Sopenharmony_ci const struct tomoyo_path_info *transit; /* Maybe NULL. */ 6628c2ecf20Sopenharmony_ci /* 6638c2ecf20Sopenharmony_ci * struct tomoyo_condition_element condition[condc]; 6648c2ecf20Sopenharmony_ci * struct tomoyo_number_union values[numbers_count]; 6658c2ecf20Sopenharmony_ci * struct tomoyo_name_union names[names_count]; 6668c2ecf20Sopenharmony_ci * struct tomoyo_argv argv[argc]; 6678c2ecf20Sopenharmony_ci * struct tomoyo_envp envp[envc]; 6688c2ecf20Sopenharmony_ci */ 6698c2ecf20Sopenharmony_ci}; 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci/* Common header for individual entries. */ 6728c2ecf20Sopenharmony_cistruct tomoyo_acl_info { 6738c2ecf20Sopenharmony_ci struct list_head list; 6748c2ecf20Sopenharmony_ci struct tomoyo_condition *cond; /* Maybe NULL. */ 6758c2ecf20Sopenharmony_ci s8 is_deleted; /* true or false or TOMOYO_GC_IN_PROGRESS */ 6768c2ecf20Sopenharmony_ci u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */ 6778c2ecf20Sopenharmony_ci} __packed; 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci/* Structure for domain information. */ 6808c2ecf20Sopenharmony_cistruct tomoyo_domain_info { 6818c2ecf20Sopenharmony_ci struct list_head list; 6828c2ecf20Sopenharmony_ci struct list_head acl_info_list; 6838c2ecf20Sopenharmony_ci /* Name of this domain. Never NULL. */ 6848c2ecf20Sopenharmony_ci const struct tomoyo_path_info *domainname; 6858c2ecf20Sopenharmony_ci /* Namespace for this domain. Never NULL. */ 6868c2ecf20Sopenharmony_ci struct tomoyo_policy_namespace *ns; 6878c2ecf20Sopenharmony_ci /* Group numbers to use. */ 6888c2ecf20Sopenharmony_ci unsigned long group[TOMOYO_MAX_ACL_GROUPS / BITS_PER_LONG]; 6898c2ecf20Sopenharmony_ci u8 profile; /* Profile number to use. */ 6908c2ecf20Sopenharmony_ci bool is_deleted; /* Delete flag. */ 6918c2ecf20Sopenharmony_ci bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS]; 6928c2ecf20Sopenharmony_ci atomic_t users; /* Number of referring tasks. */ 6938c2ecf20Sopenharmony_ci}; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci/* 6968c2ecf20Sopenharmony_ci * Structure for "task manual_domain_transition" directive. 6978c2ecf20Sopenharmony_ci */ 6988c2ecf20Sopenharmony_cistruct tomoyo_task_acl { 6998c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MANUAL_TASK_ACL */ 7008c2ecf20Sopenharmony_ci /* Pointer to domainname. */ 7018c2ecf20Sopenharmony_ci const struct tomoyo_path_info *domainname; 7028c2ecf20Sopenharmony_ci}; 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci/* 7058c2ecf20Sopenharmony_ci * Structure for "file execute", "file read", "file write", "file append", 7068c2ecf20Sopenharmony_ci * "file unlink", "file getattr", "file rmdir", "file truncate", 7078c2ecf20Sopenharmony_ci * "file symlink", "file chroot" and "file unmount" directive. 7088c2ecf20Sopenharmony_ci */ 7098c2ecf20Sopenharmony_cistruct tomoyo_path_acl { 7108c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 7118c2ecf20Sopenharmony_ci u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */ 7128c2ecf20Sopenharmony_ci struct tomoyo_name_union name; 7138c2ecf20Sopenharmony_ci}; 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci/* 7168c2ecf20Sopenharmony_ci * Structure for "file create", "file mkdir", "file mkfifo", "file mksock", 7178c2ecf20Sopenharmony_ci * "file ioctl", "file chmod", "file chown" and "file chgrp" directive. 7188c2ecf20Sopenharmony_ci */ 7198c2ecf20Sopenharmony_cistruct tomoyo_path_number_acl { 7208c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ 7218c2ecf20Sopenharmony_ci /* Bitmask of values in "enum tomoyo_path_number_acl_index". */ 7228c2ecf20Sopenharmony_ci u8 perm; 7238c2ecf20Sopenharmony_ci struct tomoyo_name_union name; 7248c2ecf20Sopenharmony_ci struct tomoyo_number_union number; 7258c2ecf20Sopenharmony_ci}; 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci/* Structure for "file mkblock" and "file mkchar" directive. */ 7288c2ecf20Sopenharmony_cistruct tomoyo_mkdev_acl { 7298c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ 7308c2ecf20Sopenharmony_ci u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */ 7318c2ecf20Sopenharmony_ci struct tomoyo_name_union name; 7328c2ecf20Sopenharmony_ci struct tomoyo_number_union mode; 7338c2ecf20Sopenharmony_ci struct tomoyo_number_union major; 7348c2ecf20Sopenharmony_ci struct tomoyo_number_union minor; 7358c2ecf20Sopenharmony_ci}; 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci/* 7388c2ecf20Sopenharmony_ci * Structure for "file rename", "file link" and "file pivot_root" directive. 7398c2ecf20Sopenharmony_ci */ 7408c2ecf20Sopenharmony_cistruct tomoyo_path2_acl { 7418c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ 7428c2ecf20Sopenharmony_ci u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */ 7438c2ecf20Sopenharmony_ci struct tomoyo_name_union name1; 7448c2ecf20Sopenharmony_ci struct tomoyo_name_union name2; 7458c2ecf20Sopenharmony_ci}; 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci/* Structure for "file mount" directive. */ 7488c2ecf20Sopenharmony_cistruct tomoyo_mount_acl { 7498c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ 7508c2ecf20Sopenharmony_ci struct tomoyo_name_union dev_name; 7518c2ecf20Sopenharmony_ci struct tomoyo_name_union dir_name; 7528c2ecf20Sopenharmony_ci struct tomoyo_name_union fs_type; 7538c2ecf20Sopenharmony_ci struct tomoyo_number_union flags; 7548c2ecf20Sopenharmony_ci}; 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci/* Structure for "misc env" directive in domain policy. */ 7578c2ecf20Sopenharmony_cistruct tomoyo_env_acl { 7588c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_ENV_ACL */ 7598c2ecf20Sopenharmony_ci const struct tomoyo_path_info *env; /* environment variable */ 7608c2ecf20Sopenharmony_ci}; 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci/* Structure for "network inet" directive. */ 7638c2ecf20Sopenharmony_cistruct tomoyo_inet_acl { 7648c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_INET_ACL */ 7658c2ecf20Sopenharmony_ci u8 protocol; 7668c2ecf20Sopenharmony_ci u8 perm; /* Bitmask of values in "enum tomoyo_network_acl_index" */ 7678c2ecf20Sopenharmony_ci struct tomoyo_ipaddr_union address; 7688c2ecf20Sopenharmony_ci struct tomoyo_number_union port; 7698c2ecf20Sopenharmony_ci}; 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci/* Structure for "network unix" directive. */ 7728c2ecf20Sopenharmony_cistruct tomoyo_unix_acl { 7738c2ecf20Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_UNIX_ACL */ 7748c2ecf20Sopenharmony_ci u8 protocol; 7758c2ecf20Sopenharmony_ci u8 perm; /* Bitmask of values in "enum tomoyo_network_acl_index" */ 7768c2ecf20Sopenharmony_ci struct tomoyo_name_union name; 7778c2ecf20Sopenharmony_ci}; 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci/* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */ 7808c2ecf20Sopenharmony_cistruct tomoyo_acl_param { 7818c2ecf20Sopenharmony_ci char *data; 7828c2ecf20Sopenharmony_ci struct list_head *list; 7838c2ecf20Sopenharmony_ci struct tomoyo_policy_namespace *ns; 7848c2ecf20Sopenharmony_ci bool is_delete; 7858c2ecf20Sopenharmony_ci}; 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci#define TOMOYO_MAX_IO_READ_QUEUE 64 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci/* 7908c2ecf20Sopenharmony_ci * Structure for reading/writing policy via /sys/kernel/security/tomoyo 7918c2ecf20Sopenharmony_ci * interfaces. 7928c2ecf20Sopenharmony_ci */ 7938c2ecf20Sopenharmony_cistruct tomoyo_io_buffer { 7948c2ecf20Sopenharmony_ci void (*read)(struct tomoyo_io_buffer *head); 7958c2ecf20Sopenharmony_ci int (*write)(struct tomoyo_io_buffer *head); 7968c2ecf20Sopenharmony_ci __poll_t (*poll)(struct file *file, poll_table *wait); 7978c2ecf20Sopenharmony_ci /* Exclusive lock for this structure. */ 7988c2ecf20Sopenharmony_ci struct mutex io_sem; 7998c2ecf20Sopenharmony_ci char __user *read_user_buf; 8008c2ecf20Sopenharmony_ci size_t read_user_buf_avail; 8018c2ecf20Sopenharmony_ci struct { 8028c2ecf20Sopenharmony_ci struct list_head *ns; 8038c2ecf20Sopenharmony_ci struct list_head *domain; 8048c2ecf20Sopenharmony_ci struct list_head *group; 8058c2ecf20Sopenharmony_ci struct list_head *acl; 8068c2ecf20Sopenharmony_ci size_t avail; 8078c2ecf20Sopenharmony_ci unsigned int step; 8088c2ecf20Sopenharmony_ci unsigned int query_index; 8098c2ecf20Sopenharmony_ci u16 index; 8108c2ecf20Sopenharmony_ci u16 cond_index; 8118c2ecf20Sopenharmony_ci u8 acl_group_index; 8128c2ecf20Sopenharmony_ci u8 cond_step; 8138c2ecf20Sopenharmony_ci u8 bit; 8148c2ecf20Sopenharmony_ci u8 w_pos; 8158c2ecf20Sopenharmony_ci bool eof; 8168c2ecf20Sopenharmony_ci bool print_this_domain_only; 8178c2ecf20Sopenharmony_ci bool print_transition_related_only; 8188c2ecf20Sopenharmony_ci bool print_cond_part; 8198c2ecf20Sopenharmony_ci const char *w[TOMOYO_MAX_IO_READ_QUEUE]; 8208c2ecf20Sopenharmony_ci } r; 8218c2ecf20Sopenharmony_ci struct { 8228c2ecf20Sopenharmony_ci struct tomoyo_policy_namespace *ns; 8238c2ecf20Sopenharmony_ci /* The position currently writing to. */ 8248c2ecf20Sopenharmony_ci struct tomoyo_domain_info *domain; 8258c2ecf20Sopenharmony_ci /* Bytes available for writing. */ 8268c2ecf20Sopenharmony_ci size_t avail; 8278c2ecf20Sopenharmony_ci bool is_delete; 8288c2ecf20Sopenharmony_ci } w; 8298c2ecf20Sopenharmony_ci /* Buffer for reading. */ 8308c2ecf20Sopenharmony_ci char *read_buf; 8318c2ecf20Sopenharmony_ci /* Size of read buffer. */ 8328c2ecf20Sopenharmony_ci size_t readbuf_size; 8338c2ecf20Sopenharmony_ci /* Buffer for writing. */ 8348c2ecf20Sopenharmony_ci char *write_buf; 8358c2ecf20Sopenharmony_ci /* Size of write buffer. */ 8368c2ecf20Sopenharmony_ci size_t writebuf_size; 8378c2ecf20Sopenharmony_ci /* Type of this interface. */ 8388c2ecf20Sopenharmony_ci enum tomoyo_securityfs_interface_index type; 8398c2ecf20Sopenharmony_ci /* Users counter protected by tomoyo_io_buffer_list_lock. */ 8408c2ecf20Sopenharmony_ci u8 users; 8418c2ecf20Sopenharmony_ci /* List for telling GC not to kfree() elements. */ 8428c2ecf20Sopenharmony_ci struct list_head list; 8438c2ecf20Sopenharmony_ci}; 8448c2ecf20Sopenharmony_ci 8458c2ecf20Sopenharmony_ci/* 8468c2ecf20Sopenharmony_ci * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/ 8478c2ecf20Sopenharmony_ci * "no_keep_domain" keyword. 8488c2ecf20Sopenharmony_ci */ 8498c2ecf20Sopenharmony_cistruct tomoyo_transition_control { 8508c2ecf20Sopenharmony_ci struct tomoyo_acl_head head; 8518c2ecf20Sopenharmony_ci u8 type; /* One of values in "enum tomoyo_transition_type". */ 8528c2ecf20Sopenharmony_ci /* True if the domainname is tomoyo_get_last_name(). */ 8538c2ecf20Sopenharmony_ci bool is_last_name; 8548c2ecf20Sopenharmony_ci const struct tomoyo_path_info *domainname; /* Maybe NULL */ 8558c2ecf20Sopenharmony_ci const struct tomoyo_path_info *program; /* Maybe NULL */ 8568c2ecf20Sopenharmony_ci}; 8578c2ecf20Sopenharmony_ci 8588c2ecf20Sopenharmony_ci/* Structure for "aggregator" keyword. */ 8598c2ecf20Sopenharmony_cistruct tomoyo_aggregator { 8608c2ecf20Sopenharmony_ci struct tomoyo_acl_head head; 8618c2ecf20Sopenharmony_ci const struct tomoyo_path_info *original_name; 8628c2ecf20Sopenharmony_ci const struct tomoyo_path_info *aggregated_name; 8638c2ecf20Sopenharmony_ci}; 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_ci/* Structure for policy manager. */ 8668c2ecf20Sopenharmony_cistruct tomoyo_manager { 8678c2ecf20Sopenharmony_ci struct tomoyo_acl_head head; 8688c2ecf20Sopenharmony_ci /* A path to program or a domainname. */ 8698c2ecf20Sopenharmony_ci const struct tomoyo_path_info *manager; 8708c2ecf20Sopenharmony_ci}; 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_cistruct tomoyo_preference { 8738c2ecf20Sopenharmony_ci unsigned int learning_max_entry; 8748c2ecf20Sopenharmony_ci bool enforcing_verbose; 8758c2ecf20Sopenharmony_ci bool learning_verbose; 8768c2ecf20Sopenharmony_ci bool permissive_verbose; 8778c2ecf20Sopenharmony_ci}; 8788c2ecf20Sopenharmony_ci 8798c2ecf20Sopenharmony_ci/* Structure for /sys/kernel/security/tomnoyo/profile interface. */ 8808c2ecf20Sopenharmony_cistruct tomoyo_profile { 8818c2ecf20Sopenharmony_ci const struct tomoyo_path_info *comment; 8828c2ecf20Sopenharmony_ci struct tomoyo_preference *learning; 8838c2ecf20Sopenharmony_ci struct tomoyo_preference *permissive; 8848c2ecf20Sopenharmony_ci struct tomoyo_preference *enforcing; 8858c2ecf20Sopenharmony_ci struct tomoyo_preference preference; 8868c2ecf20Sopenharmony_ci u8 default_config; 8878c2ecf20Sopenharmony_ci u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; 8888c2ecf20Sopenharmony_ci unsigned int pref[TOMOYO_MAX_PREF]; 8898c2ecf20Sopenharmony_ci}; 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci/* Structure for representing YYYY/MM/DD hh/mm/ss. */ 8928c2ecf20Sopenharmony_cistruct tomoyo_time { 8938c2ecf20Sopenharmony_ci u16 year; 8948c2ecf20Sopenharmony_ci u8 month; 8958c2ecf20Sopenharmony_ci u8 day; 8968c2ecf20Sopenharmony_ci u8 hour; 8978c2ecf20Sopenharmony_ci u8 min; 8988c2ecf20Sopenharmony_ci u8 sec; 8998c2ecf20Sopenharmony_ci}; 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_ci/* Structure for policy namespace. */ 9028c2ecf20Sopenharmony_cistruct tomoyo_policy_namespace { 9038c2ecf20Sopenharmony_ci /* Profile table. Memory is allocated as needed. */ 9048c2ecf20Sopenharmony_ci struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES]; 9058c2ecf20Sopenharmony_ci /* List of "struct tomoyo_group". */ 9068c2ecf20Sopenharmony_ci struct list_head group_list[TOMOYO_MAX_GROUP]; 9078c2ecf20Sopenharmony_ci /* List of policy. */ 9088c2ecf20Sopenharmony_ci struct list_head policy_list[TOMOYO_MAX_POLICY]; 9098c2ecf20Sopenharmony_ci /* The global ACL referred by "use_group" keyword. */ 9108c2ecf20Sopenharmony_ci struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS]; 9118c2ecf20Sopenharmony_ci /* List for connecting to tomoyo_namespace_list list. */ 9128c2ecf20Sopenharmony_ci struct list_head namespace_list; 9138c2ecf20Sopenharmony_ci /* Profile version. Currently only 20150505 is defined. */ 9148c2ecf20Sopenharmony_ci unsigned int profile_version; 9158c2ecf20Sopenharmony_ci /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */ 9168c2ecf20Sopenharmony_ci const char *name; 9178c2ecf20Sopenharmony_ci}; 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci/* Structure for "struct task_struct"->security. */ 9208c2ecf20Sopenharmony_cistruct tomoyo_task { 9218c2ecf20Sopenharmony_ci struct tomoyo_domain_info *domain_info; 9228c2ecf20Sopenharmony_ci struct tomoyo_domain_info *old_domain_info; 9238c2ecf20Sopenharmony_ci}; 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci/********** Function prototypes. **********/ 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_cibool tomoyo_address_matches_group(const bool is_ipv6, const __be32 *address, 9288c2ecf20Sopenharmony_ci const struct tomoyo_group *group); 9298c2ecf20Sopenharmony_cibool tomoyo_compare_number_union(const unsigned long value, 9308c2ecf20Sopenharmony_ci const struct tomoyo_number_union *ptr); 9318c2ecf20Sopenharmony_cibool tomoyo_condition(struct tomoyo_request_info *r, 9328c2ecf20Sopenharmony_ci const struct tomoyo_condition *cond); 9338c2ecf20Sopenharmony_cibool tomoyo_correct_domain(const unsigned char *domainname); 9348c2ecf20Sopenharmony_cibool tomoyo_correct_path(const char *filename); 9358c2ecf20Sopenharmony_cibool tomoyo_correct_word(const char *string); 9368c2ecf20Sopenharmony_cibool tomoyo_domain_def(const unsigned char *buffer); 9378c2ecf20Sopenharmony_cibool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); 9388c2ecf20Sopenharmony_cibool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos, 9398c2ecf20Sopenharmony_ci struct tomoyo_page_dump *dump); 9408c2ecf20Sopenharmony_cibool tomoyo_memory_ok(void *ptr); 9418c2ecf20Sopenharmony_cibool tomoyo_number_matches_group(const unsigned long min, 9428c2ecf20Sopenharmony_ci const unsigned long max, 9438c2ecf20Sopenharmony_ci const struct tomoyo_group *group); 9448c2ecf20Sopenharmony_cibool tomoyo_parse_ipaddr_union(struct tomoyo_acl_param *param, 9458c2ecf20Sopenharmony_ci struct tomoyo_ipaddr_union *ptr); 9468c2ecf20Sopenharmony_cibool tomoyo_parse_name_union(struct tomoyo_acl_param *param, 9478c2ecf20Sopenharmony_ci struct tomoyo_name_union *ptr); 9488c2ecf20Sopenharmony_cibool tomoyo_parse_number_union(struct tomoyo_acl_param *param, 9498c2ecf20Sopenharmony_ci struct tomoyo_number_union *ptr); 9508c2ecf20Sopenharmony_cibool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 9518c2ecf20Sopenharmony_ci const struct tomoyo_path_info *pattern); 9528c2ecf20Sopenharmony_cibool tomoyo_permstr(const char *string, const char *keyword); 9538c2ecf20Sopenharmony_cibool tomoyo_str_starts(char **src, const char *find); 9548c2ecf20Sopenharmony_cichar *tomoyo_encode(const char *str); 9558c2ecf20Sopenharmony_cichar *tomoyo_encode2(const char *str, int str_len); 9568c2ecf20Sopenharmony_cichar *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt, 9578c2ecf20Sopenharmony_ci va_list args); 9588c2ecf20Sopenharmony_cichar *tomoyo_read_token(struct tomoyo_acl_param *param); 9598c2ecf20Sopenharmony_cichar *tomoyo_realpath_from_path(const struct path *path); 9608c2ecf20Sopenharmony_cichar *tomoyo_realpath_nofollow(const char *pathname); 9618c2ecf20Sopenharmony_ciconst char *tomoyo_get_exe(void); 9628c2ecf20Sopenharmony_ciconst char *tomoyo_yesno(const unsigned int value); 9638c2ecf20Sopenharmony_ciconst struct tomoyo_path_info *tomoyo_compare_name_union 9648c2ecf20Sopenharmony_ci(const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr); 9658c2ecf20Sopenharmony_ciconst struct tomoyo_path_info *tomoyo_get_domainname 9668c2ecf20Sopenharmony_ci(struct tomoyo_acl_param *param); 9678c2ecf20Sopenharmony_ciconst struct tomoyo_path_info *tomoyo_get_name(const char *name); 9688c2ecf20Sopenharmony_ciconst struct tomoyo_path_info *tomoyo_path_matches_group 9698c2ecf20Sopenharmony_ci(const struct tomoyo_path_info *pathname, const struct tomoyo_group *group); 9708c2ecf20Sopenharmony_ciint tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 9718c2ecf20Sopenharmony_ci const struct path *path, const int flag); 9728c2ecf20Sopenharmony_civoid tomoyo_close_control(struct tomoyo_io_buffer *head); 9738c2ecf20Sopenharmony_ciint tomoyo_env_perm(struct tomoyo_request_info *r, const char *env); 9748c2ecf20Sopenharmony_ciint tomoyo_execute_permission(struct tomoyo_request_info *r, 9758c2ecf20Sopenharmony_ci const struct tomoyo_path_info *filename); 9768c2ecf20Sopenharmony_ciint tomoyo_find_next_domain(struct linux_binprm *bprm); 9778c2ecf20Sopenharmony_ciint tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile, 9788c2ecf20Sopenharmony_ci const u8 index); 9798c2ecf20Sopenharmony_ciint tomoyo_init_request_info(struct tomoyo_request_info *r, 9808c2ecf20Sopenharmony_ci struct tomoyo_domain_info *domain, 9818c2ecf20Sopenharmony_ci const u8 index); 9828c2ecf20Sopenharmony_ciint tomoyo_mkdev_perm(const u8 operation, const struct path *path, 9838c2ecf20Sopenharmony_ci const unsigned int mode, unsigned int dev); 9848c2ecf20Sopenharmony_ciint tomoyo_mount_permission(const char *dev_name, const struct path *path, 9858c2ecf20Sopenharmony_ci const char *type, unsigned long flags, 9868c2ecf20Sopenharmony_ci void *data_page); 9878c2ecf20Sopenharmony_ciint tomoyo_open_control(const u8 type, struct file *file); 9888c2ecf20Sopenharmony_ciint tomoyo_path2_perm(const u8 operation, const struct path *path1, 9898c2ecf20Sopenharmony_ci const struct path *path2); 9908c2ecf20Sopenharmony_ciint tomoyo_path_number_perm(const u8 operation, const struct path *path, 9918c2ecf20Sopenharmony_ci unsigned long number); 9928c2ecf20Sopenharmony_ciint tomoyo_path_perm(const u8 operation, const struct path *path, 9938c2ecf20Sopenharmony_ci const char *target); 9948c2ecf20Sopenharmony_ci__poll_t tomoyo_poll_control(struct file *file, poll_table *wait); 9958c2ecf20Sopenharmony_ci__poll_t tomoyo_poll_log(struct file *file, poll_table *wait); 9968c2ecf20Sopenharmony_ciint tomoyo_socket_bind_permission(struct socket *sock, struct sockaddr *addr, 9978c2ecf20Sopenharmony_ci int addr_len); 9988c2ecf20Sopenharmony_ciint tomoyo_socket_connect_permission(struct socket *sock, 9998c2ecf20Sopenharmony_ci struct sockaddr *addr, int addr_len); 10008c2ecf20Sopenharmony_ciint tomoyo_socket_listen_permission(struct socket *sock); 10018c2ecf20Sopenharmony_ciint tomoyo_socket_sendmsg_permission(struct socket *sock, struct msghdr *msg, 10028c2ecf20Sopenharmony_ci int size); 10038c2ecf20Sopenharmony_ciint tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) 10048c2ecf20Sopenharmony_ci __printf(2, 3); 10058c2ecf20Sopenharmony_ciint tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, 10068c2ecf20Sopenharmony_ci struct tomoyo_acl_param *param, 10078c2ecf20Sopenharmony_ci bool (*check_duplicate) 10088c2ecf20Sopenharmony_ci (const struct tomoyo_acl_info *, 10098c2ecf20Sopenharmony_ci const struct tomoyo_acl_info *), 10108c2ecf20Sopenharmony_ci bool (*merge_duplicate) 10118c2ecf20Sopenharmony_ci (struct tomoyo_acl_info *, struct tomoyo_acl_info *, 10128c2ecf20Sopenharmony_ci const bool)); 10138c2ecf20Sopenharmony_ciint tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, 10148c2ecf20Sopenharmony_ci struct tomoyo_acl_param *param, 10158c2ecf20Sopenharmony_ci bool (*check_duplicate) 10168c2ecf20Sopenharmony_ci (const struct tomoyo_acl_head *, 10178c2ecf20Sopenharmony_ci const struct tomoyo_acl_head *)); 10188c2ecf20Sopenharmony_ciint tomoyo_write_aggregator(struct tomoyo_acl_param *param); 10198c2ecf20Sopenharmony_ciint tomoyo_write_file(struct tomoyo_acl_param *param); 10208c2ecf20Sopenharmony_ciint tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type); 10218c2ecf20Sopenharmony_ciint tomoyo_write_misc(struct tomoyo_acl_param *param); 10228c2ecf20Sopenharmony_ciint tomoyo_write_inet_network(struct tomoyo_acl_param *param); 10238c2ecf20Sopenharmony_ciint tomoyo_write_transition_control(struct tomoyo_acl_param *param, 10248c2ecf20Sopenharmony_ci const u8 type); 10258c2ecf20Sopenharmony_ciint tomoyo_write_unix_network(struct tomoyo_acl_param *param); 10268c2ecf20Sopenharmony_cissize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, 10278c2ecf20Sopenharmony_ci const int buffer_len); 10288c2ecf20Sopenharmony_cissize_t tomoyo_write_control(struct tomoyo_io_buffer *head, 10298c2ecf20Sopenharmony_ci const char __user *buffer, const int buffer_len); 10308c2ecf20Sopenharmony_cistruct tomoyo_condition *tomoyo_get_condition(struct tomoyo_acl_param *param); 10318c2ecf20Sopenharmony_cistruct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, 10328c2ecf20Sopenharmony_ci const bool transit); 10338c2ecf20Sopenharmony_cistruct tomoyo_domain_info *tomoyo_domain(void); 10348c2ecf20Sopenharmony_cistruct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 10358c2ecf20Sopenharmony_cistruct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param, 10368c2ecf20Sopenharmony_ci const u8 idx); 10378c2ecf20Sopenharmony_cistruct tomoyo_policy_namespace *tomoyo_assign_namespace 10388c2ecf20Sopenharmony_ci(const char *domainname); 10398c2ecf20Sopenharmony_cistruct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns, 10408c2ecf20Sopenharmony_ci const u8 profile); 10418c2ecf20Sopenharmony_ciunsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 10428c2ecf20Sopenharmony_ci const u8 index); 10438c2ecf20Sopenharmony_ciu8 tomoyo_parse_ulong(unsigned long *result, char **str); 10448c2ecf20Sopenharmony_civoid *tomoyo_commit_ok(void *data, const unsigned int size); 10458c2ecf20Sopenharmony_civoid __init tomoyo_load_builtin_policy(void); 10468c2ecf20Sopenharmony_civoid __init tomoyo_mm_init(void); 10478c2ecf20Sopenharmony_civoid tomoyo_check_acl(struct tomoyo_request_info *r, 10488c2ecf20Sopenharmony_ci bool (*check_entry)(struct tomoyo_request_info *, 10498c2ecf20Sopenharmony_ci const struct tomoyo_acl_info *)); 10508c2ecf20Sopenharmony_civoid tomoyo_check_profile(void); 10518c2ecf20Sopenharmony_civoid tomoyo_convert_time(time64_t time, struct tomoyo_time *stamp); 10528c2ecf20Sopenharmony_civoid tomoyo_del_condition(struct list_head *element); 10538c2ecf20Sopenharmony_civoid tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 10548c2ecf20Sopenharmony_civoid tomoyo_get_attributes(struct tomoyo_obj_info *obj); 10558c2ecf20Sopenharmony_civoid tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns); 10568c2ecf20Sopenharmony_civoid tomoyo_load_policy(const char *filename); 10578c2ecf20Sopenharmony_civoid tomoyo_normalize_line(unsigned char *buffer); 10588c2ecf20Sopenharmony_civoid tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register); 10598c2ecf20Sopenharmony_civoid tomoyo_print_ip(char *buf, const unsigned int size, 10608c2ecf20Sopenharmony_ci const struct tomoyo_ipaddr_union *ptr); 10618c2ecf20Sopenharmony_civoid tomoyo_print_ulong(char *buffer, const int buffer_len, 10628c2ecf20Sopenharmony_ci const unsigned long value, const u8 type); 10638c2ecf20Sopenharmony_civoid tomoyo_put_name_union(struct tomoyo_name_union *ptr); 10648c2ecf20Sopenharmony_civoid tomoyo_put_number_union(struct tomoyo_number_union *ptr); 10658c2ecf20Sopenharmony_civoid tomoyo_read_log(struct tomoyo_io_buffer *head); 10668c2ecf20Sopenharmony_civoid tomoyo_update_stat(const u8 index); 10678c2ecf20Sopenharmony_civoid tomoyo_warn_oom(const char *function); 10688c2ecf20Sopenharmony_civoid tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...) 10698c2ecf20Sopenharmony_ci __printf(2, 3); 10708c2ecf20Sopenharmony_civoid tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt, 10718c2ecf20Sopenharmony_ci va_list args); 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci/********** External variable definitions. **********/ 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ciextern bool tomoyo_policy_loaded; 10768c2ecf20Sopenharmony_ciextern int tomoyo_enabled; 10778c2ecf20Sopenharmony_ciextern const char * const tomoyo_condition_keyword 10788c2ecf20Sopenharmony_ci[TOMOYO_MAX_CONDITION_KEYWORD]; 10798c2ecf20Sopenharmony_ciextern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS]; 10808c2ecf20Sopenharmony_ciextern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX 10818c2ecf20Sopenharmony_ci + TOMOYO_MAX_MAC_CATEGORY_INDEX]; 10828c2ecf20Sopenharmony_ciextern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE]; 10838c2ecf20Sopenharmony_ciextern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; 10848c2ecf20Sopenharmony_ciextern const char * const tomoyo_proto_keyword[TOMOYO_SOCK_MAX]; 10858c2ecf20Sopenharmony_ciextern const char * const tomoyo_socket_keyword[TOMOYO_MAX_NETWORK_OPERATION]; 10868c2ecf20Sopenharmony_ciextern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX]; 10878c2ecf20Sopenharmony_ciextern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION]; 10888c2ecf20Sopenharmony_ciextern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION]; 10898c2ecf20Sopenharmony_ciextern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION]; 10908c2ecf20Sopenharmony_ciextern struct list_head tomoyo_condition_list; 10918c2ecf20Sopenharmony_ciextern struct list_head tomoyo_domain_list; 10928c2ecf20Sopenharmony_ciextern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 10938c2ecf20Sopenharmony_ciextern struct list_head tomoyo_namespace_list; 10948c2ecf20Sopenharmony_ciextern struct mutex tomoyo_policy_lock; 10958c2ecf20Sopenharmony_ciextern struct srcu_struct tomoyo_ss; 10968c2ecf20Sopenharmony_ciextern struct tomoyo_domain_info tomoyo_kernel_domain; 10978c2ecf20Sopenharmony_ciextern struct tomoyo_policy_namespace tomoyo_kernel_namespace; 10988c2ecf20Sopenharmony_ciextern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT]; 10998c2ecf20Sopenharmony_ciextern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT]; 11008c2ecf20Sopenharmony_ciextern struct lsm_blob_sizes tomoyo_blob_sizes; 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_ci/********** Inlined functions. **********/ 11038c2ecf20Sopenharmony_ci 11048c2ecf20Sopenharmony_ci/** 11058c2ecf20Sopenharmony_ci * tomoyo_read_lock - Take lock for protecting policy. 11068c2ecf20Sopenharmony_ci * 11078c2ecf20Sopenharmony_ci * Returns index number for tomoyo_read_unlock(). 11088c2ecf20Sopenharmony_ci */ 11098c2ecf20Sopenharmony_cistatic inline int tomoyo_read_lock(void) 11108c2ecf20Sopenharmony_ci{ 11118c2ecf20Sopenharmony_ci return srcu_read_lock(&tomoyo_ss); 11128c2ecf20Sopenharmony_ci} 11138c2ecf20Sopenharmony_ci 11148c2ecf20Sopenharmony_ci/** 11158c2ecf20Sopenharmony_ci * tomoyo_read_unlock - Release lock for protecting policy. 11168c2ecf20Sopenharmony_ci * 11178c2ecf20Sopenharmony_ci * @idx: Index number returned by tomoyo_read_lock(). 11188c2ecf20Sopenharmony_ci * 11198c2ecf20Sopenharmony_ci * Returns nothing. 11208c2ecf20Sopenharmony_ci */ 11218c2ecf20Sopenharmony_cistatic inline void tomoyo_read_unlock(int idx) 11228c2ecf20Sopenharmony_ci{ 11238c2ecf20Sopenharmony_ci srcu_read_unlock(&tomoyo_ss, idx); 11248c2ecf20Sopenharmony_ci} 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci/** 11278c2ecf20Sopenharmony_ci * tomoyo_sys_getppid - Copy of getppid(). 11288c2ecf20Sopenharmony_ci * 11298c2ecf20Sopenharmony_ci * Returns parent process's PID. 11308c2ecf20Sopenharmony_ci * 11318c2ecf20Sopenharmony_ci * Alpha does not have getppid() defined. To be able to build this module on 11328c2ecf20Sopenharmony_ci * Alpha, I have to copy getppid() from kernel/timer.c. 11338c2ecf20Sopenharmony_ci */ 11348c2ecf20Sopenharmony_cistatic inline pid_t tomoyo_sys_getppid(void) 11358c2ecf20Sopenharmony_ci{ 11368c2ecf20Sopenharmony_ci pid_t pid; 11378c2ecf20Sopenharmony_ci 11388c2ecf20Sopenharmony_ci rcu_read_lock(); 11398c2ecf20Sopenharmony_ci pid = task_tgid_vnr(rcu_dereference(current->real_parent)); 11408c2ecf20Sopenharmony_ci rcu_read_unlock(); 11418c2ecf20Sopenharmony_ci return pid; 11428c2ecf20Sopenharmony_ci} 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci/** 11458c2ecf20Sopenharmony_ci * tomoyo_sys_getpid - Copy of getpid(). 11468c2ecf20Sopenharmony_ci * 11478c2ecf20Sopenharmony_ci * Returns current thread's PID. 11488c2ecf20Sopenharmony_ci * 11498c2ecf20Sopenharmony_ci * Alpha does not have getpid() defined. To be able to build this module on 11508c2ecf20Sopenharmony_ci * Alpha, I have to copy getpid() from kernel/timer.c. 11518c2ecf20Sopenharmony_ci */ 11528c2ecf20Sopenharmony_cistatic inline pid_t tomoyo_sys_getpid(void) 11538c2ecf20Sopenharmony_ci{ 11548c2ecf20Sopenharmony_ci return task_tgid_vnr(current); 11558c2ecf20Sopenharmony_ci} 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci/** 11588c2ecf20Sopenharmony_ci * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure. 11598c2ecf20Sopenharmony_ci * 11608c2ecf20Sopenharmony_ci * @a: Pointer to "struct tomoyo_path_info". 11618c2ecf20Sopenharmony_ci * @b: Pointer to "struct tomoyo_path_info". 11628c2ecf20Sopenharmony_ci * 11638c2ecf20Sopenharmony_ci * Returns true if @a == @b, false otherwise. 11648c2ecf20Sopenharmony_ci */ 11658c2ecf20Sopenharmony_cistatic inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, 11668c2ecf20Sopenharmony_ci const struct tomoyo_path_info *b) 11678c2ecf20Sopenharmony_ci{ 11688c2ecf20Sopenharmony_ci return a->hash != b->hash || strcmp(a->name, b->name); 11698c2ecf20Sopenharmony_ci} 11708c2ecf20Sopenharmony_ci 11718c2ecf20Sopenharmony_ci/** 11728c2ecf20Sopenharmony_ci * tomoyo_put_name - Drop reference on "struct tomoyo_name". 11738c2ecf20Sopenharmony_ci * 11748c2ecf20Sopenharmony_ci * @name: Pointer to "struct tomoyo_path_info". Maybe NULL. 11758c2ecf20Sopenharmony_ci * 11768c2ecf20Sopenharmony_ci * Returns nothing. 11778c2ecf20Sopenharmony_ci */ 11788c2ecf20Sopenharmony_cistatic inline void tomoyo_put_name(const struct tomoyo_path_info *name) 11798c2ecf20Sopenharmony_ci{ 11808c2ecf20Sopenharmony_ci if (name) { 11818c2ecf20Sopenharmony_ci struct tomoyo_name *ptr = 11828c2ecf20Sopenharmony_ci container_of(name, typeof(*ptr), entry); 11838c2ecf20Sopenharmony_ci atomic_dec(&ptr->head.users); 11848c2ecf20Sopenharmony_ci } 11858c2ecf20Sopenharmony_ci} 11868c2ecf20Sopenharmony_ci 11878c2ecf20Sopenharmony_ci/** 11888c2ecf20Sopenharmony_ci * tomoyo_put_condition - Drop reference on "struct tomoyo_condition". 11898c2ecf20Sopenharmony_ci * 11908c2ecf20Sopenharmony_ci * @cond: Pointer to "struct tomoyo_condition". Maybe NULL. 11918c2ecf20Sopenharmony_ci * 11928c2ecf20Sopenharmony_ci * Returns nothing. 11938c2ecf20Sopenharmony_ci */ 11948c2ecf20Sopenharmony_cistatic inline void tomoyo_put_condition(struct tomoyo_condition *cond) 11958c2ecf20Sopenharmony_ci{ 11968c2ecf20Sopenharmony_ci if (cond) 11978c2ecf20Sopenharmony_ci atomic_dec(&cond->head.users); 11988c2ecf20Sopenharmony_ci} 11998c2ecf20Sopenharmony_ci 12008c2ecf20Sopenharmony_ci/** 12018c2ecf20Sopenharmony_ci * tomoyo_put_group - Drop reference on "struct tomoyo_group". 12028c2ecf20Sopenharmony_ci * 12038c2ecf20Sopenharmony_ci * @group: Pointer to "struct tomoyo_group". Maybe NULL. 12048c2ecf20Sopenharmony_ci * 12058c2ecf20Sopenharmony_ci * Returns nothing. 12068c2ecf20Sopenharmony_ci */ 12078c2ecf20Sopenharmony_cistatic inline void tomoyo_put_group(struct tomoyo_group *group) 12088c2ecf20Sopenharmony_ci{ 12098c2ecf20Sopenharmony_ci if (group) 12108c2ecf20Sopenharmony_ci atomic_dec(&group->head.users); 12118c2ecf20Sopenharmony_ci} 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_ci/** 12148c2ecf20Sopenharmony_ci * tomoyo_task - Get "struct tomoyo_task" for specified thread. 12158c2ecf20Sopenharmony_ci * 12168c2ecf20Sopenharmony_ci * @task - Pointer to "struct task_struct". 12178c2ecf20Sopenharmony_ci * 12188c2ecf20Sopenharmony_ci * Returns pointer to "struct tomoyo_task" for specified thread. 12198c2ecf20Sopenharmony_ci */ 12208c2ecf20Sopenharmony_cistatic inline struct tomoyo_task *tomoyo_task(struct task_struct *task) 12218c2ecf20Sopenharmony_ci{ 12228c2ecf20Sopenharmony_ci return task->security + tomoyo_blob_sizes.lbs_task; 12238c2ecf20Sopenharmony_ci} 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci/** 12268c2ecf20Sopenharmony_ci * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry. 12278c2ecf20Sopenharmony_ci * 12288c2ecf20Sopenharmony_ci * @a: Pointer to "struct tomoyo_name_union". 12298c2ecf20Sopenharmony_ci * @b: Pointer to "struct tomoyo_name_union". 12308c2ecf20Sopenharmony_ci * 12318c2ecf20Sopenharmony_ci * Returns true if @a == @b, false otherwise. 12328c2ecf20Sopenharmony_ci */ 12338c2ecf20Sopenharmony_cistatic inline bool tomoyo_same_name_union 12348c2ecf20Sopenharmony_ci(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b) 12358c2ecf20Sopenharmony_ci{ 12368c2ecf20Sopenharmony_ci return a->filename == b->filename && a->group == b->group; 12378c2ecf20Sopenharmony_ci} 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci/** 12408c2ecf20Sopenharmony_ci * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry. 12418c2ecf20Sopenharmony_ci * 12428c2ecf20Sopenharmony_ci * @a: Pointer to "struct tomoyo_number_union". 12438c2ecf20Sopenharmony_ci * @b: Pointer to "struct tomoyo_number_union". 12448c2ecf20Sopenharmony_ci * 12458c2ecf20Sopenharmony_ci * Returns true if @a == @b, false otherwise. 12468c2ecf20Sopenharmony_ci */ 12478c2ecf20Sopenharmony_cistatic inline bool tomoyo_same_number_union 12488c2ecf20Sopenharmony_ci(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b) 12498c2ecf20Sopenharmony_ci{ 12508c2ecf20Sopenharmony_ci return a->values[0] == b->values[0] && a->values[1] == b->values[1] && 12518c2ecf20Sopenharmony_ci a->group == b->group && a->value_type[0] == b->value_type[0] && 12528c2ecf20Sopenharmony_ci a->value_type[1] == b->value_type[1]; 12538c2ecf20Sopenharmony_ci} 12548c2ecf20Sopenharmony_ci 12558c2ecf20Sopenharmony_ci/** 12568c2ecf20Sopenharmony_ci * tomoyo_same_ipaddr_union - Check for duplicated "struct tomoyo_ipaddr_union" entry. 12578c2ecf20Sopenharmony_ci * 12588c2ecf20Sopenharmony_ci * @a: Pointer to "struct tomoyo_ipaddr_union". 12598c2ecf20Sopenharmony_ci * @b: Pointer to "struct tomoyo_ipaddr_union". 12608c2ecf20Sopenharmony_ci * 12618c2ecf20Sopenharmony_ci * Returns true if @a == @b, false otherwise. 12628c2ecf20Sopenharmony_ci */ 12638c2ecf20Sopenharmony_cistatic inline bool tomoyo_same_ipaddr_union 12648c2ecf20Sopenharmony_ci(const struct tomoyo_ipaddr_union *a, const struct tomoyo_ipaddr_union *b) 12658c2ecf20Sopenharmony_ci{ 12668c2ecf20Sopenharmony_ci return !memcmp(a->ip, b->ip, sizeof(a->ip)) && a->group == b->group && 12678c2ecf20Sopenharmony_ci a->is_ipv6 == b->is_ipv6; 12688c2ecf20Sopenharmony_ci} 12698c2ecf20Sopenharmony_ci 12708c2ecf20Sopenharmony_ci/** 12718c2ecf20Sopenharmony_ci * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread. 12728c2ecf20Sopenharmony_ci * 12738c2ecf20Sopenharmony_ci * Returns pointer to "struct tomoyo_policy_namespace" for current thread. 12748c2ecf20Sopenharmony_ci */ 12758c2ecf20Sopenharmony_cistatic inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void) 12768c2ecf20Sopenharmony_ci{ 12778c2ecf20Sopenharmony_ci return tomoyo_domain()->ns; 12788c2ecf20Sopenharmony_ci} 12798c2ecf20Sopenharmony_ci 12808c2ecf20Sopenharmony_ci#if defined(CONFIG_SLOB) 12818c2ecf20Sopenharmony_ci 12828c2ecf20Sopenharmony_ci/** 12838c2ecf20Sopenharmony_ci * tomoyo_round2 - Round up to power of 2 for calculating memory usage. 12848c2ecf20Sopenharmony_ci * 12858c2ecf20Sopenharmony_ci * @size: Size to be rounded up. 12868c2ecf20Sopenharmony_ci * 12878c2ecf20Sopenharmony_ci * Returns @size. 12888c2ecf20Sopenharmony_ci * 12898c2ecf20Sopenharmony_ci * Since SLOB does not round up, this function simply returns @size. 12908c2ecf20Sopenharmony_ci */ 12918c2ecf20Sopenharmony_cistatic inline int tomoyo_round2(size_t size) 12928c2ecf20Sopenharmony_ci{ 12938c2ecf20Sopenharmony_ci return size; 12948c2ecf20Sopenharmony_ci} 12958c2ecf20Sopenharmony_ci 12968c2ecf20Sopenharmony_ci#else 12978c2ecf20Sopenharmony_ci 12988c2ecf20Sopenharmony_ci/** 12998c2ecf20Sopenharmony_ci * tomoyo_round2 - Round up to power of 2 for calculating memory usage. 13008c2ecf20Sopenharmony_ci * 13018c2ecf20Sopenharmony_ci * @size: Size to be rounded up. 13028c2ecf20Sopenharmony_ci * 13038c2ecf20Sopenharmony_ci * Returns rounded size. 13048c2ecf20Sopenharmony_ci * 13058c2ecf20Sopenharmony_ci * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of 13068c2ecf20Sopenharmony_ci * (e.g.) 128 bytes. 13078c2ecf20Sopenharmony_ci */ 13088c2ecf20Sopenharmony_cistatic inline int tomoyo_round2(size_t size) 13098c2ecf20Sopenharmony_ci{ 13108c2ecf20Sopenharmony_ci#if PAGE_SIZE == 4096 13118c2ecf20Sopenharmony_ci size_t bsize = 32; 13128c2ecf20Sopenharmony_ci#else 13138c2ecf20Sopenharmony_ci size_t bsize = 64; 13148c2ecf20Sopenharmony_ci#endif 13158c2ecf20Sopenharmony_ci if (!size) 13168c2ecf20Sopenharmony_ci return 0; 13178c2ecf20Sopenharmony_ci while (size > bsize) 13188c2ecf20Sopenharmony_ci bsize <<= 1; 13198c2ecf20Sopenharmony_ci return bsize; 13208c2ecf20Sopenharmony_ci} 13218c2ecf20Sopenharmony_ci 13228c2ecf20Sopenharmony_ci#endif 13238c2ecf20Sopenharmony_ci 13248c2ecf20Sopenharmony_ci/** 13258c2ecf20Sopenharmony_ci * list_for_each_cookie - iterate over a list with cookie. 13268c2ecf20Sopenharmony_ci * @pos: the &struct list_head to use as a loop cursor. 13278c2ecf20Sopenharmony_ci * @head: the head for your list. 13288c2ecf20Sopenharmony_ci */ 13298c2ecf20Sopenharmony_ci#define list_for_each_cookie(pos, head) \ 13308c2ecf20Sopenharmony_ci if (!pos) \ 13318c2ecf20Sopenharmony_ci pos = srcu_dereference((head)->next, &tomoyo_ss); \ 13328c2ecf20Sopenharmony_ci for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss)) 13338c2ecf20Sopenharmony_ci 13348c2ecf20Sopenharmony_ci#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ 1335