162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * security/tomoyo/common.h 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Header file for TOMOYO. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright (C) 2005-2011 NTT DATA CORPORATION 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef _SECURITY_TOMOYO_COMMON_H 1162306a36Sopenharmony_ci#define _SECURITY_TOMOYO_COMMON_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define pr_fmt(fmt) fmt 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <linux/ctype.h> 1662306a36Sopenharmony_ci#include <linux/string.h> 1762306a36Sopenharmony_ci#include <linux/mm.h> 1862306a36Sopenharmony_ci#include <linux/file.h> 1962306a36Sopenharmony_ci#include <linux/kmod.h> 2062306a36Sopenharmony_ci#include <linux/fs.h> 2162306a36Sopenharmony_ci#include <linux/sched.h> 2262306a36Sopenharmony_ci#include <linux/namei.h> 2362306a36Sopenharmony_ci#include <linux/mount.h> 2462306a36Sopenharmony_ci#include <linux/list.h> 2562306a36Sopenharmony_ci#include <linux/cred.h> 2662306a36Sopenharmony_ci#include <linux/poll.h> 2762306a36Sopenharmony_ci#include <linux/binfmts.h> 2862306a36Sopenharmony_ci#include <linux/highmem.h> 2962306a36Sopenharmony_ci#include <linux/net.h> 3062306a36Sopenharmony_ci#include <linux/inet.h> 3162306a36Sopenharmony_ci#include <linux/in.h> 3262306a36Sopenharmony_ci#include <linux/in6.h> 3362306a36Sopenharmony_ci#include <linux/un.h> 3462306a36Sopenharmony_ci#include <linux/lsm_hooks.h> 3562306a36Sopenharmony_ci#include <net/sock.h> 3662306a36Sopenharmony_ci#include <net/af_unix.h> 3762306a36Sopenharmony_ci#include <net/ip.h> 3862306a36Sopenharmony_ci#include <net/ipv6.h> 3962306a36Sopenharmony_ci#include <net/udp.h> 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/********** Constants definitions. **********/ 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* 4462306a36Sopenharmony_ci * TOMOYO uses this hash only when appending a string into the string 4562306a36Sopenharmony_ci * table. Frequency of appending strings is very low. So we don't need 4662306a36Sopenharmony_ci * large (e.g. 64k) hash size. 256 will be sufficient. 4762306a36Sopenharmony_ci */ 4862306a36Sopenharmony_ci#define TOMOYO_HASH_BITS 8 4962306a36Sopenharmony_ci#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* 5262306a36Sopenharmony_ci * TOMOYO checks only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET. 5362306a36Sopenharmony_ci * Therefore, we don't need SOCK_MAX. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ci#define TOMOYO_SOCK_MAX 6 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#define TOMOYO_EXEC_TMPSIZE 4096 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* Garbage collector is trying to kfree() this element. */ 6062306a36Sopenharmony_ci#define TOMOYO_GC_IN_PROGRESS -1 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* Profile number is an integer between 0 and 255. */ 6362306a36Sopenharmony_ci#define TOMOYO_MAX_PROFILES 256 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* Group number is an integer between 0 and 255. */ 6662306a36Sopenharmony_ci#define TOMOYO_MAX_ACL_GROUPS 256 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/* Index numbers for "struct tomoyo_condition". */ 6962306a36Sopenharmony_cienum tomoyo_conditions_index { 7062306a36Sopenharmony_ci TOMOYO_TASK_UID, /* current_uid() */ 7162306a36Sopenharmony_ci TOMOYO_TASK_EUID, /* current_euid() */ 7262306a36Sopenharmony_ci TOMOYO_TASK_SUID, /* current_suid() */ 7362306a36Sopenharmony_ci TOMOYO_TASK_FSUID, /* current_fsuid() */ 7462306a36Sopenharmony_ci TOMOYO_TASK_GID, /* current_gid() */ 7562306a36Sopenharmony_ci TOMOYO_TASK_EGID, /* current_egid() */ 7662306a36Sopenharmony_ci TOMOYO_TASK_SGID, /* current_sgid() */ 7762306a36Sopenharmony_ci TOMOYO_TASK_FSGID, /* current_fsgid() */ 7862306a36Sopenharmony_ci TOMOYO_TASK_PID, /* sys_getpid() */ 7962306a36Sopenharmony_ci TOMOYO_TASK_PPID, /* sys_getppid() */ 8062306a36Sopenharmony_ci TOMOYO_EXEC_ARGC, /* "struct linux_binprm *"->argc */ 8162306a36Sopenharmony_ci TOMOYO_EXEC_ENVC, /* "struct linux_binprm *"->envc */ 8262306a36Sopenharmony_ci TOMOYO_TYPE_IS_SOCKET, /* S_IFSOCK */ 8362306a36Sopenharmony_ci TOMOYO_TYPE_IS_SYMLINK, /* S_IFLNK */ 8462306a36Sopenharmony_ci TOMOYO_TYPE_IS_FILE, /* S_IFREG */ 8562306a36Sopenharmony_ci TOMOYO_TYPE_IS_BLOCK_DEV, /* S_IFBLK */ 8662306a36Sopenharmony_ci TOMOYO_TYPE_IS_DIRECTORY, /* S_IFDIR */ 8762306a36Sopenharmony_ci TOMOYO_TYPE_IS_CHAR_DEV, /* S_IFCHR */ 8862306a36Sopenharmony_ci TOMOYO_TYPE_IS_FIFO, /* S_IFIFO */ 8962306a36Sopenharmony_ci TOMOYO_MODE_SETUID, /* S_ISUID */ 9062306a36Sopenharmony_ci TOMOYO_MODE_SETGID, /* S_ISGID */ 9162306a36Sopenharmony_ci TOMOYO_MODE_STICKY, /* S_ISVTX */ 9262306a36Sopenharmony_ci TOMOYO_MODE_OWNER_READ, /* S_IRUSR */ 9362306a36Sopenharmony_ci TOMOYO_MODE_OWNER_WRITE, /* S_IWUSR */ 9462306a36Sopenharmony_ci TOMOYO_MODE_OWNER_EXECUTE, /* S_IXUSR */ 9562306a36Sopenharmony_ci TOMOYO_MODE_GROUP_READ, /* S_IRGRP */ 9662306a36Sopenharmony_ci TOMOYO_MODE_GROUP_WRITE, /* S_IWGRP */ 9762306a36Sopenharmony_ci TOMOYO_MODE_GROUP_EXECUTE, /* S_IXGRP */ 9862306a36Sopenharmony_ci TOMOYO_MODE_OTHERS_READ, /* S_IROTH */ 9962306a36Sopenharmony_ci TOMOYO_MODE_OTHERS_WRITE, /* S_IWOTH */ 10062306a36Sopenharmony_ci TOMOYO_MODE_OTHERS_EXECUTE, /* S_IXOTH */ 10162306a36Sopenharmony_ci TOMOYO_EXEC_REALPATH, 10262306a36Sopenharmony_ci TOMOYO_SYMLINK_TARGET, 10362306a36Sopenharmony_ci TOMOYO_PATH1_UID, 10462306a36Sopenharmony_ci TOMOYO_PATH1_GID, 10562306a36Sopenharmony_ci TOMOYO_PATH1_INO, 10662306a36Sopenharmony_ci TOMOYO_PATH1_MAJOR, 10762306a36Sopenharmony_ci TOMOYO_PATH1_MINOR, 10862306a36Sopenharmony_ci TOMOYO_PATH1_PERM, 10962306a36Sopenharmony_ci TOMOYO_PATH1_TYPE, 11062306a36Sopenharmony_ci TOMOYO_PATH1_DEV_MAJOR, 11162306a36Sopenharmony_ci TOMOYO_PATH1_DEV_MINOR, 11262306a36Sopenharmony_ci TOMOYO_PATH2_UID, 11362306a36Sopenharmony_ci TOMOYO_PATH2_GID, 11462306a36Sopenharmony_ci TOMOYO_PATH2_INO, 11562306a36Sopenharmony_ci TOMOYO_PATH2_MAJOR, 11662306a36Sopenharmony_ci TOMOYO_PATH2_MINOR, 11762306a36Sopenharmony_ci TOMOYO_PATH2_PERM, 11862306a36Sopenharmony_ci TOMOYO_PATH2_TYPE, 11962306a36Sopenharmony_ci TOMOYO_PATH2_DEV_MAJOR, 12062306a36Sopenharmony_ci TOMOYO_PATH2_DEV_MINOR, 12162306a36Sopenharmony_ci TOMOYO_PATH1_PARENT_UID, 12262306a36Sopenharmony_ci TOMOYO_PATH1_PARENT_GID, 12362306a36Sopenharmony_ci TOMOYO_PATH1_PARENT_INO, 12462306a36Sopenharmony_ci TOMOYO_PATH1_PARENT_PERM, 12562306a36Sopenharmony_ci TOMOYO_PATH2_PARENT_UID, 12662306a36Sopenharmony_ci TOMOYO_PATH2_PARENT_GID, 12762306a36Sopenharmony_ci TOMOYO_PATH2_PARENT_INO, 12862306a36Sopenharmony_ci TOMOYO_PATH2_PARENT_PERM, 12962306a36Sopenharmony_ci TOMOYO_MAX_CONDITION_KEYWORD, 13062306a36Sopenharmony_ci TOMOYO_NUMBER_UNION, 13162306a36Sopenharmony_ci TOMOYO_NAME_UNION, 13262306a36Sopenharmony_ci TOMOYO_ARGV_ENTRY, 13362306a36Sopenharmony_ci TOMOYO_ENVP_ENTRY, 13462306a36Sopenharmony_ci}; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci/* Index numbers for stat(). */ 13862306a36Sopenharmony_cienum tomoyo_path_stat_index { 13962306a36Sopenharmony_ci /* Do not change this order. */ 14062306a36Sopenharmony_ci TOMOYO_PATH1, 14162306a36Sopenharmony_ci TOMOYO_PATH1_PARENT, 14262306a36Sopenharmony_ci TOMOYO_PATH2, 14362306a36Sopenharmony_ci TOMOYO_PATH2_PARENT, 14462306a36Sopenharmony_ci TOMOYO_MAX_PATH_STAT 14562306a36Sopenharmony_ci}; 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci/* Index numbers for operation mode. */ 14862306a36Sopenharmony_cienum tomoyo_mode_index { 14962306a36Sopenharmony_ci TOMOYO_CONFIG_DISABLED, 15062306a36Sopenharmony_ci TOMOYO_CONFIG_LEARNING, 15162306a36Sopenharmony_ci TOMOYO_CONFIG_PERMISSIVE, 15262306a36Sopenharmony_ci TOMOYO_CONFIG_ENFORCING, 15362306a36Sopenharmony_ci TOMOYO_CONFIG_MAX_MODE, 15462306a36Sopenharmony_ci TOMOYO_CONFIG_WANT_REJECT_LOG = 64, 15562306a36Sopenharmony_ci TOMOYO_CONFIG_WANT_GRANT_LOG = 128, 15662306a36Sopenharmony_ci TOMOYO_CONFIG_USE_DEFAULT = 255, 15762306a36Sopenharmony_ci}; 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci/* Index numbers for entry type. */ 16062306a36Sopenharmony_cienum tomoyo_policy_id { 16162306a36Sopenharmony_ci TOMOYO_ID_GROUP, 16262306a36Sopenharmony_ci TOMOYO_ID_ADDRESS_GROUP, 16362306a36Sopenharmony_ci TOMOYO_ID_PATH_GROUP, 16462306a36Sopenharmony_ci TOMOYO_ID_NUMBER_GROUP, 16562306a36Sopenharmony_ci TOMOYO_ID_TRANSITION_CONTROL, 16662306a36Sopenharmony_ci TOMOYO_ID_AGGREGATOR, 16762306a36Sopenharmony_ci TOMOYO_ID_MANAGER, 16862306a36Sopenharmony_ci TOMOYO_ID_CONDITION, 16962306a36Sopenharmony_ci TOMOYO_ID_NAME, 17062306a36Sopenharmony_ci TOMOYO_ID_ACL, 17162306a36Sopenharmony_ci TOMOYO_ID_DOMAIN, 17262306a36Sopenharmony_ci TOMOYO_MAX_POLICY 17362306a36Sopenharmony_ci}; 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci/* Index numbers for domain's attributes. */ 17662306a36Sopenharmony_cienum tomoyo_domain_info_flags_index { 17762306a36Sopenharmony_ci /* Quota warnning flag. */ 17862306a36Sopenharmony_ci TOMOYO_DIF_QUOTA_WARNED, 17962306a36Sopenharmony_ci /* 18062306a36Sopenharmony_ci * This domain was unable to create a new domain at 18162306a36Sopenharmony_ci * tomoyo_find_next_domain() because the name of the domain to be 18262306a36Sopenharmony_ci * created was too long or it could not allocate memory. 18362306a36Sopenharmony_ci * More than one process continued execve() without domain transition. 18462306a36Sopenharmony_ci */ 18562306a36Sopenharmony_ci TOMOYO_DIF_TRANSITION_FAILED, 18662306a36Sopenharmony_ci TOMOYO_MAX_DOMAIN_INFO_FLAGS 18762306a36Sopenharmony_ci}; 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci/* Index numbers for audit type. */ 19062306a36Sopenharmony_cienum tomoyo_grant_log { 19162306a36Sopenharmony_ci /* Follow profile's configuration. */ 19262306a36Sopenharmony_ci TOMOYO_GRANTLOG_AUTO, 19362306a36Sopenharmony_ci /* Do not generate grant log. */ 19462306a36Sopenharmony_ci TOMOYO_GRANTLOG_NO, 19562306a36Sopenharmony_ci /* Generate grant_log. */ 19662306a36Sopenharmony_ci TOMOYO_GRANTLOG_YES, 19762306a36Sopenharmony_ci}; 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci/* Index numbers for group entries. */ 20062306a36Sopenharmony_cienum tomoyo_group_id { 20162306a36Sopenharmony_ci TOMOYO_PATH_GROUP, 20262306a36Sopenharmony_ci TOMOYO_NUMBER_GROUP, 20362306a36Sopenharmony_ci TOMOYO_ADDRESS_GROUP, 20462306a36Sopenharmony_ci TOMOYO_MAX_GROUP 20562306a36Sopenharmony_ci}; 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci/* Index numbers for type of numeric values. */ 20862306a36Sopenharmony_cienum tomoyo_value_type { 20962306a36Sopenharmony_ci TOMOYO_VALUE_TYPE_INVALID, 21062306a36Sopenharmony_ci TOMOYO_VALUE_TYPE_DECIMAL, 21162306a36Sopenharmony_ci TOMOYO_VALUE_TYPE_OCTAL, 21262306a36Sopenharmony_ci TOMOYO_VALUE_TYPE_HEXADECIMAL, 21362306a36Sopenharmony_ci}; 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci/* Index numbers for domain transition control keywords. */ 21662306a36Sopenharmony_cienum tomoyo_transition_type { 21762306a36Sopenharmony_ci /* Do not change this order, */ 21862306a36Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_NO_RESET, 21962306a36Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_RESET, 22062306a36Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, 22162306a36Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_INITIALIZE, 22262306a36Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_NO_KEEP, 22362306a36Sopenharmony_ci TOMOYO_TRANSITION_CONTROL_KEEP, 22462306a36Sopenharmony_ci TOMOYO_MAX_TRANSITION_TYPE 22562306a36Sopenharmony_ci}; 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ci/* Index numbers for Access Controls. */ 22862306a36Sopenharmony_cienum tomoyo_acl_entry_type_index { 22962306a36Sopenharmony_ci TOMOYO_TYPE_PATH_ACL, 23062306a36Sopenharmony_ci TOMOYO_TYPE_PATH2_ACL, 23162306a36Sopenharmony_ci TOMOYO_TYPE_PATH_NUMBER_ACL, 23262306a36Sopenharmony_ci TOMOYO_TYPE_MKDEV_ACL, 23362306a36Sopenharmony_ci TOMOYO_TYPE_MOUNT_ACL, 23462306a36Sopenharmony_ci TOMOYO_TYPE_INET_ACL, 23562306a36Sopenharmony_ci TOMOYO_TYPE_UNIX_ACL, 23662306a36Sopenharmony_ci TOMOYO_TYPE_ENV_ACL, 23762306a36Sopenharmony_ci TOMOYO_TYPE_MANUAL_TASK_ACL, 23862306a36Sopenharmony_ci}; 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci/* Index numbers for access controls with one pathname. */ 24162306a36Sopenharmony_cienum tomoyo_path_acl_index { 24262306a36Sopenharmony_ci TOMOYO_TYPE_EXECUTE, 24362306a36Sopenharmony_ci TOMOYO_TYPE_READ, 24462306a36Sopenharmony_ci TOMOYO_TYPE_WRITE, 24562306a36Sopenharmony_ci TOMOYO_TYPE_APPEND, 24662306a36Sopenharmony_ci TOMOYO_TYPE_UNLINK, 24762306a36Sopenharmony_ci TOMOYO_TYPE_GETATTR, 24862306a36Sopenharmony_ci TOMOYO_TYPE_RMDIR, 24962306a36Sopenharmony_ci TOMOYO_TYPE_TRUNCATE, 25062306a36Sopenharmony_ci TOMOYO_TYPE_SYMLINK, 25162306a36Sopenharmony_ci TOMOYO_TYPE_CHROOT, 25262306a36Sopenharmony_ci TOMOYO_TYPE_UMOUNT, 25362306a36Sopenharmony_ci TOMOYO_MAX_PATH_OPERATION 25462306a36Sopenharmony_ci}; 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci/* Index numbers for /sys/kernel/security/tomoyo/stat interface. */ 25762306a36Sopenharmony_cienum tomoyo_memory_stat_type { 25862306a36Sopenharmony_ci TOMOYO_MEMORY_POLICY, 25962306a36Sopenharmony_ci TOMOYO_MEMORY_AUDIT, 26062306a36Sopenharmony_ci TOMOYO_MEMORY_QUERY, 26162306a36Sopenharmony_ci TOMOYO_MAX_MEMORY_STAT 26262306a36Sopenharmony_ci}; 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_cienum tomoyo_mkdev_acl_index { 26562306a36Sopenharmony_ci TOMOYO_TYPE_MKBLOCK, 26662306a36Sopenharmony_ci TOMOYO_TYPE_MKCHAR, 26762306a36Sopenharmony_ci TOMOYO_MAX_MKDEV_OPERATION 26862306a36Sopenharmony_ci}; 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ci/* Index numbers for socket operations. */ 27162306a36Sopenharmony_cienum tomoyo_network_acl_index { 27262306a36Sopenharmony_ci TOMOYO_NETWORK_BIND, /* bind() operation. */ 27362306a36Sopenharmony_ci TOMOYO_NETWORK_LISTEN, /* listen() operation. */ 27462306a36Sopenharmony_ci TOMOYO_NETWORK_CONNECT, /* connect() operation. */ 27562306a36Sopenharmony_ci TOMOYO_NETWORK_SEND, /* send() operation. */ 27662306a36Sopenharmony_ci TOMOYO_MAX_NETWORK_OPERATION 27762306a36Sopenharmony_ci}; 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci/* Index numbers for access controls with two pathnames. */ 28062306a36Sopenharmony_cienum tomoyo_path2_acl_index { 28162306a36Sopenharmony_ci TOMOYO_TYPE_LINK, 28262306a36Sopenharmony_ci TOMOYO_TYPE_RENAME, 28362306a36Sopenharmony_ci TOMOYO_TYPE_PIVOT_ROOT, 28462306a36Sopenharmony_ci TOMOYO_MAX_PATH2_OPERATION 28562306a36Sopenharmony_ci}; 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ci/* Index numbers for access controls with one pathname and one number. */ 28862306a36Sopenharmony_cienum tomoyo_path_number_acl_index { 28962306a36Sopenharmony_ci TOMOYO_TYPE_CREATE, 29062306a36Sopenharmony_ci TOMOYO_TYPE_MKDIR, 29162306a36Sopenharmony_ci TOMOYO_TYPE_MKFIFO, 29262306a36Sopenharmony_ci TOMOYO_TYPE_MKSOCK, 29362306a36Sopenharmony_ci TOMOYO_TYPE_IOCTL, 29462306a36Sopenharmony_ci TOMOYO_TYPE_CHMOD, 29562306a36Sopenharmony_ci TOMOYO_TYPE_CHOWN, 29662306a36Sopenharmony_ci TOMOYO_TYPE_CHGRP, 29762306a36Sopenharmony_ci TOMOYO_MAX_PATH_NUMBER_OPERATION 29862306a36Sopenharmony_ci}; 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */ 30162306a36Sopenharmony_cienum tomoyo_securityfs_interface_index { 30262306a36Sopenharmony_ci TOMOYO_DOMAINPOLICY, 30362306a36Sopenharmony_ci TOMOYO_EXCEPTIONPOLICY, 30462306a36Sopenharmony_ci TOMOYO_PROCESS_STATUS, 30562306a36Sopenharmony_ci TOMOYO_STAT, 30662306a36Sopenharmony_ci TOMOYO_AUDIT, 30762306a36Sopenharmony_ci TOMOYO_VERSION, 30862306a36Sopenharmony_ci TOMOYO_PROFILE, 30962306a36Sopenharmony_ci TOMOYO_QUERY, 31062306a36Sopenharmony_ci TOMOYO_MANAGER 31162306a36Sopenharmony_ci}; 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci/* Index numbers for special mount operations. */ 31462306a36Sopenharmony_cienum tomoyo_special_mount { 31562306a36Sopenharmony_ci TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */ 31662306a36Sopenharmony_ci TOMOYO_MOUNT_MOVE, /* mount --move /old /new */ 31762306a36Sopenharmony_ci TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */ 31862306a36Sopenharmony_ci TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */ 31962306a36Sopenharmony_ci TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */ 32062306a36Sopenharmony_ci TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */ 32162306a36Sopenharmony_ci TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */ 32262306a36Sopenharmony_ci TOMOYO_MAX_SPECIAL_MOUNT 32362306a36Sopenharmony_ci}; 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci/* Index numbers for functionality. */ 32662306a36Sopenharmony_cienum tomoyo_mac_index { 32762306a36Sopenharmony_ci TOMOYO_MAC_FILE_EXECUTE, 32862306a36Sopenharmony_ci TOMOYO_MAC_FILE_OPEN, 32962306a36Sopenharmony_ci TOMOYO_MAC_FILE_CREATE, 33062306a36Sopenharmony_ci TOMOYO_MAC_FILE_UNLINK, 33162306a36Sopenharmony_ci TOMOYO_MAC_FILE_GETATTR, 33262306a36Sopenharmony_ci TOMOYO_MAC_FILE_MKDIR, 33362306a36Sopenharmony_ci TOMOYO_MAC_FILE_RMDIR, 33462306a36Sopenharmony_ci TOMOYO_MAC_FILE_MKFIFO, 33562306a36Sopenharmony_ci TOMOYO_MAC_FILE_MKSOCK, 33662306a36Sopenharmony_ci TOMOYO_MAC_FILE_TRUNCATE, 33762306a36Sopenharmony_ci TOMOYO_MAC_FILE_SYMLINK, 33862306a36Sopenharmony_ci TOMOYO_MAC_FILE_MKBLOCK, 33962306a36Sopenharmony_ci TOMOYO_MAC_FILE_MKCHAR, 34062306a36Sopenharmony_ci TOMOYO_MAC_FILE_LINK, 34162306a36Sopenharmony_ci TOMOYO_MAC_FILE_RENAME, 34262306a36Sopenharmony_ci TOMOYO_MAC_FILE_CHMOD, 34362306a36Sopenharmony_ci TOMOYO_MAC_FILE_CHOWN, 34462306a36Sopenharmony_ci TOMOYO_MAC_FILE_CHGRP, 34562306a36Sopenharmony_ci TOMOYO_MAC_FILE_IOCTL, 34662306a36Sopenharmony_ci TOMOYO_MAC_FILE_CHROOT, 34762306a36Sopenharmony_ci TOMOYO_MAC_FILE_MOUNT, 34862306a36Sopenharmony_ci TOMOYO_MAC_FILE_UMOUNT, 34962306a36Sopenharmony_ci TOMOYO_MAC_FILE_PIVOT_ROOT, 35062306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_STREAM_BIND, 35162306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_STREAM_LISTEN, 35262306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_STREAM_CONNECT, 35362306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_DGRAM_BIND, 35462306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_DGRAM_SEND, 35562306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_RAW_BIND, 35662306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_INET_RAW_SEND, 35762306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_STREAM_BIND, 35862306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_STREAM_LISTEN, 35962306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_STREAM_CONNECT, 36062306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_DGRAM_BIND, 36162306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_DGRAM_SEND, 36262306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_BIND, 36362306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_LISTEN, 36462306a36Sopenharmony_ci TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_CONNECT, 36562306a36Sopenharmony_ci TOMOYO_MAC_ENVIRON, 36662306a36Sopenharmony_ci TOMOYO_MAX_MAC_INDEX 36762306a36Sopenharmony_ci}; 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci/* Index numbers for category of functionality. */ 37062306a36Sopenharmony_cienum tomoyo_mac_category_index { 37162306a36Sopenharmony_ci TOMOYO_MAC_CATEGORY_FILE, 37262306a36Sopenharmony_ci TOMOYO_MAC_CATEGORY_NETWORK, 37362306a36Sopenharmony_ci TOMOYO_MAC_CATEGORY_MISC, 37462306a36Sopenharmony_ci TOMOYO_MAX_MAC_CATEGORY_INDEX 37562306a36Sopenharmony_ci}; 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ci/* 37862306a36Sopenharmony_ci * Retry this request. Returned by tomoyo_supervisor() if policy violation has 37962306a36Sopenharmony_ci * occurred in enforcing mode and the userspace daemon decided to retry. 38062306a36Sopenharmony_ci * 38162306a36Sopenharmony_ci * We must choose a positive value in order to distinguish "granted" (which is 38262306a36Sopenharmony_ci * 0) and "rejected" (which is a negative value) and "retry". 38362306a36Sopenharmony_ci */ 38462306a36Sopenharmony_ci#define TOMOYO_RETRY_REQUEST 1 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ci/* Index numbers for /sys/kernel/security/tomoyo/stat interface. */ 38762306a36Sopenharmony_cienum tomoyo_policy_stat_type { 38862306a36Sopenharmony_ci /* Do not change this order. */ 38962306a36Sopenharmony_ci TOMOYO_STAT_POLICY_UPDATES, 39062306a36Sopenharmony_ci TOMOYO_STAT_POLICY_LEARNING, /* == TOMOYO_CONFIG_LEARNING */ 39162306a36Sopenharmony_ci TOMOYO_STAT_POLICY_PERMISSIVE, /* == TOMOYO_CONFIG_PERMISSIVE */ 39262306a36Sopenharmony_ci TOMOYO_STAT_POLICY_ENFORCING, /* == TOMOYO_CONFIG_ENFORCING */ 39362306a36Sopenharmony_ci TOMOYO_MAX_POLICY_STAT 39462306a36Sopenharmony_ci}; 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci/* Index numbers for profile's PREFERENCE values. */ 39762306a36Sopenharmony_cienum tomoyo_pref_index { 39862306a36Sopenharmony_ci TOMOYO_PREF_MAX_AUDIT_LOG, 39962306a36Sopenharmony_ci TOMOYO_PREF_MAX_LEARNING_ENTRY, 40062306a36Sopenharmony_ci TOMOYO_MAX_PREF 40162306a36Sopenharmony_ci}; 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci/********** Structure definitions. **********/ 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ci/* Common header for holding ACL entries. */ 40662306a36Sopenharmony_cistruct tomoyo_acl_head { 40762306a36Sopenharmony_ci struct list_head list; 40862306a36Sopenharmony_ci s8 is_deleted; /* true or false or TOMOYO_GC_IN_PROGRESS */ 40962306a36Sopenharmony_ci} __packed; 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci/* Common header for shared entries. */ 41262306a36Sopenharmony_cistruct tomoyo_shared_acl_head { 41362306a36Sopenharmony_ci struct list_head list; 41462306a36Sopenharmony_ci atomic_t users; 41562306a36Sopenharmony_ci} __packed; 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_cistruct tomoyo_policy_namespace; 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_ci/* Structure for request info. */ 42062306a36Sopenharmony_cistruct tomoyo_request_info { 42162306a36Sopenharmony_ci /* 42262306a36Sopenharmony_ci * For holding parameters specific to operations which deal files. 42362306a36Sopenharmony_ci * NULL if not dealing files. 42462306a36Sopenharmony_ci */ 42562306a36Sopenharmony_ci struct tomoyo_obj_info *obj; 42662306a36Sopenharmony_ci /* 42762306a36Sopenharmony_ci * For holding parameters specific to execve() request. 42862306a36Sopenharmony_ci * NULL if not dealing execve(). 42962306a36Sopenharmony_ci */ 43062306a36Sopenharmony_ci struct tomoyo_execve *ee; 43162306a36Sopenharmony_ci struct tomoyo_domain_info *domain; 43262306a36Sopenharmony_ci /* For holding parameters. */ 43362306a36Sopenharmony_ci union { 43462306a36Sopenharmony_ci struct { 43562306a36Sopenharmony_ci const struct tomoyo_path_info *filename; 43662306a36Sopenharmony_ci /* For using wildcards at tomoyo_find_next_domain(). */ 43762306a36Sopenharmony_ci const struct tomoyo_path_info *matched_path; 43862306a36Sopenharmony_ci /* One of values in "enum tomoyo_path_acl_index". */ 43962306a36Sopenharmony_ci u8 operation; 44062306a36Sopenharmony_ci } path; 44162306a36Sopenharmony_ci struct { 44262306a36Sopenharmony_ci const struct tomoyo_path_info *filename1; 44362306a36Sopenharmony_ci const struct tomoyo_path_info *filename2; 44462306a36Sopenharmony_ci /* One of values in "enum tomoyo_path2_acl_index". */ 44562306a36Sopenharmony_ci u8 operation; 44662306a36Sopenharmony_ci } path2; 44762306a36Sopenharmony_ci struct { 44862306a36Sopenharmony_ci const struct tomoyo_path_info *filename; 44962306a36Sopenharmony_ci unsigned int mode; 45062306a36Sopenharmony_ci unsigned int major; 45162306a36Sopenharmony_ci unsigned int minor; 45262306a36Sopenharmony_ci /* One of values in "enum tomoyo_mkdev_acl_index". */ 45362306a36Sopenharmony_ci u8 operation; 45462306a36Sopenharmony_ci } mkdev; 45562306a36Sopenharmony_ci struct { 45662306a36Sopenharmony_ci const struct tomoyo_path_info *filename; 45762306a36Sopenharmony_ci unsigned long number; 45862306a36Sopenharmony_ci /* 45962306a36Sopenharmony_ci * One of values in 46062306a36Sopenharmony_ci * "enum tomoyo_path_number_acl_index". 46162306a36Sopenharmony_ci */ 46262306a36Sopenharmony_ci u8 operation; 46362306a36Sopenharmony_ci } path_number; 46462306a36Sopenharmony_ci struct { 46562306a36Sopenharmony_ci const struct tomoyo_path_info *name; 46662306a36Sopenharmony_ci } environ; 46762306a36Sopenharmony_ci struct { 46862306a36Sopenharmony_ci const __be32 *address; 46962306a36Sopenharmony_ci u16 port; 47062306a36Sopenharmony_ci /* One of values smaller than TOMOYO_SOCK_MAX. */ 47162306a36Sopenharmony_ci u8 protocol; 47262306a36Sopenharmony_ci /* One of values in "enum tomoyo_network_acl_index". */ 47362306a36Sopenharmony_ci u8 operation; 47462306a36Sopenharmony_ci bool is_ipv6; 47562306a36Sopenharmony_ci } inet_network; 47662306a36Sopenharmony_ci struct { 47762306a36Sopenharmony_ci const struct tomoyo_path_info *address; 47862306a36Sopenharmony_ci /* One of values smaller than TOMOYO_SOCK_MAX. */ 47962306a36Sopenharmony_ci u8 protocol; 48062306a36Sopenharmony_ci /* One of values in "enum tomoyo_network_acl_index". */ 48162306a36Sopenharmony_ci u8 operation; 48262306a36Sopenharmony_ci } unix_network; 48362306a36Sopenharmony_ci struct { 48462306a36Sopenharmony_ci const struct tomoyo_path_info *type; 48562306a36Sopenharmony_ci const struct tomoyo_path_info *dir; 48662306a36Sopenharmony_ci const struct tomoyo_path_info *dev; 48762306a36Sopenharmony_ci unsigned long flags; 48862306a36Sopenharmony_ci int need_dev; 48962306a36Sopenharmony_ci } mount; 49062306a36Sopenharmony_ci struct { 49162306a36Sopenharmony_ci const struct tomoyo_path_info *domainname; 49262306a36Sopenharmony_ci } task; 49362306a36Sopenharmony_ci } param; 49462306a36Sopenharmony_ci struct tomoyo_acl_info *matched_acl; 49562306a36Sopenharmony_ci u8 param_type; 49662306a36Sopenharmony_ci bool granted; 49762306a36Sopenharmony_ci u8 retry; 49862306a36Sopenharmony_ci u8 profile; 49962306a36Sopenharmony_ci u8 mode; /* One of tomoyo_mode_index . */ 50062306a36Sopenharmony_ci u8 type; 50162306a36Sopenharmony_ci}; 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci/* Structure for holding a token. */ 50462306a36Sopenharmony_cistruct tomoyo_path_info { 50562306a36Sopenharmony_ci const char *name; 50662306a36Sopenharmony_ci u32 hash; /* = full_name_hash(name, strlen(name)) */ 50762306a36Sopenharmony_ci u16 const_len; /* = tomoyo_const_part_length(name) */ 50862306a36Sopenharmony_ci bool is_dir; /* = tomoyo_strendswith(name, "/") */ 50962306a36Sopenharmony_ci bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 51062306a36Sopenharmony_ci}; 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ci/* Structure for holding string data. */ 51362306a36Sopenharmony_cistruct tomoyo_name { 51462306a36Sopenharmony_ci struct tomoyo_shared_acl_head head; 51562306a36Sopenharmony_ci struct tomoyo_path_info entry; 51662306a36Sopenharmony_ci}; 51762306a36Sopenharmony_ci 51862306a36Sopenharmony_ci/* Structure for holding a word. */ 51962306a36Sopenharmony_cistruct tomoyo_name_union { 52062306a36Sopenharmony_ci /* Either @filename or @group is NULL. */ 52162306a36Sopenharmony_ci const struct tomoyo_path_info *filename; 52262306a36Sopenharmony_ci struct tomoyo_group *group; 52362306a36Sopenharmony_ci}; 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_ci/* Structure for holding a number. */ 52662306a36Sopenharmony_cistruct tomoyo_number_union { 52762306a36Sopenharmony_ci unsigned long values[2]; 52862306a36Sopenharmony_ci struct tomoyo_group *group; /* Maybe NULL. */ 52962306a36Sopenharmony_ci /* One of values in "enum tomoyo_value_type". */ 53062306a36Sopenharmony_ci u8 value_type[2]; 53162306a36Sopenharmony_ci}; 53262306a36Sopenharmony_ci 53362306a36Sopenharmony_ci/* Structure for holding an IP address. */ 53462306a36Sopenharmony_cistruct tomoyo_ipaddr_union { 53562306a36Sopenharmony_ci struct in6_addr ip[2]; /* Big endian. */ 53662306a36Sopenharmony_ci struct tomoyo_group *group; /* Pointer to address group. */ 53762306a36Sopenharmony_ci bool is_ipv6; /* Valid only if @group == NULL. */ 53862306a36Sopenharmony_ci}; 53962306a36Sopenharmony_ci 54062306a36Sopenharmony_ci/* Structure for "path_group"/"number_group"/"address_group" directive. */ 54162306a36Sopenharmony_cistruct tomoyo_group { 54262306a36Sopenharmony_ci struct tomoyo_shared_acl_head head; 54362306a36Sopenharmony_ci const struct tomoyo_path_info *group_name; 54462306a36Sopenharmony_ci struct list_head member_list; 54562306a36Sopenharmony_ci}; 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci/* Structure for "path_group" directive. */ 54862306a36Sopenharmony_cistruct tomoyo_path_group { 54962306a36Sopenharmony_ci struct tomoyo_acl_head head; 55062306a36Sopenharmony_ci const struct tomoyo_path_info *member_name; 55162306a36Sopenharmony_ci}; 55262306a36Sopenharmony_ci 55362306a36Sopenharmony_ci/* Structure for "number_group" directive. */ 55462306a36Sopenharmony_cistruct tomoyo_number_group { 55562306a36Sopenharmony_ci struct tomoyo_acl_head head; 55662306a36Sopenharmony_ci struct tomoyo_number_union number; 55762306a36Sopenharmony_ci}; 55862306a36Sopenharmony_ci 55962306a36Sopenharmony_ci/* Structure for "address_group" directive. */ 56062306a36Sopenharmony_cistruct tomoyo_address_group { 56162306a36Sopenharmony_ci struct tomoyo_acl_head head; 56262306a36Sopenharmony_ci /* Structure for holding an IP address. */ 56362306a36Sopenharmony_ci struct tomoyo_ipaddr_union address; 56462306a36Sopenharmony_ci}; 56562306a36Sopenharmony_ci 56662306a36Sopenharmony_ci/* Subset of "struct stat". Used by conditional ACL and audit logs. */ 56762306a36Sopenharmony_cistruct tomoyo_mini_stat { 56862306a36Sopenharmony_ci kuid_t uid; 56962306a36Sopenharmony_ci kgid_t gid; 57062306a36Sopenharmony_ci ino_t ino; 57162306a36Sopenharmony_ci umode_t mode; 57262306a36Sopenharmony_ci dev_t dev; 57362306a36Sopenharmony_ci dev_t rdev; 57462306a36Sopenharmony_ci}; 57562306a36Sopenharmony_ci 57662306a36Sopenharmony_ci/* Structure for dumping argv[] and envp[] of "struct linux_binprm". */ 57762306a36Sopenharmony_cistruct tomoyo_page_dump { 57862306a36Sopenharmony_ci struct page *page; /* Previously dumped page. */ 57962306a36Sopenharmony_ci char *data; /* Contents of "page". Size is PAGE_SIZE. */ 58062306a36Sopenharmony_ci}; 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci/* Structure for attribute checks in addition to pathname checks. */ 58362306a36Sopenharmony_cistruct tomoyo_obj_info { 58462306a36Sopenharmony_ci /* 58562306a36Sopenharmony_ci * True if tomoyo_get_attributes() was already called, false otherwise. 58662306a36Sopenharmony_ci */ 58762306a36Sopenharmony_ci bool validate_done; 58862306a36Sopenharmony_ci /* True if @stat[] is valid. */ 58962306a36Sopenharmony_ci bool stat_valid[TOMOYO_MAX_PATH_STAT]; 59062306a36Sopenharmony_ci /* First pathname. Initialized with { NULL, NULL } if no path. */ 59162306a36Sopenharmony_ci struct path path1; 59262306a36Sopenharmony_ci /* Second pathname. Initialized with { NULL, NULL } if no path. */ 59362306a36Sopenharmony_ci struct path path2; 59462306a36Sopenharmony_ci /* 59562306a36Sopenharmony_ci * Information on @path1, @path1's parent directory, @path2, @path2's 59662306a36Sopenharmony_ci * parent directory. 59762306a36Sopenharmony_ci */ 59862306a36Sopenharmony_ci struct tomoyo_mini_stat stat[TOMOYO_MAX_PATH_STAT]; 59962306a36Sopenharmony_ci /* 60062306a36Sopenharmony_ci * Content of symbolic link to be created. NULL for operations other 60162306a36Sopenharmony_ci * than symlink(). 60262306a36Sopenharmony_ci */ 60362306a36Sopenharmony_ci struct tomoyo_path_info *symlink_target; 60462306a36Sopenharmony_ci}; 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci/* Structure for argv[]. */ 60762306a36Sopenharmony_cistruct tomoyo_argv { 60862306a36Sopenharmony_ci unsigned long index; 60962306a36Sopenharmony_ci const struct tomoyo_path_info *value; 61062306a36Sopenharmony_ci bool is_not; 61162306a36Sopenharmony_ci}; 61262306a36Sopenharmony_ci 61362306a36Sopenharmony_ci/* Structure for envp[]. */ 61462306a36Sopenharmony_cistruct tomoyo_envp { 61562306a36Sopenharmony_ci const struct tomoyo_path_info *name; 61662306a36Sopenharmony_ci const struct tomoyo_path_info *value; 61762306a36Sopenharmony_ci bool is_not; 61862306a36Sopenharmony_ci}; 61962306a36Sopenharmony_ci 62062306a36Sopenharmony_ci/* Structure for execve() operation. */ 62162306a36Sopenharmony_cistruct tomoyo_execve { 62262306a36Sopenharmony_ci struct tomoyo_request_info r; 62362306a36Sopenharmony_ci struct tomoyo_obj_info obj; 62462306a36Sopenharmony_ci struct linux_binprm *bprm; 62562306a36Sopenharmony_ci const struct tomoyo_path_info *transition; 62662306a36Sopenharmony_ci /* For dumping argv[] and envp[]. */ 62762306a36Sopenharmony_ci struct tomoyo_page_dump dump; 62862306a36Sopenharmony_ci /* For temporary use. */ 62962306a36Sopenharmony_ci char *tmp; /* Size is TOMOYO_EXEC_TMPSIZE bytes */ 63062306a36Sopenharmony_ci}; 63162306a36Sopenharmony_ci 63262306a36Sopenharmony_ci/* Structure for entries which follows "struct tomoyo_condition". */ 63362306a36Sopenharmony_cistruct tomoyo_condition_element { 63462306a36Sopenharmony_ci /* 63562306a36Sopenharmony_ci * Left hand operand. A "struct tomoyo_argv" for TOMOYO_ARGV_ENTRY, a 63662306a36Sopenharmony_ci * "struct tomoyo_envp" for TOMOYO_ENVP_ENTRY is attached to the tail 63762306a36Sopenharmony_ci * of the array of this struct. 63862306a36Sopenharmony_ci */ 63962306a36Sopenharmony_ci u8 left; 64062306a36Sopenharmony_ci /* 64162306a36Sopenharmony_ci * Right hand operand. A "struct tomoyo_number_union" for 64262306a36Sopenharmony_ci * TOMOYO_NUMBER_UNION, a "struct tomoyo_name_union" for 64362306a36Sopenharmony_ci * TOMOYO_NAME_UNION is attached to the tail of the array of this 64462306a36Sopenharmony_ci * struct. 64562306a36Sopenharmony_ci */ 64662306a36Sopenharmony_ci u8 right; 64762306a36Sopenharmony_ci /* Equation operator. True if equals or overlaps, false otherwise. */ 64862306a36Sopenharmony_ci bool equals; 64962306a36Sopenharmony_ci}; 65062306a36Sopenharmony_ci 65162306a36Sopenharmony_ci/* Structure for optional arguments. */ 65262306a36Sopenharmony_cistruct tomoyo_condition { 65362306a36Sopenharmony_ci struct tomoyo_shared_acl_head head; 65462306a36Sopenharmony_ci u32 size; /* Memory size allocated for this entry. */ 65562306a36Sopenharmony_ci u16 condc; /* Number of conditions in this struct. */ 65662306a36Sopenharmony_ci u16 numbers_count; /* Number of "struct tomoyo_number_union values". */ 65762306a36Sopenharmony_ci u16 names_count; /* Number of "struct tomoyo_name_union names". */ 65862306a36Sopenharmony_ci u16 argc; /* Number of "struct tomoyo_argv". */ 65962306a36Sopenharmony_ci u16 envc; /* Number of "struct tomoyo_envp". */ 66062306a36Sopenharmony_ci u8 grant_log; /* One of values in "enum tomoyo_grant_log". */ 66162306a36Sopenharmony_ci const struct tomoyo_path_info *transit; /* Maybe NULL. */ 66262306a36Sopenharmony_ci /* 66362306a36Sopenharmony_ci * struct tomoyo_condition_element condition[condc]; 66462306a36Sopenharmony_ci * struct tomoyo_number_union values[numbers_count]; 66562306a36Sopenharmony_ci * struct tomoyo_name_union names[names_count]; 66662306a36Sopenharmony_ci * struct tomoyo_argv argv[argc]; 66762306a36Sopenharmony_ci * struct tomoyo_envp envp[envc]; 66862306a36Sopenharmony_ci */ 66962306a36Sopenharmony_ci}; 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_ci/* Common header for individual entries. */ 67262306a36Sopenharmony_cistruct tomoyo_acl_info { 67362306a36Sopenharmony_ci struct list_head list; 67462306a36Sopenharmony_ci struct tomoyo_condition *cond; /* Maybe NULL. */ 67562306a36Sopenharmony_ci s8 is_deleted; /* true or false or TOMOYO_GC_IN_PROGRESS */ 67662306a36Sopenharmony_ci u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */ 67762306a36Sopenharmony_ci} __packed; 67862306a36Sopenharmony_ci 67962306a36Sopenharmony_ci/* Structure for domain information. */ 68062306a36Sopenharmony_cistruct tomoyo_domain_info { 68162306a36Sopenharmony_ci struct list_head list; 68262306a36Sopenharmony_ci struct list_head acl_info_list; 68362306a36Sopenharmony_ci /* Name of this domain. Never NULL. */ 68462306a36Sopenharmony_ci const struct tomoyo_path_info *domainname; 68562306a36Sopenharmony_ci /* Namespace for this domain. Never NULL. */ 68662306a36Sopenharmony_ci struct tomoyo_policy_namespace *ns; 68762306a36Sopenharmony_ci /* Group numbers to use. */ 68862306a36Sopenharmony_ci unsigned long group[TOMOYO_MAX_ACL_GROUPS / BITS_PER_LONG]; 68962306a36Sopenharmony_ci u8 profile; /* Profile number to use. */ 69062306a36Sopenharmony_ci bool is_deleted; /* Delete flag. */ 69162306a36Sopenharmony_ci bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS]; 69262306a36Sopenharmony_ci atomic_t users; /* Number of referring tasks. */ 69362306a36Sopenharmony_ci}; 69462306a36Sopenharmony_ci 69562306a36Sopenharmony_ci/* 69662306a36Sopenharmony_ci * Structure for "task manual_domain_transition" directive. 69762306a36Sopenharmony_ci */ 69862306a36Sopenharmony_cistruct tomoyo_task_acl { 69962306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MANUAL_TASK_ACL */ 70062306a36Sopenharmony_ci /* Pointer to domainname. */ 70162306a36Sopenharmony_ci const struct tomoyo_path_info *domainname; 70262306a36Sopenharmony_ci}; 70362306a36Sopenharmony_ci 70462306a36Sopenharmony_ci/* 70562306a36Sopenharmony_ci * Structure for "file execute", "file read", "file write", "file append", 70662306a36Sopenharmony_ci * "file unlink", "file getattr", "file rmdir", "file truncate", 70762306a36Sopenharmony_ci * "file symlink", "file chroot" and "file unmount" directive. 70862306a36Sopenharmony_ci */ 70962306a36Sopenharmony_cistruct tomoyo_path_acl { 71062306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */ 71162306a36Sopenharmony_ci u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */ 71262306a36Sopenharmony_ci struct tomoyo_name_union name; 71362306a36Sopenharmony_ci}; 71462306a36Sopenharmony_ci 71562306a36Sopenharmony_ci/* 71662306a36Sopenharmony_ci * Structure for "file create", "file mkdir", "file mkfifo", "file mksock", 71762306a36Sopenharmony_ci * "file ioctl", "file chmod", "file chown" and "file chgrp" directive. 71862306a36Sopenharmony_ci */ 71962306a36Sopenharmony_cistruct tomoyo_path_number_acl { 72062306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */ 72162306a36Sopenharmony_ci /* Bitmask of values in "enum tomoyo_path_number_acl_index". */ 72262306a36Sopenharmony_ci u8 perm; 72362306a36Sopenharmony_ci struct tomoyo_name_union name; 72462306a36Sopenharmony_ci struct tomoyo_number_union number; 72562306a36Sopenharmony_ci}; 72662306a36Sopenharmony_ci 72762306a36Sopenharmony_ci/* Structure for "file mkblock" and "file mkchar" directive. */ 72862306a36Sopenharmony_cistruct tomoyo_mkdev_acl { 72962306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */ 73062306a36Sopenharmony_ci u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */ 73162306a36Sopenharmony_ci struct tomoyo_name_union name; 73262306a36Sopenharmony_ci struct tomoyo_number_union mode; 73362306a36Sopenharmony_ci struct tomoyo_number_union major; 73462306a36Sopenharmony_ci struct tomoyo_number_union minor; 73562306a36Sopenharmony_ci}; 73662306a36Sopenharmony_ci 73762306a36Sopenharmony_ci/* 73862306a36Sopenharmony_ci * Structure for "file rename", "file link" and "file pivot_root" directive. 73962306a36Sopenharmony_ci */ 74062306a36Sopenharmony_cistruct tomoyo_path2_acl { 74162306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */ 74262306a36Sopenharmony_ci u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */ 74362306a36Sopenharmony_ci struct tomoyo_name_union name1; 74462306a36Sopenharmony_ci struct tomoyo_name_union name2; 74562306a36Sopenharmony_ci}; 74662306a36Sopenharmony_ci 74762306a36Sopenharmony_ci/* Structure for "file mount" directive. */ 74862306a36Sopenharmony_cistruct tomoyo_mount_acl { 74962306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */ 75062306a36Sopenharmony_ci struct tomoyo_name_union dev_name; 75162306a36Sopenharmony_ci struct tomoyo_name_union dir_name; 75262306a36Sopenharmony_ci struct tomoyo_name_union fs_type; 75362306a36Sopenharmony_ci struct tomoyo_number_union flags; 75462306a36Sopenharmony_ci}; 75562306a36Sopenharmony_ci 75662306a36Sopenharmony_ci/* Structure for "misc env" directive in domain policy. */ 75762306a36Sopenharmony_cistruct tomoyo_env_acl { 75862306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_ENV_ACL */ 75962306a36Sopenharmony_ci const struct tomoyo_path_info *env; /* environment variable */ 76062306a36Sopenharmony_ci}; 76162306a36Sopenharmony_ci 76262306a36Sopenharmony_ci/* Structure for "network inet" directive. */ 76362306a36Sopenharmony_cistruct tomoyo_inet_acl { 76462306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_INET_ACL */ 76562306a36Sopenharmony_ci u8 protocol; 76662306a36Sopenharmony_ci u8 perm; /* Bitmask of values in "enum tomoyo_network_acl_index" */ 76762306a36Sopenharmony_ci struct tomoyo_ipaddr_union address; 76862306a36Sopenharmony_ci struct tomoyo_number_union port; 76962306a36Sopenharmony_ci}; 77062306a36Sopenharmony_ci 77162306a36Sopenharmony_ci/* Structure for "network unix" directive. */ 77262306a36Sopenharmony_cistruct tomoyo_unix_acl { 77362306a36Sopenharmony_ci struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_UNIX_ACL */ 77462306a36Sopenharmony_ci u8 protocol; 77562306a36Sopenharmony_ci u8 perm; /* Bitmask of values in "enum tomoyo_network_acl_index" */ 77662306a36Sopenharmony_ci struct tomoyo_name_union name; 77762306a36Sopenharmony_ci}; 77862306a36Sopenharmony_ci 77962306a36Sopenharmony_ci/* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */ 78062306a36Sopenharmony_cistruct tomoyo_acl_param { 78162306a36Sopenharmony_ci char *data; 78262306a36Sopenharmony_ci struct list_head *list; 78362306a36Sopenharmony_ci struct tomoyo_policy_namespace *ns; 78462306a36Sopenharmony_ci bool is_delete; 78562306a36Sopenharmony_ci}; 78662306a36Sopenharmony_ci 78762306a36Sopenharmony_ci#define TOMOYO_MAX_IO_READ_QUEUE 64 78862306a36Sopenharmony_ci 78962306a36Sopenharmony_ci/* 79062306a36Sopenharmony_ci * Structure for reading/writing policy via /sys/kernel/security/tomoyo 79162306a36Sopenharmony_ci * interfaces. 79262306a36Sopenharmony_ci */ 79362306a36Sopenharmony_cistruct tomoyo_io_buffer { 79462306a36Sopenharmony_ci void (*read)(struct tomoyo_io_buffer *head); 79562306a36Sopenharmony_ci int (*write)(struct tomoyo_io_buffer *head); 79662306a36Sopenharmony_ci __poll_t (*poll)(struct file *file, poll_table *wait); 79762306a36Sopenharmony_ci /* Exclusive lock for this structure. */ 79862306a36Sopenharmony_ci struct mutex io_sem; 79962306a36Sopenharmony_ci char __user *read_user_buf; 80062306a36Sopenharmony_ci size_t read_user_buf_avail; 80162306a36Sopenharmony_ci struct { 80262306a36Sopenharmony_ci struct list_head *ns; 80362306a36Sopenharmony_ci struct list_head *domain; 80462306a36Sopenharmony_ci struct list_head *group; 80562306a36Sopenharmony_ci struct list_head *acl; 80662306a36Sopenharmony_ci size_t avail; 80762306a36Sopenharmony_ci unsigned int step; 80862306a36Sopenharmony_ci unsigned int query_index; 80962306a36Sopenharmony_ci u16 index; 81062306a36Sopenharmony_ci u16 cond_index; 81162306a36Sopenharmony_ci u8 acl_group_index; 81262306a36Sopenharmony_ci u8 cond_step; 81362306a36Sopenharmony_ci u8 bit; 81462306a36Sopenharmony_ci u8 w_pos; 81562306a36Sopenharmony_ci bool eof; 81662306a36Sopenharmony_ci bool print_this_domain_only; 81762306a36Sopenharmony_ci bool print_transition_related_only; 81862306a36Sopenharmony_ci bool print_cond_part; 81962306a36Sopenharmony_ci const char *w[TOMOYO_MAX_IO_READ_QUEUE]; 82062306a36Sopenharmony_ci } r; 82162306a36Sopenharmony_ci struct { 82262306a36Sopenharmony_ci struct tomoyo_policy_namespace *ns; 82362306a36Sopenharmony_ci /* The position currently writing to. */ 82462306a36Sopenharmony_ci struct tomoyo_domain_info *domain; 82562306a36Sopenharmony_ci /* Bytes available for writing. */ 82662306a36Sopenharmony_ci size_t avail; 82762306a36Sopenharmony_ci bool is_delete; 82862306a36Sopenharmony_ci } w; 82962306a36Sopenharmony_ci /* Buffer for reading. */ 83062306a36Sopenharmony_ci char *read_buf; 83162306a36Sopenharmony_ci /* Size of read buffer. */ 83262306a36Sopenharmony_ci size_t readbuf_size; 83362306a36Sopenharmony_ci /* Buffer for writing. */ 83462306a36Sopenharmony_ci char *write_buf; 83562306a36Sopenharmony_ci /* Size of write buffer. */ 83662306a36Sopenharmony_ci size_t writebuf_size; 83762306a36Sopenharmony_ci /* Type of this interface. */ 83862306a36Sopenharmony_ci enum tomoyo_securityfs_interface_index type; 83962306a36Sopenharmony_ci /* Users counter protected by tomoyo_io_buffer_list_lock. */ 84062306a36Sopenharmony_ci u8 users; 84162306a36Sopenharmony_ci /* List for telling GC not to kfree() elements. */ 84262306a36Sopenharmony_ci struct list_head list; 84362306a36Sopenharmony_ci}; 84462306a36Sopenharmony_ci 84562306a36Sopenharmony_ci/* 84662306a36Sopenharmony_ci * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/ 84762306a36Sopenharmony_ci * "no_keep_domain" keyword. 84862306a36Sopenharmony_ci */ 84962306a36Sopenharmony_cistruct tomoyo_transition_control { 85062306a36Sopenharmony_ci struct tomoyo_acl_head head; 85162306a36Sopenharmony_ci u8 type; /* One of values in "enum tomoyo_transition_type". */ 85262306a36Sopenharmony_ci /* True if the domainname is tomoyo_get_last_name(). */ 85362306a36Sopenharmony_ci bool is_last_name; 85462306a36Sopenharmony_ci const struct tomoyo_path_info *domainname; /* Maybe NULL */ 85562306a36Sopenharmony_ci const struct tomoyo_path_info *program; /* Maybe NULL */ 85662306a36Sopenharmony_ci}; 85762306a36Sopenharmony_ci 85862306a36Sopenharmony_ci/* Structure for "aggregator" keyword. */ 85962306a36Sopenharmony_cistruct tomoyo_aggregator { 86062306a36Sopenharmony_ci struct tomoyo_acl_head head; 86162306a36Sopenharmony_ci const struct tomoyo_path_info *original_name; 86262306a36Sopenharmony_ci const struct tomoyo_path_info *aggregated_name; 86362306a36Sopenharmony_ci}; 86462306a36Sopenharmony_ci 86562306a36Sopenharmony_ci/* Structure for policy manager. */ 86662306a36Sopenharmony_cistruct tomoyo_manager { 86762306a36Sopenharmony_ci struct tomoyo_acl_head head; 86862306a36Sopenharmony_ci /* A path to program or a domainname. */ 86962306a36Sopenharmony_ci const struct tomoyo_path_info *manager; 87062306a36Sopenharmony_ci}; 87162306a36Sopenharmony_ci 87262306a36Sopenharmony_cistruct tomoyo_preference { 87362306a36Sopenharmony_ci unsigned int learning_max_entry; 87462306a36Sopenharmony_ci bool enforcing_verbose; 87562306a36Sopenharmony_ci bool learning_verbose; 87662306a36Sopenharmony_ci bool permissive_verbose; 87762306a36Sopenharmony_ci}; 87862306a36Sopenharmony_ci 87962306a36Sopenharmony_ci/* Structure for /sys/kernel/security/tomnoyo/profile interface. */ 88062306a36Sopenharmony_cistruct tomoyo_profile { 88162306a36Sopenharmony_ci const struct tomoyo_path_info *comment; 88262306a36Sopenharmony_ci struct tomoyo_preference *learning; 88362306a36Sopenharmony_ci struct tomoyo_preference *permissive; 88462306a36Sopenharmony_ci struct tomoyo_preference *enforcing; 88562306a36Sopenharmony_ci struct tomoyo_preference preference; 88662306a36Sopenharmony_ci u8 default_config; 88762306a36Sopenharmony_ci u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX]; 88862306a36Sopenharmony_ci unsigned int pref[TOMOYO_MAX_PREF]; 88962306a36Sopenharmony_ci}; 89062306a36Sopenharmony_ci 89162306a36Sopenharmony_ci/* Structure for representing YYYY/MM/DD hh/mm/ss. */ 89262306a36Sopenharmony_cistruct tomoyo_time { 89362306a36Sopenharmony_ci u16 year; 89462306a36Sopenharmony_ci u8 month; 89562306a36Sopenharmony_ci u8 day; 89662306a36Sopenharmony_ci u8 hour; 89762306a36Sopenharmony_ci u8 min; 89862306a36Sopenharmony_ci u8 sec; 89962306a36Sopenharmony_ci}; 90062306a36Sopenharmony_ci 90162306a36Sopenharmony_ci/* Structure for policy namespace. */ 90262306a36Sopenharmony_cistruct tomoyo_policy_namespace { 90362306a36Sopenharmony_ci /* Profile table. Memory is allocated as needed. */ 90462306a36Sopenharmony_ci struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES]; 90562306a36Sopenharmony_ci /* List of "struct tomoyo_group". */ 90662306a36Sopenharmony_ci struct list_head group_list[TOMOYO_MAX_GROUP]; 90762306a36Sopenharmony_ci /* List of policy. */ 90862306a36Sopenharmony_ci struct list_head policy_list[TOMOYO_MAX_POLICY]; 90962306a36Sopenharmony_ci /* The global ACL referred by "use_group" keyword. */ 91062306a36Sopenharmony_ci struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS]; 91162306a36Sopenharmony_ci /* List for connecting to tomoyo_namespace_list list. */ 91262306a36Sopenharmony_ci struct list_head namespace_list; 91362306a36Sopenharmony_ci /* Profile version. Currently only 20150505 is defined. */ 91462306a36Sopenharmony_ci unsigned int profile_version; 91562306a36Sopenharmony_ci /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */ 91662306a36Sopenharmony_ci const char *name; 91762306a36Sopenharmony_ci}; 91862306a36Sopenharmony_ci 91962306a36Sopenharmony_ci/* Structure for "struct task_struct"->security. */ 92062306a36Sopenharmony_cistruct tomoyo_task { 92162306a36Sopenharmony_ci struct tomoyo_domain_info *domain_info; 92262306a36Sopenharmony_ci struct tomoyo_domain_info *old_domain_info; 92362306a36Sopenharmony_ci}; 92462306a36Sopenharmony_ci 92562306a36Sopenharmony_ci/********** Function prototypes. **********/ 92662306a36Sopenharmony_ci 92762306a36Sopenharmony_cibool tomoyo_address_matches_group(const bool is_ipv6, const __be32 *address, 92862306a36Sopenharmony_ci const struct tomoyo_group *group); 92962306a36Sopenharmony_cibool tomoyo_compare_number_union(const unsigned long value, 93062306a36Sopenharmony_ci const struct tomoyo_number_union *ptr); 93162306a36Sopenharmony_cibool tomoyo_condition(struct tomoyo_request_info *r, 93262306a36Sopenharmony_ci const struct tomoyo_condition *cond); 93362306a36Sopenharmony_cibool tomoyo_correct_domain(const unsigned char *domainname); 93462306a36Sopenharmony_cibool tomoyo_correct_path(const char *filename); 93562306a36Sopenharmony_cibool tomoyo_correct_word(const char *string); 93662306a36Sopenharmony_cibool tomoyo_domain_def(const unsigned char *buffer); 93762306a36Sopenharmony_cibool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r); 93862306a36Sopenharmony_cibool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos, 93962306a36Sopenharmony_ci struct tomoyo_page_dump *dump); 94062306a36Sopenharmony_cibool tomoyo_memory_ok(void *ptr); 94162306a36Sopenharmony_cibool tomoyo_number_matches_group(const unsigned long min, 94262306a36Sopenharmony_ci const unsigned long max, 94362306a36Sopenharmony_ci const struct tomoyo_group *group); 94462306a36Sopenharmony_cibool tomoyo_parse_ipaddr_union(struct tomoyo_acl_param *param, 94562306a36Sopenharmony_ci struct tomoyo_ipaddr_union *ptr); 94662306a36Sopenharmony_cibool tomoyo_parse_name_union(struct tomoyo_acl_param *param, 94762306a36Sopenharmony_ci struct tomoyo_name_union *ptr); 94862306a36Sopenharmony_cibool tomoyo_parse_number_union(struct tomoyo_acl_param *param, 94962306a36Sopenharmony_ci struct tomoyo_number_union *ptr); 95062306a36Sopenharmony_cibool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, 95162306a36Sopenharmony_ci const struct tomoyo_path_info *pattern); 95262306a36Sopenharmony_cibool tomoyo_permstr(const char *string, const char *keyword); 95362306a36Sopenharmony_cibool tomoyo_str_starts(char **src, const char *find); 95462306a36Sopenharmony_cichar *tomoyo_encode(const char *str); 95562306a36Sopenharmony_cichar *tomoyo_encode2(const char *str, int str_len); 95662306a36Sopenharmony_cichar *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt, 95762306a36Sopenharmony_ci va_list args) __printf(3, 0); 95862306a36Sopenharmony_cichar *tomoyo_read_token(struct tomoyo_acl_param *param); 95962306a36Sopenharmony_cichar *tomoyo_realpath_from_path(const struct path *path); 96062306a36Sopenharmony_cichar *tomoyo_realpath_nofollow(const char *pathname); 96162306a36Sopenharmony_ciconst char *tomoyo_get_exe(void); 96262306a36Sopenharmony_ciconst struct tomoyo_path_info *tomoyo_compare_name_union 96362306a36Sopenharmony_ci(const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr); 96462306a36Sopenharmony_ciconst struct tomoyo_path_info *tomoyo_get_domainname 96562306a36Sopenharmony_ci(struct tomoyo_acl_param *param); 96662306a36Sopenharmony_ciconst struct tomoyo_path_info *tomoyo_get_name(const char *name); 96762306a36Sopenharmony_ciconst struct tomoyo_path_info *tomoyo_path_matches_group 96862306a36Sopenharmony_ci(const struct tomoyo_path_info *pathname, const struct tomoyo_group *group); 96962306a36Sopenharmony_ciint tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 97062306a36Sopenharmony_ci const struct path *path, const int flag); 97162306a36Sopenharmony_civoid tomoyo_close_control(struct tomoyo_io_buffer *head); 97262306a36Sopenharmony_ciint tomoyo_env_perm(struct tomoyo_request_info *r, const char *env); 97362306a36Sopenharmony_ciint tomoyo_execute_permission(struct tomoyo_request_info *r, 97462306a36Sopenharmony_ci const struct tomoyo_path_info *filename); 97562306a36Sopenharmony_ciint tomoyo_find_next_domain(struct linux_binprm *bprm); 97662306a36Sopenharmony_ciint tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile, 97762306a36Sopenharmony_ci const u8 index); 97862306a36Sopenharmony_ciint tomoyo_init_request_info(struct tomoyo_request_info *r, 97962306a36Sopenharmony_ci struct tomoyo_domain_info *domain, 98062306a36Sopenharmony_ci const u8 index); 98162306a36Sopenharmony_ciint tomoyo_mkdev_perm(const u8 operation, const struct path *path, 98262306a36Sopenharmony_ci const unsigned int mode, unsigned int dev); 98362306a36Sopenharmony_ciint tomoyo_mount_permission(const char *dev_name, const struct path *path, 98462306a36Sopenharmony_ci const char *type, unsigned long flags, 98562306a36Sopenharmony_ci void *data_page); 98662306a36Sopenharmony_ciint tomoyo_open_control(const u8 type, struct file *file); 98762306a36Sopenharmony_ciint tomoyo_path2_perm(const u8 operation, const struct path *path1, 98862306a36Sopenharmony_ci const struct path *path2); 98962306a36Sopenharmony_ciint tomoyo_path_number_perm(const u8 operation, const struct path *path, 99062306a36Sopenharmony_ci unsigned long number); 99162306a36Sopenharmony_ciint tomoyo_path_perm(const u8 operation, const struct path *path, 99262306a36Sopenharmony_ci const char *target); 99362306a36Sopenharmony_ci__poll_t tomoyo_poll_control(struct file *file, poll_table *wait); 99462306a36Sopenharmony_ci__poll_t tomoyo_poll_log(struct file *file, poll_table *wait); 99562306a36Sopenharmony_ciint tomoyo_socket_bind_permission(struct socket *sock, struct sockaddr *addr, 99662306a36Sopenharmony_ci int addr_len); 99762306a36Sopenharmony_ciint tomoyo_socket_connect_permission(struct socket *sock, 99862306a36Sopenharmony_ci struct sockaddr *addr, int addr_len); 99962306a36Sopenharmony_ciint tomoyo_socket_listen_permission(struct socket *sock); 100062306a36Sopenharmony_ciint tomoyo_socket_sendmsg_permission(struct socket *sock, struct msghdr *msg, 100162306a36Sopenharmony_ci int size); 100262306a36Sopenharmony_ciint tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) 100362306a36Sopenharmony_ci __printf(2, 3); 100462306a36Sopenharmony_ciint tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size, 100562306a36Sopenharmony_ci struct tomoyo_acl_param *param, 100662306a36Sopenharmony_ci bool (*check_duplicate) 100762306a36Sopenharmony_ci (const struct tomoyo_acl_info *, 100862306a36Sopenharmony_ci const struct tomoyo_acl_info *), 100962306a36Sopenharmony_ci bool (*merge_duplicate) 101062306a36Sopenharmony_ci (struct tomoyo_acl_info *, struct tomoyo_acl_info *, 101162306a36Sopenharmony_ci const bool)); 101262306a36Sopenharmony_ciint tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size, 101362306a36Sopenharmony_ci struct tomoyo_acl_param *param, 101462306a36Sopenharmony_ci bool (*check_duplicate) 101562306a36Sopenharmony_ci (const struct tomoyo_acl_head *, 101662306a36Sopenharmony_ci const struct tomoyo_acl_head *)); 101762306a36Sopenharmony_ciint tomoyo_write_aggregator(struct tomoyo_acl_param *param); 101862306a36Sopenharmony_ciint tomoyo_write_file(struct tomoyo_acl_param *param); 101962306a36Sopenharmony_ciint tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type); 102062306a36Sopenharmony_ciint tomoyo_write_misc(struct tomoyo_acl_param *param); 102162306a36Sopenharmony_ciint tomoyo_write_inet_network(struct tomoyo_acl_param *param); 102262306a36Sopenharmony_ciint tomoyo_write_transition_control(struct tomoyo_acl_param *param, 102362306a36Sopenharmony_ci const u8 type); 102462306a36Sopenharmony_ciint tomoyo_write_unix_network(struct tomoyo_acl_param *param); 102562306a36Sopenharmony_cissize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, 102662306a36Sopenharmony_ci const int buffer_len); 102762306a36Sopenharmony_cissize_t tomoyo_write_control(struct tomoyo_io_buffer *head, 102862306a36Sopenharmony_ci const char __user *buffer, const int buffer_len); 102962306a36Sopenharmony_cistruct tomoyo_condition *tomoyo_get_condition(struct tomoyo_acl_param *param); 103062306a36Sopenharmony_cistruct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, 103162306a36Sopenharmony_ci const bool transit); 103262306a36Sopenharmony_cistruct tomoyo_domain_info *tomoyo_domain(void); 103362306a36Sopenharmony_cistruct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 103462306a36Sopenharmony_cistruct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param, 103562306a36Sopenharmony_ci const u8 idx); 103662306a36Sopenharmony_cistruct tomoyo_policy_namespace *tomoyo_assign_namespace 103762306a36Sopenharmony_ci(const char *domainname); 103862306a36Sopenharmony_cistruct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns, 103962306a36Sopenharmony_ci const u8 profile); 104062306a36Sopenharmony_ciu8 tomoyo_parse_ulong(unsigned long *result, char **str); 104162306a36Sopenharmony_civoid *tomoyo_commit_ok(void *data, const unsigned int size); 104262306a36Sopenharmony_civoid __init tomoyo_load_builtin_policy(void); 104362306a36Sopenharmony_civoid __init tomoyo_mm_init(void); 104462306a36Sopenharmony_civoid tomoyo_check_acl(struct tomoyo_request_info *r, 104562306a36Sopenharmony_ci bool (*check_entry)(struct tomoyo_request_info *, 104662306a36Sopenharmony_ci const struct tomoyo_acl_info *)); 104762306a36Sopenharmony_civoid tomoyo_check_profile(void); 104862306a36Sopenharmony_civoid tomoyo_convert_time(time64_t time, struct tomoyo_time *stamp); 104962306a36Sopenharmony_civoid tomoyo_del_condition(struct list_head *element); 105062306a36Sopenharmony_civoid tomoyo_fill_path_info(struct tomoyo_path_info *ptr); 105162306a36Sopenharmony_civoid tomoyo_get_attributes(struct tomoyo_obj_info *obj); 105262306a36Sopenharmony_civoid tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns); 105362306a36Sopenharmony_civoid tomoyo_load_policy(const char *filename); 105462306a36Sopenharmony_civoid tomoyo_normalize_line(unsigned char *buffer); 105562306a36Sopenharmony_civoid tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register); 105662306a36Sopenharmony_civoid tomoyo_print_ip(char *buf, const unsigned int size, 105762306a36Sopenharmony_ci const struct tomoyo_ipaddr_union *ptr); 105862306a36Sopenharmony_civoid tomoyo_print_ulong(char *buffer, const int buffer_len, 105962306a36Sopenharmony_ci const unsigned long value, const u8 type); 106062306a36Sopenharmony_civoid tomoyo_put_name_union(struct tomoyo_name_union *ptr); 106162306a36Sopenharmony_civoid tomoyo_put_number_union(struct tomoyo_number_union *ptr); 106262306a36Sopenharmony_civoid tomoyo_read_log(struct tomoyo_io_buffer *head); 106362306a36Sopenharmony_civoid tomoyo_update_stat(const u8 index); 106462306a36Sopenharmony_civoid tomoyo_warn_oom(const char *function); 106562306a36Sopenharmony_civoid tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...) 106662306a36Sopenharmony_ci __printf(2, 3); 106762306a36Sopenharmony_civoid tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt, 106862306a36Sopenharmony_ci va_list args) __printf(3, 0); 106962306a36Sopenharmony_ci 107062306a36Sopenharmony_ci/********** External variable definitions. **********/ 107162306a36Sopenharmony_ci 107262306a36Sopenharmony_ciextern bool tomoyo_policy_loaded; 107362306a36Sopenharmony_ciextern int tomoyo_enabled; 107462306a36Sopenharmony_ciextern const char * const tomoyo_condition_keyword 107562306a36Sopenharmony_ci[TOMOYO_MAX_CONDITION_KEYWORD]; 107662306a36Sopenharmony_ciextern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS]; 107762306a36Sopenharmony_ciextern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX 107862306a36Sopenharmony_ci + TOMOYO_MAX_MAC_CATEGORY_INDEX]; 107962306a36Sopenharmony_ciextern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE]; 108062306a36Sopenharmony_ciextern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; 108162306a36Sopenharmony_ciextern const char * const tomoyo_proto_keyword[TOMOYO_SOCK_MAX]; 108262306a36Sopenharmony_ciextern const char * const tomoyo_socket_keyword[TOMOYO_MAX_NETWORK_OPERATION]; 108362306a36Sopenharmony_ciextern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX]; 108462306a36Sopenharmony_ciextern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION]; 108562306a36Sopenharmony_ciextern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION]; 108662306a36Sopenharmony_ciextern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION]; 108762306a36Sopenharmony_ciextern struct list_head tomoyo_condition_list; 108862306a36Sopenharmony_ciextern struct list_head tomoyo_domain_list; 108962306a36Sopenharmony_ciextern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 109062306a36Sopenharmony_ciextern struct list_head tomoyo_namespace_list; 109162306a36Sopenharmony_ciextern struct mutex tomoyo_policy_lock; 109262306a36Sopenharmony_ciextern struct srcu_struct tomoyo_ss; 109362306a36Sopenharmony_ciextern struct tomoyo_domain_info tomoyo_kernel_domain; 109462306a36Sopenharmony_ciextern struct tomoyo_policy_namespace tomoyo_kernel_namespace; 109562306a36Sopenharmony_ciextern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT]; 109662306a36Sopenharmony_ciextern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT]; 109762306a36Sopenharmony_ciextern struct lsm_blob_sizes tomoyo_blob_sizes; 109862306a36Sopenharmony_ci 109962306a36Sopenharmony_ci/********** Inlined functions. **********/ 110062306a36Sopenharmony_ci 110162306a36Sopenharmony_ci/** 110262306a36Sopenharmony_ci * tomoyo_read_lock - Take lock for protecting policy. 110362306a36Sopenharmony_ci * 110462306a36Sopenharmony_ci * Returns index number for tomoyo_read_unlock(). 110562306a36Sopenharmony_ci */ 110662306a36Sopenharmony_cistatic inline int tomoyo_read_lock(void) 110762306a36Sopenharmony_ci{ 110862306a36Sopenharmony_ci return srcu_read_lock(&tomoyo_ss); 110962306a36Sopenharmony_ci} 111062306a36Sopenharmony_ci 111162306a36Sopenharmony_ci/** 111262306a36Sopenharmony_ci * tomoyo_read_unlock - Release lock for protecting policy. 111362306a36Sopenharmony_ci * 111462306a36Sopenharmony_ci * @idx: Index number returned by tomoyo_read_lock(). 111562306a36Sopenharmony_ci * 111662306a36Sopenharmony_ci * Returns nothing. 111762306a36Sopenharmony_ci */ 111862306a36Sopenharmony_cistatic inline void tomoyo_read_unlock(int idx) 111962306a36Sopenharmony_ci{ 112062306a36Sopenharmony_ci srcu_read_unlock(&tomoyo_ss, idx); 112162306a36Sopenharmony_ci} 112262306a36Sopenharmony_ci 112362306a36Sopenharmony_ci/** 112462306a36Sopenharmony_ci * tomoyo_sys_getppid - Copy of getppid(). 112562306a36Sopenharmony_ci * 112662306a36Sopenharmony_ci * Returns parent process's PID. 112762306a36Sopenharmony_ci * 112862306a36Sopenharmony_ci * Alpha does not have getppid() defined. To be able to build this module on 112962306a36Sopenharmony_ci * Alpha, I have to copy getppid() from kernel/timer.c. 113062306a36Sopenharmony_ci */ 113162306a36Sopenharmony_cistatic inline pid_t tomoyo_sys_getppid(void) 113262306a36Sopenharmony_ci{ 113362306a36Sopenharmony_ci pid_t pid; 113462306a36Sopenharmony_ci 113562306a36Sopenharmony_ci rcu_read_lock(); 113662306a36Sopenharmony_ci pid = task_tgid_vnr(rcu_dereference(current->real_parent)); 113762306a36Sopenharmony_ci rcu_read_unlock(); 113862306a36Sopenharmony_ci return pid; 113962306a36Sopenharmony_ci} 114062306a36Sopenharmony_ci 114162306a36Sopenharmony_ci/** 114262306a36Sopenharmony_ci * tomoyo_sys_getpid - Copy of getpid(). 114362306a36Sopenharmony_ci * 114462306a36Sopenharmony_ci * Returns current thread's PID. 114562306a36Sopenharmony_ci * 114662306a36Sopenharmony_ci * Alpha does not have getpid() defined. To be able to build this module on 114762306a36Sopenharmony_ci * Alpha, I have to copy getpid() from kernel/timer.c. 114862306a36Sopenharmony_ci */ 114962306a36Sopenharmony_cistatic inline pid_t tomoyo_sys_getpid(void) 115062306a36Sopenharmony_ci{ 115162306a36Sopenharmony_ci return task_tgid_vnr(current); 115262306a36Sopenharmony_ci} 115362306a36Sopenharmony_ci 115462306a36Sopenharmony_ci/** 115562306a36Sopenharmony_ci * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure. 115662306a36Sopenharmony_ci * 115762306a36Sopenharmony_ci * @a: Pointer to "struct tomoyo_path_info". 115862306a36Sopenharmony_ci * @b: Pointer to "struct tomoyo_path_info". 115962306a36Sopenharmony_ci * 116062306a36Sopenharmony_ci * Returns true if @a == @b, false otherwise. 116162306a36Sopenharmony_ci */ 116262306a36Sopenharmony_cistatic inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a, 116362306a36Sopenharmony_ci const struct tomoyo_path_info *b) 116462306a36Sopenharmony_ci{ 116562306a36Sopenharmony_ci return a->hash != b->hash || strcmp(a->name, b->name); 116662306a36Sopenharmony_ci} 116762306a36Sopenharmony_ci 116862306a36Sopenharmony_ci/** 116962306a36Sopenharmony_ci * tomoyo_put_name - Drop reference on "struct tomoyo_name". 117062306a36Sopenharmony_ci * 117162306a36Sopenharmony_ci * @name: Pointer to "struct tomoyo_path_info". Maybe NULL. 117262306a36Sopenharmony_ci * 117362306a36Sopenharmony_ci * Returns nothing. 117462306a36Sopenharmony_ci */ 117562306a36Sopenharmony_cistatic inline void tomoyo_put_name(const struct tomoyo_path_info *name) 117662306a36Sopenharmony_ci{ 117762306a36Sopenharmony_ci if (name) { 117862306a36Sopenharmony_ci struct tomoyo_name *ptr = 117962306a36Sopenharmony_ci container_of(name, typeof(*ptr), entry); 118062306a36Sopenharmony_ci atomic_dec(&ptr->head.users); 118162306a36Sopenharmony_ci } 118262306a36Sopenharmony_ci} 118362306a36Sopenharmony_ci 118462306a36Sopenharmony_ci/** 118562306a36Sopenharmony_ci * tomoyo_put_condition - Drop reference on "struct tomoyo_condition". 118662306a36Sopenharmony_ci * 118762306a36Sopenharmony_ci * @cond: Pointer to "struct tomoyo_condition". Maybe NULL. 118862306a36Sopenharmony_ci * 118962306a36Sopenharmony_ci * Returns nothing. 119062306a36Sopenharmony_ci */ 119162306a36Sopenharmony_cistatic inline void tomoyo_put_condition(struct tomoyo_condition *cond) 119262306a36Sopenharmony_ci{ 119362306a36Sopenharmony_ci if (cond) 119462306a36Sopenharmony_ci atomic_dec(&cond->head.users); 119562306a36Sopenharmony_ci} 119662306a36Sopenharmony_ci 119762306a36Sopenharmony_ci/** 119862306a36Sopenharmony_ci * tomoyo_put_group - Drop reference on "struct tomoyo_group". 119962306a36Sopenharmony_ci * 120062306a36Sopenharmony_ci * @group: Pointer to "struct tomoyo_group". Maybe NULL. 120162306a36Sopenharmony_ci * 120262306a36Sopenharmony_ci * Returns nothing. 120362306a36Sopenharmony_ci */ 120462306a36Sopenharmony_cistatic inline void tomoyo_put_group(struct tomoyo_group *group) 120562306a36Sopenharmony_ci{ 120662306a36Sopenharmony_ci if (group) 120762306a36Sopenharmony_ci atomic_dec(&group->head.users); 120862306a36Sopenharmony_ci} 120962306a36Sopenharmony_ci 121062306a36Sopenharmony_ci/** 121162306a36Sopenharmony_ci * tomoyo_task - Get "struct tomoyo_task" for specified thread. 121262306a36Sopenharmony_ci * 121362306a36Sopenharmony_ci * @task - Pointer to "struct task_struct". 121462306a36Sopenharmony_ci * 121562306a36Sopenharmony_ci * Returns pointer to "struct tomoyo_task" for specified thread. 121662306a36Sopenharmony_ci */ 121762306a36Sopenharmony_cistatic inline struct tomoyo_task *tomoyo_task(struct task_struct *task) 121862306a36Sopenharmony_ci{ 121962306a36Sopenharmony_ci return task->security + tomoyo_blob_sizes.lbs_task; 122062306a36Sopenharmony_ci} 122162306a36Sopenharmony_ci 122262306a36Sopenharmony_ci/** 122362306a36Sopenharmony_ci * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry. 122462306a36Sopenharmony_ci * 122562306a36Sopenharmony_ci * @a: Pointer to "struct tomoyo_name_union". 122662306a36Sopenharmony_ci * @b: Pointer to "struct tomoyo_name_union". 122762306a36Sopenharmony_ci * 122862306a36Sopenharmony_ci * Returns true if @a == @b, false otherwise. 122962306a36Sopenharmony_ci */ 123062306a36Sopenharmony_cistatic inline bool tomoyo_same_name_union 123162306a36Sopenharmony_ci(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b) 123262306a36Sopenharmony_ci{ 123362306a36Sopenharmony_ci return a->filename == b->filename && a->group == b->group; 123462306a36Sopenharmony_ci} 123562306a36Sopenharmony_ci 123662306a36Sopenharmony_ci/** 123762306a36Sopenharmony_ci * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry. 123862306a36Sopenharmony_ci * 123962306a36Sopenharmony_ci * @a: Pointer to "struct tomoyo_number_union". 124062306a36Sopenharmony_ci * @b: Pointer to "struct tomoyo_number_union". 124162306a36Sopenharmony_ci * 124262306a36Sopenharmony_ci * Returns true if @a == @b, false otherwise. 124362306a36Sopenharmony_ci */ 124462306a36Sopenharmony_cistatic inline bool tomoyo_same_number_union 124562306a36Sopenharmony_ci(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b) 124662306a36Sopenharmony_ci{ 124762306a36Sopenharmony_ci return a->values[0] == b->values[0] && a->values[1] == b->values[1] && 124862306a36Sopenharmony_ci a->group == b->group && a->value_type[0] == b->value_type[0] && 124962306a36Sopenharmony_ci a->value_type[1] == b->value_type[1]; 125062306a36Sopenharmony_ci} 125162306a36Sopenharmony_ci 125262306a36Sopenharmony_ci/** 125362306a36Sopenharmony_ci * tomoyo_same_ipaddr_union - Check for duplicated "struct tomoyo_ipaddr_union" entry. 125462306a36Sopenharmony_ci * 125562306a36Sopenharmony_ci * @a: Pointer to "struct tomoyo_ipaddr_union". 125662306a36Sopenharmony_ci * @b: Pointer to "struct tomoyo_ipaddr_union". 125762306a36Sopenharmony_ci * 125862306a36Sopenharmony_ci * Returns true if @a == @b, false otherwise. 125962306a36Sopenharmony_ci */ 126062306a36Sopenharmony_cistatic inline bool tomoyo_same_ipaddr_union 126162306a36Sopenharmony_ci(const struct tomoyo_ipaddr_union *a, const struct tomoyo_ipaddr_union *b) 126262306a36Sopenharmony_ci{ 126362306a36Sopenharmony_ci return !memcmp(a->ip, b->ip, sizeof(a->ip)) && a->group == b->group && 126462306a36Sopenharmony_ci a->is_ipv6 == b->is_ipv6; 126562306a36Sopenharmony_ci} 126662306a36Sopenharmony_ci 126762306a36Sopenharmony_ci/** 126862306a36Sopenharmony_ci * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread. 126962306a36Sopenharmony_ci * 127062306a36Sopenharmony_ci * Returns pointer to "struct tomoyo_policy_namespace" for current thread. 127162306a36Sopenharmony_ci */ 127262306a36Sopenharmony_cistatic inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void) 127362306a36Sopenharmony_ci{ 127462306a36Sopenharmony_ci return tomoyo_domain()->ns; 127562306a36Sopenharmony_ci} 127662306a36Sopenharmony_ci 127762306a36Sopenharmony_ci/** 127862306a36Sopenharmony_ci * list_for_each_cookie - iterate over a list with cookie. 127962306a36Sopenharmony_ci * @pos: the &struct list_head to use as a loop cursor. 128062306a36Sopenharmony_ci * @head: the head for your list. 128162306a36Sopenharmony_ci */ 128262306a36Sopenharmony_ci#define list_for_each_cookie(pos, head) \ 128362306a36Sopenharmony_ci if (!pos) \ 128462306a36Sopenharmony_ci pos = srcu_dereference((head)->next, &tomoyo_ss); \ 128562306a36Sopenharmony_ci for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss)) 128662306a36Sopenharmony_ci 128762306a36Sopenharmony_ci#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */ 1288