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 group entries. */
71 enum tomoyo_group_id
{
77 /* Index numbers for type of numeric values. */
78 enum tomoyo_value_type
{
79 TOMOYO_VALUE_TYPE_INVALID
,
80 TOMOYO_VALUE_TYPE_DECIMAL
,
81 TOMOYO_VALUE_TYPE_OCTAL
,
82 TOMOYO_VALUE_TYPE_HEXADECIMAL
,
85 /* Index numbers for domain transition control keywords. */
86 enum tomoyo_transition_type
{
87 /* Do not change this order, */
88 TOMOYO_TRANSITION_CONTROL_NO_RESET
,
89 TOMOYO_TRANSITION_CONTROL_RESET
,
90 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE
,
91 TOMOYO_TRANSITION_CONTROL_INITIALIZE
,
92 TOMOYO_TRANSITION_CONTROL_NO_KEEP
,
93 TOMOYO_TRANSITION_CONTROL_KEEP
,
94 TOMOYO_MAX_TRANSITION_TYPE
97 /* Index numbers for Access Controls. */
98 enum tomoyo_acl_entry_type_index
{
100 TOMOYO_TYPE_PATH2_ACL
,
101 TOMOYO_TYPE_PATH_NUMBER_ACL
,
102 TOMOYO_TYPE_MKDEV_ACL
,
103 TOMOYO_TYPE_MOUNT_ACL
,
106 /* Index numbers for access controls with one pathname. */
107 enum tomoyo_path_acl_index
{
115 TOMOYO_TYPE_TRUNCATE
,
119 TOMOYO_MAX_PATH_OPERATION
122 enum tomoyo_memory_stat_type
{
123 TOMOYO_MEMORY_POLICY
,
126 TOMOYO_MAX_MEMORY_STAT
129 enum tomoyo_mkdev_acl_index
{
132 TOMOYO_MAX_MKDEV_OPERATION
135 /* Index numbers for access controls with two pathnames. */
136 enum tomoyo_path2_acl_index
{
139 TOMOYO_TYPE_PIVOT_ROOT
,
140 TOMOYO_MAX_PATH2_OPERATION
143 /* Index numbers for access controls with one pathname and one number. */
144 enum tomoyo_path_number_acl_index
{
153 TOMOYO_MAX_PATH_NUMBER_OPERATION
156 /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
157 enum tomoyo_securityfs_interface_index
{
159 TOMOYO_EXCEPTIONPOLICY
,
160 TOMOYO_DOMAIN_STATUS
,
161 TOMOYO_PROCESS_STATUS
,
171 /* Index numbers for special mount operations. */
172 enum tomoyo_special_mount
{
173 TOMOYO_MOUNT_BIND
, /* mount --bind /source /dest */
174 TOMOYO_MOUNT_MOVE
, /* mount --move /old /new */
175 TOMOYO_MOUNT_REMOUNT
, /* mount -o remount /dir */
176 TOMOYO_MOUNT_MAKE_UNBINDABLE
, /* mount --make-unbindable /dir */
177 TOMOYO_MOUNT_MAKE_PRIVATE
, /* mount --make-private /dir */
178 TOMOYO_MOUNT_MAKE_SLAVE
, /* mount --make-slave /dir */
179 TOMOYO_MOUNT_MAKE_SHARED
, /* mount --make-shared /dir */
180 TOMOYO_MAX_SPECIAL_MOUNT
183 /* Index numbers for functionality. */
184 enum tomoyo_mac_index
{
185 TOMOYO_MAC_FILE_EXECUTE
,
186 TOMOYO_MAC_FILE_OPEN
,
187 TOMOYO_MAC_FILE_CREATE
,
188 TOMOYO_MAC_FILE_UNLINK
,
189 TOMOYO_MAC_FILE_GETATTR
,
190 TOMOYO_MAC_FILE_MKDIR
,
191 TOMOYO_MAC_FILE_RMDIR
,
192 TOMOYO_MAC_FILE_MKFIFO
,
193 TOMOYO_MAC_FILE_MKSOCK
,
194 TOMOYO_MAC_FILE_TRUNCATE
,
195 TOMOYO_MAC_FILE_SYMLINK
,
196 TOMOYO_MAC_FILE_MKBLOCK
,
197 TOMOYO_MAC_FILE_MKCHAR
,
198 TOMOYO_MAC_FILE_LINK
,
199 TOMOYO_MAC_FILE_RENAME
,
200 TOMOYO_MAC_FILE_CHMOD
,
201 TOMOYO_MAC_FILE_CHOWN
,
202 TOMOYO_MAC_FILE_CHGRP
,
203 TOMOYO_MAC_FILE_IOCTL
,
204 TOMOYO_MAC_FILE_CHROOT
,
205 TOMOYO_MAC_FILE_MOUNT
,
206 TOMOYO_MAC_FILE_UMOUNT
,
207 TOMOYO_MAC_FILE_PIVOT_ROOT
,
211 /* Index numbers for category of functionality. */
212 enum tomoyo_mac_category_index
{
213 TOMOYO_MAC_CATEGORY_FILE
,
214 TOMOYO_MAX_MAC_CATEGORY_INDEX
218 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
219 * occurred in enforcing mode and the userspace daemon decided to retry.
221 * We must choose a positive value in order to distinguish "granted" (which is
222 * 0) and "rejected" (which is a negative value) and "retry".
224 #define TOMOYO_RETRY_REQUEST 1
226 /* Index numbers for profile's PREFERENCE values. */
227 enum tomoyo_pref_index
{
228 TOMOYO_PREF_MAX_AUDIT_LOG
,
229 TOMOYO_PREF_MAX_LEARNING_ENTRY
,
233 /********** Structure definitions. **********/
235 /* Common header for holding ACL entries. */
236 struct tomoyo_acl_head
{
237 struct list_head list
;
241 /* Common header for shared entries. */
242 struct tomoyo_shared_acl_head
{
243 struct list_head list
;
247 struct tomoyo_policy_namespace
;
249 /* Structure for request info. */
250 struct tomoyo_request_info
{
251 struct tomoyo_domain_info
*domain
;
252 /* For holding parameters. */
255 const struct tomoyo_path_info
*filename
;
256 /* For using wildcards at tomoyo_find_next_domain(). */
257 const struct tomoyo_path_info
*matched_path
;
258 /* One of values in "enum tomoyo_path_acl_index". */
262 const struct tomoyo_path_info
*filename1
;
263 const struct tomoyo_path_info
*filename2
;
264 /* One of values in "enum tomoyo_path2_acl_index". */
268 const struct tomoyo_path_info
*filename
;
272 /* One of values in "enum tomoyo_mkdev_acl_index". */
276 const struct tomoyo_path_info
*filename
;
277 unsigned long number
;
280 * "enum tomoyo_path_number_acl_index".
285 const struct tomoyo_path_info
*type
;
286 const struct tomoyo_path_info
*dir
;
287 const struct tomoyo_path_info
*dev
;
296 u8 mode
; /* One of tomoyo_mode_index . */
300 /* Structure for holding a token. */
301 struct tomoyo_path_info
{
303 u32 hash
; /* = full_name_hash(name, strlen(name)) */
304 u16 const_len
; /* = tomoyo_const_part_length(name) */
305 bool is_dir
; /* = tomoyo_strendswith(name, "/") */
306 bool is_patterned
; /* = tomoyo_path_contains_pattern(name) */
309 /* Structure for holding string data. */
311 struct tomoyo_shared_acl_head head
;
312 struct tomoyo_path_info entry
;
315 /* Structure for holding a word. */
316 struct tomoyo_name_union
{
317 /* Either @filename or @group is NULL. */
318 const struct tomoyo_path_info
*filename
;
319 struct tomoyo_group
*group
;
322 /* Structure for holding a number. */
323 struct tomoyo_number_union
{
324 unsigned long values
[2];
325 struct tomoyo_group
*group
; /* Maybe NULL. */
326 /* One of values in "enum tomoyo_value_type". */
330 /* Structure for "path_group"/"number_group" directive. */
331 struct tomoyo_group
{
332 struct tomoyo_shared_acl_head head
;
333 const struct tomoyo_path_info
*group_name
;
334 struct list_head member_list
;
337 /* Structure for "path_group" directive. */
338 struct tomoyo_path_group
{
339 struct tomoyo_acl_head head
;
340 const struct tomoyo_path_info
*member_name
;
343 /* Structure for "number_group" directive. */
344 struct tomoyo_number_group
{
345 struct tomoyo_acl_head head
;
346 struct tomoyo_number_union number
;
349 /* Common header for individual entries. */
350 struct tomoyo_acl_info
{
351 struct list_head list
;
353 u8 type
; /* One of values in "enum tomoyo_acl_entry_type_index". */
356 /* Structure for domain information. */
357 struct tomoyo_domain_info
{
358 struct list_head list
;
359 struct list_head acl_info_list
;
360 /* Name of this domain. Never NULL. */
361 const struct tomoyo_path_info
*domainname
;
362 /* Namespace for this domain. Never NULL. */
363 struct tomoyo_policy_namespace
*ns
;
364 u8 profile
; /* Profile number to use. */
365 u8 group
; /* Group number to use. */
366 bool is_deleted
; /* Delete flag. */
367 bool quota_warned
; /* Quota warnning flag. */
368 bool transition_failed
; /* Domain transition failed flag. */
369 atomic_t users
; /* Number of referring credentials. */
373 * Structure for "file execute", "file read", "file write", "file append",
374 * "file unlink", "file getattr", "file rmdir", "file truncate",
375 * "file symlink", "file chroot" and "file unmount" directive.
377 struct tomoyo_path_acl
{
378 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_ACL */
379 u16 perm
; /* Bitmask of values in "enum tomoyo_path_acl_index". */
380 struct tomoyo_name_union name
;
384 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
385 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
387 struct tomoyo_path_number_acl
{
388 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
389 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
391 struct tomoyo_name_union name
;
392 struct tomoyo_number_union number
;
395 /* Structure for "file mkblock" and "file mkchar" directive. */
396 struct tomoyo_mkdev_acl
{
397 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MKDEV_ACL */
398 u8 perm
; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
399 struct tomoyo_name_union name
;
400 struct tomoyo_number_union mode
;
401 struct tomoyo_number_union major
;
402 struct tomoyo_number_union minor
;
406 * Structure for "file rename", "file link" and "file pivot_root" directive.
408 struct tomoyo_path2_acl
{
409 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH2_ACL */
410 u8 perm
; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
411 struct tomoyo_name_union name1
;
412 struct tomoyo_name_union name2
;
415 /* Structure for "file mount" directive. */
416 struct tomoyo_mount_acl
{
417 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MOUNT_ACL */
418 struct tomoyo_name_union dev_name
;
419 struct tomoyo_name_union dir_name
;
420 struct tomoyo_name_union fs_type
;
421 struct tomoyo_number_union flags
;
424 /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
425 struct tomoyo_acl_param
{
427 struct list_head
*list
;
428 struct tomoyo_policy_namespace
*ns
;
432 #define TOMOYO_MAX_IO_READ_QUEUE 64
435 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
438 struct tomoyo_io_buffer
{
439 void (*read
) (struct tomoyo_io_buffer
*);
440 int (*write
) (struct tomoyo_io_buffer
*);
441 int (*poll
) (struct file
*file
, poll_table
*wait
);
442 /* Exclusive lock for this structure. */
444 char __user
*read_user_buf
;
445 int read_user_buf_avail
;
447 struct list_head
*ns
;
448 struct list_head
*domain
;
449 struct list_head
*group
;
450 struct list_head
*acl
;
459 bool print_this_domain_only
;
460 bool print_transition_related_only
;
461 const char *w
[TOMOYO_MAX_IO_READ_QUEUE
];
464 struct tomoyo_policy_namespace
*ns
;
465 /* The position currently writing to. */
466 struct tomoyo_domain_info
*domain
;
467 /* Bytes available for writing. */
471 /* Buffer for reading. */
473 /* Size of read buffer. */
475 /* Buffer for writing. */
477 /* Size of write buffer. */
479 /* Type of this interface. */
481 /* Users counter protected by tomoyo_io_buffer_list_lock. */
483 /* List for telling GC not to kfree() elements. */
484 struct list_head list
;
488 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
489 * "no_keep_domain" keyword.
491 struct tomoyo_transition_control
{
492 struct tomoyo_acl_head head
;
493 u8 type
; /* One of values in "enum tomoyo_transition_type". */
494 /* True if the domainname is tomoyo_get_last_name(). */
496 const struct tomoyo_path_info
*domainname
; /* Maybe NULL */
497 const struct tomoyo_path_info
*program
; /* Maybe NULL */
500 /* Structure for "aggregator" keyword. */
501 struct tomoyo_aggregator
{
502 struct tomoyo_acl_head head
;
503 const struct tomoyo_path_info
*original_name
;
504 const struct tomoyo_path_info
*aggregated_name
;
507 /* Structure for policy manager. */
508 struct tomoyo_manager
{
509 struct tomoyo_acl_head head
;
510 bool is_domain
; /* True if manager is a domainname. */
511 /* A path to program or a domainname. */
512 const struct tomoyo_path_info
*manager
;
515 struct tomoyo_preference
{
516 unsigned int learning_max_entry
;
517 bool enforcing_verbose
;
518 bool learning_verbose
;
519 bool permissive_verbose
;
522 /* Structure for /sys/kernel/security/tomnoyo/profile interface. */
523 struct tomoyo_profile
{
524 const struct tomoyo_path_info
*comment
;
525 struct tomoyo_preference
*learning
;
526 struct tomoyo_preference
*permissive
;
527 struct tomoyo_preference
*enforcing
;
528 struct tomoyo_preference preference
;
530 u8 config
[TOMOYO_MAX_MAC_INDEX
+ TOMOYO_MAX_MAC_CATEGORY_INDEX
];
531 unsigned int pref
[TOMOYO_MAX_PREF
];
534 /* Structure for representing YYYY/MM/DD hh/mm/ss. */
544 /* Structure for policy namespace. */
545 struct tomoyo_policy_namespace
{
546 /* Profile table. Memory is allocated as needed. */
547 struct tomoyo_profile
*profile_ptr
[TOMOYO_MAX_PROFILES
];
548 /* List of "struct tomoyo_group". */
549 struct list_head group_list
[TOMOYO_MAX_GROUP
];
550 /* List of policy. */
551 struct list_head policy_list
[TOMOYO_MAX_POLICY
];
552 /* The global ACL referred by "use_group" keyword. */
553 struct list_head acl_group
[TOMOYO_MAX_ACL_GROUPS
];
554 /* List for connecting to tomoyo_namespace_list list. */
555 struct list_head namespace_list
;
556 /* Profile version. Currently only 20100903 is defined. */
557 unsigned int profile_version
;
558 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
562 /********** Function prototypes. **********/
564 void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace
*ns
);
565 bool tomoyo_str_starts(char **src
, const char *find
);
566 const char *tomoyo_get_exe(void);
567 void tomoyo_normalize_line(unsigned char *buffer
);
568 void tomoyo_check_profile(void);
569 int tomoyo_open_control(const u8 type
, struct file
*file
);
570 int tomoyo_close_control(struct tomoyo_io_buffer
*head
);
571 int tomoyo_poll_control(struct file
*file
, poll_table
*wait
);
572 int tomoyo_read_control(struct tomoyo_io_buffer
*head
, char __user
*buffer
,
573 const int buffer_len
);
574 int tomoyo_write_control(struct tomoyo_io_buffer
*head
,
575 const char __user
*buffer
, const int buffer_len
);
576 bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info
*r
);
577 void tomoyo_warn_oom(const char *function
);
578 const struct tomoyo_path_info
*
579 tomoyo_compare_name_union(const struct tomoyo_path_info
*name
,
580 const struct tomoyo_name_union
*ptr
);
581 bool tomoyo_compare_number_union(const unsigned long value
,
582 const struct tomoyo_number_union
*ptr
);
583 int tomoyo_get_mode(const struct tomoyo_policy_namespace
*ns
, const u8 profile
,
585 void tomoyo_io_printf(struct tomoyo_io_buffer
*head
, const char *fmt
, ...)
586 __attribute__ ((format(printf
, 2, 3)));
587 bool tomoyo_correct_domain(const unsigned char *domainname
);
588 bool tomoyo_correct_path(const char *filename
);
589 bool tomoyo_correct_word(const char *string
);
590 bool tomoyo_domain_def(const unsigned char *buffer
);
591 bool tomoyo_parse_name_union(struct tomoyo_acl_param
*param
,
592 struct tomoyo_name_union
*ptr
);
593 const struct tomoyo_path_info
*
594 tomoyo_path_matches_group(const struct tomoyo_path_info
*pathname
,
595 const struct tomoyo_group
*group
);
596 bool tomoyo_number_matches_group(const unsigned long min
,
597 const unsigned long max
,
598 const struct tomoyo_group
*group
);
599 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info
*filename
,
600 const struct tomoyo_path_info
*pattern
);
601 bool tomoyo_parse_number_union(struct tomoyo_acl_param
*param
,
602 struct tomoyo_number_union
*ptr
);
603 bool tomoyo_tokenize(char *buffer
, char *w
[], size_t size
);
604 bool tomoyo_verbose_mode(const struct tomoyo_domain_info
*domain
);
605 int tomoyo_init_request_info(struct tomoyo_request_info
*r
,
606 struct tomoyo_domain_info
*domain
,
608 int tomoyo_mount_permission(char *dev_name
, struct path
*path
,
609 const char *type
, unsigned long flags
,
611 int tomoyo_write_aggregator(struct tomoyo_acl_param
*param
);
612 int tomoyo_write_transition_control(struct tomoyo_acl_param
*param
,
614 int tomoyo_write_file(struct tomoyo_acl_param
*param
);
615 int tomoyo_write_group(struct tomoyo_acl_param
*param
, const u8 type
);
616 int tomoyo_supervisor(struct tomoyo_request_info
*r
, const char *fmt
, ...)
617 __attribute__ ((format(printf
, 2, 3)));
618 struct tomoyo_domain_info
*tomoyo_find_domain(const char *domainname
);
619 struct tomoyo_domain_info
*tomoyo_assign_domain(const char *domainname
,
621 struct tomoyo_profile
*tomoyo_profile(const struct tomoyo_policy_namespace
*ns
,
623 struct tomoyo_policy_namespace
*tomoyo_assign_namespace
624 (const char *domainname
);
625 struct tomoyo_group
*tomoyo_get_group(struct tomoyo_acl_param
*param
,
627 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info
*domain
,
629 void tomoyo_fill_path_info(struct tomoyo_path_info
*ptr
);
630 void tomoyo_load_policy(const char *filename
);
631 void tomoyo_put_number_union(struct tomoyo_number_union
*ptr
);
632 char *tomoyo_encode(const char *str
);
633 char *tomoyo_realpath_nofollow(const char *pathname
);
634 char *tomoyo_realpath_from_path(struct path
*path
);
635 bool tomoyo_memory_ok(void *ptr
);
636 void *tomoyo_commit_ok(void *data
, const unsigned int size
);
637 const struct tomoyo_path_info
*tomoyo_get_name(const char *name
);
638 void tomoyo_read_memory_counter(struct tomoyo_io_buffer
*head
);
639 int tomoyo_write_memory_quota(struct tomoyo_io_buffer
*head
);
640 void __init
tomoyo_mm_init(void);
641 int tomoyo_path_permission(struct tomoyo_request_info
*r
, u8 operation
,
642 const struct tomoyo_path_info
*filename
);
643 int tomoyo_check_open_permission(struct tomoyo_domain_info
*domain
,
644 struct path
*path
, const int flag
);
645 int tomoyo_path_number_perm(const u8 operation
, struct path
*path
,
646 unsigned long number
);
647 int tomoyo_mkdev_perm(const u8 operation
, struct path
*path
,
648 const unsigned int mode
, unsigned int dev
);
649 int tomoyo_path_perm(const u8 operation
, struct path
*path
);
650 int tomoyo_path2_perm(const u8 operation
, struct path
*path1
,
652 int tomoyo_find_next_domain(struct linux_binprm
*bprm
);
653 void tomoyo_print_ulong(char *buffer
, const int buffer_len
,
654 const unsigned long value
, const u8 type
);
655 void tomoyo_put_name_union(struct tomoyo_name_union
*ptr
);
656 void tomoyo_notify_gc(struct tomoyo_io_buffer
*head
, const bool is_register
);
657 void tomoyo_memory_free(void *ptr
);
658 int tomoyo_update_domain(struct tomoyo_acl_info
*new_entry
, const int size
,
659 struct tomoyo_acl_param
*param
,
660 bool (*check_duplicate
) (const struct tomoyo_acl_info
662 const struct tomoyo_acl_info
664 bool (*merge_duplicate
) (struct tomoyo_acl_info
*,
665 struct tomoyo_acl_info
*,
667 int tomoyo_update_policy(struct tomoyo_acl_head
*new_entry
, const int size
,
668 struct tomoyo_acl_param
*param
,
669 bool (*check_duplicate
) (const struct tomoyo_acl_head
671 const struct tomoyo_acl_head
673 void tomoyo_check_acl(struct tomoyo_request_info
*r
,
674 bool (*check_entry
) (struct tomoyo_request_info
*,
675 const struct tomoyo_acl_info
*));
676 char *tomoyo_read_token(struct tomoyo_acl_param
*param
);
677 bool tomoyo_permstr(const char *string
, const char *keyword
);
679 const char *tomoyo_yesno(const unsigned int value
);
680 void tomoyo_write_log(struct tomoyo_request_info
*r
, const char *fmt
, ...)
681 __attribute__ ((format(printf
, 2, 3)));
682 void tomoyo_write_log2(struct tomoyo_request_info
*r
, int len
, const char *fmt
,
684 void tomoyo_read_log(struct tomoyo_io_buffer
*head
);
685 int tomoyo_poll_log(struct file
*file
, poll_table
*wait
);
686 char *tomoyo_init_log(struct tomoyo_request_info
*r
, int len
, const char *fmt
,
689 /********** External variable definitions. **********/
692 extern struct srcu_struct tomoyo_ss
;
694 /* The list for "struct tomoyo_domain_info". */
695 extern struct list_head tomoyo_domain_list
;
697 extern struct list_head tomoyo_name_list
[TOMOYO_MAX_HASH
];
699 /* Lock for protecting policy. */
700 extern struct mutex tomoyo_policy_lock
;
702 /* Has /sbin/init started? */
703 extern bool tomoyo_policy_loaded
;
705 /* The kernel's domain. */
706 extern struct tomoyo_domain_info tomoyo_kernel_domain
;
707 extern struct tomoyo_policy_namespace tomoyo_kernel_namespace
;
708 extern struct list_head tomoyo_namespace_list
;
710 extern const char *tomoyo_path_keyword
[TOMOYO_MAX_PATH_OPERATION
];
711 extern const char *tomoyo_mkdev_keyword
[TOMOYO_MAX_MKDEV_OPERATION
];
712 extern const char *tomoyo_path2_keyword
[TOMOYO_MAX_PATH2_OPERATION
];
713 extern const char *tomoyo_path_number_keyword
[TOMOYO_MAX_PATH_NUMBER_OPERATION
];
715 extern const u8 tomoyo_pnnn2mac
[TOMOYO_MAX_MKDEV_OPERATION
];
716 extern const u8 tomoyo_pp2mac
[TOMOYO_MAX_PATH2_OPERATION
];
717 extern const u8 tomoyo_pn2mac
[TOMOYO_MAX_PATH_NUMBER_OPERATION
];
719 extern const char * const tomoyo_mode
[TOMOYO_CONFIG_MAX_MODE
];
720 extern unsigned int tomoyo_memory_quota
[TOMOYO_MAX_MEMORY_STAT
];
721 extern unsigned int tomoyo_memory_used
[TOMOYO_MAX_MEMORY_STAT
];
723 /********** Inlined functions. **********/
726 * tomoyo_read_lock - Take lock for protecting policy.
728 * Returns index number for tomoyo_read_unlock().
730 static inline int tomoyo_read_lock(void)
732 return srcu_read_lock(&tomoyo_ss
);
736 * tomoyo_read_unlock - Release lock for protecting policy.
738 * @idx: Index number returned by tomoyo_read_lock().
742 static inline void tomoyo_read_unlock(int idx
)
744 srcu_read_unlock(&tomoyo_ss
, idx
);
748 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
750 * @a: Pointer to "struct tomoyo_path_info".
751 * @b: Pointer to "struct tomoyo_path_info".
753 * Returns true if @a == @b, false otherwise.
755 static inline bool tomoyo_pathcmp(const struct tomoyo_path_info
*a
,
756 const struct tomoyo_path_info
*b
)
758 return a
->hash
!= b
->hash
|| strcmp(a
->name
, b
->name
);
762 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
764 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
768 static inline void tomoyo_put_name(const struct tomoyo_path_info
*name
)
771 struct tomoyo_name
*ptr
=
772 container_of(name
, typeof(*ptr
), entry
);
773 atomic_dec(&ptr
->head
.users
);
778 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
780 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
784 static inline void tomoyo_put_group(struct tomoyo_group
*group
)
787 atomic_dec(&group
->head
.users
);
791 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
793 * Returns pointer to "struct tomoyo_domain_info" for current thread.
795 static inline struct tomoyo_domain_info
*tomoyo_domain(void)
797 return current_cred()->security
;
801 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
803 * @task: Pointer to "struct task_struct".
805 * Returns pointer to "struct tomoyo_security" for specified thread.
807 static inline struct tomoyo_domain_info
*tomoyo_real_domain(struct task_struct
810 return task_cred_xxx(task
, security
);
814 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
816 * @a: Pointer to "struct tomoyo_name_union".
817 * @b: Pointer to "struct tomoyo_name_union".
819 * Returns true if @a == @b, false otherwise.
821 static inline bool tomoyo_same_name_union
822 (const struct tomoyo_name_union
*a
, const struct tomoyo_name_union
*b
)
824 return a
->filename
== b
->filename
&& a
->group
== b
->group
;
828 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
830 * @a: Pointer to "struct tomoyo_number_union".
831 * @b: Pointer to "struct tomoyo_number_union".
833 * Returns true if @a == @b, false otherwise.
835 static inline bool tomoyo_same_number_union
836 (const struct tomoyo_number_union
*a
, const struct tomoyo_number_union
*b
)
838 return a
->values
[0] == b
->values
[0] && a
->values
[1] == b
->values
[1] &&
839 a
->group
== b
->group
&& a
->value_type
[0] == b
->value_type
[0] &&
840 a
->value_type
[1] == b
->value_type
[1];
844 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
846 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
848 static inline struct tomoyo_policy_namespace
*tomoyo_current_namespace(void)
850 return tomoyo_domain()->ns
;
853 #if defined(CONFIG_SLOB)
856 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
858 * @size: Size to be rounded up.
862 * Since SLOB does not round up, this function simply returns @size.
864 static inline int tomoyo_round2(size_t size
)
872 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
874 * @size: Size to be rounded up.
876 * Returns rounded size.
878 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
881 static inline int tomoyo_round2(size_t size
)
883 #if PAGE_SIZE == 4096
898 * list_for_each_cookie - iterate over a list with cookie.
899 * @pos: the &struct list_head to use as a loop cursor.
900 * @head: the head for your list.
902 #define list_for_each_cookie(pos, head) \
904 pos = srcu_dereference((head)->next, &tomoyo_ss); \
905 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
907 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */