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 enum tomoyo_mode_index
{
42 TOMOYO_CONFIG_DISABLED
,
43 TOMOYO_CONFIG_LEARNING
,
44 TOMOYO_CONFIG_PERMISSIVE
,
45 TOMOYO_CONFIG_ENFORCING
,
46 TOMOYO_CONFIG_USE_DEFAULT
= 255
49 enum tomoyo_policy_id
{
52 TOMOYO_ID_NUMBER_GROUP
,
53 TOMOYO_ID_DOMAIN_INITIALIZER
,
54 TOMOYO_ID_DOMAIN_KEEPER
,
57 TOMOYO_ID_GLOBALLY_READABLE
,
67 enum tomoyo_group_id
{
73 /* Keywords for ACLs. */
74 #define TOMOYO_KEYWORD_AGGREGATOR "aggregator "
75 #define TOMOYO_KEYWORD_ALIAS "alias "
76 #define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount "
77 #define TOMOYO_KEYWORD_ALLOW_READ "allow_read "
78 #define TOMOYO_KEYWORD_DELETE "delete "
79 #define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite "
80 #define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern "
81 #define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain "
82 #define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain "
83 #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain "
84 #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain "
85 #define TOMOYO_KEYWORD_PATH_GROUP "path_group "
86 #define TOMOYO_KEYWORD_NUMBER_GROUP "number_group "
87 #define TOMOYO_KEYWORD_SELECT "select "
88 #define TOMOYO_KEYWORD_USE_PROFILE "use_profile "
89 #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read"
90 #define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded"
91 #define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed"
92 /* A domain definition starts with <kernel>. */
93 #define TOMOYO_ROOT_NAME "<kernel>"
94 #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
96 /* Value type definition. */
97 #define TOMOYO_VALUE_TYPE_INVALID 0
98 #define TOMOYO_VALUE_TYPE_DECIMAL 1
99 #define TOMOYO_VALUE_TYPE_OCTAL 2
100 #define TOMOYO_VALUE_TYPE_HEXADECIMAL 3
102 /* Index numbers for Access Controls. */
103 enum tomoyo_acl_entry_type_index
{
104 TOMOYO_TYPE_PATH_ACL
,
105 TOMOYO_TYPE_PATH2_ACL
,
106 TOMOYO_TYPE_PATH_NUMBER_ACL
,
107 TOMOYO_TYPE_MKDEV_ACL
,
108 TOMOYO_TYPE_MOUNT_ACL
,
111 /* Index numbers for File Controls. */
114 * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically
115 * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set.
116 * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if
117 * TOMOYO_TYPE_READ_WRITE is set.
118 * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ
119 * or TOMOYO_TYPE_WRITE is cleared.
120 * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if
121 * TOMOYO_TYPE_READ_WRITE is cleared.
124 enum tomoyo_path_acl_index
{
125 TOMOYO_TYPE_READ_WRITE
,
131 TOMOYO_TYPE_TRUNCATE
,
136 TOMOYO_MAX_PATH_OPERATION
139 #define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE))
141 enum tomoyo_mkdev_acl_index
{
144 TOMOYO_MAX_MKDEV_OPERATION
147 enum tomoyo_path2_acl_index
{
150 TOMOYO_TYPE_PIVOT_ROOT
,
151 TOMOYO_MAX_PATH2_OPERATION
154 enum tomoyo_path_number_acl_index
{
163 TOMOYO_MAX_PATH_NUMBER_OPERATION
166 enum tomoyo_securityfs_interface_index
{
168 TOMOYO_EXCEPTIONPOLICY
,
169 TOMOYO_DOMAIN_STATUS
,
170 TOMOYO_PROCESS_STATUS
,
179 enum tomoyo_mac_index
{
180 TOMOYO_MAC_FILE_EXECUTE
,
181 TOMOYO_MAC_FILE_OPEN
,
182 TOMOYO_MAC_FILE_CREATE
,
183 TOMOYO_MAC_FILE_UNLINK
,
184 TOMOYO_MAC_FILE_MKDIR
,
185 TOMOYO_MAC_FILE_RMDIR
,
186 TOMOYO_MAC_FILE_MKFIFO
,
187 TOMOYO_MAC_FILE_MKSOCK
,
188 TOMOYO_MAC_FILE_TRUNCATE
,
189 TOMOYO_MAC_FILE_SYMLINK
,
190 TOMOYO_MAC_FILE_REWRITE
,
191 TOMOYO_MAC_FILE_MKBLOCK
,
192 TOMOYO_MAC_FILE_MKCHAR
,
193 TOMOYO_MAC_FILE_LINK
,
194 TOMOYO_MAC_FILE_RENAME
,
195 TOMOYO_MAC_FILE_CHMOD
,
196 TOMOYO_MAC_FILE_CHOWN
,
197 TOMOYO_MAC_FILE_CHGRP
,
198 TOMOYO_MAC_FILE_IOCTL
,
199 TOMOYO_MAC_FILE_CHROOT
,
200 TOMOYO_MAC_FILE_MOUNT
,
201 TOMOYO_MAC_FILE_UMOUNT
,
202 TOMOYO_MAC_FILE_PIVOT_ROOT
,
206 enum tomoyo_mac_category_index
{
207 TOMOYO_MAC_CATEGORY_FILE
,
208 TOMOYO_MAX_MAC_CATEGORY_INDEX
211 #define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */
213 /********** Structure definitions. **********/
216 * tomoyo_acl_head is a structure which is used for holding elements not in
218 * It has following fields.
220 * (1) "list" which is linked to tomoyo_policy_list[] .
221 * (2) "is_deleted" is a bool which is true if marked as deleted, false
224 struct tomoyo_acl_head
{
225 struct list_head list
;
230 * tomoyo_request_info is a structure which is used for holding
232 * (1) Domain information of current process.
233 * (2) How many retries are made for this request.
234 * (3) Profile number used for this request.
235 * (4) Access control mode of the profile.
237 struct tomoyo_request_info
{
238 struct tomoyo_domain_info
*domain
;
239 /* For holding parameters. */
242 const struct tomoyo_path_info
*filename
;
246 const struct tomoyo_path_info
*filename1
;
247 const struct tomoyo_path_info
*filename2
;
251 const struct tomoyo_path_info
*filename
;
258 const struct tomoyo_path_info
*filename
;
259 unsigned long number
;
263 const struct tomoyo_path_info
*type
;
264 const struct tomoyo_path_info
*dir
;
265 const struct tomoyo_path_info
*dev
;
274 u8 mode
; /* One of tomoyo_mode_index . */
279 * tomoyo_path_info is a structure which is used for holding a string data
281 * This structure has several fields for supporting pattern matching.
283 * (1) "name" is the '\0' terminated string data.
284 * (2) "hash" is full_name_hash(name, strlen(name)).
285 * This allows tomoyo_pathcmp() to compare by hash before actually compare
287 * (3) "const_len" is the length of the initial segment of "name" which
288 * consists entirely of non wildcard characters. In other words, the length
289 * which we can compare two strings using strncmp().
290 * (4) "is_dir" is a bool which is true if "name" ends with "/",
292 * TOMOYO distinguishes directory and non-directory. A directory ends with
293 * "/" and non-directory does not end with "/".
294 * (5) "is_patterned" is a bool which is true if "name" contains wildcard
295 * characters, false otherwise. This allows TOMOYO to use "hash" and
296 * strcmp() for string comparison if "is_patterned" is false.
298 struct tomoyo_path_info
{
300 u32 hash
; /* = full_name_hash(name, strlen(name)) */
301 u16 const_len
; /* = tomoyo_const_part_length(name) */
302 bool is_dir
; /* = tomoyo_strendswith(name, "/") */
303 bool is_patterned
; /* = tomoyo_path_contains_pattern(name) */
307 * tomoyo_name_entry is a structure which is used for linking
308 * "struct tomoyo_path_info" into tomoyo_name_list .
310 struct tomoyo_name_entry
{
311 struct list_head list
;
313 struct tomoyo_path_info entry
;
316 struct tomoyo_name_union
{
317 const struct tomoyo_path_info
*filename
;
318 struct tomoyo_group
*group
;
322 struct tomoyo_number_union
{
323 unsigned long values
[2];
324 struct tomoyo_group
*group
;
330 /* Structure for "path_group"/"number_group" directive. */
331 struct tomoyo_group
{
332 struct list_head list
;
333 const struct tomoyo_path_info
*group_name
;
334 struct list_head member_list
;
338 /* Structure for "path_group" directive. */
339 struct tomoyo_path_group
{
340 struct tomoyo_acl_head head
;
341 const struct tomoyo_path_info
*member_name
;
344 /* Structure for "number_group" directive. */
345 struct tomoyo_number_group
{
346 struct tomoyo_acl_head head
;
347 struct tomoyo_number_union number
;
351 * tomoyo_acl_info is a structure which is used for holding
353 * (1) "list" which is linked to the ->acl_info_list of
354 * "struct tomoyo_domain_info"
355 * (2) "is_deleted" is a bool which is true if this domain is marked as
356 * "deleted", false otherwise.
357 * (3) "type" which tells type of the entry.
359 * Packing "struct tomoyo_acl_info" allows
360 * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl"
361 * "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed
362 * "u8" without enlarging their structure size.
364 struct tomoyo_acl_info
{
365 struct list_head list
;
367 u8 type
; /* = one of values in "enum tomoyo_acl_entry_type_index". */
371 * tomoyo_domain_info is a structure which is used for holding permissions
372 * (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
373 * It has following fields.
375 * (1) "list" which is linked to tomoyo_domain_list .
376 * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info".
377 * (3) "domainname" which holds the name of the domain.
378 * (4) "profile" which remembers profile number assigned to this domain.
379 * (5) "is_deleted" is a bool which is true if this domain is marked as
380 * "deleted", false otherwise.
381 * (6) "quota_warned" is a bool which is used for suppressing warning message
382 * when learning mode learned too much entries.
383 * (7) "ignore_global_allow_read" is a bool which is true if this domain
384 * should ignore "allow_read" directive in exception policy.
385 * (8) "transition_failed" is a bool which is set to true when this domain was
386 * unable to create a new domain at tomoyo_find_next_domain() because the
387 * name of the domain to be created was too long or it could not allocate
388 * memory. If set to true, more than one process continued execve()
389 * without domain transition.
390 * (9) "users" is an atomic_t that holds how many "struct cred"->security
391 * are referring this "struct tomoyo_domain_info". If is_deleted == true
392 * and users == 0, this struct will be kfree()d upon next garbage
395 * A domain's lifecycle is an analogy of files on / directory.
396 * Multiple domains with the same domainname cannot be created (as with
397 * creating files with the same filename fails with -EEXIST).
398 * If a process reached a domain, that process can reside in that domain after
399 * that domain is marked as "deleted" (as with a process can access an already
400 * open()ed file after that file was unlink()ed).
402 struct tomoyo_domain_info
{
403 struct list_head list
;
404 struct list_head acl_info_list
;
405 /* Name of this domain. Never NULL. */
406 const struct tomoyo_path_info
*domainname
;
407 u8 profile
; /* Profile number to use. */
408 bool is_deleted
; /* Delete flag. */
409 bool quota_warned
; /* Quota warnning flag. */
410 bool ignore_global_allow_read
; /* Ignore "allow_read" flag. */
411 bool transition_failed
; /* Domain transition failed flag. */
412 atomic_t users
; /* Number of referring credentials. */
416 * tomoyo_path_acl is a structure which is used for holding an
417 * entry with one pathname operation (e.g. open(), mkdir()).
418 * It has following fields.
420 * (1) "head" which is a "struct tomoyo_acl_info".
421 * (2) "perm" which is a bitmask of permitted operations.
422 * (3) "name" is the pathname.
424 * Directives held by this structure are "allow_read/write", "allow_execute",
425 * "allow_read", "allow_write", "allow_unlink", "allow_rmdir",
426 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and
429 struct tomoyo_path_acl
{
430 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_ACL */
432 struct tomoyo_name_union name
;
436 * tomoyo_path_number_acl is a structure which is used for holding an
437 * entry with one pathname and one number operation.
438 * It has following fields.
440 * (1) "head" which is a "struct tomoyo_acl_info".
441 * (2) "perm" which is a bitmask of permitted operations.
442 * (3) "name" is the pathname.
443 * (4) "number" is the numeric value.
445 * Directives held by this structure are "allow_create", "allow_mkdir",
446 * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown"
450 struct tomoyo_path_number_acl
{
451 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
453 struct tomoyo_name_union name
;
454 struct tomoyo_number_union number
;
458 * tomoyo_mkdev_acl is a structure which is used for holding an
459 * entry with one pathname and three numbers operation.
460 * It has following fields.
462 * (1) "head" which is a "struct tomoyo_acl_info".
463 * (2) "perm" which is a bitmask of permitted operations.
464 * (3) "mode" is the create mode.
465 * (4) "major" is the major number of device node.
466 * (5) "minor" is the minor number of device node.
468 * Directives held by this structure are "allow_mkchar", "allow_mkblock".
471 struct tomoyo_mkdev_acl
{
472 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MKDEV_ACL */
474 struct tomoyo_name_union name
;
475 struct tomoyo_number_union mode
;
476 struct tomoyo_number_union major
;
477 struct tomoyo_number_union minor
;
481 * tomoyo_path2_acl is a structure which is used for holding an
482 * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
483 * It has following fields.
485 * (1) "head" which is a "struct tomoyo_acl_info".
486 * (2) "perm" which is a bitmask of permitted operations.
487 * (3) "name1" is the source/old pathname.
488 * (4) "name2" is the destination/new pathname.
490 * Directives held by this structure are "allow_rename", "allow_link" and
491 * "allow_pivot_root".
493 struct tomoyo_path2_acl
{
494 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_PATH2_ACL */
496 struct tomoyo_name_union name1
;
497 struct tomoyo_name_union name2
;
501 * tomoyo_mount_acl is a structure which is used for holding an
502 * entry for mount operation.
503 * It has following fields.
505 * (1) "head" which is a "struct tomoyo_acl_info".
506 * (2) "dev_name" is the device name.
507 * (3) "dir_name" is the mount point.
508 * (4) "fs_type" is the filesystem type.
509 * (5) "flags" is the mount flags.
511 * Directive held by this structure is "allow_mount".
513 struct tomoyo_mount_acl
{
514 struct tomoyo_acl_info head
; /* type = TOMOYO_TYPE_MOUNT_ACL */
515 struct tomoyo_name_union dev_name
;
516 struct tomoyo_name_union dir_name
;
517 struct tomoyo_name_union fs_type
;
518 struct tomoyo_number_union flags
;
522 * tomoyo_io_buffer is a structure which is used for reading and modifying
523 * configuration via /sys/kernel/security/tomoyo/ interface.
524 * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as
527 * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of
528 * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info"
529 * entry has a list of "struct tomoyo_acl_info", we need two cursors when
530 * reading (one is for traversing tomoyo_domain_list and the other is for
531 * traversing "struct tomoyo_acl_info"->acl_info_list ).
533 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
534 * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the
535 * domain with the domainname specified by the rest of that line (NULL is set
537 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
538 * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that
539 * line (->write_var1 is set to NULL if a domain was deleted).
540 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
541 * neither "select " nor "delete ", an entry or a domain specified by that line
544 struct tomoyo_io_buffer
{
545 void (*read
) (struct tomoyo_io_buffer
*);
546 int (*write
) (struct tomoyo_io_buffer
*);
547 int (*poll
) (struct file
*file
, poll_table
*wait
);
548 /* Exclusive lock for this structure. */
550 /* Index returned by tomoyo_read_lock(). */
552 /* The position currently reading from. */
553 struct list_head
*read_var1
;
554 /* Extra variables for reading. */
555 struct list_head
*read_var2
;
556 /* The position currently writing to. */
557 struct tomoyo_domain_info
*write_var1
;
558 /* The step for reading. */
560 /* Buffer for reading. */
562 /* EOF flag for reading. */
564 /* Read domain ACL of specified PID? */
565 bool read_single_domain
;
566 /* Extra variable for reading. */
568 /* Bytes available for reading. */
570 /* Size of read buffer. */
572 /* Buffer for writing. */
574 /* Bytes available for writing. */
576 /* Size of write buffer. */
578 /* Type of this interface. */
583 * tomoyo_globally_readable_file_entry is a structure which is used for holding
584 * "allow_read" entries.
585 * It has following fields.
587 * (1) "head" is "struct tomoyo_acl_head".
588 * (2) "filename" is a pathname which is allowed to open(O_RDONLY).
590 struct tomoyo_globally_readable_file_entry
{
591 struct tomoyo_acl_head head
;
592 const struct tomoyo_path_info
*filename
;
596 * tomoyo_pattern_entry is a structure which is used for holding
597 * "file_pattern" entries.
598 * It has following fields.
600 * (1) "head" is "struct tomoyo_acl_head".
601 * (2) "pattern" is a pathname pattern which is used for converting pathnames
602 * to pathname patterns during learning mode.
604 struct tomoyo_pattern_entry
{
605 struct tomoyo_acl_head head
;
606 const struct tomoyo_path_info
*pattern
;
610 * tomoyo_no_rewrite_entry is a structure which is used for holding
611 * "deny_rewrite" entries.
612 * It has following fields.
614 * (1) "head" is "struct tomoyo_acl_head".
615 * (2) "pattern" is a pathname which is by default not permitted to modify
616 * already existing content.
618 struct tomoyo_no_rewrite_entry
{
619 struct tomoyo_acl_head head
;
620 const struct tomoyo_path_info
*pattern
;
624 * tomoyo_domain_initializer_entry is a structure which is used for holding
625 * "initialize_domain" and "no_initialize_domain" entries.
626 * It has following fields.
628 * (1) "head" is "struct tomoyo_acl_head".
629 * (2) "is_not" is a bool which is true if "no_initialize_domain", false
631 * (3) "is_last_name" is a bool which is true if "domainname" is "the last
632 * component of a domainname", false otherwise.
633 * (4) "domainname" which is "a domainname" or "the last component of a
634 * domainname". This field is NULL if "from" clause is not specified.
635 * (5) "program" which is a program's pathname.
637 struct tomoyo_domain_initializer_entry
{
638 struct tomoyo_acl_head head
;
639 bool is_not
; /* True if this entry is "no_initialize_domain". */
640 /* True if the domainname is tomoyo_get_last_name(). */
642 const struct tomoyo_path_info
*domainname
; /* This may be NULL */
643 const struct tomoyo_path_info
*program
;
647 * tomoyo_domain_keeper_entry is a structure which is used for holding
648 * "keep_domain" and "no_keep_domain" entries.
649 * It has following fields.
651 * (1) "head" is "struct tomoyo_acl_head".
652 * (2) "is_not" is a bool which is true if "no_initialize_domain", false
654 * (3) "is_last_name" is a bool which is true if "domainname" is "the last
655 * component of a domainname", false otherwise.
656 * (4) "domainname" which is "a domainname" or "the last component of a
658 * (5) "program" which is a program's pathname.
659 * This field is NULL if "from" clause is not specified.
661 struct tomoyo_domain_keeper_entry
{
662 struct tomoyo_acl_head head
;
663 bool is_not
; /* True if this entry is "no_keep_domain". */
664 /* True if the domainname is tomoyo_get_last_name(). */
666 const struct tomoyo_path_info
*domainname
;
667 const struct tomoyo_path_info
*program
; /* This may be NULL */
671 * tomoyo_aggregator_entry is a structure which is used for holding
672 * "aggregator" entries.
673 * It has following fields.
675 * (1) "head" is "struct tomoyo_acl_head".
676 * (2) "original_name" which is originally requested name.
677 * (3) "aggregated_name" which is name to rewrite.
679 struct tomoyo_aggregator_entry
{
680 struct tomoyo_acl_head head
;
681 const struct tomoyo_path_info
*original_name
;
682 const struct tomoyo_path_info
*aggregated_name
;
686 * tomoyo_alias_entry is a structure which is used for holding "alias" entries.
687 * It has following fields.
689 * (1) "head" is "struct tomoyo_acl_head".
690 * (2) "original_name" which is a dereferenced pathname.
691 * (3) "aliased_name" which is a symlink's pathname.
693 struct tomoyo_alias_entry
{
694 struct tomoyo_acl_head head
;
695 const struct tomoyo_path_info
*original_name
;
696 const struct tomoyo_path_info
*aliased_name
;
700 * tomoyo_policy_manager_entry is a structure which is used for holding list of
701 * domainnames or programs which are permitted to modify configuration via
702 * /sys/kernel/security/tomoyo/ interface.
703 * It has following fields.
705 * (1) "head" is "struct tomoyo_acl_head".
706 * (2) "is_domain" is a bool which is true if "manager" is a domainname, false
708 * (3) "manager" is a domainname or a program's pathname.
710 struct tomoyo_policy_manager_entry
{
711 struct tomoyo_acl_head head
;
712 bool is_domain
; /* True if manager is a domainname. */
713 /* A path to program or a domainname. */
714 const struct tomoyo_path_info
*manager
;
717 struct tomoyo_preference
{
718 unsigned int learning_max_entry
;
719 bool enforcing_verbose
;
720 bool learning_verbose
;
721 bool permissive_verbose
;
724 struct tomoyo_profile
{
725 const struct tomoyo_path_info
*comment
;
726 struct tomoyo_preference
*learning
;
727 struct tomoyo_preference
*permissive
;
728 struct tomoyo_preference
*enforcing
;
729 struct tomoyo_preference preference
;
731 u8 config
[TOMOYO_MAX_MAC_INDEX
+ TOMOYO_MAX_MAC_CATEGORY_INDEX
];
734 /********** Function prototypes. **********/
736 extern asmlinkage
long sys_getpid(void);
737 extern asmlinkage
long sys_getppid(void);
739 /* Check whether the given string starts with the given keyword. */
740 bool tomoyo_str_starts(char **src
, const char *find
);
741 /* Get tomoyo_realpath() of current process. */
742 const char *tomoyo_get_exe(void);
744 void tomoyo_normalize_line(unsigned char *buffer
);
745 /* Print warning or error message on console. */
746 void tomoyo_warn_log(struct tomoyo_request_info
*r
, const char *fmt
, ...)
747 __attribute__ ((format(printf
, 2, 3)));
748 /* Check all profiles currently assigned to domains are defined. */
749 void tomoyo_check_profile(void);
750 /* Open operation for /sys/kernel/security/tomoyo/ interface. */
751 int tomoyo_open_control(const u8 type
, struct file
*file
);
752 /* Close /sys/kernel/security/tomoyo/ interface. */
753 int tomoyo_close_control(struct file
*file
);
754 /* Read operation for /sys/kernel/security/tomoyo/ interface. */
755 int tomoyo_read_control(struct file
*file
, char __user
*buffer
,
756 const int buffer_len
);
757 /* Write operation for /sys/kernel/security/tomoyo/ interface. */
758 int tomoyo_write_control(struct file
*file
, const char __user
*buffer
,
759 const int buffer_len
);
760 /* Check whether the domain has too many ACL entries to hold. */
761 bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info
*r
);
762 /* Print out of memory warning message. */
763 void tomoyo_warn_oom(const char *function
);
764 /* Check whether the given name matches the given name_union. */
765 bool tomoyo_compare_name_union(const struct tomoyo_path_info
*name
,
766 const struct tomoyo_name_union
*ptr
);
767 /* Check whether the given number matches the given number_union. */
768 bool tomoyo_compare_number_union(const unsigned long value
,
769 const struct tomoyo_number_union
*ptr
);
770 int tomoyo_get_mode(const u8 profile
, const u8 index
);
771 /* Transactional sprintf() for policy dump. */
772 bool tomoyo_io_printf(struct tomoyo_io_buffer
*head
, const char *fmt
, ...)
773 __attribute__ ((format(printf
, 2, 3)));
774 /* Check whether the domainname is correct. */
775 bool tomoyo_correct_domain(const unsigned char *domainname
);
776 /* Check whether the token is correct. */
777 bool tomoyo_correct_path(const char *filename
);
778 bool tomoyo_correct_word(const char *string
);
779 /* Check whether the token can be a domainname. */
780 bool tomoyo_domain_def(const unsigned char *buffer
);
781 bool tomoyo_parse_name_union(const char *filename
,
782 struct tomoyo_name_union
*ptr
);
783 /* Check whether the given filename matches the given path_group. */
784 bool tomoyo_path_matches_group(const struct tomoyo_path_info
*pathname
,
785 const struct tomoyo_group
*group
);
786 /* Check whether the given value matches the given number_group. */
787 bool tomoyo_number_matches_group(const unsigned long min
,
788 const unsigned long max
,
789 const struct tomoyo_group
*group
);
790 /* Check whether the given filename matches the given pattern. */
791 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info
*filename
,
792 const struct tomoyo_path_info
*pattern
);
794 bool tomoyo_print_number_union(struct tomoyo_io_buffer
*head
,
795 const struct tomoyo_number_union
*ptr
);
796 bool tomoyo_parse_number_union(char *data
, struct tomoyo_number_union
*num
);
797 /* Tokenize a line. */
798 bool tomoyo_tokenize(char *buffer
, char *w
[], size_t size
);
799 /* Write domain policy violation warning message to console? */
800 bool tomoyo_verbose_mode(const struct tomoyo_domain_info
*domain
);
801 /* Get the last component of the given domainname. */
802 const char *tomoyo_get_last_name(const struct tomoyo_domain_info
*domain
);
803 /* Fill "struct tomoyo_request_info". */
804 int tomoyo_init_request_info(struct tomoyo_request_info
*r
,
805 struct tomoyo_domain_info
*domain
,
807 /* Check permission for mount operation. */
808 int tomoyo_mount_permission(char *dev_name
, struct path
*path
, char *type
,
809 unsigned long flags
, void *data_page
);
810 /* Create "aggregator" entry in exception policy. */
811 int tomoyo_write_aggregator_policy(char *data
, const bool is_delete
);
812 /* Create "alias" entry in exception policy. */
813 int tomoyo_write_alias_policy(char *data
, const bool is_delete
);
815 * Create "initialize_domain" and "no_initialize_domain" entry
816 * in exception policy.
818 int tomoyo_write_domain_initializer_policy(char *data
, const bool is_not
,
819 const bool is_delete
);
820 /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */
821 int tomoyo_write_domain_keeper_policy(char *data
, const bool is_not
,
822 const bool is_delete
);
824 * Create "allow_read/write", "allow_execute", "allow_read", "allow_write",
825 * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",
826 * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar",
827 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and
828 * "allow_link" entry in domain policy.
830 int tomoyo_write_file_policy(char *data
, struct tomoyo_domain_info
*domain
,
831 const bool is_delete
);
832 /* Create "allow_read" entry in exception policy. */
833 int tomoyo_write_globally_readable_policy(char *data
, const bool is_delete
);
834 /* Create "allow_mount" entry in domain policy. */
835 int tomoyo_write_mount_policy(char *data
, struct tomoyo_domain_info
*domain
,
836 const bool is_delete
);
837 /* Create "deny_rewrite" entry in exception policy. */
838 int tomoyo_write_no_rewrite_policy(char *data
, const bool is_delete
);
839 /* Create "file_pattern" entry in exception policy. */
840 int tomoyo_write_pattern_policy(char *data
, const bool is_delete
);
841 /* Create "path_group" entry in exception policy. */
842 int tomoyo_write_path_group_policy(char *data
, const bool is_delete
);
843 int tomoyo_supervisor(struct tomoyo_request_info
*r
, const char *fmt
, ...)
844 __attribute__ ((format(printf
, 2, 3)));
845 /* Create "number_group" entry in exception policy. */
846 int tomoyo_write_number_group_policy(char *data
, const bool is_delete
);
847 /* Find a domain by the given name. */
848 struct tomoyo_domain_info
*tomoyo_find_domain(const char *domainname
);
849 /* Find or create a domain by the given name. */
850 struct tomoyo_domain_info
*tomoyo_find_or_assign_new_domain(const char *
853 struct tomoyo_profile
*tomoyo_profile(const u8 profile
);
854 /* Allocate memory for "struct tomoyo_path_group". */
855 struct tomoyo_group
*tomoyo_get_path_group(const char *group_name
);
856 struct tomoyo_group
*tomoyo_get_number_group(const char *group_name
);
858 /* Check mode for specified functionality. */
859 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info
*domain
,
861 /* Fill in "struct tomoyo_path_info" members. */
862 void tomoyo_fill_path_info(struct tomoyo_path_info
*ptr
);
863 /* Run policy loader when /sbin/init starts. */
864 void tomoyo_load_policy(const char *filename
);
866 void tomoyo_put_number_union(struct tomoyo_number_union
*ptr
);
868 /* Convert binary string to ascii string. */
869 char *tomoyo_encode(const char *str
);
872 * Returns realpath(3) of the given pathname but ignores chroot'ed root.
873 * These functions use kzalloc(), so the caller must call kfree()
874 * if these functions didn't return NULL.
876 char *tomoyo_realpath(const char *pathname
);
878 * Same with tomoyo_realpath() except that it doesn't follow the final symlink.
880 char *tomoyo_realpath_nofollow(const char *pathname
);
881 /* Same with tomoyo_realpath() except that the pathname is already solved. */
882 char *tomoyo_realpath_from_path(struct path
*path
);
883 /* Get patterned pathname. */
884 const char *tomoyo_file_pattern(const struct tomoyo_path_info
*filename
);
886 /* Check memory quota. */
887 bool tomoyo_memory_ok(void *ptr
);
888 void *tomoyo_commit_ok(void *data
, const unsigned int size
);
891 * Keep the given name on the RAM.
892 * The RAM is shared, so NEVER try to modify or kfree() the returned name.
894 const struct tomoyo_path_info
*tomoyo_get_name(const char *name
);
896 /* Check for memory usage. */
897 void tomoyo_read_memory_counter(struct tomoyo_io_buffer
*head
);
899 /* Set memory quota. */
900 int tomoyo_write_memory_quota(struct tomoyo_io_buffer
*head
);
902 /* Initialize mm related code. */
903 void __init
tomoyo_mm_init(void);
904 int tomoyo_path_permission(struct tomoyo_request_info
*r
, u8 operation
,
905 const struct tomoyo_path_info
*filename
);
906 int tomoyo_check_open_permission(struct tomoyo_domain_info
*domain
,
907 struct path
*path
, const int flag
);
908 int tomoyo_path_number_perm(const u8 operation
, struct path
*path
,
909 unsigned long number
);
910 int tomoyo_mkdev_perm(const u8 operation
, struct path
*path
,
911 const unsigned int mode
, unsigned int dev
);
912 int tomoyo_path_perm(const u8 operation
, struct path
*path
);
913 int tomoyo_path2_perm(const u8 operation
, struct path
*path1
,
915 int tomoyo_find_next_domain(struct linux_binprm
*bprm
);
917 void tomoyo_print_ulong(char *buffer
, const int buffer_len
,
918 const unsigned long value
, const u8 type
);
920 /* Drop refcount on tomoyo_name_union. */
921 void tomoyo_put_name_union(struct tomoyo_name_union
*ptr
);
923 /* Run garbage collector. */
924 void tomoyo_run_gc(void);
926 void tomoyo_memory_free(void *ptr
);
928 int tomoyo_update_domain(struct tomoyo_acl_info
*new_entry
, const int size
,
929 bool is_delete
, struct tomoyo_domain_info
*domain
,
930 bool (*check_duplicate
) (const struct tomoyo_acl_info
932 const struct tomoyo_acl_info
934 bool (*merge_duplicate
) (struct tomoyo_acl_info
*,
935 struct tomoyo_acl_info
*,
937 int tomoyo_update_policy(struct tomoyo_acl_head
*new_entry
, const int size
,
938 bool is_delete
, struct list_head
*list
,
939 bool (*check_duplicate
) (const struct tomoyo_acl_head
941 const struct tomoyo_acl_head
943 void tomoyo_check_acl(struct tomoyo_request_info
*r
,
944 bool (*check_entry
) (const struct tomoyo_request_info
*,
945 const struct tomoyo_acl_info
*));
947 /********** External variable definitions. **********/
950 extern struct srcu_struct tomoyo_ss
;
952 /* The list for "struct tomoyo_domain_info". */
953 extern struct list_head tomoyo_domain_list
;
955 extern struct list_head tomoyo_policy_list
[TOMOYO_MAX_POLICY
];
956 extern struct list_head tomoyo_group_list
[TOMOYO_MAX_GROUP
];
957 extern struct list_head tomoyo_name_list
[TOMOYO_MAX_HASH
];
959 /* Lock for protecting policy. */
960 extern struct mutex tomoyo_policy_lock
;
962 /* Has /sbin/init started? */
963 extern bool tomoyo_policy_loaded
;
965 /* The kernel's domain. */
966 extern struct tomoyo_domain_info tomoyo_kernel_domain
;
968 extern const char *tomoyo_path_keyword
[TOMOYO_MAX_PATH_OPERATION
];
969 extern const char *tomoyo_mkdev_keyword
[TOMOYO_MAX_MKDEV_OPERATION
];
970 extern const char *tomoyo_path2_keyword
[TOMOYO_MAX_PATH2_OPERATION
];
971 extern const char *tomoyo_path_number_keyword
[TOMOYO_MAX_PATH_NUMBER_OPERATION
];
973 extern unsigned int tomoyo_quota_for_query
;
974 extern unsigned int tomoyo_query_memory_size
;
976 /********** Inlined functions. **********/
978 static inline int tomoyo_read_lock(void)
980 return srcu_read_lock(&tomoyo_ss
);
983 static inline void tomoyo_read_unlock(int idx
)
985 srcu_read_unlock(&tomoyo_ss
, idx
);
988 /* strcmp() for "struct tomoyo_path_info" structure. */
989 static inline bool tomoyo_pathcmp(const struct tomoyo_path_info
*a
,
990 const struct tomoyo_path_info
*b
)
992 return a
->hash
!= b
->hash
|| strcmp(a
->name
, b
->name
);
996 * tomoyo_valid - Check whether the character is a valid char.
998 * @c: The character to check.
1000 * Returns true if @c is a valid character, false otherwise.
1002 static inline bool tomoyo_valid(const unsigned char c
)
1004 return c
> ' ' && c
< 127;
1008 * tomoyo_invalid - Check whether the character is an invalid char.
1010 * @c: The character to check.
1012 * Returns true if @c is an invalid character, false otherwise.
1014 static inline bool tomoyo_invalid(const unsigned char c
)
1016 return c
&& (c
<= ' ' || c
>= 127);
1019 static inline void tomoyo_put_name(const struct tomoyo_path_info
*name
)
1022 struct tomoyo_name_entry
*ptr
=
1023 container_of(name
, struct tomoyo_name_entry
, entry
);
1024 atomic_dec(&ptr
->users
);
1028 static inline void tomoyo_put_group(struct tomoyo_group
*group
)
1031 atomic_dec(&group
->users
);
1034 static inline struct tomoyo_domain_info
*tomoyo_domain(void)
1036 return current_cred()->security
;
1039 static inline struct tomoyo_domain_info
*tomoyo_real_domain(struct task_struct
1042 return task_cred_xxx(task
, security
);
1045 static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info
*p1
,
1046 const struct tomoyo_acl_info
*p2
)
1048 return p1
->type
== p2
->type
;
1051 static inline bool tomoyo_same_name_union
1052 (const struct tomoyo_name_union
*p1
, const struct tomoyo_name_union
*p2
)
1054 return p1
->filename
== p2
->filename
&& p1
->group
== p2
->group
&&
1055 p1
->is_group
== p2
->is_group
;
1058 static inline bool tomoyo_same_number_union
1059 (const struct tomoyo_number_union
*p1
, const struct tomoyo_number_union
*p2
)
1061 return p1
->values
[0] == p2
->values
[0] && p1
->values
[1] == p2
->values
[1]
1062 && p1
->group
== p2
->group
&& p1
->min_type
== p2
->min_type
&&
1063 p1
->max_type
== p2
->max_type
&& p1
->is_group
== p2
->is_group
;
1067 * list_for_each_cookie - iterate over a list with cookie.
1068 * @pos: the &struct list_head to use as a loop cursor.
1069 * @cookie: the &struct list_head to use as a cookie.
1070 * @head: the head for your list.
1072 * Same with list_for_each_rcu() except that this primitive uses @cookie
1073 * so that we can continue iteration.
1074 * @cookie must be NULL when iteration starts, and @cookie will become
1075 * NULL when iteration finishes.
1077 #define list_for_each_cookie(pos, cookie, head) \
1078 for (({ if (!cookie) \
1079 cookie = head; }), \
1080 pos = rcu_dereference((cookie)->next); \
1081 prefetch(pos->next), pos != (head) || ((cookie) = NULL); \
1082 (cookie) = pos, pos = rcu_dereference(pos->next))
1084 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */