xref: /openbmc/linux/security/tomoyo/common.h (revision 609fcd1b)
19590837bSKentaro Takeda /*
29590837bSKentaro Takeda  * security/tomoyo/common.h
39590837bSKentaro Takeda  *
476bb0895STetsuo Handa  * Header file for TOMOYO.
59590837bSKentaro Takeda  *
6843d183cSTetsuo Handa  * Copyright (C) 2005-2011  NTT DATA CORPORATION
79590837bSKentaro Takeda  */
89590837bSKentaro Takeda 
99590837bSKentaro Takeda #ifndef _SECURITY_TOMOYO_COMMON_H
109590837bSKentaro Takeda #define _SECURITY_TOMOYO_COMMON_H
119590837bSKentaro Takeda 
129590837bSKentaro Takeda #include <linux/ctype.h>
139590837bSKentaro Takeda #include <linux/string.h>
149590837bSKentaro Takeda #include <linux/mm.h>
159590837bSKentaro Takeda #include <linux/file.h>
169590837bSKentaro Takeda #include <linux/kmod.h>
179590837bSKentaro Takeda #include <linux/fs.h>
189590837bSKentaro Takeda #include <linux/sched.h>
199590837bSKentaro Takeda #include <linux/namei.h>
209590837bSKentaro Takeda #include <linux/mount.h>
219590837bSKentaro Takeda #include <linux/list.h>
2276bb0895STetsuo Handa #include <linux/cred.h>
2317fcfbd9STetsuo Handa #include <linux/poll.h>
242066a361STetsuo Handa #include <linux/binfmts.h>
252066a361STetsuo Handa #include <linux/highmem.h>
26059d84dbSTetsuo Handa #include <linux/net.h>
27059d84dbSTetsuo Handa #include <linux/inet.h>
28059d84dbSTetsuo Handa #include <linux/in.h>
29059d84dbSTetsuo Handa #include <linux/in6.h>
30059d84dbSTetsuo Handa #include <linux/un.h>
31059d84dbSTetsuo Handa #include <net/sock.h>
32059d84dbSTetsuo Handa #include <net/af_unix.h>
33059d84dbSTetsuo Handa #include <net/ip.h>
34059d84dbSTetsuo Handa #include <net/ipv6.h>
35059d84dbSTetsuo Handa #include <net/udp.h>
369590837bSKentaro Takeda 
3776bb0895STetsuo Handa /********** Constants definitions. **********/
3876bb0895STetsuo Handa 
3976bb0895STetsuo Handa /*
4076bb0895STetsuo Handa  * TOMOYO uses this hash only when appending a string into the string
4176bb0895STetsuo Handa  * table. Frequency of appending strings is very low. So we don't need
4276bb0895STetsuo Handa  * large (e.g. 64k) hash size. 256 will be sufficient.
4376bb0895STetsuo Handa  */
4476bb0895STetsuo Handa #define TOMOYO_HASH_BITS  8
4576bb0895STetsuo Handa #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
4676bb0895STetsuo Handa 
47059d84dbSTetsuo Handa /*
48059d84dbSTetsuo Handa  * TOMOYO checks only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET.
49059d84dbSTetsuo Handa  * Therefore, we don't need SOCK_MAX.
50059d84dbSTetsuo Handa  */
51059d84dbSTetsuo Handa #define TOMOYO_SOCK_MAX 6
52059d84dbSTetsuo Handa 
53c8c57e84STetsuo Handa #define TOMOYO_EXEC_TMPSIZE     4096
5476bb0895STetsuo Handa 
55f9732ea1STetsuo Handa /* Garbage collector is trying to kfree() this element. */
56f9732ea1STetsuo Handa #define TOMOYO_GC_IN_PROGRESS -1
57f9732ea1STetsuo Handa 
5876bb0895STetsuo Handa /* Profile number is an integer between 0 and 255. */
5976bb0895STetsuo Handa #define TOMOYO_MAX_PROFILES 256
6076bb0895STetsuo Handa 
6132997144STetsuo Handa /* Group number is an integer between 0 and 255. */
6232997144STetsuo Handa #define TOMOYO_MAX_ACL_GROUPS 256
6332997144STetsuo Handa 
642066a361STetsuo Handa /* Index numbers for "struct tomoyo_condition". */
652066a361STetsuo Handa enum tomoyo_conditions_index {
662066a361STetsuo Handa 	TOMOYO_TASK_UID,             /* current_uid()   */
672066a361STetsuo Handa 	TOMOYO_TASK_EUID,            /* current_euid()  */
682066a361STetsuo Handa 	TOMOYO_TASK_SUID,            /* current_suid()  */
692066a361STetsuo Handa 	TOMOYO_TASK_FSUID,           /* current_fsuid() */
702066a361STetsuo Handa 	TOMOYO_TASK_GID,             /* current_gid()   */
712066a361STetsuo Handa 	TOMOYO_TASK_EGID,            /* current_egid()  */
722066a361STetsuo Handa 	TOMOYO_TASK_SGID,            /* current_sgid()  */
732066a361STetsuo Handa 	TOMOYO_TASK_FSGID,           /* current_fsgid() */
742066a361STetsuo Handa 	TOMOYO_TASK_PID,             /* sys_getpid()   */
752066a361STetsuo Handa 	TOMOYO_TASK_PPID,            /* sys_getppid()  */
765b636857STetsuo Handa 	TOMOYO_EXEC_ARGC,            /* "struct linux_binprm *"->argc */
775b636857STetsuo Handa 	TOMOYO_EXEC_ENVC,            /* "struct linux_binprm *"->envc */
788761afd4STetsuo Handa 	TOMOYO_TYPE_IS_SOCKET,       /* S_IFSOCK */
798761afd4STetsuo Handa 	TOMOYO_TYPE_IS_SYMLINK,      /* S_IFLNK */
808761afd4STetsuo Handa 	TOMOYO_TYPE_IS_FILE,         /* S_IFREG */
818761afd4STetsuo Handa 	TOMOYO_TYPE_IS_BLOCK_DEV,    /* S_IFBLK */
828761afd4STetsuo Handa 	TOMOYO_TYPE_IS_DIRECTORY,    /* S_IFDIR */
838761afd4STetsuo Handa 	TOMOYO_TYPE_IS_CHAR_DEV,     /* S_IFCHR */
848761afd4STetsuo Handa 	TOMOYO_TYPE_IS_FIFO,         /* S_IFIFO */
858761afd4STetsuo Handa 	TOMOYO_MODE_SETUID,          /* S_ISUID */
868761afd4STetsuo Handa 	TOMOYO_MODE_SETGID,          /* S_ISGID */
878761afd4STetsuo Handa 	TOMOYO_MODE_STICKY,          /* S_ISVTX */
888761afd4STetsuo Handa 	TOMOYO_MODE_OWNER_READ,      /* S_IRUSR */
898761afd4STetsuo Handa 	TOMOYO_MODE_OWNER_WRITE,     /* S_IWUSR */
908761afd4STetsuo Handa 	TOMOYO_MODE_OWNER_EXECUTE,   /* S_IXUSR */
918761afd4STetsuo Handa 	TOMOYO_MODE_GROUP_READ,      /* S_IRGRP */
928761afd4STetsuo Handa 	TOMOYO_MODE_GROUP_WRITE,     /* S_IWGRP */
938761afd4STetsuo Handa 	TOMOYO_MODE_GROUP_EXECUTE,   /* S_IXGRP */
948761afd4STetsuo Handa 	TOMOYO_MODE_OTHERS_READ,     /* S_IROTH */
958761afd4STetsuo Handa 	TOMOYO_MODE_OTHERS_WRITE,    /* S_IWOTH */
968761afd4STetsuo Handa 	TOMOYO_MODE_OTHERS_EXECUTE,  /* S_IXOTH */
972ca9bf45STetsuo Handa 	TOMOYO_EXEC_REALPATH,
982ca9bf45STetsuo Handa 	TOMOYO_SYMLINK_TARGET,
998761afd4STetsuo Handa 	TOMOYO_PATH1_UID,
1008761afd4STetsuo Handa 	TOMOYO_PATH1_GID,
1018761afd4STetsuo Handa 	TOMOYO_PATH1_INO,
1028761afd4STetsuo Handa 	TOMOYO_PATH1_MAJOR,
1038761afd4STetsuo Handa 	TOMOYO_PATH1_MINOR,
1048761afd4STetsuo Handa 	TOMOYO_PATH1_PERM,
1058761afd4STetsuo Handa 	TOMOYO_PATH1_TYPE,
1068761afd4STetsuo Handa 	TOMOYO_PATH1_DEV_MAJOR,
1078761afd4STetsuo Handa 	TOMOYO_PATH1_DEV_MINOR,
1088761afd4STetsuo Handa 	TOMOYO_PATH2_UID,
1098761afd4STetsuo Handa 	TOMOYO_PATH2_GID,
1108761afd4STetsuo Handa 	TOMOYO_PATH2_INO,
1118761afd4STetsuo Handa 	TOMOYO_PATH2_MAJOR,
1128761afd4STetsuo Handa 	TOMOYO_PATH2_MINOR,
1138761afd4STetsuo Handa 	TOMOYO_PATH2_PERM,
1148761afd4STetsuo Handa 	TOMOYO_PATH2_TYPE,
1158761afd4STetsuo Handa 	TOMOYO_PATH2_DEV_MAJOR,
1168761afd4STetsuo Handa 	TOMOYO_PATH2_DEV_MINOR,
1178761afd4STetsuo Handa 	TOMOYO_PATH1_PARENT_UID,
1188761afd4STetsuo Handa 	TOMOYO_PATH1_PARENT_GID,
1198761afd4STetsuo Handa 	TOMOYO_PATH1_PARENT_INO,
1208761afd4STetsuo Handa 	TOMOYO_PATH1_PARENT_PERM,
1218761afd4STetsuo Handa 	TOMOYO_PATH2_PARENT_UID,
1228761afd4STetsuo Handa 	TOMOYO_PATH2_PARENT_GID,
1238761afd4STetsuo Handa 	TOMOYO_PATH2_PARENT_INO,
1248761afd4STetsuo Handa 	TOMOYO_PATH2_PARENT_PERM,
1252066a361STetsuo Handa 	TOMOYO_MAX_CONDITION_KEYWORD,
1262066a361STetsuo Handa 	TOMOYO_NUMBER_UNION,
1272ca9bf45STetsuo Handa 	TOMOYO_NAME_UNION,
1285b636857STetsuo Handa 	TOMOYO_ARGV_ENTRY,
1295b636857STetsuo Handa 	TOMOYO_ENVP_ENTRY,
1302066a361STetsuo Handa };
1312066a361STetsuo Handa 
1328761afd4STetsuo Handa 
1338761afd4STetsuo Handa /* Index numbers for stat(). */
1348761afd4STetsuo Handa enum tomoyo_path_stat_index {
1358761afd4STetsuo Handa 	/* Do not change this order. */
1368761afd4STetsuo Handa 	TOMOYO_PATH1,
1378761afd4STetsuo Handa 	TOMOYO_PATH1_PARENT,
1388761afd4STetsuo Handa 	TOMOYO_PATH2,
1398761afd4STetsuo Handa 	TOMOYO_PATH2_PARENT,
1408761afd4STetsuo Handa 	TOMOYO_MAX_PATH_STAT
1418761afd4STetsuo Handa };
1428761afd4STetsuo Handa 
143b5bc60b4STetsuo Handa /* Index numbers for operation mode. */
144cb0abe6aSTetsuo Handa enum tomoyo_mode_index {
145cb0abe6aSTetsuo Handa 	TOMOYO_CONFIG_DISABLED,
146cb0abe6aSTetsuo Handa 	TOMOYO_CONFIG_LEARNING,
147cb0abe6aSTetsuo Handa 	TOMOYO_CONFIG_PERMISSIVE,
14857c2590fSTetsuo Handa 	TOMOYO_CONFIG_ENFORCING,
149eadd99ccSTetsuo Handa 	TOMOYO_CONFIG_MAX_MODE,
150eadd99ccSTetsuo Handa 	TOMOYO_CONFIG_WANT_REJECT_LOG =  64,
151eadd99ccSTetsuo Handa 	TOMOYO_CONFIG_WANT_GRANT_LOG  = 128,
152eadd99ccSTetsuo Handa 	TOMOYO_CONFIG_USE_DEFAULT     = 255,
153cb0abe6aSTetsuo Handa };
154cb0abe6aSTetsuo Handa 
155b5bc60b4STetsuo Handa /* Index numbers for entry type. */
156a230f9e7STetsuo Handa enum tomoyo_policy_id {
157a230f9e7STetsuo Handa 	TOMOYO_ID_GROUP,
158059d84dbSTetsuo Handa 	TOMOYO_ID_ADDRESS_GROUP,
159a230f9e7STetsuo Handa 	TOMOYO_ID_PATH_GROUP,
160a230f9e7STetsuo Handa 	TOMOYO_ID_NUMBER_GROUP,
1615448ec4fSTetsuo Handa 	TOMOYO_ID_TRANSITION_CONTROL,
162a230f9e7STetsuo Handa 	TOMOYO_ID_AGGREGATOR,
163a230f9e7STetsuo Handa 	TOMOYO_ID_MANAGER,
1642066a361STetsuo Handa 	TOMOYO_ID_CONDITION,
165a230f9e7STetsuo Handa 	TOMOYO_ID_NAME,
166a230f9e7STetsuo Handa 	TOMOYO_ID_ACL,
167a230f9e7STetsuo Handa 	TOMOYO_ID_DOMAIN,
168a230f9e7STetsuo Handa 	TOMOYO_MAX_POLICY
169a230f9e7STetsuo Handa };
170a230f9e7STetsuo Handa 
1712c47ab93STetsuo Handa /* Index numbers for domain's attributes. */
1722c47ab93STetsuo Handa enum tomoyo_domain_info_flags_index {
1732c47ab93STetsuo Handa 	/* Quota warnning flag.   */
1742c47ab93STetsuo Handa 	TOMOYO_DIF_QUOTA_WARNED,
1752c47ab93STetsuo Handa 	/*
1762c47ab93STetsuo Handa 	 * This domain was unable to create a new domain at
1772c47ab93STetsuo Handa 	 * tomoyo_find_next_domain() because the name of the domain to be
1782c47ab93STetsuo Handa 	 * created was too long or it could not allocate memory.
1792c47ab93STetsuo Handa 	 * More than one process continued execve() without domain transition.
1802c47ab93STetsuo Handa 	 */
1812c47ab93STetsuo Handa 	TOMOYO_DIF_TRANSITION_FAILED,
1822c47ab93STetsuo Handa 	TOMOYO_MAX_DOMAIN_INFO_FLAGS
1832c47ab93STetsuo Handa };
1842c47ab93STetsuo Handa 
1851f067a68STetsuo Handa /* Index numbers for audit type. */
1861f067a68STetsuo Handa enum tomoyo_grant_log {
1871f067a68STetsuo Handa 	/* Follow profile's configuration. */
1881f067a68STetsuo Handa 	TOMOYO_GRANTLOG_AUTO,
1891f067a68STetsuo Handa 	/* Do not generate grant log. */
1901f067a68STetsuo Handa 	TOMOYO_GRANTLOG_NO,
1911f067a68STetsuo Handa 	/* Generate grant_log. */
1921f067a68STetsuo Handa 	TOMOYO_GRANTLOG_YES,
1931f067a68STetsuo Handa };
1941f067a68STetsuo Handa 
195b5bc60b4STetsuo Handa /* Index numbers for group entries. */
196a230f9e7STetsuo Handa enum tomoyo_group_id {
197a230f9e7STetsuo Handa 	TOMOYO_PATH_GROUP,
198a230f9e7STetsuo Handa 	TOMOYO_NUMBER_GROUP,
199059d84dbSTetsuo Handa 	TOMOYO_ADDRESS_GROUP,
200a230f9e7STetsuo Handa 	TOMOYO_MAX_GROUP
201a230f9e7STetsuo Handa };
202a230f9e7STetsuo Handa 
203b5bc60b4STetsuo Handa /* Index numbers for type of numeric values. */
204b5bc60b4STetsuo Handa enum tomoyo_value_type {
205b5bc60b4STetsuo Handa 	TOMOYO_VALUE_TYPE_INVALID,
206b5bc60b4STetsuo Handa 	TOMOYO_VALUE_TYPE_DECIMAL,
207b5bc60b4STetsuo Handa 	TOMOYO_VALUE_TYPE_OCTAL,
208b5bc60b4STetsuo Handa 	TOMOYO_VALUE_TYPE_HEXADECIMAL,
209b5bc60b4STetsuo Handa };
2104c3e9e2dSTetsuo Handa 
211b5bc60b4STetsuo Handa /* Index numbers for domain transition control keywords. */
2125448ec4fSTetsuo Handa enum tomoyo_transition_type {
2135448ec4fSTetsuo Handa 	/* Do not change this order, */
214bd03a3e4STetsuo Handa 	TOMOYO_TRANSITION_CONTROL_NO_RESET,
215bd03a3e4STetsuo Handa 	TOMOYO_TRANSITION_CONTROL_RESET,
2165448ec4fSTetsuo Handa 	TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
2175448ec4fSTetsuo Handa 	TOMOYO_TRANSITION_CONTROL_INITIALIZE,
2185448ec4fSTetsuo Handa 	TOMOYO_TRANSITION_CONTROL_NO_KEEP,
2195448ec4fSTetsuo Handa 	TOMOYO_TRANSITION_CONTROL_KEEP,
2205448ec4fSTetsuo Handa 	TOMOYO_MAX_TRANSITION_TYPE
2215448ec4fSTetsuo Handa };
2225448ec4fSTetsuo Handa 
22376bb0895STetsuo Handa /* Index numbers for Access Controls. */
224084da356STetsuo Handa enum tomoyo_acl_entry_type_index {
2257ef61233STetsuo Handa 	TOMOYO_TYPE_PATH_ACL,
2267ef61233STetsuo Handa 	TOMOYO_TYPE_PATH2_ACL,
227a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_PATH_NUMBER_ACL,
22875093152STetsuo Handa 	TOMOYO_TYPE_MKDEV_ACL,
2292106ccd9STetsuo Handa 	TOMOYO_TYPE_MOUNT_ACL,
230059d84dbSTetsuo Handa 	TOMOYO_TYPE_INET_ACL,
231059d84dbSTetsuo Handa 	TOMOYO_TYPE_UNIX_ACL,
232d58e0da8STetsuo Handa 	TOMOYO_TYPE_ENV_ACL,
233731d37aaSTetsuo Handa 	TOMOYO_TYPE_MANUAL_TASK_ACL,
234084da356STetsuo Handa };
23576bb0895STetsuo Handa 
236b5bc60b4STetsuo Handa /* Index numbers for access controls with one pathname. */
237084da356STetsuo Handa enum tomoyo_path_acl_index {
2387ef61233STetsuo Handa 	TOMOYO_TYPE_EXECUTE,
2397ef61233STetsuo Handa 	TOMOYO_TYPE_READ,
2407ef61233STetsuo Handa 	TOMOYO_TYPE_WRITE,
2417c75964fSTetsuo Handa 	TOMOYO_TYPE_APPEND,
2427ef61233STetsuo Handa 	TOMOYO_TYPE_UNLINK,
2437c75964fSTetsuo Handa 	TOMOYO_TYPE_GETATTR,
2447ef61233STetsuo Handa 	TOMOYO_TYPE_RMDIR,
2457ef61233STetsuo Handa 	TOMOYO_TYPE_TRUNCATE,
2467ef61233STetsuo Handa 	TOMOYO_TYPE_SYMLINK,
2477ef61233STetsuo Handa 	TOMOYO_TYPE_CHROOT,
2487ef61233STetsuo Handa 	TOMOYO_TYPE_UMOUNT,
2497ef61233STetsuo Handa 	TOMOYO_MAX_PATH_OPERATION
250084da356STetsuo Handa };
25176bb0895STetsuo Handa 
252b22b8b9fSTetsuo Handa /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
253eadd99ccSTetsuo Handa enum tomoyo_memory_stat_type {
254eadd99ccSTetsuo Handa 	TOMOYO_MEMORY_POLICY,
255eadd99ccSTetsuo Handa 	TOMOYO_MEMORY_AUDIT,
256eadd99ccSTetsuo Handa 	TOMOYO_MEMORY_QUERY,
257eadd99ccSTetsuo Handa 	TOMOYO_MAX_MEMORY_STAT
258eadd99ccSTetsuo Handa };
259eadd99ccSTetsuo Handa 
26075093152STetsuo Handa enum tomoyo_mkdev_acl_index {
261a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_MKBLOCK,
262a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_MKCHAR,
26375093152STetsuo Handa 	TOMOYO_MAX_MKDEV_OPERATION
264a1f9bb6aSTetsuo Handa };
265a1f9bb6aSTetsuo Handa 
266059d84dbSTetsuo Handa /* Index numbers for socket operations. */
267059d84dbSTetsuo Handa enum tomoyo_network_acl_index {
268059d84dbSTetsuo Handa 	TOMOYO_NETWORK_BIND,    /* bind() operation. */
269059d84dbSTetsuo Handa 	TOMOYO_NETWORK_LISTEN,  /* listen() operation. */
270059d84dbSTetsuo Handa 	TOMOYO_NETWORK_CONNECT, /* connect() operation. */
271059d84dbSTetsuo Handa 	TOMOYO_NETWORK_SEND,    /* send() operation. */
272059d84dbSTetsuo Handa 	TOMOYO_MAX_NETWORK_OPERATION
273059d84dbSTetsuo Handa };
274059d84dbSTetsuo Handa 
275b5bc60b4STetsuo Handa /* Index numbers for access controls with two pathnames. */
276084da356STetsuo Handa enum tomoyo_path2_acl_index {
2777ef61233STetsuo Handa 	TOMOYO_TYPE_LINK,
2787ef61233STetsuo Handa 	TOMOYO_TYPE_RENAME,
2797ef61233STetsuo Handa 	TOMOYO_TYPE_PIVOT_ROOT,
2807ef61233STetsuo Handa 	TOMOYO_MAX_PATH2_OPERATION
281084da356STetsuo Handa };
28276bb0895STetsuo Handa 
283b5bc60b4STetsuo Handa /* Index numbers for access controls with one pathname and one number. */
284a1f9bb6aSTetsuo Handa enum tomoyo_path_number_acl_index {
285a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_CREATE,
286a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_MKDIR,
287a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_MKFIFO,
288a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_MKSOCK,
289a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_IOCTL,
290a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_CHMOD,
291a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_CHOWN,
292a1f9bb6aSTetsuo Handa 	TOMOYO_TYPE_CHGRP,
293a1f9bb6aSTetsuo Handa 	TOMOYO_MAX_PATH_NUMBER_OPERATION
294a1f9bb6aSTetsuo Handa };
295a1f9bb6aSTetsuo Handa 
296b5bc60b4STetsuo Handa /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
297084da356STetsuo Handa enum tomoyo_securityfs_interface_index {
298084da356STetsuo Handa 	TOMOYO_DOMAINPOLICY,
299084da356STetsuo Handa 	TOMOYO_EXCEPTIONPOLICY,
300084da356STetsuo Handa 	TOMOYO_PROCESS_STATUS,
301b22b8b9fSTetsuo Handa 	TOMOYO_STAT,
302eadd99ccSTetsuo Handa 	TOMOYO_AUDIT,
303084da356STetsuo Handa 	TOMOYO_VERSION,
304084da356STetsuo Handa 	TOMOYO_PROFILE,
30517fcfbd9STetsuo Handa 	TOMOYO_QUERY,
306084da356STetsuo Handa 	TOMOYO_MANAGER
307084da356STetsuo Handa };
30876bb0895STetsuo Handa 
309b5bc60b4STetsuo Handa /* Index numbers for special mount operations. */
310b5bc60b4STetsuo Handa enum tomoyo_special_mount {
311b5bc60b4STetsuo Handa 	TOMOYO_MOUNT_BIND,            /* mount --bind /source /dest   */
312b5bc60b4STetsuo Handa 	TOMOYO_MOUNT_MOVE,            /* mount --move /old /new       */
313b5bc60b4STetsuo Handa 	TOMOYO_MOUNT_REMOUNT,         /* mount -o remount /dir        */
314b5bc60b4STetsuo Handa 	TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
315b5bc60b4STetsuo Handa 	TOMOYO_MOUNT_MAKE_PRIVATE,    /* mount --make-private /dir    */
316b5bc60b4STetsuo Handa 	TOMOYO_MOUNT_MAKE_SLAVE,      /* mount --make-slave /dir      */
317b5bc60b4STetsuo Handa 	TOMOYO_MOUNT_MAKE_SHARED,     /* mount --make-shared /dir     */
318b5bc60b4STetsuo Handa 	TOMOYO_MAX_SPECIAL_MOUNT
319b5bc60b4STetsuo Handa };
320b5bc60b4STetsuo Handa 
321b5bc60b4STetsuo Handa /* Index numbers for functionality. */
32257c2590fSTetsuo Handa enum tomoyo_mac_index {
32357c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_EXECUTE,
32457c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_OPEN,
32557c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_CREATE,
32657c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_UNLINK,
3277c75964fSTetsuo Handa 	TOMOYO_MAC_FILE_GETATTR,
32857c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_MKDIR,
32957c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_RMDIR,
33057c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_MKFIFO,
33157c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_MKSOCK,
33257c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_TRUNCATE,
33357c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_SYMLINK,
33457c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_MKBLOCK,
33557c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_MKCHAR,
33657c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_LINK,
33757c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_RENAME,
33857c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_CHMOD,
33957c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_CHOWN,
34057c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_CHGRP,
34157c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_IOCTL,
34257c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_CHROOT,
34357c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_MOUNT,
34457c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_UMOUNT,
34557c2590fSTetsuo Handa 	TOMOYO_MAC_FILE_PIVOT_ROOT,
346059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_INET_STREAM_BIND,
347059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_INET_STREAM_LISTEN,
348059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_INET_STREAM_CONNECT,
349059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_INET_DGRAM_BIND,
350059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_INET_DGRAM_SEND,
351059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_INET_RAW_BIND,
352059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_INET_RAW_SEND,
353059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_UNIX_STREAM_BIND,
354059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_UNIX_STREAM_LISTEN,
355059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_UNIX_STREAM_CONNECT,
356059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_UNIX_DGRAM_BIND,
357059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_UNIX_DGRAM_SEND,
358059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_BIND,
359059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_LISTEN,
360059d84dbSTetsuo Handa 	TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_CONNECT,
361d58e0da8STetsuo Handa 	TOMOYO_MAC_ENVIRON,
36257c2590fSTetsuo Handa 	TOMOYO_MAX_MAC_INDEX
36357c2590fSTetsuo Handa };
36457c2590fSTetsuo Handa 
365b5bc60b4STetsuo Handa /* Index numbers for category of functionality. */
36657c2590fSTetsuo Handa enum tomoyo_mac_category_index {
36757c2590fSTetsuo Handa 	TOMOYO_MAC_CATEGORY_FILE,
368059d84dbSTetsuo Handa 	TOMOYO_MAC_CATEGORY_NETWORK,
369d58e0da8STetsuo Handa 	TOMOYO_MAC_CATEGORY_MISC,
37057c2590fSTetsuo Handa 	TOMOYO_MAX_MAC_CATEGORY_INDEX
37157c2590fSTetsuo Handa };
37257c2590fSTetsuo Handa 
373b5bc60b4STetsuo Handa /*
374b5bc60b4STetsuo Handa  * Retry this request. Returned by tomoyo_supervisor() if policy violation has
375b5bc60b4STetsuo Handa  * occurred in enforcing mode and the userspace daemon decided to retry.
376b5bc60b4STetsuo Handa  *
377b5bc60b4STetsuo Handa  * We must choose a positive value in order to distinguish "granted" (which is
378b5bc60b4STetsuo Handa  * 0) and "rejected" (which is a negative value) and "retry".
379b5bc60b4STetsuo Handa  */
380b5bc60b4STetsuo Handa #define TOMOYO_RETRY_REQUEST 1
38117fcfbd9STetsuo Handa 
382b22b8b9fSTetsuo Handa /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
383b22b8b9fSTetsuo Handa enum tomoyo_policy_stat_type {
384b22b8b9fSTetsuo Handa 	/* Do not change this order. */
385b22b8b9fSTetsuo Handa 	TOMOYO_STAT_POLICY_UPDATES,
386b22b8b9fSTetsuo Handa 	TOMOYO_STAT_POLICY_LEARNING,   /* == TOMOYO_CONFIG_LEARNING */
387b22b8b9fSTetsuo Handa 	TOMOYO_STAT_POLICY_PERMISSIVE, /* == TOMOYO_CONFIG_PERMISSIVE */
388b22b8b9fSTetsuo Handa 	TOMOYO_STAT_POLICY_ENFORCING,  /* == TOMOYO_CONFIG_ENFORCING */
389b22b8b9fSTetsuo Handa 	TOMOYO_MAX_POLICY_STAT
390b22b8b9fSTetsuo Handa };
391b22b8b9fSTetsuo Handa 
392d5ca1725STetsuo Handa /* Index numbers for profile's PREFERENCE values. */
393d5ca1725STetsuo Handa enum tomoyo_pref_index {
394eadd99ccSTetsuo Handa 	TOMOYO_PREF_MAX_AUDIT_LOG,
395d5ca1725STetsuo Handa 	TOMOYO_PREF_MAX_LEARNING_ENTRY,
396d5ca1725STetsuo Handa 	TOMOYO_MAX_PREF
397d5ca1725STetsuo Handa };
398d5ca1725STetsuo Handa 
39976bb0895STetsuo Handa /********** Structure definitions. **********/
4009590837bSKentaro Takeda 
401b5bc60b4STetsuo Handa /* Common header for holding ACL entries. */
40282e0f001STetsuo Handa struct tomoyo_acl_head {
40382e0f001STetsuo Handa 	struct list_head list;
404f9732ea1STetsuo Handa 	s8 is_deleted; /* true or false or TOMOYO_GC_IN_PROGRESS */
40582e0f001STetsuo Handa } __packed;
40682e0f001STetsuo Handa 
4070df7e8b8STetsuo Handa /* Common header for shared entries. */
4080df7e8b8STetsuo Handa struct tomoyo_shared_acl_head {
4090df7e8b8STetsuo Handa 	struct list_head list;
4100df7e8b8STetsuo Handa 	atomic_t users;
4110df7e8b8STetsuo Handa } __packed;
4120df7e8b8STetsuo Handa 
413bd03a3e4STetsuo Handa struct tomoyo_policy_namespace;
414bd03a3e4STetsuo Handa 
415b5bc60b4STetsuo Handa /* Structure for request info. */
416cb0abe6aSTetsuo Handa struct tomoyo_request_info {
4178761afd4STetsuo Handa 	/*
4188761afd4STetsuo Handa 	 * For holding parameters specific to operations which deal files.
4198761afd4STetsuo Handa 	 * NULL if not dealing files.
4208761afd4STetsuo Handa 	 */
4218761afd4STetsuo Handa 	struct tomoyo_obj_info *obj;
4222ca9bf45STetsuo Handa 	/*
4232ca9bf45STetsuo Handa 	 * For holding parameters specific to execve() request.
4242ca9bf45STetsuo Handa 	 * NULL if not dealing do_execve().
4252ca9bf45STetsuo Handa 	 */
4262ca9bf45STetsuo Handa 	struct tomoyo_execve *ee;
427cb0abe6aSTetsuo Handa 	struct tomoyo_domain_info *domain;
428cf6e9a64STetsuo Handa 	/* For holding parameters. */
429cf6e9a64STetsuo Handa 	union {
430cf6e9a64STetsuo Handa 		struct {
431cf6e9a64STetsuo Handa 			const struct tomoyo_path_info *filename;
432484ca79cSTetsuo Handa 			/* For using wildcards at tomoyo_find_next_domain(). */
433484ca79cSTetsuo Handa 			const struct tomoyo_path_info *matched_path;
434b5bc60b4STetsuo Handa 			/* One of values in "enum tomoyo_path_acl_index". */
435cf6e9a64STetsuo Handa 			u8 operation;
436cf6e9a64STetsuo Handa 		} path;
437cf6e9a64STetsuo Handa 		struct {
438cf6e9a64STetsuo Handa 			const struct tomoyo_path_info *filename1;
439cf6e9a64STetsuo Handa 			const struct tomoyo_path_info *filename2;
440b5bc60b4STetsuo Handa 			/* One of values in "enum tomoyo_path2_acl_index". */
441cf6e9a64STetsuo Handa 			u8 operation;
442cf6e9a64STetsuo Handa 		} path2;
443cf6e9a64STetsuo Handa 		struct {
444cf6e9a64STetsuo Handa 			const struct tomoyo_path_info *filename;
445cf6e9a64STetsuo Handa 			unsigned int mode;
446cf6e9a64STetsuo Handa 			unsigned int major;
447cf6e9a64STetsuo Handa 			unsigned int minor;
448b5bc60b4STetsuo Handa 			/* One of values in "enum tomoyo_mkdev_acl_index". */
449cf6e9a64STetsuo Handa 			u8 operation;
450cf6e9a64STetsuo Handa 		} mkdev;
451cf6e9a64STetsuo Handa 		struct {
452cf6e9a64STetsuo Handa 			const struct tomoyo_path_info *filename;
453cf6e9a64STetsuo Handa 			unsigned long number;
454b5bc60b4STetsuo Handa 			/*
455b5bc60b4STetsuo Handa 			 * One of values in
456b5bc60b4STetsuo Handa 			 * "enum tomoyo_path_number_acl_index".
457b5bc60b4STetsuo Handa 			 */
458cf6e9a64STetsuo Handa 			u8 operation;
459cf6e9a64STetsuo Handa 		} path_number;
460cf6e9a64STetsuo Handa 		struct {
461d58e0da8STetsuo Handa 			const struct tomoyo_path_info *name;
462d58e0da8STetsuo Handa 		} environ;
463d58e0da8STetsuo Handa 		struct {
464059d84dbSTetsuo Handa 			const __be32 *address;
465059d84dbSTetsuo Handa 			u16 port;
466059d84dbSTetsuo Handa 			/* One of values smaller than TOMOYO_SOCK_MAX. */
467059d84dbSTetsuo Handa 			u8 protocol;
468059d84dbSTetsuo Handa 			/* One of values in "enum tomoyo_network_acl_index". */
469059d84dbSTetsuo Handa 			u8 operation;
470059d84dbSTetsuo Handa 			bool is_ipv6;
471059d84dbSTetsuo Handa 		} inet_network;
472059d84dbSTetsuo Handa 		struct {
473059d84dbSTetsuo Handa 			const struct tomoyo_path_info *address;
474059d84dbSTetsuo Handa 			/* One of values smaller than TOMOYO_SOCK_MAX. */
475059d84dbSTetsuo Handa 			u8 protocol;
476059d84dbSTetsuo Handa 			/* One of values in "enum tomoyo_network_acl_index". */
477059d84dbSTetsuo Handa 			u8 operation;
478059d84dbSTetsuo Handa 		} unix_network;
479059d84dbSTetsuo Handa 		struct {
480cf6e9a64STetsuo Handa 			const struct tomoyo_path_info *type;
481cf6e9a64STetsuo Handa 			const struct tomoyo_path_info *dir;
482cf6e9a64STetsuo Handa 			const struct tomoyo_path_info *dev;
483cf6e9a64STetsuo Handa 			unsigned long flags;
484cf6e9a64STetsuo Handa 			int need_dev;
485cf6e9a64STetsuo Handa 		} mount;
486731d37aaSTetsuo Handa 		struct {
487731d37aaSTetsuo Handa 			const struct tomoyo_path_info *domainname;
488731d37aaSTetsuo Handa 		} task;
489cf6e9a64STetsuo Handa 	} param;
4901f067a68STetsuo Handa 	struct tomoyo_acl_info *matched_acl;
491cf6e9a64STetsuo Handa 	u8 param_type;
492cf6e9a64STetsuo Handa 	bool granted;
49317fcfbd9STetsuo Handa 	u8 retry;
49417fcfbd9STetsuo Handa 	u8 profile;
495cb0abe6aSTetsuo Handa 	u8 mode; /* One of tomoyo_mode_index . */
49657c2590fSTetsuo Handa 	u8 type;
497cb0abe6aSTetsuo Handa };
498cb0abe6aSTetsuo Handa 
499b5bc60b4STetsuo Handa /* Structure for holding a token. */
5009590837bSKentaro Takeda struct tomoyo_path_info {
5019590837bSKentaro Takeda 	const char *name;
5029590837bSKentaro Takeda 	u32 hash;          /* = full_name_hash(name, strlen(name)) */
5039590837bSKentaro Takeda 	u16 const_len;     /* = tomoyo_const_part_length(name)     */
5049590837bSKentaro Takeda 	bool is_dir;       /* = tomoyo_strendswith(name, "/")      */
5059590837bSKentaro Takeda 	bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
5069590837bSKentaro Takeda };
5079590837bSKentaro Takeda 
508b5bc60b4STetsuo Handa /* Structure for holding string data. */
509e2bf6907STetsuo Handa struct tomoyo_name {
5100df7e8b8STetsuo Handa 	struct tomoyo_shared_acl_head head;
51176bb0895STetsuo Handa 	struct tomoyo_path_info entry;
51276bb0895STetsuo Handa };
5139590837bSKentaro Takeda 
514b5bc60b4STetsuo Handa /* Structure for holding a word. */
5157762fbffSTetsuo Handa struct tomoyo_name_union {
516b5bc60b4STetsuo Handa 	/* Either @filename or @group is NULL. */
5177762fbffSTetsuo Handa 	const struct tomoyo_path_info *filename;
518a98aa4deSTetsuo Handa 	struct tomoyo_group *group;
5197762fbffSTetsuo Handa };
5207762fbffSTetsuo Handa 
521b5bc60b4STetsuo Handa /* Structure for holding a number. */
5224c3e9e2dSTetsuo Handa struct tomoyo_number_union {
5234c3e9e2dSTetsuo Handa 	unsigned long values[2];
524b5bc60b4STetsuo Handa 	struct tomoyo_group *group; /* Maybe NULL. */
525b5bc60b4STetsuo Handa 	/* One of values in "enum tomoyo_value_type". */
5260df7e8b8STetsuo Handa 	u8 value_type[2];
5274c3e9e2dSTetsuo Handa };
5284c3e9e2dSTetsuo Handa 
529059d84dbSTetsuo Handa /* Structure for holding an IP address. */
530059d84dbSTetsuo Handa struct tomoyo_ipaddr_union {
531059d84dbSTetsuo Handa 	struct in6_addr ip[2]; /* Big endian. */
532059d84dbSTetsuo Handa 	struct tomoyo_group *group; /* Pointer to address group. */
533059d84dbSTetsuo Handa 	bool is_ipv6; /* Valid only if @group == NULL. */
534059d84dbSTetsuo Handa };
535059d84dbSTetsuo Handa 
536059d84dbSTetsuo Handa /* Structure for "path_group"/"number_group"/"address_group" directive. */
537a98aa4deSTetsuo Handa struct tomoyo_group {
5380df7e8b8STetsuo Handa 	struct tomoyo_shared_acl_head head;
539a98aa4deSTetsuo Handa 	const struct tomoyo_path_info *group_name;
540a98aa4deSTetsuo Handa 	struct list_head member_list;
541a98aa4deSTetsuo Handa };
542a98aa4deSTetsuo Handa 
5437762fbffSTetsuo Handa /* Structure for "path_group" directive. */
5447762fbffSTetsuo Handa struct tomoyo_path_group {
54582e0f001STetsuo Handa 	struct tomoyo_acl_head head;
5467762fbffSTetsuo Handa 	const struct tomoyo_path_info *member_name;
5477762fbffSTetsuo Handa };
5487762fbffSTetsuo Handa 
5494c3e9e2dSTetsuo Handa /* Structure for "number_group" directive. */
550a98aa4deSTetsuo Handa struct tomoyo_number_group {
55182e0f001STetsuo Handa 	struct tomoyo_acl_head head;
5524c3e9e2dSTetsuo Handa 	struct tomoyo_number_union number;
5534c3e9e2dSTetsuo Handa };
5544c3e9e2dSTetsuo Handa 
555059d84dbSTetsuo Handa /* Structure for "address_group" directive. */
556059d84dbSTetsuo Handa struct tomoyo_address_group {
557059d84dbSTetsuo Handa 	struct tomoyo_acl_head head;
558059d84dbSTetsuo Handa 	/* Structure for holding an IP address. */
559059d84dbSTetsuo Handa 	struct tomoyo_ipaddr_union address;
560059d84dbSTetsuo Handa };
561059d84dbSTetsuo Handa 
5628761afd4STetsuo Handa /* Subset of "struct stat". Used by conditional ACL and audit logs. */
5638761afd4STetsuo Handa struct tomoyo_mini_stat {
564609fcd1bSEric W. Biederman 	kuid_t uid;
565609fcd1bSEric W. Biederman 	kgid_t gid;
5668761afd4STetsuo Handa 	ino_t ino;
567d179333fSAl Viro 	umode_t mode;
5688761afd4STetsuo Handa 	dev_t dev;
5698761afd4STetsuo Handa 	dev_t rdev;
5708761afd4STetsuo Handa };
5718761afd4STetsuo Handa 
5725b636857STetsuo Handa /* Structure for dumping argv[] and envp[] of "struct linux_binprm". */
5735b636857STetsuo Handa struct tomoyo_page_dump {
5745b636857STetsuo Handa 	struct page *page;    /* Previously dumped page. */
5755b636857STetsuo Handa 	char *data;           /* Contents of "page". Size is PAGE_SIZE. */
5765b636857STetsuo Handa };
5775b636857STetsuo Handa 
5788761afd4STetsuo Handa /* Structure for attribute checks in addition to pathname checks. */
5798761afd4STetsuo Handa struct tomoyo_obj_info {
5808761afd4STetsuo Handa 	/*
5818761afd4STetsuo Handa 	 * True if tomoyo_get_attributes() was already called, false otherwise.
5828761afd4STetsuo Handa 	 */
5838761afd4STetsuo Handa 	bool validate_done;
5848761afd4STetsuo Handa 	/* True if @stat[] is valid. */
5858761afd4STetsuo Handa 	bool stat_valid[TOMOYO_MAX_PATH_STAT];
5868761afd4STetsuo Handa 	/* First pathname. Initialized with { NULL, NULL } if no path. */
5878761afd4STetsuo Handa 	struct path path1;
5888761afd4STetsuo Handa 	/* Second pathname. Initialized with { NULL, NULL } if no path. */
5898761afd4STetsuo Handa 	struct path path2;
5908761afd4STetsuo Handa 	/*
5918761afd4STetsuo Handa 	 * Information on @path1, @path1's parent directory, @path2, @path2's
5928761afd4STetsuo Handa 	 * parent directory.
5938761afd4STetsuo Handa 	 */
5948761afd4STetsuo Handa 	struct tomoyo_mini_stat stat[TOMOYO_MAX_PATH_STAT];
5952ca9bf45STetsuo Handa 	/*
5962ca9bf45STetsuo Handa 	 * Content of symbolic link to be created. NULL for operations other
5972ca9bf45STetsuo Handa 	 * than symlink().
5982ca9bf45STetsuo Handa 	 */
5992ca9bf45STetsuo Handa 	struct tomoyo_path_info *symlink_target;
6002ca9bf45STetsuo Handa };
6012ca9bf45STetsuo Handa 
6025b636857STetsuo Handa /* Structure for argv[]. */
6035b636857STetsuo Handa struct tomoyo_argv {
6045b636857STetsuo Handa 	unsigned long index;
6055b636857STetsuo Handa 	const struct tomoyo_path_info *value;
6065b636857STetsuo Handa 	bool is_not;
6075b636857STetsuo Handa };
6085b636857STetsuo Handa 
6095b636857STetsuo Handa /* Structure for envp[]. */
6105b636857STetsuo Handa struct tomoyo_envp {
6115b636857STetsuo Handa 	const struct tomoyo_path_info *name;
6125b636857STetsuo Handa 	const struct tomoyo_path_info *value;
6135b636857STetsuo Handa 	bool is_not;
6145b636857STetsuo Handa };
6155b636857STetsuo Handa 
6162ca9bf45STetsuo Handa /* Structure for execve() operation. */
6172ca9bf45STetsuo Handa struct tomoyo_execve {
6182ca9bf45STetsuo Handa 	struct tomoyo_request_info r;
6192ca9bf45STetsuo Handa 	struct tomoyo_obj_info obj;
6202ca9bf45STetsuo Handa 	struct linux_binprm *bprm;
6216bce98edSTetsuo Handa 	const struct tomoyo_path_info *transition;
6225b636857STetsuo Handa 	/* For dumping argv[] and envp[]. */
6235b636857STetsuo Handa 	struct tomoyo_page_dump dump;
6242ca9bf45STetsuo Handa 	/* For temporary use. */
6252ca9bf45STetsuo Handa 	char *tmp; /* Size is TOMOYO_EXEC_TMPSIZE bytes */
6268761afd4STetsuo Handa };
6278761afd4STetsuo Handa 
6282066a361STetsuo Handa /* Structure for entries which follows "struct tomoyo_condition". */
6292066a361STetsuo Handa struct tomoyo_condition_element {
6305b636857STetsuo Handa 	/*
6315b636857STetsuo Handa 	 * Left hand operand. A "struct tomoyo_argv" for TOMOYO_ARGV_ENTRY, a
6325b636857STetsuo Handa 	 * "struct tomoyo_envp" for TOMOYO_ENVP_ENTRY is attached to the tail
6335b636857STetsuo Handa 	 * of the array of this struct.
6345b636857STetsuo Handa 	 */
6352066a361STetsuo Handa 	u8 left;
6365b636857STetsuo Handa 	/*
6375b636857STetsuo Handa 	 * Right hand operand. A "struct tomoyo_number_union" for
6385b636857STetsuo Handa 	 * TOMOYO_NUMBER_UNION, a "struct tomoyo_name_union" for
6395b636857STetsuo Handa 	 * TOMOYO_NAME_UNION is attached to the tail of the array of this
6405b636857STetsuo Handa 	 * struct.
6415b636857STetsuo Handa 	 */
6422066a361STetsuo Handa 	u8 right;
6432066a361STetsuo Handa 	/* Equation operator. True if equals or overlaps, false otherwise. */
6442066a361STetsuo Handa 	bool equals;
6452066a361STetsuo Handa };
6462066a361STetsuo Handa 
6472066a361STetsuo Handa /* Structure for optional arguments. */
6482066a361STetsuo Handa struct tomoyo_condition {
6492066a361STetsuo Handa 	struct tomoyo_shared_acl_head head;
6502066a361STetsuo Handa 	u32 size; /* Memory size allocated for this entry. */
6512066a361STetsuo Handa 	u16 condc; /* Number of conditions in this struct. */
6522066a361STetsuo Handa 	u16 numbers_count; /* Number of "struct tomoyo_number_union values". */
6532ca9bf45STetsuo Handa 	u16 names_count; /* Number of "struct tomoyo_name_union names". */
6545b636857STetsuo Handa 	u16 argc; /* Number of "struct tomoyo_argv". */
6555b636857STetsuo Handa 	u16 envc; /* Number of "struct tomoyo_envp". */
6561f067a68STetsuo Handa 	u8 grant_log; /* One of values in "enum tomoyo_grant_log". */
6576bce98edSTetsuo Handa 	const struct tomoyo_path_info *transit; /* Maybe NULL. */
6582066a361STetsuo Handa 	/*
6592066a361STetsuo Handa 	 * struct tomoyo_condition_element condition[condc];
6602066a361STetsuo Handa 	 * struct tomoyo_number_union values[numbers_count];
6612ca9bf45STetsuo Handa 	 * struct tomoyo_name_union names[names_count];
6625b636857STetsuo Handa 	 * struct tomoyo_argv argv[argc];
6635b636857STetsuo Handa 	 * struct tomoyo_envp envp[envc];
6642066a361STetsuo Handa 	 */
6652066a361STetsuo Handa };
6662066a361STetsuo Handa 
667b5bc60b4STetsuo Handa /* Common header for individual entries. */
6689590837bSKentaro Takeda struct tomoyo_acl_info {
6699590837bSKentaro Takeda 	struct list_head list;
6702066a361STetsuo Handa 	struct tomoyo_condition *cond; /* Maybe NULL. */
671f9732ea1STetsuo Handa 	s8 is_deleted; /* true or false or TOMOYO_GC_IN_PROGRESS */
672b5bc60b4STetsuo Handa 	u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
6739590837bSKentaro Takeda } __packed;
6749590837bSKentaro Takeda 
675b5bc60b4STetsuo Handa /* Structure for domain information. */
6769590837bSKentaro Takeda struct tomoyo_domain_info {
6779590837bSKentaro Takeda 	struct list_head list;
6789590837bSKentaro Takeda 	struct list_head acl_info_list;
6799590837bSKentaro Takeda 	/* Name of this domain. Never NULL.          */
6809590837bSKentaro Takeda 	const struct tomoyo_path_info *domainname;
681bd03a3e4STetsuo Handa 	/* Namespace for this domain. Never NULL. */
682bd03a3e4STetsuo Handa 	struct tomoyo_policy_namespace *ns;
6839590837bSKentaro Takeda 	u8 profile;        /* Profile number to use. */
68432997144STetsuo Handa 	u8 group;          /* Group number to use.   */
685a0558fc3STetsuo Handa 	bool is_deleted;   /* Delete flag.           */
6862c47ab93STetsuo Handa 	bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
687ec8e6a4eSTetsuo Handa 	atomic_t users; /* Number of referring credentials. */
6889590837bSKentaro Takeda };
6899590837bSKentaro Takeda 
6909590837bSKentaro Takeda /*
691731d37aaSTetsuo Handa  * Structure for "task manual_domain_transition" directive.
692731d37aaSTetsuo Handa  */
693731d37aaSTetsuo Handa struct tomoyo_task_acl {
694731d37aaSTetsuo Handa 	struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MANUAL_TASK_ACL */
695731d37aaSTetsuo Handa 	/* Pointer to domainname. */
696731d37aaSTetsuo Handa 	const struct tomoyo_path_info *domainname;
697731d37aaSTetsuo Handa };
698731d37aaSTetsuo Handa 
699731d37aaSTetsuo Handa /*
700b5bc60b4STetsuo Handa  * Structure for "file execute", "file read", "file write", "file append",
701b5bc60b4STetsuo Handa  * "file unlink", "file getattr", "file rmdir", "file truncate",
702b5bc60b4STetsuo Handa  * "file symlink", "file chroot" and "file unmount" directive.
7039590837bSKentaro Takeda  */
7047ef61233STetsuo Handa struct tomoyo_path_acl {
7057ef61233STetsuo Handa 	struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
706b5bc60b4STetsuo Handa 	u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
7077762fbffSTetsuo Handa 	struct tomoyo_name_union name;
7089590837bSKentaro Takeda };
7099590837bSKentaro Takeda 
710c3fa109aSTetsuo Handa /*
711b5bc60b4STetsuo Handa  * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
712b5bc60b4STetsuo Handa  * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
713a1f9bb6aSTetsuo Handa  */
714a1f9bb6aSTetsuo Handa struct tomoyo_path_number_acl {
715a1f9bb6aSTetsuo Handa 	struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
716b5bc60b4STetsuo Handa 	/* Bitmask of values in "enum tomoyo_path_number_acl_index". */
717a1f9bb6aSTetsuo Handa 	u8 perm;
718a1f9bb6aSTetsuo Handa 	struct tomoyo_name_union name;
719a1f9bb6aSTetsuo Handa 	struct tomoyo_number_union number;
720a1f9bb6aSTetsuo Handa };
721a1f9bb6aSTetsuo Handa 
722b5bc60b4STetsuo Handa /* Structure for "file mkblock" and "file mkchar" directive. */
72375093152STetsuo Handa struct tomoyo_mkdev_acl {
72475093152STetsuo Handa 	struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
725b5bc60b4STetsuo Handa 	u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
726a1f9bb6aSTetsuo Handa 	struct tomoyo_name_union name;
727a1f9bb6aSTetsuo Handa 	struct tomoyo_number_union mode;
728a1f9bb6aSTetsuo Handa 	struct tomoyo_number_union major;
729a1f9bb6aSTetsuo Handa 	struct tomoyo_number_union minor;
730a1f9bb6aSTetsuo Handa };
731a1f9bb6aSTetsuo Handa 
732a1f9bb6aSTetsuo Handa /*
733b5bc60b4STetsuo Handa  * Structure for "file rename", "file link" and "file pivot_root" directive.
734c3fa109aSTetsuo Handa  */
7357ef61233STetsuo Handa struct tomoyo_path2_acl {
7367ef61233STetsuo Handa 	struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
737b5bc60b4STetsuo Handa 	u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
7387762fbffSTetsuo Handa 	struct tomoyo_name_union name1;
7397762fbffSTetsuo Handa 	struct tomoyo_name_union name2;
7409590837bSKentaro Takeda };
7419590837bSKentaro Takeda 
742b5bc60b4STetsuo Handa /* Structure for "file mount" directive. */
7432106ccd9STetsuo Handa struct tomoyo_mount_acl {
7442106ccd9STetsuo Handa 	struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
7452106ccd9STetsuo Handa 	struct tomoyo_name_union dev_name;
7462106ccd9STetsuo Handa 	struct tomoyo_name_union dir_name;
7472106ccd9STetsuo Handa 	struct tomoyo_name_union fs_type;
7482106ccd9STetsuo Handa 	struct tomoyo_number_union flags;
7492106ccd9STetsuo Handa };
7502106ccd9STetsuo Handa 
751d58e0da8STetsuo Handa /* Structure for "misc env" directive in domain policy. */
752d58e0da8STetsuo Handa struct tomoyo_env_acl {
753d58e0da8STetsuo Handa 	struct tomoyo_acl_info head;        /* type = TOMOYO_TYPE_ENV_ACL  */
754d58e0da8STetsuo Handa 	const struct tomoyo_path_info *env; /* environment variable */
755d58e0da8STetsuo Handa };
756d58e0da8STetsuo Handa 
757059d84dbSTetsuo Handa /* Structure for "network inet" directive. */
758059d84dbSTetsuo Handa struct tomoyo_inet_acl {
759059d84dbSTetsuo Handa 	struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_INET_ACL */
760059d84dbSTetsuo Handa 	u8 protocol;
761059d84dbSTetsuo Handa 	u8 perm; /* Bitmask of values in "enum tomoyo_network_acl_index" */
762059d84dbSTetsuo Handa 	struct tomoyo_ipaddr_union address;
763059d84dbSTetsuo Handa 	struct tomoyo_number_union port;
764059d84dbSTetsuo Handa };
765059d84dbSTetsuo Handa 
766059d84dbSTetsuo Handa /* Structure for "network unix" directive. */
767059d84dbSTetsuo Handa struct tomoyo_unix_acl {
768059d84dbSTetsuo Handa 	struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_UNIX_ACL */
769059d84dbSTetsuo Handa 	u8 protocol;
770059d84dbSTetsuo Handa 	u8 perm; /* Bitmask of values in "enum tomoyo_network_acl_index" */
771059d84dbSTetsuo Handa 	struct tomoyo_name_union name;
772059d84dbSTetsuo Handa };
773059d84dbSTetsuo Handa 
774a238cf5bSTetsuo Handa /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
775a238cf5bSTetsuo Handa struct tomoyo_acl_param {
776a238cf5bSTetsuo Handa 	char *data;
777a238cf5bSTetsuo Handa 	struct list_head *list;
778bd03a3e4STetsuo Handa 	struct tomoyo_policy_namespace *ns;
779a238cf5bSTetsuo Handa 	bool is_delete;
780a238cf5bSTetsuo Handa };
781a238cf5bSTetsuo Handa 
7820d2171d7STetsuo Handa #define TOMOYO_MAX_IO_READ_QUEUE 64
783f23571e8STetsuo Handa 
7842106ccd9STetsuo Handa /*
785f23571e8STetsuo Handa  * Structure for reading/writing policy via /sys/kernel/security/tomoyo
786f23571e8STetsuo Handa  * interfaces.
787c3fa109aSTetsuo Handa  */
7889590837bSKentaro Takeda struct tomoyo_io_buffer {
7898fbe71f0STetsuo Handa 	void (*read) (struct tomoyo_io_buffer *);
7909590837bSKentaro Takeda 	int (*write) (struct tomoyo_io_buffer *);
7916041e834STetsuo Handa 	unsigned int (*poll) (struct file *file, poll_table *wait);
7929590837bSKentaro Takeda 	/* Exclusive lock for this structure.   */
7939590837bSKentaro Takeda 	struct mutex io_sem;
794f23571e8STetsuo Handa 	char __user *read_user_buf;
7952c47ab93STetsuo Handa 	size_t read_user_buf_avail;
796f23571e8STetsuo Handa 	struct {
797bd03a3e4STetsuo Handa 		struct list_head *ns;
798f23571e8STetsuo Handa 		struct list_head *domain;
799f23571e8STetsuo Handa 		struct list_head *group;
800f23571e8STetsuo Handa 		struct list_head *acl;
8012c47ab93STetsuo Handa 		size_t avail;
8022c47ab93STetsuo Handa 		unsigned int step;
8032c47ab93STetsuo Handa 		unsigned int query_index;
804f23571e8STetsuo Handa 		u16 index;
8052066a361STetsuo Handa 		u16 cond_index;
80632997144STetsuo Handa 		u8 acl_group_index;
8072066a361STetsuo Handa 		u8 cond_step;
808f23571e8STetsuo Handa 		u8 bit;
809f23571e8STetsuo Handa 		u8 w_pos;
810f23571e8STetsuo Handa 		bool eof;
811f23571e8STetsuo Handa 		bool print_this_domain_only;
812bd03a3e4STetsuo Handa 		bool print_transition_related_only;
8132066a361STetsuo Handa 		bool print_cond_part;
814f23571e8STetsuo Handa 		const char *w[TOMOYO_MAX_IO_READ_QUEUE];
815f23571e8STetsuo Handa 	} r;
8160df7e8b8STetsuo Handa 	struct {
817bd03a3e4STetsuo Handa 		struct tomoyo_policy_namespace *ns;
8189590837bSKentaro Takeda 		/* The position currently writing to.   */
8190df7e8b8STetsuo Handa 		struct tomoyo_domain_info *domain;
8200df7e8b8STetsuo Handa 		/* Bytes available for writing.         */
8212c47ab93STetsuo Handa 		size_t avail;
822bd03a3e4STetsuo Handa 		bool is_delete;
8230df7e8b8STetsuo Handa 	} w;
8249590837bSKentaro Takeda 	/* Buffer for reading.                  */
8259590837bSKentaro Takeda 	char *read_buf;
8269590837bSKentaro Takeda 	/* Size of read buffer.                 */
8272c47ab93STetsuo Handa 	size_t readbuf_size;
8289590837bSKentaro Takeda 	/* Buffer for writing.                  */
8299590837bSKentaro Takeda 	char *write_buf;
8309590837bSKentaro Takeda 	/* Size of write buffer.                */
8312c47ab93STetsuo Handa 	size_t writebuf_size;
83217fcfbd9STetsuo Handa 	/* Type of this interface.              */
8332c47ab93STetsuo Handa 	enum tomoyo_securityfs_interface_index type;
8342e503bbbSTetsuo Handa 	/* Users counter protected by tomoyo_io_buffer_list_lock. */
8352e503bbbSTetsuo Handa 	u8 users;
8362e503bbbSTetsuo Handa 	/* List for telling GC not to kfree() elements. */
8372e503bbbSTetsuo Handa 	struct list_head list;
8389590837bSKentaro Takeda };
8399590837bSKentaro Takeda 
84076bb0895STetsuo Handa /*
841b5bc60b4STetsuo Handa  * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
842b5bc60b4STetsuo Handa  * "no_keep_domain" keyword.
84376bb0895STetsuo Handa  */
8445448ec4fSTetsuo Handa struct tomoyo_transition_control {
84582e0f001STetsuo Handa 	struct tomoyo_acl_head head;
8465448ec4fSTetsuo Handa 	u8 type; /* One of values in "enum tomoyo_transition_type".  */
84776bb0895STetsuo Handa 	/* True if the domainname is tomoyo_get_last_name(). */
84876bb0895STetsuo Handa 	bool is_last_name;
8495448ec4fSTetsuo Handa 	const struct tomoyo_path_info *domainname; /* Maybe NULL */
8505448ec4fSTetsuo Handa 	const struct tomoyo_path_info *program;    /* Maybe NULL */
85176bb0895STetsuo Handa };
85276bb0895STetsuo Handa 
853b5bc60b4STetsuo Handa /* Structure for "aggregator" keyword. */
854e2bf6907STetsuo Handa struct tomoyo_aggregator {
85582e0f001STetsuo Handa 	struct tomoyo_acl_head head;
8561084307cSTetsuo Handa 	const struct tomoyo_path_info *original_name;
8571084307cSTetsuo Handa 	const struct tomoyo_path_info *aggregated_name;
8581084307cSTetsuo Handa };
8591084307cSTetsuo Handa 
860b5bc60b4STetsuo Handa /* Structure for policy manager. */
861e2bf6907STetsuo Handa struct tomoyo_manager {
86282e0f001STetsuo Handa 	struct tomoyo_acl_head head;
86376bb0895STetsuo Handa 	/* A path to program or a domainname. */
86476bb0895STetsuo Handa 	const struct tomoyo_path_info *manager;
86576bb0895STetsuo Handa };
86676bb0895STetsuo Handa 
86757c2590fSTetsuo Handa struct tomoyo_preference {
86857c2590fSTetsuo Handa 	unsigned int learning_max_entry;
86957c2590fSTetsuo Handa 	bool enforcing_verbose;
87057c2590fSTetsuo Handa 	bool learning_verbose;
87157c2590fSTetsuo Handa 	bool permissive_verbose;
87257c2590fSTetsuo Handa };
87357c2590fSTetsuo Handa 
874b5bc60b4STetsuo Handa /* Structure for /sys/kernel/security/tomnoyo/profile interface. */
87557c2590fSTetsuo Handa struct tomoyo_profile {
87657c2590fSTetsuo Handa 	const struct tomoyo_path_info *comment;
87757c2590fSTetsuo Handa 	struct tomoyo_preference *learning;
87857c2590fSTetsuo Handa 	struct tomoyo_preference *permissive;
87957c2590fSTetsuo Handa 	struct tomoyo_preference *enforcing;
88057c2590fSTetsuo Handa 	struct tomoyo_preference preference;
88157c2590fSTetsuo Handa 	u8 default_config;
88257c2590fSTetsuo Handa 	u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
883d5ca1725STetsuo Handa 	unsigned int pref[TOMOYO_MAX_PREF];
88457c2590fSTetsuo Handa };
88557c2590fSTetsuo Handa 
886eadd99ccSTetsuo Handa /* Structure for representing YYYY/MM/DD hh/mm/ss. */
887eadd99ccSTetsuo Handa struct tomoyo_time {
888eadd99ccSTetsuo Handa 	u16 year;
889eadd99ccSTetsuo Handa 	u8 month;
890eadd99ccSTetsuo Handa 	u8 day;
891eadd99ccSTetsuo Handa 	u8 hour;
892eadd99ccSTetsuo Handa 	u8 min;
893eadd99ccSTetsuo Handa 	u8 sec;
894eadd99ccSTetsuo Handa };
895eadd99ccSTetsuo Handa 
896bd03a3e4STetsuo Handa /* Structure for policy namespace. */
897bd03a3e4STetsuo Handa struct tomoyo_policy_namespace {
898bd03a3e4STetsuo Handa 	/* Profile table. Memory is allocated as needed. */
899bd03a3e4STetsuo Handa 	struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES];
900bd03a3e4STetsuo Handa 	/* List of "struct tomoyo_group". */
901bd03a3e4STetsuo Handa 	struct list_head group_list[TOMOYO_MAX_GROUP];
902bd03a3e4STetsuo Handa 	/* List of policy. */
903bd03a3e4STetsuo Handa 	struct list_head policy_list[TOMOYO_MAX_POLICY];
904bd03a3e4STetsuo Handa 	/* The global ACL referred by "use_group" keyword. */
905bd03a3e4STetsuo Handa 	struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS];
906bd03a3e4STetsuo Handa 	/* List for connecting to tomoyo_namespace_list list. */
907bd03a3e4STetsuo Handa 	struct list_head namespace_list;
908843d183cSTetsuo Handa 	/* Profile version. Currently only 20110903 is defined. */
909bd03a3e4STetsuo Handa 	unsigned int profile_version;
910bd03a3e4STetsuo Handa 	/* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
911bd03a3e4STetsuo Handa 	const char *name;
912bd03a3e4STetsuo Handa };
913bd03a3e4STetsuo Handa 
91476bb0895STetsuo Handa /********** Function prototypes. **********/
91576bb0895STetsuo Handa 
916059d84dbSTetsuo Handa bool tomoyo_address_matches_group(const bool is_ipv6, const __be32 *address,
917059d84dbSTetsuo Handa 				  const struct tomoyo_group *group);
9182106ccd9STetsuo Handa bool tomoyo_compare_number_union(const unsigned long value,
9192106ccd9STetsuo Handa 				 const struct tomoyo_number_union *ptr);
9202066a361STetsuo Handa bool tomoyo_condition(struct tomoyo_request_info *r,
9212066a361STetsuo Handa 		      const struct tomoyo_condition *cond);
92275093152STetsuo Handa bool tomoyo_correct_domain(const unsigned char *domainname);
92375093152STetsuo Handa bool tomoyo_correct_path(const char *filename);
92475093152STetsuo Handa bool tomoyo_correct_word(const char *string);
92575093152STetsuo Handa bool tomoyo_domain_def(const unsigned char *buffer);
9263ddf17f0STetsuo Handa bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
9275b636857STetsuo Handa bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos,
9285b636857STetsuo Handa 		      struct tomoyo_page_dump *dump);
9293ddf17f0STetsuo Handa bool tomoyo_memory_ok(void *ptr);
9304c3e9e2dSTetsuo Handa bool tomoyo_number_matches_group(const unsigned long min,
9314c3e9e2dSTetsuo Handa 				 const unsigned long max,
932a98aa4deSTetsuo Handa 				 const struct tomoyo_group *group);
933059d84dbSTetsuo Handa bool tomoyo_parse_ipaddr_union(struct tomoyo_acl_param *param,
934059d84dbSTetsuo Handa 			       struct tomoyo_ipaddr_union *ptr);
9353ddf17f0STetsuo Handa bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
9363ddf17f0STetsuo Handa 			     struct tomoyo_name_union *ptr);
937a238cf5bSTetsuo Handa bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
938a238cf5bSTetsuo Handa 			       struct tomoyo_number_union *ptr);
9393ddf17f0STetsuo Handa bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
9403ddf17f0STetsuo Handa 				 const struct tomoyo_path_info *pattern);
9413ddf17f0STetsuo Handa bool tomoyo_permstr(const char *string, const char *keyword);
9423ddf17f0STetsuo Handa bool tomoyo_str_starts(char **src, const char *find);
9433ddf17f0STetsuo Handa char *tomoyo_encode(const char *str);
944059d84dbSTetsuo Handa char *tomoyo_encode2(const char *str, int str_len);
9453ddf17f0STetsuo Handa char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
9463ddf17f0STetsuo Handa 		      va_list args);
9473ddf17f0STetsuo Handa char *tomoyo_read_token(struct tomoyo_acl_param *param);
9483ddf17f0STetsuo Handa char *tomoyo_realpath_from_path(struct path *path);
9493ddf17f0STetsuo Handa char *tomoyo_realpath_nofollow(const char *pathname);
9503ddf17f0STetsuo Handa const char *tomoyo_get_exe(void);
9513ddf17f0STetsuo Handa const char *tomoyo_yesno(const unsigned int value);
9523ddf17f0STetsuo Handa const struct tomoyo_path_info *tomoyo_compare_name_union
9533ddf17f0STetsuo Handa (const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr);
954731d37aaSTetsuo Handa const struct tomoyo_path_info *tomoyo_get_domainname
955731d37aaSTetsuo Handa (struct tomoyo_acl_param *param);
9563ddf17f0STetsuo Handa const struct tomoyo_path_info *tomoyo_get_name(const char *name);
9573ddf17f0STetsuo Handa const struct tomoyo_path_info *tomoyo_path_matches_group
9583ddf17f0STetsuo Handa (const struct tomoyo_path_info *pathname, const struct tomoyo_group *group);
9593ddf17f0STetsuo Handa int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
9603ddf17f0STetsuo Handa 				 struct path *path, const int flag);
9613ddf17f0STetsuo Handa int tomoyo_close_control(struct tomoyo_io_buffer *head);
962d58e0da8STetsuo Handa int tomoyo_env_perm(struct tomoyo_request_info *r, const char *env);
9636bce98edSTetsuo Handa int tomoyo_execute_permission(struct tomoyo_request_info *r,
9646bce98edSTetsuo Handa 			      const struct tomoyo_path_info *filename);
9653ddf17f0STetsuo Handa int tomoyo_find_next_domain(struct linux_binprm *bprm);
9663ddf17f0STetsuo Handa int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
9673ddf17f0STetsuo Handa 		    const u8 index);
9682106ccd9STetsuo Handa int tomoyo_init_request_info(struct tomoyo_request_info *r,
96957c2590fSTetsuo Handa 			     struct tomoyo_domain_info *domain,
97057c2590fSTetsuo Handa 			     const u8 index);
9713ddf17f0STetsuo Handa int tomoyo_mkdev_perm(const u8 operation, struct path *path,
9723ddf17f0STetsuo Handa 		      const unsigned int mode, unsigned int dev);
973b5bc60b4STetsuo Handa int tomoyo_mount_permission(char *dev_name, struct path *path,
974b5bc60b4STetsuo Handa 			    const char *type, unsigned long flags,
975b5bc60b4STetsuo Handa 			    void *data_page);
9763ddf17f0STetsuo Handa int tomoyo_open_control(const u8 type, struct file *file);
97797d6931eSTetsuo Handa int tomoyo_path2_perm(const u8 operation, struct path *path1,
97897d6931eSTetsuo Handa 		      struct path *path2);
9793ddf17f0STetsuo Handa int tomoyo_path_number_perm(const u8 operation, struct path *path,
9803ddf17f0STetsuo Handa 			    unsigned long number);
98197fb35e4STetsuo Handa int tomoyo_path_perm(const u8 operation, struct path *path,
98297fb35e4STetsuo Handa 		     const char *target);
9836041e834STetsuo Handa unsigned int tomoyo_poll_control(struct file *file, poll_table *wait);
9846041e834STetsuo Handa unsigned int tomoyo_poll_log(struct file *file, poll_table *wait);
985059d84dbSTetsuo Handa int tomoyo_socket_bind_permission(struct socket *sock, struct sockaddr *addr,
986059d84dbSTetsuo Handa 				  int addr_len);
987059d84dbSTetsuo Handa int tomoyo_socket_connect_permission(struct socket *sock,
988059d84dbSTetsuo Handa 				     struct sockaddr *addr, int addr_len);
989059d84dbSTetsuo Handa int tomoyo_socket_listen_permission(struct socket *sock);
990059d84dbSTetsuo Handa int tomoyo_socket_sendmsg_permission(struct socket *sock, struct msghdr *msg,
991059d84dbSTetsuo Handa 				     int size);
9923ddf17f0STetsuo Handa int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
9933ddf17f0STetsuo Handa 	__printf(2, 3);
994237ab459STetsuo Handa int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
995a238cf5bSTetsuo Handa 			 struct tomoyo_acl_param *param,
9963ddf17f0STetsuo Handa 			 bool (*check_duplicate)
9973ddf17f0STetsuo Handa 			 (const struct tomoyo_acl_info *,
9983ddf17f0STetsuo Handa 			  const struct tomoyo_acl_info *),
9993ddf17f0STetsuo Handa 			 bool (*merge_duplicate)
10003ddf17f0STetsuo Handa 			 (struct tomoyo_acl_info *, struct tomoyo_acl_info *,
1001237ab459STetsuo Handa 			  const bool));
100236f5e1ffSTetsuo Handa int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
1003a238cf5bSTetsuo Handa 			 struct tomoyo_acl_param *param,
10043ddf17f0STetsuo Handa 			 bool (*check_duplicate)
10053ddf17f0STetsuo Handa 			 (const struct tomoyo_acl_head *,
10063ddf17f0STetsuo Handa 			  const struct tomoyo_acl_head *));
10073ddf17f0STetsuo Handa int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
10083ddf17f0STetsuo Handa int tomoyo_write_file(struct tomoyo_acl_param *param);
10093ddf17f0STetsuo Handa int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
1010d58e0da8STetsuo Handa int tomoyo_write_misc(struct tomoyo_acl_param *param);
1011059d84dbSTetsuo Handa int tomoyo_write_inet_network(struct tomoyo_acl_param *param);
10123ddf17f0STetsuo Handa int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
10133ddf17f0STetsuo Handa 				    const u8 type);
1014059d84dbSTetsuo Handa int tomoyo_write_unix_network(struct tomoyo_acl_param *param);
10153ddf17f0STetsuo Handa ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
10163ddf17f0STetsuo Handa 			    const int buffer_len);
10173ddf17f0STetsuo Handa ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
10183ddf17f0STetsuo Handa 			     const char __user *buffer, const int buffer_len);
10192066a361STetsuo Handa struct tomoyo_condition *tomoyo_get_condition(struct tomoyo_acl_param *param);
10203ddf17f0STetsuo Handa struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
10213ddf17f0STetsuo Handa 						const bool transit);
10223ddf17f0STetsuo Handa struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
10233ddf17f0STetsuo Handa struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
10243ddf17f0STetsuo Handa 				      const u8 idx);
10253ddf17f0STetsuo Handa struct tomoyo_policy_namespace *tomoyo_assign_namespace
10263ddf17f0STetsuo Handa (const char *domainname);
10273ddf17f0STetsuo Handa struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
10283ddf17f0STetsuo Handa 				      const u8 profile);
10293ddf17f0STetsuo Handa unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
10303ddf17f0STetsuo Handa 				const u8 index);
10312066a361STetsuo Handa u8 tomoyo_parse_ulong(unsigned long *result, char **str);
10323ddf17f0STetsuo Handa void *tomoyo_commit_ok(void *data, const unsigned int size);
10333ddf17f0STetsuo Handa void __init tomoyo_load_builtin_policy(void);
10343ddf17f0STetsuo Handa void __init tomoyo_mm_init(void);
103599a85259STetsuo Handa void tomoyo_check_acl(struct tomoyo_request_info *r,
1036484ca79cSTetsuo Handa 		      bool (*check_entry) (struct tomoyo_request_info *,
103799a85259STetsuo Handa 					   const struct tomoyo_acl_info *));
10383ddf17f0STetsuo Handa void tomoyo_check_profile(void);
10393ddf17f0STetsuo Handa void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp);
10402066a361STetsuo Handa void tomoyo_del_condition(struct list_head *element);
10413ddf17f0STetsuo Handa void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
10428761afd4STetsuo Handa void tomoyo_get_attributes(struct tomoyo_obj_info *obj);
10433ddf17f0STetsuo Handa void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
10443ddf17f0STetsuo Handa void tomoyo_load_policy(const char *filename);
10453ddf17f0STetsuo Handa void tomoyo_normalize_line(unsigned char *buffer);
10463ddf17f0STetsuo Handa void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
1047059d84dbSTetsuo Handa void tomoyo_print_ip(char *buf, const unsigned int size,
1048059d84dbSTetsuo Handa 		     const struct tomoyo_ipaddr_union *ptr);
10493ddf17f0STetsuo Handa void tomoyo_print_ulong(char *buffer, const int buffer_len,
10503ddf17f0STetsuo Handa 			const unsigned long value, const u8 type);
10513ddf17f0STetsuo Handa void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
10523ddf17f0STetsuo Handa void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
1053eadd99ccSTetsuo Handa void tomoyo_read_log(struct tomoyo_io_buffer *head);
10543ddf17f0STetsuo Handa void tomoyo_update_stat(const u8 index);
10553ddf17f0STetsuo Handa void tomoyo_warn_oom(const char *function);
10563ddf17f0STetsuo Handa void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
10573ddf17f0STetsuo Handa 	__printf(2, 3);
10583ddf17f0STetsuo Handa void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
1059eadd99ccSTetsuo Handa 		       va_list args);
1060eadd99ccSTetsuo Handa 
106176bb0895STetsuo Handa /********** External variable definitions. **********/
106276bb0895STetsuo Handa 
106376bb0895STetsuo Handa extern bool tomoyo_policy_loaded;
10642066a361STetsuo Handa extern const char * const tomoyo_condition_keyword
10652066a361STetsuo Handa [TOMOYO_MAX_CONDITION_KEYWORD];
10663ddf17f0STetsuo Handa extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
10673ddf17f0STetsuo Handa extern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX
10683ddf17f0STetsuo Handa 					      + TOMOYO_MAX_MAC_CATEGORY_INDEX];
10693ddf17f0STetsuo Handa extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE];
10702c47ab93STetsuo Handa extern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
1071059d84dbSTetsuo Handa extern const char * const tomoyo_proto_keyword[TOMOYO_SOCK_MAX];
1072059d84dbSTetsuo Handa extern const char * const tomoyo_socket_keyword[TOMOYO_MAX_NETWORK_OPERATION];
10732c47ab93STetsuo Handa extern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX];
10743ddf17f0STetsuo Handa extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
10750d2171d7STetsuo Handa extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
10760d2171d7STetsuo Handa extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
10772066a361STetsuo Handa extern struct list_head tomoyo_condition_list;
10783ddf17f0STetsuo Handa extern struct list_head tomoyo_domain_list;
10793ddf17f0STetsuo Handa extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
10803ddf17f0STetsuo Handa extern struct list_head tomoyo_namespace_list;
10813ddf17f0STetsuo Handa extern struct mutex tomoyo_policy_lock;
10823ddf17f0STetsuo Handa extern struct srcu_struct tomoyo_ss;
10833ddf17f0STetsuo Handa extern struct tomoyo_domain_info tomoyo_kernel_domain;
10843ddf17f0STetsuo Handa extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
1085eadd99ccSTetsuo Handa extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
1086eadd99ccSTetsuo Handa extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
108717fcfbd9STetsuo Handa 
108876bb0895STetsuo Handa /********** Inlined functions. **********/
108976bb0895STetsuo Handa 
1090b5bc60b4STetsuo Handa /**
1091b5bc60b4STetsuo Handa  * tomoyo_read_lock - Take lock for protecting policy.
1092b5bc60b4STetsuo Handa  *
1093b5bc60b4STetsuo Handa  * Returns index number for tomoyo_read_unlock().
1094b5bc60b4STetsuo Handa  */
109576bb0895STetsuo Handa static inline int tomoyo_read_lock(void)
109676bb0895STetsuo Handa {
109776bb0895STetsuo Handa 	return srcu_read_lock(&tomoyo_ss);
109876bb0895STetsuo Handa }
109976bb0895STetsuo Handa 
1100b5bc60b4STetsuo Handa /**
1101b5bc60b4STetsuo Handa  * tomoyo_read_unlock - Release lock for protecting policy.
1102b5bc60b4STetsuo Handa  *
1103b5bc60b4STetsuo Handa  * @idx: Index number returned by tomoyo_read_lock().
1104b5bc60b4STetsuo Handa  *
1105b5bc60b4STetsuo Handa  * Returns nothing.
1106b5bc60b4STetsuo Handa  */
110776bb0895STetsuo Handa static inline void tomoyo_read_unlock(int idx)
110876bb0895STetsuo Handa {
110976bb0895STetsuo Handa 	srcu_read_unlock(&tomoyo_ss, idx);
111076bb0895STetsuo Handa }
111176bb0895STetsuo Handa 
1112b5bc60b4STetsuo Handa /**
11132066a361STetsuo Handa  * tomoyo_sys_getppid - Copy of getppid().
11142066a361STetsuo Handa  *
11152066a361STetsuo Handa  * Returns parent process's PID.
11162066a361STetsuo Handa  *
11172066a361STetsuo Handa  * Alpha does not have getppid() defined. To be able to build this module on
11182066a361STetsuo Handa  * Alpha, I have to copy getppid() from kernel/timer.c.
11192066a361STetsuo Handa  */
11202066a361STetsuo Handa static inline pid_t tomoyo_sys_getppid(void)
11212066a361STetsuo Handa {
11222066a361STetsuo Handa 	pid_t pid;
11232066a361STetsuo Handa 	rcu_read_lock();
1124bb80d880SKees Cook 	pid = task_tgid_vnr(rcu_dereference(current->real_parent));
11252066a361STetsuo Handa 	rcu_read_unlock();
11262066a361STetsuo Handa 	return pid;
11272066a361STetsuo Handa }
11282066a361STetsuo Handa 
11292066a361STetsuo Handa /**
11302066a361STetsuo Handa  * tomoyo_sys_getpid - Copy of getpid().
11312066a361STetsuo Handa  *
11322066a361STetsuo Handa  * Returns current thread's PID.
11332066a361STetsuo Handa  *
11342066a361STetsuo Handa  * Alpha does not have getpid() defined. To be able to build this module on
11352066a361STetsuo Handa  * Alpha, I have to copy getpid() from kernel/timer.c.
11362066a361STetsuo Handa  */
11372066a361STetsuo Handa static inline pid_t tomoyo_sys_getpid(void)
11382066a361STetsuo Handa {
11392066a361STetsuo Handa 	return task_tgid_vnr(current);
11402066a361STetsuo Handa }
11412066a361STetsuo Handa 
11422066a361STetsuo Handa /**
1143b5bc60b4STetsuo Handa  * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
1144b5bc60b4STetsuo Handa  *
1145b5bc60b4STetsuo Handa  * @a: Pointer to "struct tomoyo_path_info".
1146b5bc60b4STetsuo Handa  * @b: Pointer to "struct tomoyo_path_info".
1147b5bc60b4STetsuo Handa  *
1148b5bc60b4STetsuo Handa  * Returns true if @a == @b, false otherwise.
1149b5bc60b4STetsuo Handa  */
11509590837bSKentaro Takeda static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
11519590837bSKentaro Takeda 				  const struct tomoyo_path_info *b)
11529590837bSKentaro Takeda {
11539590837bSKentaro Takeda 	return a->hash != b->hash || strcmp(a->name, b->name);
11549590837bSKentaro Takeda }
11559590837bSKentaro Takeda 
11569590837bSKentaro Takeda /**
1157b5bc60b4STetsuo Handa  * tomoyo_put_name - Drop reference on "struct tomoyo_name".
1158b5bc60b4STetsuo Handa  *
1159b5bc60b4STetsuo Handa  * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
1160b5bc60b4STetsuo Handa  *
1161b5bc60b4STetsuo Handa  * Returns nothing.
1162b5bc60b4STetsuo Handa  */
116376bb0895STetsuo Handa static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
116476bb0895STetsuo Handa {
116576bb0895STetsuo Handa 	if (name) {
1166e2bf6907STetsuo Handa 		struct tomoyo_name *ptr =
1167e2bf6907STetsuo Handa 			container_of(name, typeof(*ptr), entry);
11680df7e8b8STetsuo Handa 		atomic_dec(&ptr->head.users);
116976bb0895STetsuo Handa 	}
117076bb0895STetsuo Handa }
11719590837bSKentaro Takeda 
1172b5bc60b4STetsuo Handa /**
11732066a361STetsuo Handa  * tomoyo_put_condition - Drop reference on "struct tomoyo_condition".
11742066a361STetsuo Handa  *
11752066a361STetsuo Handa  * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
11762066a361STetsuo Handa  *
11772066a361STetsuo Handa  * Returns nothing.
11782066a361STetsuo Handa  */
11792066a361STetsuo Handa static inline void tomoyo_put_condition(struct tomoyo_condition *cond)
11802066a361STetsuo Handa {
11812066a361STetsuo Handa 	if (cond)
11822066a361STetsuo Handa 		atomic_dec(&cond->head.users);
11832066a361STetsuo Handa }
11842066a361STetsuo Handa 
11852066a361STetsuo Handa /**
1186b5bc60b4STetsuo Handa  * tomoyo_put_group - Drop reference on "struct tomoyo_group".
1187b5bc60b4STetsuo Handa  *
1188b5bc60b4STetsuo Handa  * @group: Pointer to "struct tomoyo_group". Maybe NULL.
1189b5bc60b4STetsuo Handa  *
1190b5bc60b4STetsuo Handa  * Returns nothing.
1191b5bc60b4STetsuo Handa  */
1192a98aa4deSTetsuo Handa static inline void tomoyo_put_group(struct tomoyo_group *group)
11934c3e9e2dSTetsuo Handa {
11944c3e9e2dSTetsuo Handa 	if (group)
11950df7e8b8STetsuo Handa 		atomic_dec(&group->head.users);
11964c3e9e2dSTetsuo Handa }
11974c3e9e2dSTetsuo Handa 
1198b5bc60b4STetsuo Handa /**
1199b5bc60b4STetsuo Handa  * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
1200b5bc60b4STetsuo Handa  *
1201b5bc60b4STetsuo Handa  * Returns pointer to "struct tomoyo_domain_info" for current thread.
1202b5bc60b4STetsuo Handa  */
120376bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_domain(void)
120476bb0895STetsuo Handa {
120576bb0895STetsuo Handa 	return current_cred()->security;
120676bb0895STetsuo Handa }
12079590837bSKentaro Takeda 
1208b5bc60b4STetsuo Handa /**
1209b5bc60b4STetsuo Handa  * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
1210b5bc60b4STetsuo Handa  *
1211b5bc60b4STetsuo Handa  * @task: Pointer to "struct task_struct".
1212b5bc60b4STetsuo Handa  *
1213b5bc60b4STetsuo Handa  * Returns pointer to "struct tomoyo_security" for specified thread.
1214b5bc60b4STetsuo Handa  */
121576bb0895STetsuo Handa static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
121676bb0895STetsuo Handa 							    *task)
121776bb0895STetsuo Handa {
121876bb0895STetsuo Handa 	return task_cred_xxx(task, security);
121976bb0895STetsuo Handa }
12209590837bSKentaro Takeda 
1221b5bc60b4STetsuo Handa /**
1222b5bc60b4STetsuo Handa  * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
1223b5bc60b4STetsuo Handa  *
1224b5bc60b4STetsuo Handa  * @a: Pointer to "struct tomoyo_name_union".
1225b5bc60b4STetsuo Handa  * @b: Pointer to "struct tomoyo_name_union".
1226b5bc60b4STetsuo Handa  *
1227b5bc60b4STetsuo Handa  * Returns true if @a == @b, false otherwise.
1228b5bc60b4STetsuo Handa  */
122975093152STetsuo Handa static inline bool tomoyo_same_name_union
1230b5bc60b4STetsuo Handa (const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
12317762fbffSTetsuo Handa {
12320df7e8b8STetsuo Handa 	return a->filename == b->filename && a->group == b->group;
12337762fbffSTetsuo Handa }
12347762fbffSTetsuo Handa 
1235b5bc60b4STetsuo Handa /**
1236b5bc60b4STetsuo Handa  * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
1237b5bc60b4STetsuo Handa  *
1238b5bc60b4STetsuo Handa  * @a: Pointer to "struct tomoyo_number_union".
1239b5bc60b4STetsuo Handa  * @b: Pointer to "struct tomoyo_number_union".
1240b5bc60b4STetsuo Handa  *
1241b5bc60b4STetsuo Handa  * Returns true if @a == @b, false otherwise.
1242b5bc60b4STetsuo Handa  */
124375093152STetsuo Handa static inline bool tomoyo_same_number_union
1244b5bc60b4STetsuo Handa (const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
12454c3e9e2dSTetsuo Handa {
1246b5bc60b4STetsuo Handa 	return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
12470df7e8b8STetsuo Handa 		a->group == b->group && a->value_type[0] == b->value_type[0] &&
12480df7e8b8STetsuo Handa 		a->value_type[1] == b->value_type[1];
12494c3e9e2dSTetsuo Handa }
12504c3e9e2dSTetsuo Handa 
1251bd03a3e4STetsuo Handa /**
1252059d84dbSTetsuo Handa  * tomoyo_same_ipaddr_union - Check for duplicated "struct tomoyo_ipaddr_union" entry.
1253059d84dbSTetsuo Handa  *
1254059d84dbSTetsuo Handa  * @a: Pointer to "struct tomoyo_ipaddr_union".
1255059d84dbSTetsuo Handa  * @b: Pointer to "struct tomoyo_ipaddr_union".
1256059d84dbSTetsuo Handa  *
1257059d84dbSTetsuo Handa  * Returns true if @a == @b, false otherwise.
1258059d84dbSTetsuo Handa  */
1259059d84dbSTetsuo Handa static inline bool tomoyo_same_ipaddr_union
1260059d84dbSTetsuo Handa (const struct tomoyo_ipaddr_union *a, const struct tomoyo_ipaddr_union *b)
1261059d84dbSTetsuo Handa {
1262059d84dbSTetsuo Handa 	return !memcmp(a->ip, b->ip, sizeof(a->ip)) && a->group == b->group &&
1263059d84dbSTetsuo Handa 		a->is_ipv6 == b->is_ipv6;
1264059d84dbSTetsuo Handa }
1265059d84dbSTetsuo Handa 
1266059d84dbSTetsuo Handa /**
1267bd03a3e4STetsuo Handa  * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
1268bd03a3e4STetsuo Handa  *
1269bd03a3e4STetsuo Handa  * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
1270bd03a3e4STetsuo Handa  */
1271bd03a3e4STetsuo Handa static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void)
1272bd03a3e4STetsuo Handa {
1273bd03a3e4STetsuo Handa 	return tomoyo_domain()->ns;
1274bd03a3e4STetsuo Handa }
1275bd03a3e4STetsuo Handa 
1276eadd99ccSTetsuo Handa #if defined(CONFIG_SLOB)
1277eadd99ccSTetsuo Handa 
1278eadd99ccSTetsuo Handa /**
1279eadd99ccSTetsuo Handa  * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
1280eadd99ccSTetsuo Handa  *
1281eadd99ccSTetsuo Handa  * @size: Size to be rounded up.
1282eadd99ccSTetsuo Handa  *
1283eadd99ccSTetsuo Handa  * Returns @size.
1284eadd99ccSTetsuo Handa  *
1285eadd99ccSTetsuo Handa  * Since SLOB does not round up, this function simply returns @size.
1286eadd99ccSTetsuo Handa  */
1287eadd99ccSTetsuo Handa static inline int tomoyo_round2(size_t size)
1288eadd99ccSTetsuo Handa {
1289eadd99ccSTetsuo Handa 	return size;
1290eadd99ccSTetsuo Handa }
1291eadd99ccSTetsuo Handa 
1292eadd99ccSTetsuo Handa #else
1293eadd99ccSTetsuo Handa 
1294eadd99ccSTetsuo Handa /**
1295eadd99ccSTetsuo Handa  * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
1296eadd99ccSTetsuo Handa  *
1297eadd99ccSTetsuo Handa  * @size: Size to be rounded up.
1298eadd99ccSTetsuo Handa  *
1299eadd99ccSTetsuo Handa  * Returns rounded size.
1300eadd99ccSTetsuo Handa  *
1301eadd99ccSTetsuo Handa  * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
1302eadd99ccSTetsuo Handa  * (e.g.) 128 bytes.
1303eadd99ccSTetsuo Handa  */
1304eadd99ccSTetsuo Handa static inline int tomoyo_round2(size_t size)
1305eadd99ccSTetsuo Handa {
1306eadd99ccSTetsuo Handa #if PAGE_SIZE == 4096
1307eadd99ccSTetsuo Handa 	size_t bsize = 32;
1308eadd99ccSTetsuo Handa #else
1309eadd99ccSTetsuo Handa 	size_t bsize = 64;
1310eadd99ccSTetsuo Handa #endif
1311eadd99ccSTetsuo Handa 	if (!size)
1312eadd99ccSTetsuo Handa 		return 0;
1313eadd99ccSTetsuo Handa 	while (size > bsize)
1314eadd99ccSTetsuo Handa 		bsize <<= 1;
1315eadd99ccSTetsuo Handa 	return bsize;
1316eadd99ccSTetsuo Handa }
1317eadd99ccSTetsuo Handa 
1318eadd99ccSTetsuo Handa #endif
1319eadd99ccSTetsuo Handa 
13209590837bSKentaro Takeda /**
13219590837bSKentaro Takeda  * list_for_each_cookie - iterate over a list with cookie.
13229590837bSKentaro Takeda  * @pos:        the &struct list_head to use as a loop cursor.
13239590837bSKentaro Takeda  * @head:       the head for your list.
13249590837bSKentaro Takeda  */
1325475e6fa3STetsuo Handa #define list_for_each_cookie(pos, head)					\
1326475e6fa3STetsuo Handa 	if (!pos)							\
1327475e6fa3STetsuo Handa 		pos =  srcu_dereference((head)->next, &tomoyo_ss);	\
1328475e6fa3STetsuo Handa 	for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
1329fdb8ebb7STetsuo Handa 
13309590837bSKentaro Takeda #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */
1331