/*1* security/tomoyo/common.h2*3* Header file for TOMOYO.4*5* Copyright (C) 2005-2010 NTT DATA CORPORATION6*/78#ifndef _SECURITY_TOMOYO_COMMON_H9#define _SECURITY_TOMOYO_COMMON_H1011#include <linux/ctype.h>12#include <linux/string.h>13#include <linux/mm.h>14#include <linux/file.h>15#include <linux/kmod.h>16#include <linux/fs.h>17#include <linux/sched.h>18#include <linux/namei.h>19#include <linux/mount.h>20#include <linux/list.h>21#include <linux/cred.h>22#include <linux/poll.h>23struct linux_binprm;2425/********** Constants definitions. **********/2627/*28* TOMOYO uses this hash only when appending a string into the string29* table. Frequency of appending strings is very low. So we don't need30* large (e.g. 64k) hash size. 256 will be sufficient.31*/32#define TOMOYO_HASH_BITS 833#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)3435#define TOMOYO_EXEC_TMPSIZE 40963637/* Profile number is an integer between 0 and 255. */38#define TOMOYO_MAX_PROFILES 2563940enum tomoyo_mode_index {41TOMOYO_CONFIG_DISABLED,42TOMOYO_CONFIG_LEARNING,43TOMOYO_CONFIG_PERMISSIVE,44TOMOYO_CONFIG_ENFORCING,45TOMOYO_CONFIG_USE_DEFAULT = 25546};4748enum tomoyo_policy_id {49TOMOYO_ID_GROUP,50TOMOYO_ID_PATH_GROUP,51TOMOYO_ID_NUMBER_GROUP,52TOMOYO_ID_TRANSITION_CONTROL,53TOMOYO_ID_AGGREGATOR,54TOMOYO_ID_GLOBALLY_READABLE,55TOMOYO_ID_PATTERN,56TOMOYO_ID_NO_REWRITE,57TOMOYO_ID_MANAGER,58TOMOYO_ID_NAME,59TOMOYO_ID_ACL,60TOMOYO_ID_DOMAIN,61TOMOYO_MAX_POLICY62};6364enum tomoyo_group_id {65TOMOYO_PATH_GROUP,66TOMOYO_NUMBER_GROUP,67TOMOYO_MAX_GROUP68};6970/* Keywords for ACLs. */71#define TOMOYO_KEYWORD_AGGREGATOR "aggregator "72#define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount "73#define TOMOYO_KEYWORD_ALLOW_READ "allow_read "74#define TOMOYO_KEYWORD_DELETE "delete "75#define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite "76#define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern "77#define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain "78#define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain "79#define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain "80#define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain "81#define TOMOYO_KEYWORD_PATH_GROUP "path_group "82#define TOMOYO_KEYWORD_NUMBER_GROUP "number_group "83#define TOMOYO_KEYWORD_SELECT "select "84#define TOMOYO_KEYWORD_USE_PROFILE "use_profile "85#define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read"86#define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded"87#define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed"88/* A domain definition starts with <kernel>. */89#define TOMOYO_ROOT_NAME "<kernel>"90#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)9192/* Value type definition. */93#define TOMOYO_VALUE_TYPE_INVALID 094#define TOMOYO_VALUE_TYPE_DECIMAL 195#define TOMOYO_VALUE_TYPE_OCTAL 296#define TOMOYO_VALUE_TYPE_HEXADECIMAL 39798enum tomoyo_transition_type {99/* Do not change this order, */100TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,101TOMOYO_TRANSITION_CONTROL_INITIALIZE,102TOMOYO_TRANSITION_CONTROL_NO_KEEP,103TOMOYO_TRANSITION_CONTROL_KEEP,104TOMOYO_MAX_TRANSITION_TYPE105};106107/* Index numbers for Access Controls. */108enum tomoyo_acl_entry_type_index {109TOMOYO_TYPE_PATH_ACL,110TOMOYO_TYPE_PATH2_ACL,111TOMOYO_TYPE_PATH_NUMBER_ACL,112TOMOYO_TYPE_MKDEV_ACL,113TOMOYO_TYPE_MOUNT_ACL,114};115116/* Index numbers for File Controls. */117118/*119* TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically120* set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set.121* Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if122* TOMOYO_TYPE_READ_WRITE is set.123* TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ124* or TOMOYO_TYPE_WRITE is cleared.125* Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if126* TOMOYO_TYPE_READ_WRITE is cleared.127*/128129enum tomoyo_path_acl_index {130TOMOYO_TYPE_READ_WRITE,131TOMOYO_TYPE_EXECUTE,132TOMOYO_TYPE_READ,133TOMOYO_TYPE_WRITE,134TOMOYO_TYPE_UNLINK,135TOMOYO_TYPE_RMDIR,136TOMOYO_TYPE_TRUNCATE,137TOMOYO_TYPE_SYMLINK,138TOMOYO_TYPE_REWRITE,139TOMOYO_TYPE_CHROOT,140TOMOYO_TYPE_UMOUNT,141TOMOYO_MAX_PATH_OPERATION142};143144#define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE))145146enum tomoyo_mkdev_acl_index {147TOMOYO_TYPE_MKBLOCK,148TOMOYO_TYPE_MKCHAR,149TOMOYO_MAX_MKDEV_OPERATION150};151152enum tomoyo_path2_acl_index {153TOMOYO_TYPE_LINK,154TOMOYO_TYPE_RENAME,155TOMOYO_TYPE_PIVOT_ROOT,156TOMOYO_MAX_PATH2_OPERATION157};158159enum tomoyo_path_number_acl_index {160TOMOYO_TYPE_CREATE,161TOMOYO_TYPE_MKDIR,162TOMOYO_TYPE_MKFIFO,163TOMOYO_TYPE_MKSOCK,164TOMOYO_TYPE_IOCTL,165TOMOYO_TYPE_CHMOD,166TOMOYO_TYPE_CHOWN,167TOMOYO_TYPE_CHGRP,168TOMOYO_MAX_PATH_NUMBER_OPERATION169};170171enum tomoyo_securityfs_interface_index {172TOMOYO_DOMAINPOLICY,173TOMOYO_EXCEPTIONPOLICY,174TOMOYO_DOMAIN_STATUS,175TOMOYO_PROCESS_STATUS,176TOMOYO_MEMINFO,177TOMOYO_SELFDOMAIN,178TOMOYO_VERSION,179TOMOYO_PROFILE,180TOMOYO_QUERY,181TOMOYO_MANAGER182};183184enum tomoyo_mac_index {185TOMOYO_MAC_FILE_EXECUTE,186TOMOYO_MAC_FILE_OPEN,187TOMOYO_MAC_FILE_CREATE,188TOMOYO_MAC_FILE_UNLINK,189TOMOYO_MAC_FILE_MKDIR,190TOMOYO_MAC_FILE_RMDIR,191TOMOYO_MAC_FILE_MKFIFO,192TOMOYO_MAC_FILE_MKSOCK,193TOMOYO_MAC_FILE_TRUNCATE,194TOMOYO_MAC_FILE_SYMLINK,195TOMOYO_MAC_FILE_REWRITE,196TOMOYO_MAC_FILE_MKBLOCK,197TOMOYO_MAC_FILE_MKCHAR,198TOMOYO_MAC_FILE_LINK,199TOMOYO_MAC_FILE_RENAME,200TOMOYO_MAC_FILE_CHMOD,201TOMOYO_MAC_FILE_CHOWN,202TOMOYO_MAC_FILE_CHGRP,203TOMOYO_MAC_FILE_IOCTL,204TOMOYO_MAC_FILE_CHROOT,205TOMOYO_MAC_FILE_MOUNT,206TOMOYO_MAC_FILE_UMOUNT,207TOMOYO_MAC_FILE_PIVOT_ROOT,208TOMOYO_MAX_MAC_INDEX209};210211enum tomoyo_mac_category_index {212TOMOYO_MAC_CATEGORY_FILE,213TOMOYO_MAX_MAC_CATEGORY_INDEX214};215216#define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */217218/********** Structure definitions. **********/219220/*221* tomoyo_acl_head is a structure which is used for holding elements not in222* domain policy.223* It has following fields.224*225* (1) "list" which is linked to tomoyo_policy_list[] .226* (2) "is_deleted" is a bool which is true if marked as deleted, false227* otherwise.228*/229struct tomoyo_acl_head {230struct list_head list;231bool is_deleted;232} __packed;233234/*235* tomoyo_request_info is a structure which is used for holding236*237* (1) Domain information of current process.238* (2) How many retries are made for this request.239* (3) Profile number used for this request.240* (4) Access control mode of the profile.241*/242struct tomoyo_request_info {243struct tomoyo_domain_info *domain;244/* For holding parameters. */245union {246struct {247const struct tomoyo_path_info *filename;248/* For using wildcards at tomoyo_find_next_domain(). */249const struct tomoyo_path_info *matched_path;250u8 operation;251} path;252struct {253const struct tomoyo_path_info *filename1;254const struct tomoyo_path_info *filename2;255u8 operation;256} path2;257struct {258const struct tomoyo_path_info *filename;259unsigned int mode;260unsigned int major;261unsigned int minor;262u8 operation;263} mkdev;264struct {265const struct tomoyo_path_info *filename;266unsigned long number;267u8 operation;268} path_number;269struct {270const struct tomoyo_path_info *type;271const struct tomoyo_path_info *dir;272const struct tomoyo_path_info *dev;273unsigned long flags;274int need_dev;275} mount;276} param;277u8 param_type;278bool granted;279u8 retry;280u8 profile;281u8 mode; /* One of tomoyo_mode_index . */282u8 type;283};284285/*286* tomoyo_path_info is a structure which is used for holding a string data287* used by TOMOYO.288* This structure has several fields for supporting pattern matching.289*290* (1) "name" is the '\0' terminated string data.291* (2) "hash" is full_name_hash(name, strlen(name)).292* This allows tomoyo_pathcmp() to compare by hash before actually compare293* using strcmp().294* (3) "const_len" is the length of the initial segment of "name" which295* consists entirely of non wildcard characters. In other words, the length296* which we can compare two strings using strncmp().297* (4) "is_dir" is a bool which is true if "name" ends with "/",298* false otherwise.299* TOMOYO distinguishes directory and non-directory. A directory ends with300* "/" and non-directory does not end with "/".301* (5) "is_patterned" is a bool which is true if "name" contains wildcard302* characters, false otherwise. This allows TOMOYO to use "hash" and303* strcmp() for string comparison if "is_patterned" is false.304*/305struct tomoyo_path_info {306const char *name;307u32 hash; /* = full_name_hash(name, strlen(name)) */308u16 const_len; /* = tomoyo_const_part_length(name) */309bool is_dir; /* = tomoyo_strendswith(name, "/") */310bool is_patterned; /* = tomoyo_path_contains_pattern(name) */311};312313/*314* tomoyo_name is a structure which is used for linking315* "struct tomoyo_path_info" into tomoyo_name_list .316*/317struct tomoyo_name {318struct list_head list;319atomic_t users;320struct tomoyo_path_info entry;321};322323struct tomoyo_name_union {324const struct tomoyo_path_info *filename;325struct tomoyo_group *group;326u8 is_group;327};328329struct tomoyo_number_union {330unsigned long values[2];331struct tomoyo_group *group;332u8 min_type;333u8 max_type;334u8 is_group;335};336337/* Structure for "path_group"/"number_group" directive. */338struct tomoyo_group {339struct list_head list;340const struct tomoyo_path_info *group_name;341struct list_head member_list;342atomic_t users;343};344345/* Structure for "path_group" directive. */346struct tomoyo_path_group {347struct tomoyo_acl_head head;348const struct tomoyo_path_info *member_name;349};350351/* Structure for "number_group" directive. */352struct tomoyo_number_group {353struct tomoyo_acl_head head;354struct tomoyo_number_union number;355};356357/*358* tomoyo_acl_info is a structure which is used for holding359*360* (1) "list" which is linked to the ->acl_info_list of361* "struct tomoyo_domain_info"362* (2) "is_deleted" is a bool which is true if this domain is marked as363* "deleted", false otherwise.364* (3) "type" which tells type of the entry.365*366* Packing "struct tomoyo_acl_info" allows367* "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl"368* "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed369* "u8" without enlarging their structure size.370*/371struct tomoyo_acl_info {372struct list_head list;373bool is_deleted;374u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */375} __packed;376377/*378* tomoyo_domain_info is a structure which is used for holding permissions379* (e.g. "allow_read /lib/libc-2.5.so") given to each domain.380* It has following fields.381*382* (1) "list" which is linked to tomoyo_domain_list .383* (2) "acl_info_list" which is linked to "struct tomoyo_acl_info".384* (3) "domainname" which holds the name of the domain.385* (4) "profile" which remembers profile number assigned to this domain.386* (5) "is_deleted" is a bool which is true if this domain is marked as387* "deleted", false otherwise.388* (6) "quota_warned" is a bool which is used for suppressing warning message389* when learning mode learned too much entries.390* (7) "ignore_global_allow_read" is a bool which is true if this domain391* should ignore "allow_read" directive in exception policy.392* (8) "transition_failed" is a bool which is set to true when this domain was393* unable to create a new domain at tomoyo_find_next_domain() because the394* name of the domain to be created was too long or it could not allocate395* memory. If set to true, more than one process continued execve()396* without domain transition.397* (9) "users" is an atomic_t that holds how many "struct cred"->security398* are referring this "struct tomoyo_domain_info". If is_deleted == true399* and users == 0, this struct will be kfree()d upon next garbage400* collection.401*402* A domain's lifecycle is an analogy of files on / directory.403* Multiple domains with the same domainname cannot be created (as with404* creating files with the same filename fails with -EEXIST).405* If a process reached a domain, that process can reside in that domain after406* that domain is marked as "deleted" (as with a process can access an already407* open()ed file after that file was unlink()ed).408*/409struct tomoyo_domain_info {410struct list_head list;411struct list_head acl_info_list;412/* Name of this domain. Never NULL. */413const struct tomoyo_path_info *domainname;414u8 profile; /* Profile number to use. */415bool is_deleted; /* Delete flag. */416bool quota_warned; /* Quota warnning flag. */417bool ignore_global_allow_read; /* Ignore "allow_read" flag. */418bool transition_failed; /* Domain transition failed flag. */419atomic_t users; /* Number of referring credentials. */420};421422/*423* tomoyo_path_acl is a structure which is used for holding an424* entry with one pathname operation (e.g. open(), mkdir()).425* It has following fields.426*427* (1) "head" which is a "struct tomoyo_acl_info".428* (2) "perm" which is a bitmask of permitted operations.429* (3) "name" is the pathname.430*431* Directives held by this structure are "allow_read/write", "allow_execute",432* "allow_read", "allow_write", "allow_unlink", "allow_rmdir",433* "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and434* "allow_unmount".435*/436struct tomoyo_path_acl {437struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */438u16 perm;439struct tomoyo_name_union name;440};441442/*443* tomoyo_path_number_acl is a structure which is used for holding an444* entry with one pathname and one number operation.445* It has following fields.446*447* (1) "head" which is a "struct tomoyo_acl_info".448* (2) "perm" which is a bitmask of permitted operations.449* (3) "name" is the pathname.450* (4) "number" is the numeric value.451*452* Directives held by this structure are "allow_create", "allow_mkdir",453* "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown"454* and "allow_chgrp".455*456*/457struct tomoyo_path_number_acl {458struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */459u8 perm;460struct tomoyo_name_union name;461struct tomoyo_number_union number;462};463464/*465* tomoyo_mkdev_acl is a structure which is used for holding an466* entry with one pathname and three numbers operation.467* It has following fields.468*469* (1) "head" which is a "struct tomoyo_acl_info".470* (2) "perm" which is a bitmask of permitted operations.471* (3) "mode" is the create mode.472* (4) "major" is the major number of device node.473* (5) "minor" is the minor number of device node.474*475* Directives held by this structure are "allow_mkchar", "allow_mkblock".476*477*/478struct tomoyo_mkdev_acl {479struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */480u8 perm;481struct tomoyo_name_union name;482struct tomoyo_number_union mode;483struct tomoyo_number_union major;484struct tomoyo_number_union minor;485};486487/*488* tomoyo_path2_acl is a structure which is used for holding an489* entry with two pathnames operation (i.e. link(), rename() and pivot_root()).490* It has following fields.491*492* (1) "head" which is a "struct tomoyo_acl_info".493* (2) "perm" which is a bitmask of permitted operations.494* (3) "name1" is the source/old pathname.495* (4) "name2" is the destination/new pathname.496*497* Directives held by this structure are "allow_rename", "allow_link" and498* "allow_pivot_root".499*/500struct tomoyo_path2_acl {501struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */502u8 perm;503struct tomoyo_name_union name1;504struct tomoyo_name_union name2;505};506507/*508* tomoyo_mount_acl is a structure which is used for holding an509* entry for mount operation.510* It has following fields.511*512* (1) "head" which is a "struct tomoyo_acl_info".513* (2) "dev_name" is the device name.514* (3) "dir_name" is the mount point.515* (4) "fs_type" is the filesystem type.516* (5) "flags" is the mount flags.517*518* Directive held by this structure is "allow_mount".519*/520struct tomoyo_mount_acl {521struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */522struct tomoyo_name_union dev_name;523struct tomoyo_name_union dir_name;524struct tomoyo_name_union fs_type;525struct tomoyo_number_union flags;526};527528#define TOMOYO_MAX_IO_READ_QUEUE 32529530/*531* Structure for reading/writing policy via /sys/kernel/security/tomoyo532* interfaces.533*/534struct tomoyo_io_buffer {535void (*read) (struct tomoyo_io_buffer *);536int (*write) (struct tomoyo_io_buffer *);537int (*poll) (struct file *file, poll_table *wait);538/* Exclusive lock for this structure. */539struct mutex io_sem;540/* Index returned by tomoyo_read_lock(). */541int reader_idx;542char __user *read_user_buf;543int read_user_buf_avail;544struct {545struct list_head *domain;546struct list_head *group;547struct list_head *acl;548int avail;549int step;550int query_index;551u16 index;552u8 bit;553u8 w_pos;554bool eof;555bool print_this_domain_only;556bool print_execute_only;557const char *w[TOMOYO_MAX_IO_READ_QUEUE];558} r;559/* The position currently writing to. */560struct tomoyo_domain_info *write_var1;561/* Buffer for reading. */562char *read_buf;563/* Size of read buffer. */564int readbuf_size;565/* Buffer for writing. */566char *write_buf;567/* Bytes available for writing. */568int write_avail;569/* Size of write buffer. */570int writebuf_size;571/* Type of this interface. */572u8 type;573};574575/*576* tomoyo_readable_file is a structure which is used for holding577* "allow_read" entries.578* It has following fields.579*580* (1) "head" is "struct tomoyo_acl_head".581* (2) "filename" is a pathname which is allowed to open(O_RDONLY).582*/583struct tomoyo_readable_file {584struct tomoyo_acl_head head;585const struct tomoyo_path_info *filename;586};587588/*589* tomoyo_no_pattern is a structure which is used for holding590* "file_pattern" entries.591* It has following fields.592*593* (1) "head" is "struct tomoyo_acl_head".594* (2) "pattern" is a pathname pattern which is used for converting pathnames595* to pathname patterns during learning mode.596*/597struct tomoyo_no_pattern {598struct tomoyo_acl_head head;599const struct tomoyo_path_info *pattern;600};601602/*603* tomoyo_no_rewrite is a structure which is used for holding604* "deny_rewrite" entries.605* It has following fields.606*607* (1) "head" is "struct tomoyo_acl_head".608* (2) "pattern" is a pathname which is by default not permitted to modify609* already existing content.610*/611struct tomoyo_no_rewrite {612struct tomoyo_acl_head head;613const struct tomoyo_path_info *pattern;614};615616/*617* tomoyo_transition_control is a structure which is used for holding618* "initialize_domain"/"no_initialize_domain"/"keep_domain"/"no_keep_domain"619* entries.620* It has following fields.621*622* (1) "head" is "struct tomoyo_acl_head".623* (2) "type" is type of this entry.624* (3) "is_last_name" is a bool which is true if "domainname" is "the last625* component of a domainname", false otherwise.626* (4) "domainname" which is "a domainname" or "the last component of a627* domainname".628* (5) "program" which is a program's pathname.629*/630struct tomoyo_transition_control {631struct tomoyo_acl_head head;632u8 type; /* One of values in "enum tomoyo_transition_type". */633/* True if the domainname is tomoyo_get_last_name(). */634bool is_last_name;635const struct tomoyo_path_info *domainname; /* Maybe NULL */636const struct tomoyo_path_info *program; /* Maybe NULL */637};638639/*640* tomoyo_aggregator is a structure which is used for holding641* "aggregator" entries.642* It has following fields.643*644* (1) "head" is "struct tomoyo_acl_head".645* (2) "original_name" which is originally requested name.646* (3) "aggregated_name" which is name to rewrite.647*/648struct tomoyo_aggregator {649struct tomoyo_acl_head head;650const struct tomoyo_path_info *original_name;651const struct tomoyo_path_info *aggregated_name;652};653654/*655* tomoyo_manager is a structure which is used for holding list of656* domainnames or programs which are permitted to modify configuration via657* /sys/kernel/security/tomoyo/ interface.658* It has following fields.659*660* (1) "head" is "struct tomoyo_acl_head".661* (2) "is_domain" is a bool which is true if "manager" is a domainname, false662* otherwise.663* (3) "manager" is a domainname or a program's pathname.664*/665struct tomoyo_manager {666struct tomoyo_acl_head head;667bool is_domain; /* True if manager is a domainname. */668/* A path to program or a domainname. */669const struct tomoyo_path_info *manager;670};671672struct tomoyo_preference {673unsigned int learning_max_entry;674bool enforcing_verbose;675bool learning_verbose;676bool permissive_verbose;677};678679struct tomoyo_profile {680const struct tomoyo_path_info *comment;681struct tomoyo_preference *learning;682struct tomoyo_preference *permissive;683struct tomoyo_preference *enforcing;684struct tomoyo_preference preference;685u8 default_config;686u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];687};688689/********** Function prototypes. **********/690691/* Check whether the given string starts with the given keyword. */692bool tomoyo_str_starts(char **src, const char *find);693/* Get tomoyo_realpath() of current process. */694const char *tomoyo_get_exe(void);695/* Format string. */696void tomoyo_normalize_line(unsigned char *buffer);697/* Print warning or error message on console. */698void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...)699__attribute__ ((format(printf, 2, 3)));700/* Check all profiles currently assigned to domains are defined. */701void tomoyo_check_profile(void);702/* Open operation for /sys/kernel/security/tomoyo/ interface. */703int tomoyo_open_control(const u8 type, struct file *file);704/* Close /sys/kernel/security/tomoyo/ interface. */705int tomoyo_close_control(struct file *file);706/* Poll operation for /sys/kernel/security/tomoyo/ interface. */707int tomoyo_poll_control(struct file *file, poll_table *wait);708/* Read operation for /sys/kernel/security/tomoyo/ interface. */709int tomoyo_read_control(struct file *file, char __user *buffer,710const int buffer_len);711/* Write operation for /sys/kernel/security/tomoyo/ interface. */712int tomoyo_write_control(struct file *file, const char __user *buffer,713const int buffer_len);714/* Check whether the domain has too many ACL entries to hold. */715bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);716/* Print out of memory warning message. */717void tomoyo_warn_oom(const char *function);718/* Check whether the given name matches the given name_union. */719const struct tomoyo_path_info *720tomoyo_compare_name_union(const struct tomoyo_path_info *name,721const struct tomoyo_name_union *ptr);722/* Check whether the given number matches the given number_union. */723bool tomoyo_compare_number_union(const unsigned long value,724const struct tomoyo_number_union *ptr);725int tomoyo_get_mode(const u8 profile, const u8 index);726void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)727__attribute__ ((format(printf, 2, 3)));728/* Check whether the domainname is correct. */729bool tomoyo_correct_domain(const unsigned char *domainname);730/* Check whether the token is correct. */731bool tomoyo_correct_path(const char *filename);732bool tomoyo_correct_word(const char *string);733/* Check whether the token can be a domainname. */734bool tomoyo_domain_def(const unsigned char *buffer);735bool tomoyo_parse_name_union(const char *filename,736struct tomoyo_name_union *ptr);737/* Check whether the given filename matches the given path_group. */738const struct tomoyo_path_info *739tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,740const struct tomoyo_group *group);741/* Check whether the given value matches the given number_group. */742bool tomoyo_number_matches_group(const unsigned long min,743const unsigned long max,744const struct tomoyo_group *group);745/* Check whether the given filename matches the given pattern. */746bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,747const struct tomoyo_path_info *pattern);748749bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);750/* Tokenize a line. */751bool tomoyo_tokenize(char *buffer, char *w[], size_t size);752/* Write domain policy violation warning message to console? */753bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);754/* Fill "struct tomoyo_request_info". */755int tomoyo_init_request_info(struct tomoyo_request_info *r,756struct tomoyo_domain_info *domain,757const u8 index);758/* Check permission for mount operation. */759int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,760unsigned long flags, void *data_page);761/* Create "aggregator" entry in exception policy. */762int tomoyo_write_aggregator(char *data, const bool is_delete);763int tomoyo_write_transition_control(char *data, const bool is_delete,764const u8 type);765/*766* Create "allow_read/write", "allow_execute", "allow_read", "allow_write",767* "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",768* "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar",769* "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and770* "allow_link" entry in domain policy.771*/772int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,773const bool is_delete);774/* Create "allow_read" entry in exception policy. */775int tomoyo_write_globally_readable(char *data, const bool is_delete);776/* Create "allow_mount" entry in domain policy. */777int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,778const bool is_delete);779/* Create "deny_rewrite" entry in exception policy. */780int tomoyo_write_no_rewrite(char *data, const bool is_delete);781/* Create "file_pattern" entry in exception policy. */782int tomoyo_write_pattern(char *data, const bool is_delete);783/* Create "path_group"/"number_group" entry in exception policy. */784int tomoyo_write_group(char *data, const bool is_delete, const u8 type);785int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)786__attribute__ ((format(printf, 2, 3)));787/* Find a domain by the given name. */788struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);789/* Find or create a domain by the given name. */790struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,791const u8 profile);792struct tomoyo_profile *tomoyo_profile(const u8 profile);793/*794* Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group".795*/796struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type);797798/* Check mode for specified functionality. */799unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,800const u8 index);801/* Fill in "struct tomoyo_path_info" members. */802void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);803/* Run policy loader when /sbin/init starts. */804void tomoyo_load_policy(const char *filename);805806void tomoyo_put_number_union(struct tomoyo_number_union *ptr);807808/* Convert binary string to ascii string. */809char *tomoyo_encode(const char *str);810811/*812* Returns realpath(3) of the given pathname except that813* ignores chroot'ed root and does not follow the final symlink.814*/815char *tomoyo_realpath_nofollow(const char *pathname);816/*817* Returns realpath(3) of the given pathname except that818* ignores chroot'ed root and the pathname is already solved.819*/820char *tomoyo_realpath_from_path(struct path *path);821/* Get patterned pathname. */822const char *tomoyo_pattern(const struct tomoyo_path_info *filename);823824/* Check memory quota. */825bool tomoyo_memory_ok(void *ptr);826void *tomoyo_commit_ok(void *data, const unsigned int size);827828/*829* Keep the given name on the RAM.830* The RAM is shared, so NEVER try to modify or kfree() the returned name.831*/832const struct tomoyo_path_info *tomoyo_get_name(const char *name);833834/* Check for memory usage. */835void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);836837/* Set memory quota. */838int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);839840/* Initialize mm related code. */841void __init tomoyo_mm_init(void);842int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,843const struct tomoyo_path_info *filename);844int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,845struct path *path, const int flag);846int tomoyo_path_number_perm(const u8 operation, struct path *path,847unsigned long number);848int tomoyo_mkdev_perm(const u8 operation, struct path *path,849const unsigned int mode, unsigned int dev);850int tomoyo_path_perm(const u8 operation, struct path *path);851int tomoyo_path2_perm(const u8 operation, struct path *path1,852struct path *path2);853int tomoyo_find_next_domain(struct linux_binprm *bprm);854855void tomoyo_print_ulong(char *buffer, const int buffer_len,856const unsigned long value, const u8 type);857858/* Drop refcount on tomoyo_name_union. */859void tomoyo_put_name_union(struct tomoyo_name_union *ptr);860861/* Run garbage collector. */862void tomoyo_run_gc(void);863864void tomoyo_memory_free(void *ptr);865866int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,867bool is_delete, struct tomoyo_domain_info *domain,868bool (*check_duplicate) (const struct tomoyo_acl_info869*,870const struct tomoyo_acl_info871*),872bool (*merge_duplicate) (struct tomoyo_acl_info *,873struct tomoyo_acl_info *,874const bool));875int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,876bool is_delete, struct list_head *list,877bool (*check_duplicate) (const struct tomoyo_acl_head878*,879const struct tomoyo_acl_head880*));881void tomoyo_check_acl(struct tomoyo_request_info *r,882bool (*check_entry) (struct tomoyo_request_info *,883const struct tomoyo_acl_info *));884885/********** External variable definitions. **********/886887/* Lock for GC. */888extern struct srcu_struct tomoyo_ss;889890/* The list for "struct tomoyo_domain_info". */891extern struct list_head tomoyo_domain_list;892893extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];894extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];895extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];896897/* Lock for protecting policy. */898extern struct mutex tomoyo_policy_lock;899900/* Has /sbin/init started? */901extern bool tomoyo_policy_loaded;902903/* The kernel's domain. */904extern struct tomoyo_domain_info tomoyo_kernel_domain;905906extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];907extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];908extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION];909extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION];910911extern unsigned int tomoyo_quota_for_query;912extern unsigned int tomoyo_query_memory_size;913914/********** Inlined functions. **********/915916static inline int tomoyo_read_lock(void)917{918return srcu_read_lock(&tomoyo_ss);919}920921static inline void tomoyo_read_unlock(int idx)922{923srcu_read_unlock(&tomoyo_ss, idx);924}925926/* strcmp() for "struct tomoyo_path_info" structure. */927static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,928const struct tomoyo_path_info *b)929{930return a->hash != b->hash || strcmp(a->name, b->name);931}932933/**934* tomoyo_valid - Check whether the character is a valid char.935*936* @c: The character to check.937*938* Returns true if @c is a valid character, false otherwise.939*/940static inline bool tomoyo_valid(const unsigned char c)941{942return c > ' ' && c < 127;943}944945/**946* tomoyo_invalid - Check whether the character is an invalid char.947*948* @c: The character to check.949*950* Returns true if @c is an invalid character, false otherwise.951*/952static inline bool tomoyo_invalid(const unsigned char c)953{954return c && (c <= ' ' || c >= 127);955}956957static inline void tomoyo_put_name(const struct tomoyo_path_info *name)958{959if (name) {960struct tomoyo_name *ptr =961container_of(name, typeof(*ptr), entry);962atomic_dec(&ptr->users);963}964}965966static inline void tomoyo_put_group(struct tomoyo_group *group)967{968if (group)969atomic_dec(&group->users);970}971972static inline struct tomoyo_domain_info *tomoyo_domain(void)973{974return current_cred()->security;975}976977static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct978*task)979{980return task_cred_xxx(task, security);981}982983static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1,984const struct tomoyo_acl_info *p2)985{986return p1->type == p2->type;987}988989static inline bool tomoyo_same_name_union990(const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2)991{992return p1->filename == p2->filename && p1->group == p2->group &&993p1->is_group == p2->is_group;994}995996static inline bool tomoyo_same_number_union997(const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2)998{999return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1]1000&& p1->group == p2->group && p1->min_type == p2->min_type &&1001p1->max_type == p2->max_type && p1->is_group == p2->is_group;1002}10031004/**1005* list_for_each_cookie - iterate over a list with cookie.1006* @pos: the &struct list_head to use as a loop cursor.1007* @head: the head for your list.1008*/1009#define list_for_each_cookie(pos, head) \1010if (!pos) \1011pos = srcu_dereference((head)->next, &tomoyo_ss); \1012for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))10131014#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */101510161017