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 /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
137 enum tomoyo_memory_stat_type {
138 TOMOYO_MEMORY_POLICY,
141 TOMOYO_MAX_MEMORY_STAT
144 enum tomoyo_mkdev_acl_index {
147 TOMOYO_MAX_MKDEV_OPERATION
150 /* Index numbers for access controls with two pathnames. */
151 enum tomoyo_path2_acl_index {
154 TOMOYO_TYPE_PIVOT_ROOT,
155 TOMOYO_MAX_PATH2_OPERATION
158 /* Index numbers for access controls with one pathname and one number. */
159 enum tomoyo_path_number_acl_index {
168 TOMOYO_MAX_PATH_NUMBER_OPERATION
171 /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
172 enum tomoyo_securityfs_interface_index {
174 TOMOYO_EXCEPTIONPOLICY,
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 /sys/kernel/security/tomoyo/stat interface. */
241 enum tomoyo_policy_stat_type {
242 /* Do not change this order. */
243 TOMOYO_STAT_POLICY_UPDATES,
244 TOMOYO_STAT_POLICY_LEARNING, /* == TOMOYO_CONFIG_LEARNING */
245 TOMOYO_STAT_POLICY_PERMISSIVE, /* == TOMOYO_CONFIG_PERMISSIVE */
246 TOMOYO_STAT_POLICY_ENFORCING, /* == TOMOYO_CONFIG_ENFORCING */
247 TOMOYO_MAX_POLICY_STAT
250 /* Index numbers for profile's PREFERENCE values. */
251 enum tomoyo_pref_index {
252 TOMOYO_PREF_MAX_AUDIT_LOG,
253 TOMOYO_PREF_MAX_LEARNING_ENTRY,
257 /********** Structure definitions. **********/
259 /* Common header for holding ACL entries. */
260 struct tomoyo_acl_head {
261 struct list_head list;
265 /* Common header for shared entries. */
266 struct tomoyo_shared_acl_head {
267 struct list_head list;
271 struct tomoyo_policy_namespace;
273 /* Structure for request info. */
274 struct tomoyo_request_info {
275 struct tomoyo_domain_info *domain;
276 /* For holding parameters. */
279 const struct tomoyo_path_info *filename;
280 /* For using wildcards at tomoyo_find_next_domain(). */
281 const struct tomoyo_path_info *matched_path;
282 /* One of values in "enum tomoyo_path_acl_index". */
286 const struct tomoyo_path_info *filename1;
287 const struct tomoyo_path_info *filename2;
288 /* One of values in "enum tomoyo_path2_acl_index". */
292 const struct tomoyo_path_info *filename;
296 /* One of values in "enum tomoyo_mkdev_acl_index". */
300 const struct tomoyo_path_info *filename;
301 unsigned long number;
304 * "enum tomoyo_path_number_acl_index".
309 const struct tomoyo_path_info *type;
310 const struct tomoyo_path_info *dir;
311 const struct tomoyo_path_info *dev;
320 u8 mode; /* One of tomoyo_mode_index . */
324 /* Structure for holding a token. */
325 struct tomoyo_path_info {
327 u32 hash; /* = full_name_hash(name, strlen(name)) */
328 u16 const_len; /* = tomoyo_const_part_length(name) */
329 bool is_dir; /* = tomoyo_strendswith(name, "/") */
330 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
333 /* Structure for holding string data. */
335 struct tomoyo_shared_acl_head head;
336 struct tomoyo_path_info entry;
339 /* Structure for holding a word. */
340 struct tomoyo_name_union {
341 /* Either @filename or @group is NULL. */
342 const struct tomoyo_path_info *filename;
343 struct tomoyo_group *group;
346 /* Structure for holding a number. */
347 struct tomoyo_number_union {
348 unsigned long values[2];
349 struct tomoyo_group *group; /* Maybe NULL. */
350 /* One of values in "enum tomoyo_value_type". */
354 /* Structure for "path_group"/"number_group" directive. */
355 struct tomoyo_group {
356 struct tomoyo_shared_acl_head head;
357 const struct tomoyo_path_info *group_name;
358 struct list_head member_list;
361 /* Structure for "path_group" directive. */
362 struct tomoyo_path_group {
363 struct tomoyo_acl_head head;
364 const struct tomoyo_path_info *member_name;
367 /* Structure for "number_group" directive. */
368 struct tomoyo_number_group {
369 struct tomoyo_acl_head head;
370 struct tomoyo_number_union number;
373 /* Common header for individual entries. */
374 struct tomoyo_acl_info {
375 struct list_head list;
377 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
380 /* Structure for domain information. */
381 struct tomoyo_domain_info {
382 struct list_head list;
383 struct list_head acl_info_list;
384 /* Name of this domain. Never NULL. */
385 const struct tomoyo_path_info *domainname;
386 /* Namespace for this domain. Never NULL. */
387 struct tomoyo_policy_namespace *ns;
388 u8 profile; /* Profile number to use. */
389 u8 group; /* Group number to use. */
390 bool is_deleted; /* Delete flag. */
391 bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
392 atomic_t users; /* Number of referring credentials. */
396 * Structure for "file execute", "file read", "file write", "file append",
397 * "file unlink", "file getattr", "file rmdir", "file truncate",
398 * "file symlink", "file chroot" and "file unmount" directive.
400 struct tomoyo_path_acl {
401 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
402 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
403 struct tomoyo_name_union name;
407 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
408 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
410 struct tomoyo_path_number_acl {
411 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
412 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
414 struct tomoyo_name_union name;
415 struct tomoyo_number_union number;
418 /* Structure for "file mkblock" and "file mkchar" directive. */
419 struct tomoyo_mkdev_acl {
420 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
421 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
422 struct tomoyo_name_union name;
423 struct tomoyo_number_union mode;
424 struct tomoyo_number_union major;
425 struct tomoyo_number_union minor;
429 * Structure for "file rename", "file link" and "file pivot_root" directive.
431 struct tomoyo_path2_acl {
432 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
433 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
434 struct tomoyo_name_union name1;
435 struct tomoyo_name_union name2;
438 /* Structure for "file mount" directive. */
439 struct tomoyo_mount_acl {
440 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
441 struct tomoyo_name_union dev_name;
442 struct tomoyo_name_union dir_name;
443 struct tomoyo_name_union fs_type;
444 struct tomoyo_number_union flags;
447 /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
448 struct tomoyo_acl_param {
450 struct list_head *list;
451 struct tomoyo_policy_namespace *ns;
455 #define TOMOYO_MAX_IO_READ_QUEUE 64
458 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
461 struct tomoyo_io_buffer {
462 void (*read) (struct tomoyo_io_buffer *);
463 int (*write) (struct tomoyo_io_buffer *);
464 int (*poll) (struct file *file, poll_table *wait);
465 /* Exclusive lock for this structure. */
467 char __user *read_user_buf;
468 size_t read_user_buf_avail;
470 struct list_head *ns;
471 struct list_head *domain;
472 struct list_head *group;
473 struct list_head *acl;
476 unsigned int query_index;
482 bool print_this_domain_only;
483 bool print_transition_related_only;
484 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
487 struct tomoyo_policy_namespace *ns;
488 /* The position currently writing to. */
489 struct tomoyo_domain_info *domain;
490 /* Bytes available for writing. */
494 /* Buffer for reading. */
496 /* Size of read buffer. */
498 /* Buffer for writing. */
500 /* Size of write buffer. */
501 size_t writebuf_size;
502 /* Type of this interface. */
503 enum tomoyo_securityfs_interface_index type;
504 /* Users counter protected by tomoyo_io_buffer_list_lock. */
506 /* List for telling GC not to kfree() elements. */
507 struct list_head list;
511 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
512 * "no_keep_domain" keyword.
514 struct tomoyo_transition_control {
515 struct tomoyo_acl_head head;
516 u8 type; /* One of values in "enum tomoyo_transition_type". */
517 /* True if the domainname is tomoyo_get_last_name(). */
519 const struct tomoyo_path_info *domainname; /* Maybe NULL */
520 const struct tomoyo_path_info *program; /* Maybe NULL */
523 /* Structure for "aggregator" keyword. */
524 struct tomoyo_aggregator {
525 struct tomoyo_acl_head head;
526 const struct tomoyo_path_info *original_name;
527 const struct tomoyo_path_info *aggregated_name;
530 /* Structure for policy manager. */
531 struct tomoyo_manager {
532 struct tomoyo_acl_head head;
533 bool is_domain; /* True if manager is a domainname. */
534 /* A path to program or a domainname. */
535 const struct tomoyo_path_info *manager;
538 struct tomoyo_preference {
539 unsigned int learning_max_entry;
540 bool enforcing_verbose;
541 bool learning_verbose;
542 bool permissive_verbose;
545 /* Structure for /sys/kernel/security/tomnoyo/profile interface. */
546 struct tomoyo_profile {
547 const struct tomoyo_path_info *comment;
548 struct tomoyo_preference *learning;
549 struct tomoyo_preference *permissive;
550 struct tomoyo_preference *enforcing;
551 struct tomoyo_preference preference;
553 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
554 unsigned int pref[TOMOYO_MAX_PREF];
557 /* Structure for representing YYYY/MM/DD hh/mm/ss. */
567 /* Structure for policy namespace. */
568 struct tomoyo_policy_namespace {
569 /* Profile table. Memory is allocated as needed. */
570 struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES];
571 /* List of "struct tomoyo_group". */
572 struct list_head group_list[TOMOYO_MAX_GROUP];
573 /* List of policy. */
574 struct list_head policy_list[TOMOYO_MAX_POLICY];
575 /* The global ACL referred by "use_group" keyword. */
576 struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS];
577 /* List for connecting to tomoyo_namespace_list list. */
578 struct list_head namespace_list;
579 /* Profile version. Currently only 20100903 is defined. */
580 unsigned int profile_version;
581 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
585 /********** Function prototypes. **********/
587 bool tomoyo_compare_number_union(const unsigned long value,
588 const struct tomoyo_number_union *ptr);
589 bool tomoyo_correct_domain(const unsigned char *domainname);
590 bool tomoyo_correct_path(const char *filename);
591 bool tomoyo_correct_word(const char *string);
592 bool tomoyo_domain_def(const unsigned char *buffer);
593 bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
594 bool tomoyo_memory_ok(void *ptr);
595 bool tomoyo_number_matches_group(const unsigned long min,
596 const unsigned long max,
597 const struct tomoyo_group *group);
598 bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
599 struct tomoyo_name_union *ptr);
600 bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
601 struct tomoyo_number_union *ptr);
602 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
603 const struct tomoyo_path_info *pattern);
604 bool tomoyo_permstr(const char *string, const char *keyword);
605 bool tomoyo_str_starts(char **src, const char *find);
606 char *tomoyo_encode(const char *str);
607 char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
609 char *tomoyo_read_token(struct tomoyo_acl_param *param);
610 char *tomoyo_realpath_from_path(struct path *path);
611 char *tomoyo_realpath_nofollow(const char *pathname);
612 const char *tomoyo_get_exe(void);
613 const char *tomoyo_yesno(const unsigned int value);
614 const struct tomoyo_path_info *tomoyo_compare_name_union
615 (const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr);
616 const struct tomoyo_path_info *tomoyo_get_name(const char *name);
617 const struct tomoyo_path_info *tomoyo_path_matches_group
618 (const struct tomoyo_path_info *pathname, const struct tomoyo_group *group);
619 int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
620 struct path *path, const int flag);
621 int tomoyo_close_control(struct tomoyo_io_buffer *head);
622 int tomoyo_find_next_domain(struct linux_binprm *bprm);
623 int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
625 int tomoyo_init_request_info(struct tomoyo_request_info *r,
626 struct tomoyo_domain_info *domain,
628 int tomoyo_mkdev_perm(const u8 operation, struct path *path,
629 const unsigned int mode, unsigned int dev);
630 int tomoyo_mount_permission(char *dev_name, struct path *path,
631 const char *type, unsigned long flags,
633 int tomoyo_open_control(const u8 type, struct file *file);
634 int tomoyo_path2_perm(const u8 operation, struct path *path1,
636 int tomoyo_path_number_perm(const u8 operation, struct path *path,
637 unsigned long number);
638 int tomoyo_path_perm(const u8 operation, struct path *path);
639 int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
640 const struct tomoyo_path_info *filename);
641 int tomoyo_poll_control(struct file *file, poll_table *wait);
642 int tomoyo_poll_log(struct file *file, poll_table *wait);
643 int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
645 int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
646 struct tomoyo_acl_param *param,
647 bool (*check_duplicate)
648 (const struct tomoyo_acl_info *,
649 const struct tomoyo_acl_info *),
650 bool (*merge_duplicate)
651 (struct tomoyo_acl_info *, struct tomoyo_acl_info *,
653 int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
654 struct tomoyo_acl_param *param,
655 bool (*check_duplicate)
656 (const struct tomoyo_acl_head *,
657 const struct tomoyo_acl_head *));
658 int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
659 int tomoyo_write_file(struct tomoyo_acl_param *param);
660 int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
661 int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
663 ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
664 const int buffer_len);
665 ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
666 const char __user *buffer, const int buffer_len);
667 struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
669 struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
670 struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
672 struct tomoyo_policy_namespace *tomoyo_assign_namespace
673 (const char *domainname);
674 struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
676 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
678 void *tomoyo_commit_ok(void *data, const unsigned int size);
679 void __init tomoyo_load_builtin_policy(void);
680 void __init tomoyo_mm_init(void);
681 void tomoyo_check_acl(struct tomoyo_request_info *r,
682 bool (*check_entry) (struct tomoyo_request_info *,
683 const struct tomoyo_acl_info *));
684 void tomoyo_check_profile(void);
685 void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp);
686 void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
687 void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
688 void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
690 void tomoyo_load_policy(const char *filename);
691 void tomoyo_memory_free(void *ptr);
692 void tomoyo_normalize_line(unsigned char *buffer);
693 void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
694 void tomoyo_print_ulong(char *buffer, const int buffer_len,
695 const unsigned long value, const u8 type);
696 void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
697 void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
698 void tomoyo_read_log(struct tomoyo_io_buffer *head);
699 void tomoyo_update_stat(const u8 index);
700 void tomoyo_warn_oom(const char *function);
701 void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
703 void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
706 /********** External variable definitions. **********/
708 extern bool tomoyo_policy_loaded;
709 extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
710 extern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX
711 + TOMOYO_MAX_MAC_CATEGORY_INDEX];
712 extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE];
713 extern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
714 extern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX];
715 extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
716 extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
717 extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
718 extern struct list_head tomoyo_domain_list;
719 extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
720 extern struct list_head tomoyo_namespace_list;
721 extern struct mutex tomoyo_policy_lock;
722 extern struct srcu_struct tomoyo_ss;
723 extern struct tomoyo_domain_info tomoyo_kernel_domain;
724 extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
725 extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
726 extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
728 /********** Inlined functions. **********/
731 * tomoyo_read_lock - Take lock for protecting policy.
733 * Returns index number for tomoyo_read_unlock().
735 static inline int tomoyo_read_lock(void)
737 return srcu_read_lock(&tomoyo_ss);
741 * tomoyo_read_unlock - Release lock for protecting policy.
743 * @idx: Index number returned by tomoyo_read_lock().
747 static inline void tomoyo_read_unlock(int idx)
749 srcu_read_unlock(&tomoyo_ss, idx);
753 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
755 * @a: Pointer to "struct tomoyo_path_info".
756 * @b: Pointer to "struct tomoyo_path_info".
758 * Returns true if @a == @b, false otherwise.
760 static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
761 const struct tomoyo_path_info *b)
763 return a->hash != b->hash || strcmp(a->name, b->name);
767 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
769 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
773 static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
776 struct tomoyo_name *ptr =
777 container_of(name, typeof(*ptr), entry);
778 atomic_dec(&ptr->head.users);
783 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
785 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
789 static inline void tomoyo_put_group(struct tomoyo_group *group)
792 atomic_dec(&group->head.users);
796 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
798 * Returns pointer to "struct tomoyo_domain_info" for current thread.
800 static inline struct tomoyo_domain_info *tomoyo_domain(void)
802 return current_cred()->security;
806 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
808 * @task: Pointer to "struct task_struct".
810 * Returns pointer to "struct tomoyo_security" for specified thread.
812 static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
815 return task_cred_xxx(task, security);
819 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
821 * @a: Pointer to "struct tomoyo_name_union".
822 * @b: Pointer to "struct tomoyo_name_union".
824 * Returns true if @a == @b, false otherwise.
826 static inline bool tomoyo_same_name_union
827 (const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
829 return a->filename == b->filename && a->group == b->group;
833 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
835 * @a: Pointer to "struct tomoyo_number_union".
836 * @b: Pointer to "struct tomoyo_number_union".
838 * Returns true if @a == @b, false otherwise.
840 static inline bool tomoyo_same_number_union
841 (const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
843 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
844 a->group == b->group && a->value_type[0] == b->value_type[0] &&
845 a->value_type[1] == b->value_type[1];
849 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
851 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
853 static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void)
855 return tomoyo_domain()->ns;
858 #if defined(CONFIG_SLOB)
861 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
863 * @size: Size to be rounded up.
867 * Since SLOB does not round up, this function simply returns @size.
869 static inline int tomoyo_round2(size_t size)
877 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
879 * @size: Size to be rounded up.
881 * Returns rounded size.
883 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
886 static inline int tomoyo_round2(size_t size)
888 #if PAGE_SIZE == 4096
903 * list_for_each_cookie - iterate over a list with cookie.
904 * @pos: the &struct list_head to use as a loop cursor.
905 * @head: the head for your list.
907 #define list_for_each_cookie(pos, head) \
909 pos = srcu_dereference((head)->next, &tomoyo_ss); \
910 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
912 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */