2 * security/tomoyo/common.h
4 * Header file for TOMOYO.
6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
9 #ifndef _SECURITY_TOMOYO_COMMON_H
10 #define _SECURITY_TOMOYO_COMMON_H
12 #include <linux/ctype.h>
13 #include <linux/string.h>
15 #include <linux/file.h>
16 #include <linux/kmod.h>
18 #include <linux/sched.h>
19 #include <linux/namei.h>
20 #include <linux/mount.h>
21 #include <linux/list.h>
22 #include <linux/cred.h>
23 #include <linux/poll.h>
24 #include <linux/binfmts.h>
25 #include <linux/highmem.h>
27 /********** Constants definitions. **********/
30 * TOMOYO uses this hash only when appending a string into the string
31 * table. Frequency of appending strings is very low. So we don't need
32 * large (e.g. 64k) hash size. 256 will be sufficient.
34 #define TOMOYO_HASH_BITS 8
35 #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
37 #define TOMOYO_EXEC_TMPSIZE 4096
39 /* Profile number is an integer between 0 and 255. */
40 #define TOMOYO_MAX_PROFILES 256
42 /* Group number is an integer between 0 and 255. */
43 #define TOMOYO_MAX_ACL_GROUPS 256
45 /* Index numbers for "struct tomoyo_condition". */
46 enum tomoyo_conditions_index
{
47 TOMOYO_TASK_UID
, /* current_uid() */
48 TOMOYO_TASK_EUID
, /* current_euid() */
49 TOMOYO_TASK_SUID
, /* current_suid() */
50 TOMOYO_TASK_FSUID
, /* current_fsuid() */
51 TOMOYO_TASK_GID
, /* current_gid() */
52 TOMOYO_TASK_EGID
, /* current_egid() */
53 TOMOYO_TASK_SGID
, /* current_sgid() */
54 TOMOYO_TASK_FSGID
, /* current_fsgid() */
55 TOMOYO_TASK_PID
, /* sys_getpid() */
56 TOMOYO_TASK_PPID
, /* sys_getppid() */
57 TOMOYO_TYPE_IS_SOCKET
, /* S_IFSOCK */
58 TOMOYO_TYPE_IS_SYMLINK
, /* S_IFLNK */
59 TOMOYO_TYPE_IS_FILE
, /* S_IFREG */
60 TOMOYO_TYPE_IS_BLOCK_DEV
, /* S_IFBLK */
61 TOMOYO_TYPE_IS_DIRECTORY
, /* S_IFDIR */
62 TOMOYO_TYPE_IS_CHAR_DEV
, /* S_IFCHR */
63 TOMOYO_TYPE_IS_FIFO
, /* S_IFIFO */
64 TOMOYO_MODE_SETUID
, /* S_ISUID */
65 TOMOYO_MODE_SETGID
, /* S_ISGID */
66 TOMOYO_MODE_STICKY
, /* S_ISVTX */
67 TOMOYO_MODE_OWNER_READ
, /* S_IRUSR */
68 TOMOYO_MODE_OWNER_WRITE
, /* S_IWUSR */
69 TOMOYO_MODE_OWNER_EXECUTE
, /* S_IXUSR */
70 TOMOYO_MODE_GROUP_READ
, /* S_IRGRP */
71 TOMOYO_MODE_GROUP_WRITE
, /* S_IWGRP */
72 TOMOYO_MODE_GROUP_EXECUTE
, /* S_IXGRP */
73 TOMOYO_MODE_OTHERS_READ
, /* S_IROTH */
74 TOMOYO_MODE_OTHERS_WRITE
, /* S_IWOTH */
75 TOMOYO_MODE_OTHERS_EXECUTE
, /* S_IXOTH */
83 TOMOYO_PATH1_DEV_MAJOR
,
84 TOMOYO_PATH1_DEV_MINOR
,
92 TOMOYO_PATH2_DEV_MAJOR
,
93 TOMOYO_PATH2_DEV_MINOR
,
94 TOMOYO_PATH1_PARENT_UID
,
95 TOMOYO_PATH1_PARENT_GID
,
96 TOMOYO_PATH1_PARENT_INO
,
97 TOMOYO_PATH1_PARENT_PERM
,
98 TOMOYO_PATH2_PARENT_UID
,
99 TOMOYO_PATH2_PARENT_GID
,
100 TOMOYO_PATH2_PARENT_INO
,
101 TOMOYO_PATH2_PARENT_PERM
,
102 TOMOYO_MAX_CONDITION_KEYWORD
,
107 /* Index numbers for stat(). */
108 enum tomoyo_path_stat_index
{
109 /* Do not change this order. */
117 /* Index numbers for operation mode. */
118 enum tomoyo_mode_index
{
119 TOMOYO_CONFIG_DISABLED
,
120 TOMOYO_CONFIG_LEARNING
,
121 TOMOYO_CONFIG_PERMISSIVE
,
122 TOMOYO_CONFIG_ENFORCING
,
123 TOMOYO_CONFIG_MAX_MODE
,
124 TOMOYO_CONFIG_WANT_REJECT_LOG
= 64,
125 TOMOYO_CONFIG_WANT_GRANT_LOG
= 128,
126 TOMOYO_CONFIG_USE_DEFAULT
= 255,
129 /* Index numbers for entry type. */
130 enum tomoyo_policy_id
{
132 TOMOYO_ID_PATH_GROUP
,
133 TOMOYO_ID_NUMBER_GROUP
,
134 TOMOYO_ID_TRANSITION_CONTROL
,
135 TOMOYO_ID_AGGREGATOR
,
144 /* Index numbers for domain's attributes. */
145 enum tomoyo_domain_info_flags_index
{
146 /* Quota warnning flag. */
147 TOMOYO_DIF_QUOTA_WARNED
,
149 * This domain was unable to create a new domain at
150 * tomoyo_find_next_domain() because the name of the domain to be
151 * created was too long or it could not allocate memory.
152 * More than one process continued execve() without domain transition.
154 TOMOYO_DIF_TRANSITION_FAILED
,
155 TOMOYO_MAX_DOMAIN_INFO_FLAGS
158 /* Index numbers for group entries. */
159 enum tomoyo_group_id
{
165 /* Index numbers for type of numeric values. */
166 enum tomoyo_value_type
{
167 TOMOYO_VALUE_TYPE_INVALID
,
168 TOMOYO_VALUE_TYPE_DECIMAL
,
169 TOMOYO_VALUE_TYPE_OCTAL
,
170 TOMOYO_VALUE_TYPE_HEXADECIMAL
,
173 /* Index numbers for domain transition control keywords. */
174 enum tomoyo_transition_type
{
175 /* Do not change this order, */
176 TOMOYO_TRANSITION_CONTROL_NO_RESET
,
177 TOMOYO_TRANSITION_CONTROL_RESET
,
178 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE
,
179 TOMOYO_TRANSITION_CONTROL_INITIALIZE
,
180 TOMOYO_TRANSITION_CONTROL_NO_KEEP
,
181 TOMOYO_TRANSITION_CONTROL_KEEP
,
182 TOMOYO_MAX_TRANSITION_TYPE
185 /* Index numbers for Access Controls. */
186 enum tomoyo_acl_entry_type_index
{
187 TOMOYO_TYPE_PATH_ACL
,
188 TOMOYO_TYPE_PATH2_ACL
,
189 TOMOYO_TYPE_PATH_NUMBER_ACL
,
190 TOMOYO_TYPE_MKDEV_ACL
,
191 TOMOYO_TYPE_MOUNT_ACL
,
194 /* Index numbers for access controls with one pathname. */
195 enum tomoyo_path_acl_index
{
203 TOMOYO_TYPE_TRUNCATE
,
207 TOMOYO_MAX_PATH_OPERATION
210 /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
211 enum tomoyo_memory_stat_type
{
212 TOMOYO_MEMORY_POLICY
,
215 TOMOYO_MAX_MEMORY_STAT
218 enum tomoyo_mkdev_acl_index
{
221 TOMOYO_MAX_MKDEV_OPERATION
224 /* Index numbers for access controls with two pathnames. */
225 enum tomoyo_path2_acl_index
{
228 TOMOYO_TYPE_PIVOT_ROOT
,
229 TOMOYO_MAX_PATH2_OPERATION
232 /* Index numbers for access controls with one pathname and one number. */
233 enum tomoyo_path_number_acl_index
{
242 TOMOYO_MAX_PATH_NUMBER_OPERATION
245 /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
246 enum tomoyo_securityfs_interface_index
{
248 TOMOYO_EXCEPTIONPOLICY
,
249 TOMOYO_PROCESS_STATUS
,
259 /* Index numbers for special mount operations. */
260 enum tomoyo_special_mount
{
261 TOMOYO_MOUNT_BIND
, /* mount --bind /source /dest */
262 TOMOYO_MOUNT_MOVE
, /* mount --move /old /new */
263 TOMOYO_MOUNT_REMOUNT
, /* mount -o remount /dir */
264 TOMOYO_MOUNT_MAKE_UNBINDABLE
, /* mount --make-unbindable /dir */
265 TOMOYO_MOUNT_MAKE_PRIVATE
, /* mount --make-private /dir */
266 TOMOYO_MOUNT_MAKE_SLAVE
, /* mount --make-slave /dir */
267 TOMOYO_MOUNT_MAKE_SHARED
, /* mount --make-shared /dir */
268 TOMOYO_MAX_SPECIAL_MOUNT
271 /* Index numbers for functionality. */
272 enum tomoyo_mac_index
{
273 TOMOYO_MAC_FILE_EXECUTE
,
274 TOMOYO_MAC_FILE_OPEN
,
275 TOMOYO_MAC_FILE_CREATE
,
276 TOMOYO_MAC_FILE_UNLINK
,
277 TOMOYO_MAC_FILE_GETATTR
,
278 TOMOYO_MAC_FILE_MKDIR
,
279 TOMOYO_MAC_FILE_RMDIR
,
280 TOMOYO_MAC_FILE_MKFIFO
,
281 TOMOYO_MAC_FILE_MKSOCK
,
282 TOMOYO_MAC_FILE_TRUNCATE
,
283 TOMOYO_MAC_FILE_SYMLINK
,
284 TOMOYO_MAC_FILE_MKBLOCK
,
285 TOMOYO_MAC_FILE_MKCHAR
,
286 TOMOYO_MAC_FILE_LINK
,
287 TOMOYO_MAC_FILE_RENAME
,
288 TOMOYO_MAC_FILE_CHMOD
,
289 TOMOYO_MAC_FILE_CHOWN
,
290 TOMOYO_MAC_FILE_CHGRP
,
291 TOMOYO_MAC_FILE_IOCTL
,
292 TOMOYO_MAC_FILE_CHROOT
,
293 TOMOYO_MAC_FILE_MOUNT
,
294 TOMOYO_MAC_FILE_UMOUNT
,
295 TOMOYO_MAC_FILE_PIVOT_ROOT
,
299 /* Index numbers for category of functionality. */
300 enum tomoyo_mac_category_index
{
301 TOMOYO_MAC_CATEGORY_FILE
,
302 TOMOYO_MAX_MAC_CATEGORY_INDEX
306 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
307 * occurred in enforcing mode and the userspace daemon decided to retry.
309 * We must choose a positive value in order to distinguish "granted" (which is
310 * 0) and "rejected" (which is a negative value) and "retry".
312 #define TOMOYO_RETRY_REQUEST 1
314 /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
315 enum tomoyo_policy_stat_type
{
316 /* Do not change this order. */
317 TOMOYO_STAT_POLICY_UPDATES
,
318 TOMOYO_STAT_POLICY_LEARNING
, /* == TOMOYO_CONFIG_LEARNING */
319 TOMOYO_STAT_POLICY_PERMISSIVE
, /* == TOMOYO_CONFIG_PERMISSIVE */
320 TOMOYO_STAT_POLICY_ENFORCING
, /* == TOMOYO_CONFIG_ENFORCING */
321 TOMOYO_MAX_POLICY_STAT
324 /* Index numbers for profile's PREFERENCE values. */
325 enum tomoyo_pref_index
{
326 TOMOYO_PREF_MAX_AUDIT_LOG
,
327 TOMOYO_PREF_MAX_LEARNING_ENTRY
,
331 /********** Structure definitions. **********/
333 /* Common header for holding ACL entries. */
334 struct tomoyo_acl_head
{
335 struct list_head list
;
339 /* Common header for shared entries. */
340 struct tomoyo_shared_acl_head
{
341 struct list_head list
;
345 struct tomoyo_policy_namespace
;
347 /* Structure for request info. */
348 struct tomoyo_request_info
{
350 * For holding parameters specific to operations which deal files.
351 * NULL if not dealing files.
353 struct tomoyo_obj_info
*obj
;
354 struct tomoyo_domain_info
*domain
;
355 /* For holding parameters. */
358 const struct tomoyo_path_info
*filename
;
359 /* For using wildcards at tomoyo_find_next_domain(). */
360 const struct tomoyo_path_info
*matched_path
;
361 /* One of values in "enum tomoyo_path_acl_index". */
365 const struct tomoyo_path_info
*filename1
;
366 const struct tomoyo_path_info
*filename2
;
367 /* One of values in "enum tomoyo_path2_acl_index". */
371 const struct tomoyo_path_info
*filename
;
375 /* One of values in "enum tomoyo_mkdev_acl_index". */
379 const struct tomoyo_path_info
*filename
;
380 unsigned long number
;
383 * "enum tomoyo_path_number_acl_index".
388 const struct tomoyo_path_info
*type
;
389 const struct tomoyo_path_info
*dir
;
390 const struct tomoyo_path_info
*dev
;
399 u8 mode
; /* One of tomoyo_mode_index . */
403 /* Structure for holding a token. */
404 struct tomoyo_path_info
{
406 u32 hash
; /* = full_name_hash(name, strlen(name)) */
407 u16 const_len
; /* = tomoyo_const_part_length(name) */
408 bool is_dir
; /* = tomoyo_strendswith(name, "/") */
409 bool is_patterned
; /* = tomoyo_path_contains_pattern(name) */
412 /* Structure for holding string data. */
414 struct tomoyo_shared_acl_head head
;
415 struct tomoyo_path_info entry
;
418 /* Structure for holding a word. */
419 struct tomoyo_name_union
{
420 /* Either @filename or @group is NULL. */
421 const struct tomoyo_path_info
*filename
;
422 struct tomoyo_group
*group
;
425 /* Structure for holding a number. */
426 struct tomoyo_number_union
{
427 unsigned long values
[2];
428 struct tomoyo_group
*group
; /* Maybe NULL. */
429 /* One of values in "enum tomoyo_value_type". */
433 /* Structure for "path_group"/"number_group" directive. */
434 struct tomoyo_group
{
435 struct tomoyo_shared_acl_head head
;
436 const struct tomoyo_path_info
*group_name
;
437 struct list_head member_list
;
440 /* Structure for "path_group" directive. */
441 struct tomoyo_path_group
{
442 struct tomoyo_acl_head head
;
443 const struct tomoyo_path_info
*member_name
;
446 /* Structure for "number_group" directive. */
447 struct tomoyo_number_group
{
448 struct tomoyo_acl_head head
;
449 struct tomoyo_number_union number
;
452 /* Subset of "struct stat". Used by conditional ACL and audit logs. */
453 struct tomoyo_mini_stat
{
462 /* Structure for attribute checks in addition to pathname checks. */
463 struct tomoyo_obj_info
{
465 * True if tomoyo_get_attributes() was already called, false otherwise.
468 /* True if @stat[] is valid. */
469 bool stat_valid
[TOMOYO_MAX_PATH_STAT
];
470 /* First pathname. Initialized with { NULL, NULL } if no path. */
472 /* Second pathname. Initialized with { NULL, NULL } if no path. */
475 * Information on @path1, @path1's parent directory, @path2, @path2's
478 struct tomoyo_mini_stat stat
[TOMOYO_MAX_PATH_STAT
];
481 /* Structure for entries which follows "struct tomoyo_condition". */
482 struct tomoyo_condition_element
{
483 /* Left hand operand. */
485 /* Right hand operand. */
487 /* Equation operator. True if equals or overlaps, false otherwise. */
491 /* Structure for optional arguments. */
492 struct tomoyo_condition
{
493 struct tomoyo_shared_acl_head head
;
494 u32 size
; /* Memory size allocated for this entry. */
495 u16 condc
; /* Number of conditions in this struct. */
496 u16 numbers_count
; /* Number of "struct tomoyo_number_union values". */
498 * struct tomoyo_condition_element condition[condc];
499 * struct tomoyo_number_union values[numbers_count];
503 /* Common header for individual entries. */
504 struct tomoyo_acl_info
{
505 struct list_head list
;
506 struct tomoyo_condition
*cond
; /* Maybe NULL. */
508 u8 type
; /* One of values in "enum tomoyo_acl_entry_type_index". */
511 /* Structure for domain information. */
512 struct tomoyo_domain_info
{
513 struct list_head list
;
514 struct list_head acl_info_list
;
515 /* Name of this domain. Never NULL. */
516 const struct tomoyo_path_info
*domainname
;
517 /* Namespace for this domain. Never NULL. */
518 struct tomoyo_policy_namespace
*ns
;
519 u8 profile
; /* Profile number to use. */
520 u8 group
; /* Group number to use. */
521 bool is_deleted
; /* Delete flag. */
522 bool flags
[TOMOYO_MAX_DOMAIN_INFO_FLAGS
];
523 atomic_t users
; /* Number of referring credentials. */
527 * Structure for "file execute", "file read", "file write", "file append",
528 * "file unlink", "file getattr", "file rmdir", "file truncate",
529 * "file symlink", "file chroot" and "file unmount" directive.
531 struct tomoyo_path_acl
{
532 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_ACL */
533 u16 perm
; /* Bitmask of values in "enum tomoyo_path_acl_index". */
534 struct tomoyo_name_union name
;
538 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
539 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
541 struct tomoyo_path_number_acl
{
542 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
543 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
545 struct tomoyo_name_union name
;
546 struct tomoyo_number_union number
;
549 /* Structure for "file mkblock" and "file mkchar" directive. */
550 struct tomoyo_mkdev_acl
{
551 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MKDEV_ACL */
552 u8 perm
; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
553 struct tomoyo_name_union name
;
554 struct tomoyo_number_union mode
;
555 struct tomoyo_number_union major
;
556 struct tomoyo_number_union minor
;
560 * Structure for "file rename", "file link" and "file pivot_root" directive.
562 struct tomoyo_path2_acl
{
563 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH2_ACL */
564 u8 perm
; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
565 struct tomoyo_name_union name1
;
566 struct tomoyo_name_union name2
;
569 /* Structure for "file mount" directive. */
570 struct tomoyo_mount_acl
{
571 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MOUNT_ACL */
572 struct tomoyo_name_union dev_name
;
573 struct tomoyo_name_union dir_name
;
574 struct tomoyo_name_union fs_type
;
575 struct tomoyo_number_union flags
;
578 /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
579 struct tomoyo_acl_param
{
581 struct list_head
*list
;
582 struct tomoyo_policy_namespace
*ns
;
586 #define TOMOYO_MAX_IO_READ_QUEUE 64
589 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
592 struct tomoyo_io_buffer
{
593 void (*read
) (struct tomoyo_io_buffer
*);
594 int (*write
) (struct tomoyo_io_buffer
*);
595 int (*poll
) (struct file
*file
, poll_table
*wait
);
596 /* Exclusive lock for this structure. */
598 char __user
*read_user_buf
;
599 size_t read_user_buf_avail
;
601 struct list_head
*ns
;
602 struct list_head
*domain
;
603 struct list_head
*group
;
604 struct list_head
*acl
;
607 unsigned int query_index
;
615 bool print_this_domain_only
;
616 bool print_transition_related_only
;
617 bool print_cond_part
;
618 const char *w
[TOMOYO_MAX_IO_READ_QUEUE
];
621 struct tomoyo_policy_namespace
*ns
;
622 /* The position currently writing to. */
623 struct tomoyo_domain_info
*domain
;
624 /* Bytes available for writing. */
628 /* Buffer for reading. */
630 /* Size of read buffer. */
632 /* Buffer for writing. */
634 /* Size of write buffer. */
635 size_t writebuf_size
;
636 /* Type of this interface. */
637 enum tomoyo_securityfs_interface_index type
;
638 /* Users counter protected by tomoyo_io_buffer_list_lock. */
640 /* List for telling GC not to kfree() elements. */
641 struct list_head list
;
645 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
646 * "no_keep_domain" keyword.
648 struct tomoyo_transition_control
{
649 struct tomoyo_acl_head head
;
650 u8 type
; /* One of values in "enum tomoyo_transition_type". */
651 /* True if the domainname is tomoyo_get_last_name(). */
653 const struct tomoyo_path_info
*domainname
; /* Maybe NULL */
654 const struct tomoyo_path_info
*program
; /* Maybe NULL */
657 /* Structure for "aggregator" keyword. */
658 struct tomoyo_aggregator
{
659 struct tomoyo_acl_head head
;
660 const struct tomoyo_path_info
*original_name
;
661 const struct tomoyo_path_info
*aggregated_name
;
664 /* Structure for policy manager. */
665 struct tomoyo_manager
{
666 struct tomoyo_acl_head head
;
667 bool is_domain
; /* True if manager is a domainname. */
668 /* A path to program or a domainname. */
669 const struct tomoyo_path_info
*manager
;
672 struct tomoyo_preference
{
673 unsigned int learning_max_entry
;
674 bool enforcing_verbose
;
675 bool learning_verbose
;
676 bool permissive_verbose
;
679 /* Structure for /sys/kernel/security/tomnoyo/profile interface. */
680 struct tomoyo_profile
{
681 const struct tomoyo_path_info
*comment
;
682 struct tomoyo_preference
*learning
;
683 struct tomoyo_preference
*permissive
;
684 struct tomoyo_preference
*enforcing
;
685 struct tomoyo_preference preference
;
687 u8 config
[TOMOYO_MAX_MAC_INDEX
+ TOMOYO_MAX_MAC_CATEGORY_INDEX
];
688 unsigned int pref
[TOMOYO_MAX_PREF
];
691 /* Structure for representing YYYY/MM/DD hh/mm/ss. */
701 /* Structure for policy namespace. */
702 struct tomoyo_policy_namespace
{
703 /* Profile table. Memory is allocated as needed. */
704 struct tomoyo_profile
*profile_ptr
[TOMOYO_MAX_PROFILES
];
705 /* List of "struct tomoyo_group". */
706 struct list_head group_list
[TOMOYO_MAX_GROUP
];
707 /* List of policy. */
708 struct list_head policy_list
[TOMOYO_MAX_POLICY
];
709 /* The global ACL referred by "use_group" keyword. */
710 struct list_head acl_group
[TOMOYO_MAX_ACL_GROUPS
];
711 /* List for connecting to tomoyo_namespace_list list. */
712 struct list_head namespace_list
;
713 /* Profile version. Currently only 20100903 is defined. */
714 unsigned int profile_version
;
715 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
719 /********** Function prototypes. **********/
721 bool tomoyo_compare_number_union(const unsigned long value
,
722 const struct tomoyo_number_union
*ptr
);
723 bool tomoyo_condition(struct tomoyo_request_info
*r
,
724 const struct tomoyo_condition
*cond
);
725 bool tomoyo_correct_domain(const unsigned char *domainname
);
726 bool tomoyo_correct_path(const char *filename
);
727 bool tomoyo_correct_word(const char *string
);
728 bool tomoyo_domain_def(const unsigned char *buffer
);
729 bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info
*r
);
730 bool tomoyo_memory_ok(void *ptr
);
731 bool tomoyo_number_matches_group(const unsigned long min
,
732 const unsigned long max
,
733 const struct tomoyo_group
*group
);
734 bool tomoyo_parse_name_union(struct tomoyo_acl_param
*param
,
735 struct tomoyo_name_union
*ptr
);
736 bool tomoyo_parse_number_union(struct tomoyo_acl_param
*param
,
737 struct tomoyo_number_union
*ptr
);
738 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info
*filename
,
739 const struct tomoyo_path_info
*pattern
);
740 bool tomoyo_permstr(const char *string
, const char *keyword
);
741 bool tomoyo_str_starts(char **src
, const char *find
);
742 char *tomoyo_encode(const char *str
);
743 char *tomoyo_init_log(struct tomoyo_request_info
*r
, int len
, const char *fmt
,
745 char *tomoyo_read_token(struct tomoyo_acl_param
*param
);
746 char *tomoyo_realpath_from_path(struct path
*path
);
747 char *tomoyo_realpath_nofollow(const char *pathname
);
748 const char *tomoyo_get_exe(void);
749 const char *tomoyo_yesno(const unsigned int value
);
750 const struct tomoyo_path_info
*tomoyo_compare_name_union
751 (const struct tomoyo_path_info
*name
, const struct tomoyo_name_union
*ptr
);
752 const struct tomoyo_path_info
*tomoyo_get_name(const char *name
);
753 const struct tomoyo_path_info
*tomoyo_path_matches_group
754 (const struct tomoyo_path_info
*pathname
, const struct tomoyo_group
*group
);
755 int tomoyo_check_open_permission(struct tomoyo_domain_info
*domain
,
756 struct path
*path
, const int flag
);
757 int tomoyo_close_control(struct tomoyo_io_buffer
*head
);
758 int tomoyo_find_next_domain(struct linux_binprm
*bprm
);
759 int tomoyo_get_mode(const struct tomoyo_policy_namespace
*ns
, const u8 profile
,
761 int tomoyo_init_request_info(struct tomoyo_request_info
*r
,
762 struct tomoyo_domain_info
*domain
,
764 int tomoyo_mkdev_perm(const u8 operation
, struct path
*path
,
765 const unsigned int mode
, unsigned int dev
);
766 int tomoyo_mount_permission(char *dev_name
, struct path
*path
,
767 const char *type
, unsigned long flags
,
769 int tomoyo_open_control(const u8 type
, struct file
*file
);
770 int tomoyo_path2_perm(const u8 operation
, struct path
*path1
,
772 int tomoyo_path_number_perm(const u8 operation
, struct path
*path
,
773 unsigned long number
);
774 int tomoyo_path_perm(const u8 operation
, struct path
*path
);
775 int tomoyo_path_permission(struct tomoyo_request_info
*r
, u8 operation
,
776 const struct tomoyo_path_info
*filename
);
777 int tomoyo_poll_control(struct file
*file
, poll_table
*wait
);
778 int tomoyo_poll_log(struct file
*file
, poll_table
*wait
);
779 int tomoyo_supervisor(struct tomoyo_request_info
*r
, const char *fmt
, ...)
781 int tomoyo_update_domain(struct tomoyo_acl_info
*new_entry
, const int size
,
782 struct tomoyo_acl_param
*param
,
783 bool (*check_duplicate
)
784 (const struct tomoyo_acl_info
*,
785 const struct tomoyo_acl_info
*),
786 bool (*merge_duplicate
)
787 (struct tomoyo_acl_info
*, struct tomoyo_acl_info
*,
789 int tomoyo_update_policy(struct tomoyo_acl_head
*new_entry
, const int size
,
790 struct tomoyo_acl_param
*param
,
791 bool (*check_duplicate
)
792 (const struct tomoyo_acl_head
*,
793 const struct tomoyo_acl_head
*));
794 int tomoyo_write_aggregator(struct tomoyo_acl_param
*param
);
795 int tomoyo_write_file(struct tomoyo_acl_param
*param
);
796 int tomoyo_write_group(struct tomoyo_acl_param
*param
, const u8 type
);
797 int tomoyo_write_transition_control(struct tomoyo_acl_param
*param
,
799 ssize_t
tomoyo_read_control(struct tomoyo_io_buffer
*head
, char __user
*buffer
,
800 const int buffer_len
);
801 ssize_t
tomoyo_write_control(struct tomoyo_io_buffer
*head
,
802 const char __user
*buffer
, const int buffer_len
);
803 struct tomoyo_condition
*tomoyo_get_condition(struct tomoyo_acl_param
*param
);
804 struct tomoyo_domain_info
*tomoyo_assign_domain(const char *domainname
,
806 struct tomoyo_domain_info
*tomoyo_find_domain(const char *domainname
);
807 struct tomoyo_group
*tomoyo_get_group(struct tomoyo_acl_param
*param
,
809 struct tomoyo_policy_namespace
*tomoyo_assign_namespace
810 (const char *domainname
);
811 struct tomoyo_profile
*tomoyo_profile(const struct tomoyo_policy_namespace
*ns
,
813 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info
*domain
,
815 u8
tomoyo_parse_ulong(unsigned long *result
, char **str
);
816 void *tomoyo_commit_ok(void *data
, const unsigned int size
);
817 void __init
tomoyo_load_builtin_policy(void);
818 void __init
tomoyo_mm_init(void);
819 void tomoyo_check_acl(struct tomoyo_request_info
*r
,
820 bool (*check_entry
) (struct tomoyo_request_info
*,
821 const struct tomoyo_acl_info
*));
822 void tomoyo_check_profile(void);
823 void tomoyo_convert_time(time_t time
, struct tomoyo_time
*stamp
);
824 void tomoyo_del_condition(struct list_head
*element
);
825 void tomoyo_fill_path_info(struct tomoyo_path_info
*ptr
);
826 void tomoyo_get_attributes(struct tomoyo_obj_info
*obj
);
827 void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace
*ns
);
828 void tomoyo_io_printf(struct tomoyo_io_buffer
*head
, const char *fmt
, ...)
830 void tomoyo_load_policy(const char *filename
);
831 void tomoyo_memory_free(void *ptr
);
832 void tomoyo_normalize_line(unsigned char *buffer
);
833 void tomoyo_notify_gc(struct tomoyo_io_buffer
*head
, const bool is_register
);
834 void tomoyo_print_ulong(char *buffer
, const int buffer_len
,
835 const unsigned long value
, const u8 type
);
836 void tomoyo_put_name_union(struct tomoyo_name_union
*ptr
);
837 void tomoyo_put_number_union(struct tomoyo_number_union
*ptr
);
838 void tomoyo_read_log(struct tomoyo_io_buffer
*head
);
839 void tomoyo_update_stat(const u8 index
);
840 void tomoyo_warn_oom(const char *function
);
841 void tomoyo_write_log(struct tomoyo_request_info
*r
, const char *fmt
, ...)
843 void tomoyo_write_log2(struct tomoyo_request_info
*r
, int len
, const char *fmt
,
846 /********** External variable definitions. **********/
848 extern bool tomoyo_policy_loaded
;
849 extern const char * const tomoyo_condition_keyword
850 [TOMOYO_MAX_CONDITION_KEYWORD
];
851 extern const char * const tomoyo_dif
[TOMOYO_MAX_DOMAIN_INFO_FLAGS
];
852 extern const char * const tomoyo_mac_keywords
[TOMOYO_MAX_MAC_INDEX
853 + TOMOYO_MAX_MAC_CATEGORY_INDEX
];
854 extern const char * const tomoyo_mode
[TOMOYO_CONFIG_MAX_MODE
];
855 extern const char * const tomoyo_path_keyword
[TOMOYO_MAX_PATH_OPERATION
];
856 extern const u8 tomoyo_index2category
[TOMOYO_MAX_MAC_INDEX
];
857 extern const u8 tomoyo_pn2mac
[TOMOYO_MAX_PATH_NUMBER_OPERATION
];
858 extern const u8 tomoyo_pnnn2mac
[TOMOYO_MAX_MKDEV_OPERATION
];
859 extern const u8 tomoyo_pp2mac
[TOMOYO_MAX_PATH2_OPERATION
];
860 extern struct list_head tomoyo_condition_list
;
861 extern struct list_head tomoyo_domain_list
;
862 extern struct list_head tomoyo_name_list
[TOMOYO_MAX_HASH
];
863 extern struct list_head tomoyo_namespace_list
;
864 extern struct mutex tomoyo_policy_lock
;
865 extern struct srcu_struct tomoyo_ss
;
866 extern struct tomoyo_domain_info tomoyo_kernel_domain
;
867 extern struct tomoyo_policy_namespace tomoyo_kernel_namespace
;
868 extern unsigned int tomoyo_memory_quota
[TOMOYO_MAX_MEMORY_STAT
];
869 extern unsigned int tomoyo_memory_used
[TOMOYO_MAX_MEMORY_STAT
];
871 /********** Inlined functions. **********/
874 * tomoyo_read_lock - Take lock for protecting policy.
876 * Returns index number for tomoyo_read_unlock().
878 static inline int tomoyo_read_lock(void)
880 return srcu_read_lock(&tomoyo_ss
);
884 * tomoyo_read_unlock - Release lock for protecting policy.
886 * @idx: Index number returned by tomoyo_read_lock().
890 static inline void tomoyo_read_unlock(int idx
)
892 srcu_read_unlock(&tomoyo_ss
, idx
);
896 * tomoyo_sys_getppid - Copy of getppid().
898 * Returns parent process's PID.
900 * Alpha does not have getppid() defined. To be able to build this module on
901 * Alpha, I have to copy getppid() from kernel/timer.c.
903 static inline pid_t
tomoyo_sys_getppid(void)
907 pid
= task_tgid_vnr(current
->real_parent
);
913 * tomoyo_sys_getpid - Copy of getpid().
915 * Returns current thread's PID.
917 * Alpha does not have getpid() defined. To be able to build this module on
918 * Alpha, I have to copy getpid() from kernel/timer.c.
920 static inline pid_t
tomoyo_sys_getpid(void)
922 return task_tgid_vnr(current
);
926 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
928 * @a: Pointer to "struct tomoyo_path_info".
929 * @b: Pointer to "struct tomoyo_path_info".
931 * Returns true if @a == @b, false otherwise.
933 static inline bool tomoyo_pathcmp(const struct tomoyo_path_info
*a
,
934 const struct tomoyo_path_info
*b
)
936 return a
->hash
!= b
->hash
|| strcmp(a
->name
, b
->name
);
940 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
942 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
946 static inline void tomoyo_put_name(const struct tomoyo_path_info
*name
)
949 struct tomoyo_name
*ptr
=
950 container_of(name
, typeof(*ptr
), entry
);
951 atomic_dec(&ptr
->head
.users
);
956 * tomoyo_put_condition - Drop reference on "struct tomoyo_condition".
958 * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
962 static inline void tomoyo_put_condition(struct tomoyo_condition
*cond
)
965 atomic_dec(&cond
->head
.users
);
969 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
971 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
975 static inline void tomoyo_put_group(struct tomoyo_group
*group
)
978 atomic_dec(&group
->head
.users
);
982 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
984 * Returns pointer to "struct tomoyo_domain_info" for current thread.
986 static inline struct tomoyo_domain_info
*tomoyo_domain(void)
988 return current_cred()->security
;
992 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
994 * @task: Pointer to "struct task_struct".
996 * Returns pointer to "struct tomoyo_security" for specified thread.
998 static inline struct tomoyo_domain_info
*tomoyo_real_domain(struct task_struct
1001 return task_cred_xxx(task
, security
);
1005 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
1007 * @a: Pointer to "struct tomoyo_name_union".
1008 * @b: Pointer to "struct tomoyo_name_union".
1010 * Returns true if @a == @b, false otherwise.
1012 static inline bool tomoyo_same_name_union
1013 (const struct tomoyo_name_union
*a
, const struct tomoyo_name_union
*b
)
1015 return a
->filename
== b
->filename
&& a
->group
== b
->group
;
1019 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
1021 * @a: Pointer to "struct tomoyo_number_union".
1022 * @b: Pointer to "struct tomoyo_number_union".
1024 * Returns true if @a == @b, false otherwise.
1026 static inline bool tomoyo_same_number_union
1027 (const struct tomoyo_number_union
*a
, const struct tomoyo_number_union
*b
)
1029 return a
->values
[0] == b
->values
[0] && a
->values
[1] == b
->values
[1] &&
1030 a
->group
== b
->group
&& a
->value_type
[0] == b
->value_type
[0] &&
1031 a
->value_type
[1] == b
->value_type
[1];
1035 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
1037 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
1039 static inline struct tomoyo_policy_namespace
*tomoyo_current_namespace(void)
1041 return tomoyo_domain()->ns
;
1044 #if defined(CONFIG_SLOB)
1047 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
1049 * @size: Size to be rounded up.
1053 * Since SLOB does not round up, this function simply returns @size.
1055 static inline int tomoyo_round2(size_t size
)
1063 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
1065 * @size: Size to be rounded up.
1067 * Returns rounded size.
1069 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
1072 static inline int tomoyo_round2(size_t size
)
1074 #if PAGE_SIZE == 4096
1081 while (size
> bsize
)
1089 * list_for_each_cookie - iterate over a list with cookie.
1090 * @pos: the &struct list_head to use as a loop cursor.
1091 * @head: the head for your list.
1093 #define list_for_each_cookie(pos, head) \
1095 pos = srcu_dereference((head)->next, &tomoyo_ss); \
1096 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
1098 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */