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_MAX_CONDITION_KEYWORD
,
61 /* Index numbers for operation mode. */
62 enum tomoyo_mode_index
{
63 TOMOYO_CONFIG_DISABLED
,
64 TOMOYO_CONFIG_LEARNING
,
65 TOMOYO_CONFIG_PERMISSIVE
,
66 TOMOYO_CONFIG_ENFORCING
,
67 TOMOYO_CONFIG_MAX_MODE
,
68 TOMOYO_CONFIG_WANT_REJECT_LOG
= 64,
69 TOMOYO_CONFIG_WANT_GRANT_LOG
= 128,
70 TOMOYO_CONFIG_USE_DEFAULT
= 255,
73 /* Index numbers for entry type. */
74 enum tomoyo_policy_id
{
77 TOMOYO_ID_NUMBER_GROUP
,
78 TOMOYO_ID_TRANSITION_CONTROL
,
88 /* Index numbers for domain's attributes. */
89 enum tomoyo_domain_info_flags_index
{
90 /* Quota warnning flag. */
91 TOMOYO_DIF_QUOTA_WARNED
,
93 * This domain was unable to create a new domain at
94 * tomoyo_find_next_domain() because the name of the domain to be
95 * created was too long or it could not allocate memory.
96 * More than one process continued execve() without domain transition.
98 TOMOYO_DIF_TRANSITION_FAILED
,
99 TOMOYO_MAX_DOMAIN_INFO_FLAGS
102 /* Index numbers for group entries. */
103 enum tomoyo_group_id
{
109 /* Index numbers for type of numeric values. */
110 enum tomoyo_value_type
{
111 TOMOYO_VALUE_TYPE_INVALID
,
112 TOMOYO_VALUE_TYPE_DECIMAL
,
113 TOMOYO_VALUE_TYPE_OCTAL
,
114 TOMOYO_VALUE_TYPE_HEXADECIMAL
,
117 /* Index numbers for domain transition control keywords. */
118 enum tomoyo_transition_type
{
119 /* Do not change this order, */
120 TOMOYO_TRANSITION_CONTROL_NO_RESET
,
121 TOMOYO_TRANSITION_CONTROL_RESET
,
122 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE
,
123 TOMOYO_TRANSITION_CONTROL_INITIALIZE
,
124 TOMOYO_TRANSITION_CONTROL_NO_KEEP
,
125 TOMOYO_TRANSITION_CONTROL_KEEP
,
126 TOMOYO_MAX_TRANSITION_TYPE
129 /* Index numbers for Access Controls. */
130 enum tomoyo_acl_entry_type_index
{
131 TOMOYO_TYPE_PATH_ACL
,
132 TOMOYO_TYPE_PATH2_ACL
,
133 TOMOYO_TYPE_PATH_NUMBER_ACL
,
134 TOMOYO_TYPE_MKDEV_ACL
,
135 TOMOYO_TYPE_MOUNT_ACL
,
138 /* Index numbers for access controls with one pathname. */
139 enum tomoyo_path_acl_index
{
147 TOMOYO_TYPE_TRUNCATE
,
151 TOMOYO_MAX_PATH_OPERATION
154 /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
155 enum tomoyo_memory_stat_type
{
156 TOMOYO_MEMORY_POLICY
,
159 TOMOYO_MAX_MEMORY_STAT
162 enum tomoyo_mkdev_acl_index
{
165 TOMOYO_MAX_MKDEV_OPERATION
168 /* Index numbers for access controls with two pathnames. */
169 enum tomoyo_path2_acl_index
{
172 TOMOYO_TYPE_PIVOT_ROOT
,
173 TOMOYO_MAX_PATH2_OPERATION
176 /* Index numbers for access controls with one pathname and one number. */
177 enum tomoyo_path_number_acl_index
{
186 TOMOYO_MAX_PATH_NUMBER_OPERATION
189 /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
190 enum tomoyo_securityfs_interface_index
{
192 TOMOYO_EXCEPTIONPOLICY
,
193 TOMOYO_PROCESS_STATUS
,
203 /* Index numbers for special mount operations. */
204 enum tomoyo_special_mount
{
205 TOMOYO_MOUNT_BIND
, /* mount --bind /source /dest */
206 TOMOYO_MOUNT_MOVE
, /* mount --move /old /new */
207 TOMOYO_MOUNT_REMOUNT
, /* mount -o remount /dir */
208 TOMOYO_MOUNT_MAKE_UNBINDABLE
, /* mount --make-unbindable /dir */
209 TOMOYO_MOUNT_MAKE_PRIVATE
, /* mount --make-private /dir */
210 TOMOYO_MOUNT_MAKE_SLAVE
, /* mount --make-slave /dir */
211 TOMOYO_MOUNT_MAKE_SHARED
, /* mount --make-shared /dir */
212 TOMOYO_MAX_SPECIAL_MOUNT
215 /* Index numbers for functionality. */
216 enum tomoyo_mac_index
{
217 TOMOYO_MAC_FILE_EXECUTE
,
218 TOMOYO_MAC_FILE_OPEN
,
219 TOMOYO_MAC_FILE_CREATE
,
220 TOMOYO_MAC_FILE_UNLINK
,
221 TOMOYO_MAC_FILE_GETATTR
,
222 TOMOYO_MAC_FILE_MKDIR
,
223 TOMOYO_MAC_FILE_RMDIR
,
224 TOMOYO_MAC_FILE_MKFIFO
,
225 TOMOYO_MAC_FILE_MKSOCK
,
226 TOMOYO_MAC_FILE_TRUNCATE
,
227 TOMOYO_MAC_FILE_SYMLINK
,
228 TOMOYO_MAC_FILE_MKBLOCK
,
229 TOMOYO_MAC_FILE_MKCHAR
,
230 TOMOYO_MAC_FILE_LINK
,
231 TOMOYO_MAC_FILE_RENAME
,
232 TOMOYO_MAC_FILE_CHMOD
,
233 TOMOYO_MAC_FILE_CHOWN
,
234 TOMOYO_MAC_FILE_CHGRP
,
235 TOMOYO_MAC_FILE_IOCTL
,
236 TOMOYO_MAC_FILE_CHROOT
,
237 TOMOYO_MAC_FILE_MOUNT
,
238 TOMOYO_MAC_FILE_UMOUNT
,
239 TOMOYO_MAC_FILE_PIVOT_ROOT
,
243 /* Index numbers for category of functionality. */
244 enum tomoyo_mac_category_index
{
245 TOMOYO_MAC_CATEGORY_FILE
,
246 TOMOYO_MAX_MAC_CATEGORY_INDEX
250 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
251 * occurred in enforcing mode and the userspace daemon decided to retry.
253 * We must choose a positive value in order to distinguish "granted" (which is
254 * 0) and "rejected" (which is a negative value) and "retry".
256 #define TOMOYO_RETRY_REQUEST 1
258 /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
259 enum tomoyo_policy_stat_type
{
260 /* Do not change this order. */
261 TOMOYO_STAT_POLICY_UPDATES
,
262 TOMOYO_STAT_POLICY_LEARNING
, /* == TOMOYO_CONFIG_LEARNING */
263 TOMOYO_STAT_POLICY_PERMISSIVE
, /* == TOMOYO_CONFIG_PERMISSIVE */
264 TOMOYO_STAT_POLICY_ENFORCING
, /* == TOMOYO_CONFIG_ENFORCING */
265 TOMOYO_MAX_POLICY_STAT
268 /* Index numbers for profile's PREFERENCE values. */
269 enum tomoyo_pref_index
{
270 TOMOYO_PREF_MAX_AUDIT_LOG
,
271 TOMOYO_PREF_MAX_LEARNING_ENTRY
,
275 /********** Structure definitions. **********/
277 /* Common header for holding ACL entries. */
278 struct tomoyo_acl_head
{
279 struct list_head list
;
283 /* Common header for shared entries. */
284 struct tomoyo_shared_acl_head
{
285 struct list_head list
;
289 struct tomoyo_policy_namespace
;
291 /* Structure for request info. */
292 struct tomoyo_request_info
{
293 struct tomoyo_domain_info
*domain
;
294 /* For holding parameters. */
297 const struct tomoyo_path_info
*filename
;
298 /* For using wildcards at tomoyo_find_next_domain(). */
299 const struct tomoyo_path_info
*matched_path
;
300 /* One of values in "enum tomoyo_path_acl_index". */
304 const struct tomoyo_path_info
*filename1
;
305 const struct tomoyo_path_info
*filename2
;
306 /* One of values in "enum tomoyo_path2_acl_index". */
310 const struct tomoyo_path_info
*filename
;
314 /* One of values in "enum tomoyo_mkdev_acl_index". */
318 const struct tomoyo_path_info
*filename
;
319 unsigned long number
;
322 * "enum tomoyo_path_number_acl_index".
327 const struct tomoyo_path_info
*type
;
328 const struct tomoyo_path_info
*dir
;
329 const struct tomoyo_path_info
*dev
;
338 u8 mode
; /* One of tomoyo_mode_index . */
342 /* Structure for holding a token. */
343 struct tomoyo_path_info
{
345 u32 hash
; /* = full_name_hash(name, strlen(name)) */
346 u16 const_len
; /* = tomoyo_const_part_length(name) */
347 bool is_dir
; /* = tomoyo_strendswith(name, "/") */
348 bool is_patterned
; /* = tomoyo_path_contains_pattern(name) */
351 /* Structure for holding string data. */
353 struct tomoyo_shared_acl_head head
;
354 struct tomoyo_path_info entry
;
357 /* Structure for holding a word. */
358 struct tomoyo_name_union
{
359 /* Either @filename or @group is NULL. */
360 const struct tomoyo_path_info
*filename
;
361 struct tomoyo_group
*group
;
364 /* Structure for holding a number. */
365 struct tomoyo_number_union
{
366 unsigned long values
[2];
367 struct tomoyo_group
*group
; /* Maybe NULL. */
368 /* One of values in "enum tomoyo_value_type". */
372 /* Structure for "path_group"/"number_group" directive. */
373 struct tomoyo_group
{
374 struct tomoyo_shared_acl_head head
;
375 const struct tomoyo_path_info
*group_name
;
376 struct list_head member_list
;
379 /* Structure for "path_group" directive. */
380 struct tomoyo_path_group
{
381 struct tomoyo_acl_head head
;
382 const struct tomoyo_path_info
*member_name
;
385 /* Structure for "number_group" directive. */
386 struct tomoyo_number_group
{
387 struct tomoyo_acl_head head
;
388 struct tomoyo_number_union number
;
391 /* Structure for entries which follows "struct tomoyo_condition". */
392 struct tomoyo_condition_element
{
393 /* Left hand operand. */
395 /* Right hand operand. */
397 /* Equation operator. True if equals or overlaps, false otherwise. */
401 /* Structure for optional arguments. */
402 struct tomoyo_condition
{
403 struct tomoyo_shared_acl_head head
;
404 u32 size
; /* Memory size allocated for this entry. */
405 u16 condc
; /* Number of conditions in this struct. */
406 u16 numbers_count
; /* Number of "struct tomoyo_number_union values". */
408 * struct tomoyo_condition_element condition[condc];
409 * struct tomoyo_number_union values[numbers_count];
413 /* Common header for individual entries. */
414 struct tomoyo_acl_info
{
415 struct list_head list
;
416 struct tomoyo_condition
*cond
; /* Maybe NULL. */
418 u8 type
; /* One of values in "enum tomoyo_acl_entry_type_index". */
421 /* Structure for domain information. */
422 struct tomoyo_domain_info
{
423 struct list_head list
;
424 struct list_head acl_info_list
;
425 /* Name of this domain. Never NULL. */
426 const struct tomoyo_path_info
*domainname
;
427 /* Namespace for this domain. Never NULL. */
428 struct tomoyo_policy_namespace
*ns
;
429 u8 profile
; /* Profile number to use. */
430 u8 group
; /* Group number to use. */
431 bool is_deleted
; /* Delete flag. */
432 bool flags
[TOMOYO_MAX_DOMAIN_INFO_FLAGS
];
433 atomic_t users
; /* Number of referring credentials. */
437 * Structure for "file execute", "file read", "file write", "file append",
438 * "file unlink", "file getattr", "file rmdir", "file truncate",
439 * "file symlink", "file chroot" and "file unmount" directive.
441 struct tomoyo_path_acl
{
442 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_ACL */
443 u16 perm
; /* Bitmask of values in "enum tomoyo_path_acl_index". */
444 struct tomoyo_name_union name
;
448 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
449 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
451 struct tomoyo_path_number_acl
{
452 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
453 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
455 struct tomoyo_name_union name
;
456 struct tomoyo_number_union number
;
459 /* Structure for "file mkblock" and "file mkchar" directive. */
460 struct tomoyo_mkdev_acl
{
461 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MKDEV_ACL */
462 u8 perm
; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
463 struct tomoyo_name_union name
;
464 struct tomoyo_number_union mode
;
465 struct tomoyo_number_union major
;
466 struct tomoyo_number_union minor
;
470 * Structure for "file rename", "file link" and "file pivot_root" directive.
472 struct tomoyo_path2_acl
{
473 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH2_ACL */
474 u8 perm
; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
475 struct tomoyo_name_union name1
;
476 struct tomoyo_name_union name2
;
479 /* Structure for "file mount" directive. */
480 struct tomoyo_mount_acl
{
481 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MOUNT_ACL */
482 struct tomoyo_name_union dev_name
;
483 struct tomoyo_name_union dir_name
;
484 struct tomoyo_name_union fs_type
;
485 struct tomoyo_number_union flags
;
488 /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
489 struct tomoyo_acl_param
{
491 struct list_head
*list
;
492 struct tomoyo_policy_namespace
*ns
;
496 #define TOMOYO_MAX_IO_READ_QUEUE 64
499 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
502 struct tomoyo_io_buffer
{
503 void (*read
) (struct tomoyo_io_buffer
*);
504 int (*write
) (struct tomoyo_io_buffer
*);
505 int (*poll
) (struct file
*file
, poll_table
*wait
);
506 /* Exclusive lock for this structure. */
508 char __user
*read_user_buf
;
509 size_t read_user_buf_avail
;
511 struct list_head
*ns
;
512 struct list_head
*domain
;
513 struct list_head
*group
;
514 struct list_head
*acl
;
517 unsigned int query_index
;
525 bool print_this_domain_only
;
526 bool print_transition_related_only
;
527 bool print_cond_part
;
528 const char *w
[TOMOYO_MAX_IO_READ_QUEUE
];
531 struct tomoyo_policy_namespace
*ns
;
532 /* The position currently writing to. */
533 struct tomoyo_domain_info
*domain
;
534 /* Bytes available for writing. */
538 /* Buffer for reading. */
540 /* Size of read buffer. */
542 /* Buffer for writing. */
544 /* Size of write buffer. */
545 size_t writebuf_size
;
546 /* Type of this interface. */
547 enum tomoyo_securityfs_interface_index type
;
548 /* Users counter protected by tomoyo_io_buffer_list_lock. */
550 /* List for telling GC not to kfree() elements. */
551 struct list_head list
;
555 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
556 * "no_keep_domain" keyword.
558 struct tomoyo_transition_control
{
559 struct tomoyo_acl_head head
;
560 u8 type
; /* One of values in "enum tomoyo_transition_type". */
561 /* True if the domainname is tomoyo_get_last_name(). */
563 const struct tomoyo_path_info
*domainname
; /* Maybe NULL */
564 const struct tomoyo_path_info
*program
; /* Maybe NULL */
567 /* Structure for "aggregator" keyword. */
568 struct tomoyo_aggregator
{
569 struct tomoyo_acl_head head
;
570 const struct tomoyo_path_info
*original_name
;
571 const struct tomoyo_path_info
*aggregated_name
;
574 /* Structure for policy manager. */
575 struct tomoyo_manager
{
576 struct tomoyo_acl_head head
;
577 bool is_domain
; /* True if manager is a domainname. */
578 /* A path to program or a domainname. */
579 const struct tomoyo_path_info
*manager
;
582 struct tomoyo_preference
{
583 unsigned int learning_max_entry
;
584 bool enforcing_verbose
;
585 bool learning_verbose
;
586 bool permissive_verbose
;
589 /* Structure for /sys/kernel/security/tomnoyo/profile interface. */
590 struct tomoyo_profile
{
591 const struct tomoyo_path_info
*comment
;
592 struct tomoyo_preference
*learning
;
593 struct tomoyo_preference
*permissive
;
594 struct tomoyo_preference
*enforcing
;
595 struct tomoyo_preference preference
;
597 u8 config
[TOMOYO_MAX_MAC_INDEX
+ TOMOYO_MAX_MAC_CATEGORY_INDEX
];
598 unsigned int pref
[TOMOYO_MAX_PREF
];
601 /* Structure for representing YYYY/MM/DD hh/mm/ss. */
611 /* Structure for policy namespace. */
612 struct tomoyo_policy_namespace
{
613 /* Profile table. Memory is allocated as needed. */
614 struct tomoyo_profile
*profile_ptr
[TOMOYO_MAX_PROFILES
];
615 /* List of "struct tomoyo_group". */
616 struct list_head group_list
[TOMOYO_MAX_GROUP
];
617 /* List of policy. */
618 struct list_head policy_list
[TOMOYO_MAX_POLICY
];
619 /* The global ACL referred by "use_group" keyword. */
620 struct list_head acl_group
[TOMOYO_MAX_ACL_GROUPS
];
621 /* List for connecting to tomoyo_namespace_list list. */
622 struct list_head namespace_list
;
623 /* Profile version. Currently only 20100903 is defined. */
624 unsigned int profile_version
;
625 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
629 /********** Function prototypes. **********/
631 bool tomoyo_compare_number_union(const unsigned long value
,
632 const struct tomoyo_number_union
*ptr
);
633 bool tomoyo_condition(struct tomoyo_request_info
*r
,
634 const struct tomoyo_condition
*cond
);
635 bool tomoyo_correct_domain(const unsigned char *domainname
);
636 bool tomoyo_correct_path(const char *filename
);
637 bool tomoyo_correct_word(const char *string
);
638 bool tomoyo_domain_def(const unsigned char *buffer
);
639 bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info
*r
);
640 bool tomoyo_memory_ok(void *ptr
);
641 bool tomoyo_number_matches_group(const unsigned long min
,
642 const unsigned long max
,
643 const struct tomoyo_group
*group
);
644 bool tomoyo_parse_name_union(struct tomoyo_acl_param
*param
,
645 struct tomoyo_name_union
*ptr
);
646 bool tomoyo_parse_number_union(struct tomoyo_acl_param
*param
,
647 struct tomoyo_number_union
*ptr
);
648 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info
*filename
,
649 const struct tomoyo_path_info
*pattern
);
650 bool tomoyo_permstr(const char *string
, const char *keyword
);
651 bool tomoyo_str_starts(char **src
, const char *find
);
652 char *tomoyo_encode(const char *str
);
653 char *tomoyo_init_log(struct tomoyo_request_info
*r
, int len
, const char *fmt
,
655 char *tomoyo_read_token(struct tomoyo_acl_param
*param
);
656 char *tomoyo_realpath_from_path(struct path
*path
);
657 char *tomoyo_realpath_nofollow(const char *pathname
);
658 const char *tomoyo_get_exe(void);
659 const char *tomoyo_yesno(const unsigned int value
);
660 const struct tomoyo_path_info
*tomoyo_compare_name_union
661 (const struct tomoyo_path_info
*name
, const struct tomoyo_name_union
*ptr
);
662 const struct tomoyo_path_info
*tomoyo_get_name(const char *name
);
663 const struct tomoyo_path_info
*tomoyo_path_matches_group
664 (const struct tomoyo_path_info
*pathname
, const struct tomoyo_group
*group
);
665 int tomoyo_check_open_permission(struct tomoyo_domain_info
*domain
,
666 struct path
*path
, const int flag
);
667 int tomoyo_close_control(struct tomoyo_io_buffer
*head
);
668 int tomoyo_find_next_domain(struct linux_binprm
*bprm
);
669 int tomoyo_get_mode(const struct tomoyo_policy_namespace
*ns
, const u8 profile
,
671 int tomoyo_init_request_info(struct tomoyo_request_info
*r
,
672 struct tomoyo_domain_info
*domain
,
674 int tomoyo_mkdev_perm(const u8 operation
, struct path
*path
,
675 const unsigned int mode
, unsigned int dev
);
676 int tomoyo_mount_permission(char *dev_name
, struct path
*path
,
677 const char *type
, unsigned long flags
,
679 int tomoyo_open_control(const u8 type
, struct file
*file
);
680 int tomoyo_path2_perm(const u8 operation
, struct path
*path1
,
682 int tomoyo_path_number_perm(const u8 operation
, struct path
*path
,
683 unsigned long number
);
684 int tomoyo_path_perm(const u8 operation
, struct path
*path
);
685 int tomoyo_path_permission(struct tomoyo_request_info
*r
, u8 operation
,
686 const struct tomoyo_path_info
*filename
);
687 int tomoyo_poll_control(struct file
*file
, poll_table
*wait
);
688 int tomoyo_poll_log(struct file
*file
, poll_table
*wait
);
689 int tomoyo_supervisor(struct tomoyo_request_info
*r
, const char *fmt
, ...)
691 int tomoyo_update_domain(struct tomoyo_acl_info
*new_entry
, const int size
,
692 struct tomoyo_acl_param
*param
,
693 bool (*check_duplicate
)
694 (const struct tomoyo_acl_info
*,
695 const struct tomoyo_acl_info
*),
696 bool (*merge_duplicate
)
697 (struct tomoyo_acl_info
*, struct tomoyo_acl_info
*,
699 int tomoyo_update_policy(struct tomoyo_acl_head
*new_entry
, const int size
,
700 struct tomoyo_acl_param
*param
,
701 bool (*check_duplicate
)
702 (const struct tomoyo_acl_head
*,
703 const struct tomoyo_acl_head
*));
704 int tomoyo_write_aggregator(struct tomoyo_acl_param
*param
);
705 int tomoyo_write_file(struct tomoyo_acl_param
*param
);
706 int tomoyo_write_group(struct tomoyo_acl_param
*param
, const u8 type
);
707 int tomoyo_write_transition_control(struct tomoyo_acl_param
*param
,
709 ssize_t
tomoyo_read_control(struct tomoyo_io_buffer
*head
, char __user
*buffer
,
710 const int buffer_len
);
711 ssize_t
tomoyo_write_control(struct tomoyo_io_buffer
*head
,
712 const char __user
*buffer
, const int buffer_len
);
713 struct tomoyo_condition
*tomoyo_get_condition(struct tomoyo_acl_param
*param
);
714 struct tomoyo_domain_info
*tomoyo_assign_domain(const char *domainname
,
716 struct tomoyo_domain_info
*tomoyo_find_domain(const char *domainname
);
717 struct tomoyo_group
*tomoyo_get_group(struct tomoyo_acl_param
*param
,
719 struct tomoyo_policy_namespace
*tomoyo_assign_namespace
720 (const char *domainname
);
721 struct tomoyo_profile
*tomoyo_profile(const struct tomoyo_policy_namespace
*ns
,
723 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info
*domain
,
725 u8
tomoyo_parse_ulong(unsigned long *result
, char **str
);
726 void *tomoyo_commit_ok(void *data
, const unsigned int size
);
727 void __init
tomoyo_load_builtin_policy(void);
728 void __init
tomoyo_mm_init(void);
729 void tomoyo_check_acl(struct tomoyo_request_info
*r
,
730 bool (*check_entry
) (struct tomoyo_request_info
*,
731 const struct tomoyo_acl_info
*));
732 void tomoyo_check_profile(void);
733 void tomoyo_convert_time(time_t time
, struct tomoyo_time
*stamp
);
734 void tomoyo_del_condition(struct list_head
*element
);
735 void tomoyo_fill_path_info(struct tomoyo_path_info
*ptr
);
736 void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace
*ns
);
737 void tomoyo_io_printf(struct tomoyo_io_buffer
*head
, const char *fmt
, ...)
739 void tomoyo_load_policy(const char *filename
);
740 void tomoyo_memory_free(void *ptr
);
741 void tomoyo_normalize_line(unsigned char *buffer
);
742 void tomoyo_notify_gc(struct tomoyo_io_buffer
*head
, const bool is_register
);
743 void tomoyo_print_ulong(char *buffer
, const int buffer_len
,
744 const unsigned long value
, const u8 type
);
745 void tomoyo_put_name_union(struct tomoyo_name_union
*ptr
);
746 void tomoyo_put_number_union(struct tomoyo_number_union
*ptr
);
747 void tomoyo_read_log(struct tomoyo_io_buffer
*head
);
748 void tomoyo_update_stat(const u8 index
);
749 void tomoyo_warn_oom(const char *function
);
750 void tomoyo_write_log(struct tomoyo_request_info
*r
, const char *fmt
, ...)
752 void tomoyo_write_log2(struct tomoyo_request_info
*r
, int len
, const char *fmt
,
755 /********** External variable definitions. **********/
757 extern bool tomoyo_policy_loaded
;
758 extern const char * const tomoyo_condition_keyword
759 [TOMOYO_MAX_CONDITION_KEYWORD
];
760 extern const char * const tomoyo_dif
[TOMOYO_MAX_DOMAIN_INFO_FLAGS
];
761 extern const char * const tomoyo_mac_keywords
[TOMOYO_MAX_MAC_INDEX
762 + TOMOYO_MAX_MAC_CATEGORY_INDEX
];
763 extern const char * const tomoyo_mode
[TOMOYO_CONFIG_MAX_MODE
];
764 extern const char * const tomoyo_path_keyword
[TOMOYO_MAX_PATH_OPERATION
];
765 extern const u8 tomoyo_index2category
[TOMOYO_MAX_MAC_INDEX
];
766 extern const u8 tomoyo_pn2mac
[TOMOYO_MAX_PATH_NUMBER_OPERATION
];
767 extern const u8 tomoyo_pnnn2mac
[TOMOYO_MAX_MKDEV_OPERATION
];
768 extern const u8 tomoyo_pp2mac
[TOMOYO_MAX_PATH2_OPERATION
];
769 extern struct list_head tomoyo_condition_list
;
770 extern struct list_head tomoyo_domain_list
;
771 extern struct list_head tomoyo_name_list
[TOMOYO_MAX_HASH
];
772 extern struct list_head tomoyo_namespace_list
;
773 extern struct mutex tomoyo_policy_lock
;
774 extern struct srcu_struct tomoyo_ss
;
775 extern struct tomoyo_domain_info tomoyo_kernel_domain
;
776 extern struct tomoyo_policy_namespace tomoyo_kernel_namespace
;
777 extern unsigned int tomoyo_memory_quota
[TOMOYO_MAX_MEMORY_STAT
];
778 extern unsigned int tomoyo_memory_used
[TOMOYO_MAX_MEMORY_STAT
];
780 /********** Inlined functions. **********/
783 * tomoyo_read_lock - Take lock for protecting policy.
785 * Returns index number for tomoyo_read_unlock().
787 static inline int tomoyo_read_lock(void)
789 return srcu_read_lock(&tomoyo_ss
);
793 * tomoyo_read_unlock - Release lock for protecting policy.
795 * @idx: Index number returned by tomoyo_read_lock().
799 static inline void tomoyo_read_unlock(int idx
)
801 srcu_read_unlock(&tomoyo_ss
, idx
);
805 * tomoyo_sys_getppid - Copy of getppid().
807 * Returns parent process's PID.
809 * Alpha does not have getppid() defined. To be able to build this module on
810 * Alpha, I have to copy getppid() from kernel/timer.c.
812 static inline pid_t
tomoyo_sys_getppid(void)
816 pid
= task_tgid_vnr(current
->real_parent
);
822 * tomoyo_sys_getpid - Copy of getpid().
824 * Returns current thread's PID.
826 * Alpha does not have getpid() defined. To be able to build this module on
827 * Alpha, I have to copy getpid() from kernel/timer.c.
829 static inline pid_t
tomoyo_sys_getpid(void)
831 return task_tgid_vnr(current
);
835 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
837 * @a: Pointer to "struct tomoyo_path_info".
838 * @b: Pointer to "struct tomoyo_path_info".
840 * Returns true if @a == @b, false otherwise.
842 static inline bool tomoyo_pathcmp(const struct tomoyo_path_info
*a
,
843 const struct tomoyo_path_info
*b
)
845 return a
->hash
!= b
->hash
|| strcmp(a
->name
, b
->name
);
849 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
851 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
855 static inline void tomoyo_put_name(const struct tomoyo_path_info
*name
)
858 struct tomoyo_name
*ptr
=
859 container_of(name
, typeof(*ptr
), entry
);
860 atomic_dec(&ptr
->head
.users
);
865 * tomoyo_put_condition - Drop reference on "struct tomoyo_condition".
867 * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
871 static inline void tomoyo_put_condition(struct tomoyo_condition
*cond
)
874 atomic_dec(&cond
->head
.users
);
878 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
880 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
884 static inline void tomoyo_put_group(struct tomoyo_group
*group
)
887 atomic_dec(&group
->head
.users
);
891 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
893 * Returns pointer to "struct tomoyo_domain_info" for current thread.
895 static inline struct tomoyo_domain_info
*tomoyo_domain(void)
897 return current_cred()->security
;
901 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
903 * @task: Pointer to "struct task_struct".
905 * Returns pointer to "struct tomoyo_security" for specified thread.
907 static inline struct tomoyo_domain_info
*tomoyo_real_domain(struct task_struct
910 return task_cred_xxx(task
, security
);
914 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
916 * @a: Pointer to "struct tomoyo_name_union".
917 * @b: Pointer to "struct tomoyo_name_union".
919 * Returns true if @a == @b, false otherwise.
921 static inline bool tomoyo_same_name_union
922 (const struct tomoyo_name_union
*a
, const struct tomoyo_name_union
*b
)
924 return a
->filename
== b
->filename
&& a
->group
== b
->group
;
928 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
930 * @a: Pointer to "struct tomoyo_number_union".
931 * @b: Pointer to "struct tomoyo_number_union".
933 * Returns true if @a == @b, false otherwise.
935 static inline bool tomoyo_same_number_union
936 (const struct tomoyo_number_union
*a
, const struct tomoyo_number_union
*b
)
938 return a
->values
[0] == b
->values
[0] && a
->values
[1] == b
->values
[1] &&
939 a
->group
== b
->group
&& a
->value_type
[0] == b
->value_type
[0] &&
940 a
->value_type
[1] == b
->value_type
[1];
944 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
946 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
948 static inline struct tomoyo_policy_namespace
*tomoyo_current_namespace(void)
950 return tomoyo_domain()->ns
;
953 #if defined(CONFIG_SLOB)
956 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
958 * @size: Size to be rounded up.
962 * Since SLOB does not round up, this function simply returns @size.
964 static inline int tomoyo_round2(size_t size
)
972 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
974 * @size: Size to be rounded up.
976 * Returns rounded size.
978 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
981 static inline int tomoyo_round2(size_t size
)
983 #if PAGE_SIZE == 4096
998 * list_for_each_cookie - iterate over a list with cookie.
999 * @pos: the &struct list_head to use as a loop cursor.
1000 * @head: the head for your list.
1002 #define list_for_each_cookie(pos, head) \
1004 pos = srcu_dereference((head)->next, &tomoyo_ss); \
1005 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
1007 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */