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>
26 /********** Constants definitions. **********/
29 * TOMOYO uses this hash only when appending a string into the string
30 * table. Frequency of appending strings is very low. So we don't need
31 * large (e.g. 64k) hash size. 256 will be sufficient.
33 #define TOMOYO_HASH_BITS 8
34 #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
36 #define TOMOYO_EXEC_TMPSIZE 4096
38 /* Profile number is an integer between 0 and 255. */
39 #define TOMOYO_MAX_PROFILES 256
41 /* Group number is an integer between 0 and 255. */
42 #define TOMOYO_MAX_ACL_GROUPS 256
44 /* Index numbers for operation mode. */
45 enum tomoyo_mode_index
{
46 TOMOYO_CONFIG_DISABLED
,
47 TOMOYO_CONFIG_LEARNING
,
48 TOMOYO_CONFIG_PERMISSIVE
,
49 TOMOYO_CONFIG_ENFORCING
,
50 TOMOYO_CONFIG_MAX_MODE
,
51 TOMOYO_CONFIG_WANT_REJECT_LOG
= 64,
52 TOMOYO_CONFIG_WANT_GRANT_LOG
= 128,
53 TOMOYO_CONFIG_USE_DEFAULT
= 255,
56 /* Index numbers for entry type. */
57 enum tomoyo_policy_id
{
60 TOMOYO_ID_NUMBER_GROUP
,
61 TOMOYO_ID_TRANSITION_CONTROL
,
70 /* Index numbers for domain's attributes. */
71 enum tomoyo_domain_info_flags_index
{
72 /* Quota warnning flag. */
73 TOMOYO_DIF_QUOTA_WARNED
,
75 * This domain was unable to create a new domain at
76 * tomoyo_find_next_domain() because the name of the domain to be
77 * created was too long or it could not allocate memory.
78 * More than one process continued execve() without domain transition.
80 TOMOYO_DIF_TRANSITION_FAILED
,
81 TOMOYO_MAX_DOMAIN_INFO_FLAGS
84 /* Index numbers for group entries. */
85 enum tomoyo_group_id
{
91 /* Index numbers for type of numeric values. */
92 enum tomoyo_value_type
{
93 TOMOYO_VALUE_TYPE_INVALID
,
94 TOMOYO_VALUE_TYPE_DECIMAL
,
95 TOMOYO_VALUE_TYPE_OCTAL
,
96 TOMOYO_VALUE_TYPE_HEXADECIMAL
,
99 /* Index numbers for domain transition control keywords. */
100 enum tomoyo_transition_type
{
101 /* Do not change this order, */
102 TOMOYO_TRANSITION_CONTROL_NO_RESET
,
103 TOMOYO_TRANSITION_CONTROL_RESET
,
104 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE
,
105 TOMOYO_TRANSITION_CONTROL_INITIALIZE
,
106 TOMOYO_TRANSITION_CONTROL_NO_KEEP
,
107 TOMOYO_TRANSITION_CONTROL_KEEP
,
108 TOMOYO_MAX_TRANSITION_TYPE
111 /* Index numbers for Access Controls. */
112 enum tomoyo_acl_entry_type_index
{
113 TOMOYO_TYPE_PATH_ACL
,
114 TOMOYO_TYPE_PATH2_ACL
,
115 TOMOYO_TYPE_PATH_NUMBER_ACL
,
116 TOMOYO_TYPE_MKDEV_ACL
,
117 TOMOYO_TYPE_MOUNT_ACL
,
120 /* Index numbers for access controls with one pathname. */
121 enum tomoyo_path_acl_index
{
129 TOMOYO_TYPE_TRUNCATE
,
133 TOMOYO_MAX_PATH_OPERATION
136 enum tomoyo_memory_stat_type
{
137 TOMOYO_MEMORY_POLICY
,
140 TOMOYO_MAX_MEMORY_STAT
143 enum tomoyo_mkdev_acl_index
{
146 TOMOYO_MAX_MKDEV_OPERATION
149 /* Index numbers for access controls with two pathnames. */
150 enum tomoyo_path2_acl_index
{
153 TOMOYO_TYPE_PIVOT_ROOT
,
154 TOMOYO_MAX_PATH2_OPERATION
157 /* Index numbers for access controls with one pathname and one number. */
158 enum tomoyo_path_number_acl_index
{
167 TOMOYO_MAX_PATH_NUMBER_OPERATION
170 /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
171 enum tomoyo_securityfs_interface_index
{
173 TOMOYO_EXCEPTIONPOLICY
,
174 TOMOYO_DOMAIN_STATUS
,
175 TOMOYO_PROCESS_STATUS
,
185 /* Index numbers for special mount operations. */
186 enum tomoyo_special_mount
{
187 TOMOYO_MOUNT_BIND
, /* mount --bind /source /dest */
188 TOMOYO_MOUNT_MOVE
, /* mount --move /old /new */
189 TOMOYO_MOUNT_REMOUNT
, /* mount -o remount /dir */
190 TOMOYO_MOUNT_MAKE_UNBINDABLE
, /* mount --make-unbindable /dir */
191 TOMOYO_MOUNT_MAKE_PRIVATE
, /* mount --make-private /dir */
192 TOMOYO_MOUNT_MAKE_SLAVE
, /* mount --make-slave /dir */
193 TOMOYO_MOUNT_MAKE_SHARED
, /* mount --make-shared /dir */
194 TOMOYO_MAX_SPECIAL_MOUNT
197 /* Index numbers for functionality. */
198 enum tomoyo_mac_index
{
199 TOMOYO_MAC_FILE_EXECUTE
,
200 TOMOYO_MAC_FILE_OPEN
,
201 TOMOYO_MAC_FILE_CREATE
,
202 TOMOYO_MAC_FILE_UNLINK
,
203 TOMOYO_MAC_FILE_GETATTR
,
204 TOMOYO_MAC_FILE_MKDIR
,
205 TOMOYO_MAC_FILE_RMDIR
,
206 TOMOYO_MAC_FILE_MKFIFO
,
207 TOMOYO_MAC_FILE_MKSOCK
,
208 TOMOYO_MAC_FILE_TRUNCATE
,
209 TOMOYO_MAC_FILE_SYMLINK
,
210 TOMOYO_MAC_FILE_MKBLOCK
,
211 TOMOYO_MAC_FILE_MKCHAR
,
212 TOMOYO_MAC_FILE_LINK
,
213 TOMOYO_MAC_FILE_RENAME
,
214 TOMOYO_MAC_FILE_CHMOD
,
215 TOMOYO_MAC_FILE_CHOWN
,
216 TOMOYO_MAC_FILE_CHGRP
,
217 TOMOYO_MAC_FILE_IOCTL
,
218 TOMOYO_MAC_FILE_CHROOT
,
219 TOMOYO_MAC_FILE_MOUNT
,
220 TOMOYO_MAC_FILE_UMOUNT
,
221 TOMOYO_MAC_FILE_PIVOT_ROOT
,
225 /* Index numbers for category of functionality. */
226 enum tomoyo_mac_category_index
{
227 TOMOYO_MAC_CATEGORY_FILE
,
228 TOMOYO_MAX_MAC_CATEGORY_INDEX
232 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
233 * occurred in enforcing mode and the userspace daemon decided to retry.
235 * We must choose a positive value in order to distinguish "granted" (which is
236 * 0) and "rejected" (which is a negative value) and "retry".
238 #define TOMOYO_RETRY_REQUEST 1
240 /* Index numbers for profile's PREFERENCE values. */
241 enum tomoyo_pref_index
{
242 TOMOYO_PREF_MAX_AUDIT_LOG
,
243 TOMOYO_PREF_MAX_LEARNING_ENTRY
,
247 /********** Structure definitions. **********/
249 /* Common header for holding ACL entries. */
250 struct tomoyo_acl_head
{
251 struct list_head list
;
255 /* Common header for shared entries. */
256 struct tomoyo_shared_acl_head
{
257 struct list_head list
;
261 struct tomoyo_policy_namespace
;
263 /* Structure for request info. */
264 struct tomoyo_request_info
{
265 struct tomoyo_domain_info
*domain
;
266 /* For holding parameters. */
269 const struct tomoyo_path_info
*filename
;
270 /* For using wildcards at tomoyo_find_next_domain(). */
271 const struct tomoyo_path_info
*matched_path
;
272 /* One of values in "enum tomoyo_path_acl_index". */
276 const struct tomoyo_path_info
*filename1
;
277 const struct tomoyo_path_info
*filename2
;
278 /* One of values in "enum tomoyo_path2_acl_index". */
282 const struct tomoyo_path_info
*filename
;
286 /* One of values in "enum tomoyo_mkdev_acl_index". */
290 const struct tomoyo_path_info
*filename
;
291 unsigned long number
;
294 * "enum tomoyo_path_number_acl_index".
299 const struct tomoyo_path_info
*type
;
300 const struct tomoyo_path_info
*dir
;
301 const struct tomoyo_path_info
*dev
;
310 u8 mode
; /* One of tomoyo_mode_index . */
314 /* Structure for holding a token. */
315 struct tomoyo_path_info
{
317 u32 hash
; /* = full_name_hash(name, strlen(name)) */
318 u16 const_len
; /* = tomoyo_const_part_length(name) */
319 bool is_dir
; /* = tomoyo_strendswith(name, "/") */
320 bool is_patterned
; /* = tomoyo_path_contains_pattern(name) */
323 /* Structure for holding string data. */
325 struct tomoyo_shared_acl_head head
;
326 struct tomoyo_path_info entry
;
329 /* Structure for holding a word. */
330 struct tomoyo_name_union
{
331 /* Either @filename or @group is NULL. */
332 const struct tomoyo_path_info
*filename
;
333 struct tomoyo_group
*group
;
336 /* Structure for holding a number. */
337 struct tomoyo_number_union
{
338 unsigned long values
[2];
339 struct tomoyo_group
*group
; /* Maybe NULL. */
340 /* One of values in "enum tomoyo_value_type". */
344 /* Structure for "path_group"/"number_group" directive. */
345 struct tomoyo_group
{
346 struct tomoyo_shared_acl_head head
;
347 const struct tomoyo_path_info
*group_name
;
348 struct list_head member_list
;
351 /* Structure for "path_group" directive. */
352 struct tomoyo_path_group
{
353 struct tomoyo_acl_head head
;
354 const struct tomoyo_path_info
*member_name
;
357 /* Structure for "number_group" directive. */
358 struct tomoyo_number_group
{
359 struct tomoyo_acl_head head
;
360 struct tomoyo_number_union number
;
363 /* Common header for individual entries. */
364 struct tomoyo_acl_info
{
365 struct list_head list
;
367 u8 type
; /* One of values in "enum tomoyo_acl_entry_type_index". */
370 /* Structure for domain information. */
371 struct tomoyo_domain_info
{
372 struct list_head list
;
373 struct list_head acl_info_list
;
374 /* Name of this domain. Never NULL. */
375 const struct tomoyo_path_info
*domainname
;
376 /* Namespace for this domain. Never NULL. */
377 struct tomoyo_policy_namespace
*ns
;
378 u8 profile
; /* Profile number to use. */
379 u8 group
; /* Group number to use. */
380 bool is_deleted
; /* Delete flag. */
381 bool flags
[TOMOYO_MAX_DOMAIN_INFO_FLAGS
];
382 atomic_t users
; /* Number of referring credentials. */
386 * Structure for "file execute", "file read", "file write", "file append",
387 * "file unlink", "file getattr", "file rmdir", "file truncate",
388 * "file symlink", "file chroot" and "file unmount" directive.
390 struct tomoyo_path_acl
{
391 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_ACL */
392 u16 perm
; /* Bitmask of values in "enum tomoyo_path_acl_index". */
393 struct tomoyo_name_union name
;
397 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
398 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
400 struct tomoyo_path_number_acl
{
401 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
402 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
404 struct tomoyo_name_union name
;
405 struct tomoyo_number_union number
;
408 /* Structure for "file mkblock" and "file mkchar" directive. */
409 struct tomoyo_mkdev_acl
{
410 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MKDEV_ACL */
411 u8 perm
; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
412 struct tomoyo_name_union name
;
413 struct tomoyo_number_union mode
;
414 struct tomoyo_number_union major
;
415 struct tomoyo_number_union minor
;
419 * Structure for "file rename", "file link" and "file pivot_root" directive.
421 struct tomoyo_path2_acl
{
422 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH2_ACL */
423 u8 perm
; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
424 struct tomoyo_name_union name1
;
425 struct tomoyo_name_union name2
;
428 /* Structure for "file mount" directive. */
429 struct tomoyo_mount_acl
{
430 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MOUNT_ACL */
431 struct tomoyo_name_union dev_name
;
432 struct tomoyo_name_union dir_name
;
433 struct tomoyo_name_union fs_type
;
434 struct tomoyo_number_union flags
;
437 /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
438 struct tomoyo_acl_param
{
440 struct list_head
*list
;
441 struct tomoyo_policy_namespace
*ns
;
445 #define TOMOYO_MAX_IO_READ_QUEUE 64
448 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
451 struct tomoyo_io_buffer
{
452 void (*read
) (struct tomoyo_io_buffer
*);
453 int (*write
) (struct tomoyo_io_buffer
*);
454 int (*poll
) (struct file
*file
, poll_table
*wait
);
455 /* Exclusive lock for this structure. */
457 char __user
*read_user_buf
;
458 size_t read_user_buf_avail
;
460 struct list_head
*ns
;
461 struct list_head
*domain
;
462 struct list_head
*group
;
463 struct list_head
*acl
;
466 unsigned int query_index
;
472 bool print_this_domain_only
;
473 bool print_transition_related_only
;
474 const char *w
[TOMOYO_MAX_IO_READ_QUEUE
];
477 struct tomoyo_policy_namespace
*ns
;
478 /* The position currently writing to. */
479 struct tomoyo_domain_info
*domain
;
480 /* Bytes available for writing. */
484 /* Buffer for reading. */
486 /* Size of read buffer. */
488 /* Buffer for writing. */
490 /* Size of write buffer. */
491 size_t writebuf_size
;
492 /* Type of this interface. */
493 enum tomoyo_securityfs_interface_index type
;
494 /* Users counter protected by tomoyo_io_buffer_list_lock. */
496 /* List for telling GC not to kfree() elements. */
497 struct list_head list
;
501 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
502 * "no_keep_domain" keyword.
504 struct tomoyo_transition_control
{
505 struct tomoyo_acl_head head
;
506 u8 type
; /* One of values in "enum tomoyo_transition_type". */
507 /* True if the domainname is tomoyo_get_last_name(). */
509 const struct tomoyo_path_info
*domainname
; /* Maybe NULL */
510 const struct tomoyo_path_info
*program
; /* Maybe NULL */
513 /* Structure for "aggregator" keyword. */
514 struct tomoyo_aggregator
{
515 struct tomoyo_acl_head head
;
516 const struct tomoyo_path_info
*original_name
;
517 const struct tomoyo_path_info
*aggregated_name
;
520 /* Structure for policy manager. */
521 struct tomoyo_manager
{
522 struct tomoyo_acl_head head
;
523 bool is_domain
; /* True if manager is a domainname. */
524 /* A path to program or a domainname. */
525 const struct tomoyo_path_info
*manager
;
528 struct tomoyo_preference
{
529 unsigned int learning_max_entry
;
530 bool enforcing_verbose
;
531 bool learning_verbose
;
532 bool permissive_verbose
;
535 /* Structure for /sys/kernel/security/tomnoyo/profile interface. */
536 struct tomoyo_profile
{
537 const struct tomoyo_path_info
*comment
;
538 struct tomoyo_preference
*learning
;
539 struct tomoyo_preference
*permissive
;
540 struct tomoyo_preference
*enforcing
;
541 struct tomoyo_preference preference
;
543 u8 config
[TOMOYO_MAX_MAC_INDEX
+ TOMOYO_MAX_MAC_CATEGORY_INDEX
];
544 unsigned int pref
[TOMOYO_MAX_PREF
];
547 /* Structure for representing YYYY/MM/DD hh/mm/ss. */
557 /* Structure for policy namespace. */
558 struct tomoyo_policy_namespace
{
559 /* Profile table. Memory is allocated as needed. */
560 struct tomoyo_profile
*profile_ptr
[TOMOYO_MAX_PROFILES
];
561 /* List of "struct tomoyo_group". */
562 struct list_head group_list
[TOMOYO_MAX_GROUP
];
563 /* List of policy. */
564 struct list_head policy_list
[TOMOYO_MAX_POLICY
];
565 /* The global ACL referred by "use_group" keyword. */
566 struct list_head acl_group
[TOMOYO_MAX_ACL_GROUPS
];
567 /* List for connecting to tomoyo_namespace_list list. */
568 struct list_head namespace_list
;
569 /* Profile version. Currently only 20100903 is defined. */
570 unsigned int profile_version
;
571 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
575 /********** Function prototypes. **********/
577 void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace
*ns
);
578 bool tomoyo_str_starts(char **src
, const char *find
);
579 const char *tomoyo_get_exe(void);
580 void tomoyo_normalize_line(unsigned char *buffer
);
581 void tomoyo_check_profile(void);
582 int tomoyo_open_control(const u8 type
, struct file
*file
);
583 int tomoyo_close_control(struct tomoyo_io_buffer
*head
);
584 int tomoyo_poll_control(struct file
*file
, poll_table
*wait
);
585 ssize_t
tomoyo_read_control(struct tomoyo_io_buffer
*head
, char __user
*buffer
,
586 const int buffer_len
);
587 ssize_t
tomoyo_write_control(struct tomoyo_io_buffer
*head
,
588 const char __user
*buffer
, const int buffer_len
);
589 bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info
*r
);
590 void tomoyo_warn_oom(const char *function
);
591 const struct tomoyo_path_info
*
592 tomoyo_compare_name_union(const struct tomoyo_path_info
*name
,
593 const struct tomoyo_name_union
*ptr
);
594 bool tomoyo_compare_number_union(const unsigned long value
,
595 const struct tomoyo_number_union
*ptr
);
596 int tomoyo_get_mode(const struct tomoyo_policy_namespace
*ns
, const u8 profile
,
598 void tomoyo_io_printf(struct tomoyo_io_buffer
*head
, const char *fmt
, ...)
599 __attribute__ ((format(printf
, 2, 3)));
600 bool tomoyo_correct_domain(const unsigned char *domainname
);
601 bool tomoyo_correct_path(const char *filename
);
602 bool tomoyo_correct_word(const char *string
);
603 bool tomoyo_domain_def(const unsigned char *buffer
);
604 bool tomoyo_parse_name_union(struct tomoyo_acl_param
*param
,
605 struct tomoyo_name_union
*ptr
);
606 const struct tomoyo_path_info
*
607 tomoyo_path_matches_group(const struct tomoyo_path_info
*pathname
,
608 const struct tomoyo_group
*group
);
609 bool tomoyo_number_matches_group(const unsigned long min
,
610 const unsigned long max
,
611 const struct tomoyo_group
*group
);
612 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info
*filename
,
613 const struct tomoyo_path_info
*pattern
);
614 bool tomoyo_parse_number_union(struct tomoyo_acl_param
*param
,
615 struct tomoyo_number_union
*ptr
);
616 bool tomoyo_tokenize(char *buffer
, char *w
[], size_t size
);
617 bool tomoyo_verbose_mode(const struct tomoyo_domain_info
*domain
);
618 int tomoyo_init_request_info(struct tomoyo_request_info
*r
,
619 struct tomoyo_domain_info
*domain
,
621 int tomoyo_mount_permission(char *dev_name
, struct path
*path
,
622 const char *type
, unsigned long flags
,
624 int tomoyo_write_aggregator(struct tomoyo_acl_param
*param
);
625 int tomoyo_write_transition_control(struct tomoyo_acl_param
*param
,
627 int tomoyo_write_file(struct tomoyo_acl_param
*param
);
628 int tomoyo_write_group(struct tomoyo_acl_param
*param
, const u8 type
);
629 int tomoyo_supervisor(struct tomoyo_request_info
*r
, const char *fmt
, ...)
630 __attribute__ ((format(printf
, 2, 3)));
631 struct tomoyo_domain_info
*tomoyo_find_domain(const char *domainname
);
632 struct tomoyo_domain_info
*tomoyo_assign_domain(const char *domainname
,
634 struct tomoyo_profile
*tomoyo_profile(const struct tomoyo_policy_namespace
*ns
,
636 struct tomoyo_policy_namespace
*tomoyo_assign_namespace
637 (const char *domainname
);
638 struct tomoyo_group
*tomoyo_get_group(struct tomoyo_acl_param
*param
,
640 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info
*domain
,
642 void tomoyo_fill_path_info(struct tomoyo_path_info
*ptr
);
643 void tomoyo_load_policy(const char *filename
);
644 void tomoyo_put_number_union(struct tomoyo_number_union
*ptr
);
645 char *tomoyo_encode(const char *str
);
646 char *tomoyo_realpath_nofollow(const char *pathname
);
647 char *tomoyo_realpath_from_path(struct path
*path
);
648 bool tomoyo_memory_ok(void *ptr
);
649 void *tomoyo_commit_ok(void *data
, const unsigned int size
);
650 const struct tomoyo_path_info
*tomoyo_get_name(const char *name
);
651 void tomoyo_read_memory_counter(struct tomoyo_io_buffer
*head
);
652 int tomoyo_write_memory_quota(struct tomoyo_io_buffer
*head
);
653 void __init
tomoyo_mm_init(void);
654 int tomoyo_path_permission(struct tomoyo_request_info
*r
, u8 operation
,
655 const struct tomoyo_path_info
*filename
);
656 int tomoyo_check_open_permission(struct tomoyo_domain_info
*domain
,
657 struct path
*path
, const int flag
);
658 int tomoyo_path_number_perm(const u8 operation
, struct path
*path
,
659 unsigned long number
);
660 int tomoyo_mkdev_perm(const u8 operation
, struct path
*path
,
661 const unsigned int mode
, unsigned int dev
);
662 int tomoyo_path_perm(const u8 operation
, struct path
*path
);
663 int tomoyo_path2_perm(const u8 operation
, struct path
*path1
,
665 int tomoyo_find_next_domain(struct linux_binprm
*bprm
);
666 void tomoyo_print_ulong(char *buffer
, const int buffer_len
,
667 const unsigned long value
, const u8 type
);
668 void tomoyo_put_name_union(struct tomoyo_name_union
*ptr
);
669 void tomoyo_notify_gc(struct tomoyo_io_buffer
*head
, const bool is_register
);
670 void tomoyo_memory_free(void *ptr
);
671 int tomoyo_update_domain(struct tomoyo_acl_info
*new_entry
, const int size
,
672 struct tomoyo_acl_param
*param
,
673 bool (*check_duplicate
) (const struct tomoyo_acl_info
675 const struct tomoyo_acl_info
677 bool (*merge_duplicate
) (struct tomoyo_acl_info
*,
678 struct tomoyo_acl_info
*,
680 int tomoyo_update_policy(struct tomoyo_acl_head
*new_entry
, const int size
,
681 struct tomoyo_acl_param
*param
,
682 bool (*check_duplicate
) (const struct tomoyo_acl_head
684 const struct tomoyo_acl_head
686 void tomoyo_check_acl(struct tomoyo_request_info
*r
,
687 bool (*check_entry
) (struct tomoyo_request_info
*,
688 const struct tomoyo_acl_info
*));
689 char *tomoyo_read_token(struct tomoyo_acl_param
*param
);
690 bool tomoyo_permstr(const char *string
, const char *keyword
);
692 const char *tomoyo_yesno(const unsigned int value
);
693 void tomoyo_write_log(struct tomoyo_request_info
*r
, const char *fmt
, ...)
694 __attribute__ ((format(printf
, 2, 3)));
695 void tomoyo_write_log2(struct tomoyo_request_info
*r
, int len
, const char *fmt
,
697 void tomoyo_read_log(struct tomoyo_io_buffer
*head
);
698 int tomoyo_poll_log(struct file
*file
, poll_table
*wait
);
699 char *tomoyo_init_log(struct tomoyo_request_info
*r
, int len
, const char *fmt
,
702 /********** External variable definitions. **********/
705 extern struct srcu_struct tomoyo_ss
;
707 /* The list for "struct tomoyo_domain_info". */
708 extern struct list_head tomoyo_domain_list
;
710 extern struct list_head tomoyo_name_list
[TOMOYO_MAX_HASH
];
712 /* Lock for protecting policy. */
713 extern struct mutex tomoyo_policy_lock
;
715 /* Has /sbin/init started? */
716 extern bool tomoyo_policy_loaded
;
718 /* The kernel's domain. */
719 extern struct tomoyo_domain_info tomoyo_kernel_domain
;
720 extern struct tomoyo_policy_namespace tomoyo_kernel_namespace
;
721 extern struct list_head tomoyo_namespace_list
;
723 extern const char * const tomoyo_mac_keywords
[TOMOYO_MAX_MAC_INDEX
+
724 TOMOYO_MAX_MAC_CATEGORY_INDEX
];
725 extern const char * const tomoyo_path_keyword
[TOMOYO_MAX_PATH_OPERATION
];
726 extern const u8 tomoyo_index2category
[TOMOYO_MAX_MAC_INDEX
];
729 extern const u8 tomoyo_pnnn2mac
[TOMOYO_MAX_MKDEV_OPERATION
];
730 extern const u8 tomoyo_pp2mac
[TOMOYO_MAX_PATH2_OPERATION
];
731 extern const u8 tomoyo_pn2mac
[TOMOYO_MAX_PATH_NUMBER_OPERATION
];
733 extern const char * const tomoyo_dif
[TOMOYO_MAX_DOMAIN_INFO_FLAGS
];
734 extern const char * const tomoyo_mode
[TOMOYO_CONFIG_MAX_MODE
];
735 extern unsigned int tomoyo_memory_quota
[TOMOYO_MAX_MEMORY_STAT
];
736 extern unsigned int tomoyo_memory_used
[TOMOYO_MAX_MEMORY_STAT
];
738 /********** Inlined functions. **********/
741 * tomoyo_read_lock - Take lock for protecting policy.
743 * Returns index number for tomoyo_read_unlock().
745 static inline int tomoyo_read_lock(void)
747 return srcu_read_lock(&tomoyo_ss
);
751 * tomoyo_read_unlock - Release lock for protecting policy.
753 * @idx: Index number returned by tomoyo_read_lock().
757 static inline void tomoyo_read_unlock(int idx
)
759 srcu_read_unlock(&tomoyo_ss
, idx
);
763 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
765 * @a: Pointer to "struct tomoyo_path_info".
766 * @b: Pointer to "struct tomoyo_path_info".
768 * Returns true if @a == @b, false otherwise.
770 static inline bool tomoyo_pathcmp(const struct tomoyo_path_info
*a
,
771 const struct tomoyo_path_info
*b
)
773 return a
->hash
!= b
->hash
|| strcmp(a
->name
, b
->name
);
777 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
779 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
783 static inline void tomoyo_put_name(const struct tomoyo_path_info
*name
)
786 struct tomoyo_name
*ptr
=
787 container_of(name
, typeof(*ptr
), entry
);
788 atomic_dec(&ptr
->head
.users
);
793 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
795 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
799 static inline void tomoyo_put_group(struct tomoyo_group
*group
)
802 atomic_dec(&group
->head
.users
);
806 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
808 * Returns pointer to "struct tomoyo_domain_info" for current thread.
810 static inline struct tomoyo_domain_info
*tomoyo_domain(void)
812 return current_cred()->security
;
816 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
818 * @task: Pointer to "struct task_struct".
820 * Returns pointer to "struct tomoyo_security" for specified thread.
822 static inline struct tomoyo_domain_info
*tomoyo_real_domain(struct task_struct
825 return task_cred_xxx(task
, security
);
829 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
831 * @a: Pointer to "struct tomoyo_name_union".
832 * @b: Pointer to "struct tomoyo_name_union".
834 * Returns true if @a == @b, false otherwise.
836 static inline bool tomoyo_same_name_union
837 (const struct tomoyo_name_union
*a
, const struct tomoyo_name_union
*b
)
839 return a
->filename
== b
->filename
&& a
->group
== b
->group
;
843 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
845 * @a: Pointer to "struct tomoyo_number_union".
846 * @b: Pointer to "struct tomoyo_number_union".
848 * Returns true if @a == @b, false otherwise.
850 static inline bool tomoyo_same_number_union
851 (const struct tomoyo_number_union
*a
, const struct tomoyo_number_union
*b
)
853 return a
->values
[0] == b
->values
[0] && a
->values
[1] == b
->values
[1] &&
854 a
->group
== b
->group
&& a
->value_type
[0] == b
->value_type
[0] &&
855 a
->value_type
[1] == b
->value_type
[1];
859 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
861 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
863 static inline struct tomoyo_policy_namespace
*tomoyo_current_namespace(void)
865 return tomoyo_domain()->ns
;
868 #if defined(CONFIG_SLOB)
871 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
873 * @size: Size to be rounded up.
877 * Since SLOB does not round up, this function simply returns @size.
879 static inline int tomoyo_round2(size_t size
)
887 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
889 * @size: Size to be rounded up.
891 * Returns rounded size.
893 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
896 static inline int tomoyo_round2(size_t size
)
898 #if PAGE_SIZE == 4096
913 * list_for_each_cookie - iterate over a list with cookie.
914 * @pos: the &struct list_head to use as a loop cursor.
915 * @head: the head for your list.
917 #define list_for_each_cookie(pos, head) \
919 pos = srcu_dereference((head)->next, &tomoyo_ss); \
920 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
922 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */