blob: a5eeabcc0738727ca5c3966cc626f67256e49b9b [file] [log] [blame]
Kentaro Takeda95908372009-02-05 17:18:13 +09001/*
2 * security/tomoyo/common.h
3 *
Tetsuo Handa76bb0892010-02-11 09:42:40 +09004 * Header file for TOMOYO.
Kentaro Takeda95908372009-02-05 17:18:13 +09005 *
Tetsuo Handa76bb0892010-02-11 09:42:40 +09006 * Copyright (C) 2005-2010 NTT DATA CORPORATION
Kentaro Takeda95908372009-02-05 17:18:13 +09007 */
8
9#ifndef _SECURITY_TOMOYO_COMMON_H
10#define _SECURITY_TOMOYO_COMMON_H
11
12#include <linux/ctype.h>
13#include <linux/string.h>
14#include <linux/mm.h>
15#include <linux/file.h>
16#include <linux/kmod.h>
17#include <linux/fs.h>
18#include <linux/sched.h>
19#include <linux/namei.h>
20#include <linux/mount.h>
21#include <linux/list.h>
Tetsuo Handa76bb0892010-02-11 09:42:40 +090022#include <linux/cred.h>
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +090023#include <linux/poll.h>
Tetsuo Handa76bb0892010-02-11 09:42:40 +090024struct linux_binprm;
Kentaro Takeda95908372009-02-05 17:18:13 +090025
Tetsuo Handa76bb0892010-02-11 09:42:40 +090026/********** Constants definitions. **********/
27
28/*
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.
32 */
33#define TOMOYO_HASH_BITS 8
34#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
35
Tetsuo Handac8c57e82010-06-03 20:36:43 +090036#define TOMOYO_EXEC_TMPSIZE 4096
Tetsuo Handa76bb0892010-02-11 09:42:40 +090037
38/* Profile number is an integer between 0 and 255. */
39#define TOMOYO_MAX_PROFILES 256
40
Tetsuo Handa32997142011-06-26 23:19:28 +090041/* Group number is an integer between 0 and 255. */
42#define TOMOYO_MAX_ACL_GROUPS 256
43
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090044/* Index numbers for operation mode. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +090045enum tomoyo_mode_index {
46 TOMOYO_CONFIG_DISABLED,
47 TOMOYO_CONFIG_LEARNING,
48 TOMOYO_CONFIG_PERMISSIVE,
Tetsuo Handa57c25902010-06-03 20:38:44 +090049 TOMOYO_CONFIG_ENFORCING,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +090050 TOMOYO_CONFIG_MAX_MODE,
51 TOMOYO_CONFIG_WANT_REJECT_LOG = 64,
52 TOMOYO_CONFIG_WANT_GRANT_LOG = 128,
53 TOMOYO_CONFIG_USE_DEFAULT = 255,
Tetsuo Handacb0abe62010-05-17 10:08:05 +090054};
55
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090056/* Index numbers for entry type. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090057enum tomoyo_policy_id {
58 TOMOYO_ID_GROUP,
59 TOMOYO_ID_PATH_GROUP,
60 TOMOYO_ID_NUMBER_GROUP,
Tetsuo Handa5448ec42010-06-21 11:14:39 +090061 TOMOYO_ID_TRANSITION_CONTROL,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090062 TOMOYO_ID_AGGREGATOR,
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090063 TOMOYO_ID_MANAGER,
64 TOMOYO_ID_NAME,
65 TOMOYO_ID_ACL,
66 TOMOYO_ID_DOMAIN,
67 TOMOYO_MAX_POLICY
68};
69
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090070/* Index numbers for group entries. */
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090071enum tomoyo_group_id {
72 TOMOYO_PATH_GROUP,
73 TOMOYO_NUMBER_GROUP,
74 TOMOYO_MAX_GROUP
75};
76
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090077/* Index numbers for type of numeric values. */
78enum tomoyo_value_type {
79 TOMOYO_VALUE_TYPE_INVALID,
80 TOMOYO_VALUE_TYPE_DECIMAL,
81 TOMOYO_VALUE_TYPE_OCTAL,
82 TOMOYO_VALUE_TYPE_HEXADECIMAL,
83};
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090084
Tetsuo Handab5bc60b2011-06-26 23:16:03 +090085/* Index numbers for domain transition control keywords. */
Tetsuo Handa5448ec42010-06-21 11:14:39 +090086enum tomoyo_transition_type {
87 /* Do not change this order, */
Tetsuo Handabd03a3e2011-06-26 23:19:52 +090088 TOMOYO_TRANSITION_CONTROL_NO_RESET,
89 TOMOYO_TRANSITION_CONTROL_RESET,
Tetsuo Handa5448ec42010-06-21 11:14:39 +090090 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
91 TOMOYO_TRANSITION_CONTROL_INITIALIZE,
92 TOMOYO_TRANSITION_CONTROL_NO_KEEP,
93 TOMOYO_TRANSITION_CONTROL_KEEP,
94 TOMOYO_MAX_TRANSITION_TYPE
95};
96
Tetsuo Handa76bb0892010-02-11 09:42:40 +090097/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +090098enum tomoyo_acl_entry_type_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +090099 TOMOYO_TYPE_PATH_ACL,
100 TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900101 TOMOYO_TYPE_PATH_NUMBER_ACL,
Tetsuo Handa75093152010-06-16 16:23:55 +0900102 TOMOYO_TYPE_MKDEV_ACL,
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900103 TOMOYO_TYPE_MOUNT_ACL,
Tetsuo Handa084da352010-02-15 15:10:39 +0900104};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900105
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900106/* Index numbers for access controls with one pathname. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900107enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900108 TOMOYO_TYPE_EXECUTE,
109 TOMOYO_TYPE_READ,
110 TOMOYO_TYPE_WRITE,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900111 TOMOYO_TYPE_APPEND,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900112 TOMOYO_TYPE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900113 TOMOYO_TYPE_GETATTR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900114 TOMOYO_TYPE_RMDIR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900115 TOMOYO_TYPE_TRUNCATE,
116 TOMOYO_TYPE_SYMLINK,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900117 TOMOYO_TYPE_CHROOT,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900118 TOMOYO_TYPE_UMOUNT,
119 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900120};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900121
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900122enum tomoyo_memory_stat_type {
123 TOMOYO_MEMORY_POLICY,
124 TOMOYO_MEMORY_AUDIT,
125 TOMOYO_MEMORY_QUERY,
126 TOMOYO_MAX_MEMORY_STAT
127};
128
Tetsuo Handa75093152010-06-16 16:23:55 +0900129enum tomoyo_mkdev_acl_index {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900130 TOMOYO_TYPE_MKBLOCK,
131 TOMOYO_TYPE_MKCHAR,
Tetsuo Handa75093152010-06-16 16:23:55 +0900132 TOMOYO_MAX_MKDEV_OPERATION
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900133};
134
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900135/* Index numbers for access controls with two pathnames. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900136enum tomoyo_path2_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900137 TOMOYO_TYPE_LINK,
138 TOMOYO_TYPE_RENAME,
139 TOMOYO_TYPE_PIVOT_ROOT,
140 TOMOYO_MAX_PATH2_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900141};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900142
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900143/* Index numbers for access controls with one pathname and one number. */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900144enum tomoyo_path_number_acl_index {
145 TOMOYO_TYPE_CREATE,
146 TOMOYO_TYPE_MKDIR,
147 TOMOYO_TYPE_MKFIFO,
148 TOMOYO_TYPE_MKSOCK,
149 TOMOYO_TYPE_IOCTL,
150 TOMOYO_TYPE_CHMOD,
151 TOMOYO_TYPE_CHOWN,
152 TOMOYO_TYPE_CHGRP,
153 TOMOYO_MAX_PATH_NUMBER_OPERATION
154};
155
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900156/* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900157enum tomoyo_securityfs_interface_index {
158 TOMOYO_DOMAINPOLICY,
159 TOMOYO_EXCEPTIONPOLICY,
160 TOMOYO_DOMAIN_STATUS,
161 TOMOYO_PROCESS_STATUS,
162 TOMOYO_MEMINFO,
163 TOMOYO_SELFDOMAIN,
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900164 TOMOYO_AUDIT,
Tetsuo Handa084da352010-02-15 15:10:39 +0900165 TOMOYO_VERSION,
166 TOMOYO_PROFILE,
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900167 TOMOYO_QUERY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900168 TOMOYO_MANAGER
169};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900170
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900171/* Index numbers for special mount operations. */
172enum tomoyo_special_mount {
173 TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */
174 TOMOYO_MOUNT_MOVE, /* mount --move /old /new */
175 TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */
176 TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
177 TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */
178 TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */
179 TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */
180 TOMOYO_MAX_SPECIAL_MOUNT
181};
182
183/* Index numbers for functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900184enum tomoyo_mac_index {
185 TOMOYO_MAC_FILE_EXECUTE,
186 TOMOYO_MAC_FILE_OPEN,
187 TOMOYO_MAC_FILE_CREATE,
188 TOMOYO_MAC_FILE_UNLINK,
Tetsuo Handa7c759642011-06-26 23:15:31 +0900189 TOMOYO_MAC_FILE_GETATTR,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900190 TOMOYO_MAC_FILE_MKDIR,
191 TOMOYO_MAC_FILE_RMDIR,
192 TOMOYO_MAC_FILE_MKFIFO,
193 TOMOYO_MAC_FILE_MKSOCK,
194 TOMOYO_MAC_FILE_TRUNCATE,
195 TOMOYO_MAC_FILE_SYMLINK,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900196 TOMOYO_MAC_FILE_MKBLOCK,
197 TOMOYO_MAC_FILE_MKCHAR,
198 TOMOYO_MAC_FILE_LINK,
199 TOMOYO_MAC_FILE_RENAME,
200 TOMOYO_MAC_FILE_CHMOD,
201 TOMOYO_MAC_FILE_CHOWN,
202 TOMOYO_MAC_FILE_CHGRP,
203 TOMOYO_MAC_FILE_IOCTL,
204 TOMOYO_MAC_FILE_CHROOT,
205 TOMOYO_MAC_FILE_MOUNT,
206 TOMOYO_MAC_FILE_UMOUNT,
207 TOMOYO_MAC_FILE_PIVOT_ROOT,
208 TOMOYO_MAX_MAC_INDEX
209};
210
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900211/* Index numbers for category of functionality. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900212enum tomoyo_mac_category_index {
213 TOMOYO_MAC_CATEGORY_FILE,
214 TOMOYO_MAX_MAC_CATEGORY_INDEX
215};
216
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900217/*
218 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
219 * occurred in enforcing mode and the userspace daemon decided to retry.
220 *
221 * We must choose a positive value in order to distinguish "granted" (which is
222 * 0) and "rejected" (which is a negative value) and "retry".
223 */
224#define TOMOYO_RETRY_REQUEST 1
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900225
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900226/* Index numbers for profile's PREFERENCE values. */
227enum tomoyo_pref_index {
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900228 TOMOYO_PREF_MAX_AUDIT_LOG,
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900229 TOMOYO_PREF_MAX_LEARNING_ENTRY,
230 TOMOYO_MAX_PREF
231};
232
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900233/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900234
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900235/* Common header for holding ACL entries. */
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900236struct tomoyo_acl_head {
237 struct list_head list;
238 bool is_deleted;
239} __packed;
240
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900241/* Common header for shared entries. */
242struct tomoyo_shared_acl_head {
243 struct list_head list;
244 atomic_t users;
245} __packed;
246
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900247struct tomoyo_policy_namespace;
248
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900249/* Structure for request info. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900250struct tomoyo_request_info {
251 struct tomoyo_domain_info *domain;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900252 /* For holding parameters. */
253 union {
254 struct {
255 const struct tomoyo_path_info *filename;
Tetsuo Handa484ca792010-07-29 14:29:55 +0900256 /* For using wildcards at tomoyo_find_next_domain(). */
257 const struct tomoyo_path_info *matched_path;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900258 /* One of values in "enum tomoyo_path_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900259 u8 operation;
260 } path;
261 struct {
262 const struct tomoyo_path_info *filename1;
263 const struct tomoyo_path_info *filename2;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900264 /* One of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900265 u8 operation;
266 } path2;
267 struct {
268 const struct tomoyo_path_info *filename;
269 unsigned int mode;
270 unsigned int major;
271 unsigned int minor;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900272 /* One of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900273 u8 operation;
274 } mkdev;
275 struct {
276 const struct tomoyo_path_info *filename;
277 unsigned long number;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900278 /*
279 * One of values in
280 * "enum tomoyo_path_number_acl_index".
281 */
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900282 u8 operation;
283 } path_number;
284 struct {
285 const struct tomoyo_path_info *type;
286 const struct tomoyo_path_info *dir;
287 const struct tomoyo_path_info *dev;
288 unsigned long flags;
289 int need_dev;
290 } mount;
291 } param;
292 u8 param_type;
293 bool granted;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900294 u8 retry;
295 u8 profile;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900296 u8 mode; /* One of tomoyo_mode_index . */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900297 u8 type;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900298};
299
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900300/* Structure for holding a token. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900301struct tomoyo_path_info {
302 const char *name;
303 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900304 u16 const_len; /* = tomoyo_const_part_length(name) */
305 bool is_dir; /* = tomoyo_strendswith(name, "/") */
306 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900307};
308
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900309/* Structure for holding string data. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900310struct tomoyo_name {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900311 struct tomoyo_shared_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900312 struct tomoyo_path_info entry;
313};
Kentaro Takeda95908372009-02-05 17:18:13 +0900314
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900315/* Structure for holding a word. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900316struct tomoyo_name_union {
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900317 /* Either @filename or @group is NULL. */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900318 const struct tomoyo_path_info *filename;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900319 struct tomoyo_group *group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900320};
321
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900322/* Structure for holding a number. */
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900323struct tomoyo_number_union {
324 unsigned long values[2];
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900325 struct tomoyo_group *group; /* Maybe NULL. */
326 /* One of values in "enum tomoyo_value_type". */
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900327 u8 value_type[2];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900328};
329
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900330/* Structure for "path_group"/"number_group" directive. */
331struct tomoyo_group {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900332 struct tomoyo_shared_acl_head head;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900333 const struct tomoyo_path_info *group_name;
334 struct list_head member_list;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900335};
336
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900337/* Structure for "path_group" directive. */
338struct tomoyo_path_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900339 struct tomoyo_acl_head head;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900340 const struct tomoyo_path_info *member_name;
341};
342
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900343/* Structure for "number_group" directive. */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900344struct tomoyo_number_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900345 struct tomoyo_acl_head head;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900346 struct tomoyo_number_union number;
347};
348
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900349/* Common header for individual entries. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900350struct tomoyo_acl_info {
351 struct list_head list;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900352 bool is_deleted;
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900353 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
Kentaro Takeda95908372009-02-05 17:18:13 +0900354} __packed;
355
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900356/* Structure for domain information. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900357struct tomoyo_domain_info {
358 struct list_head list;
359 struct list_head acl_info_list;
360 /* Name of this domain. Never NULL. */
361 const struct tomoyo_path_info *domainname;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900362 /* Namespace for this domain. Never NULL. */
363 struct tomoyo_policy_namespace *ns;
Kentaro Takeda95908372009-02-05 17:18:13 +0900364 u8 profile; /* Profile number to use. */
Tetsuo Handa32997142011-06-26 23:19:28 +0900365 u8 group; /* Group number to use. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900366 bool is_deleted; /* Delete flag. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900367 bool quota_warned; /* Quota warnning flag. */
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900368 bool transition_failed; /* Domain transition failed flag. */
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900369 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900370};
371
Kentaro Takeda95908372009-02-05 17:18:13 +0900372/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900373 * Structure for "file execute", "file read", "file write", "file append",
374 * "file unlink", "file getattr", "file rmdir", "file truncate",
375 * "file symlink", "file chroot" and "file unmount" directive.
Kentaro Takeda95908372009-02-05 17:18:13 +0900376 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900377struct tomoyo_path_acl {
378 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900379 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900380 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900381};
382
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900383/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900384 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
385 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900386 */
387struct tomoyo_path_number_acl {
388 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900389 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900390 u8 perm;
391 struct tomoyo_name_union name;
392 struct tomoyo_number_union number;
393};
394
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900395/* Structure for "file mkblock" and "file mkchar" directive. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900396struct tomoyo_mkdev_acl {
397 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900398 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900399 struct tomoyo_name_union name;
400 struct tomoyo_number_union mode;
401 struct tomoyo_number_union major;
402 struct tomoyo_number_union minor;
403};
404
405/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900406 * Structure for "file rename", "file link" and "file pivot_root" directive.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900407 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900408struct tomoyo_path2_acl {
409 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900410 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900411 struct tomoyo_name_union name1;
412 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900413};
414
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900415/* Structure for "file mount" directive. */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900416struct tomoyo_mount_acl {
417 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900418 struct tomoyo_name_union dev_name;
419 struct tomoyo_name_union dir_name;
420 struct tomoyo_name_union fs_type;
421 struct tomoyo_number_union flags;
422};
423
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900424/* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
425struct tomoyo_acl_param {
426 char *data;
427 struct list_head *list;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900428 struct tomoyo_policy_namespace *ns;
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900429 bool is_delete;
430};
431
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900432#define TOMOYO_MAX_IO_READ_QUEUE 64
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900433
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900434/*
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900435 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
436 * interfaces.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900437 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900438struct tomoyo_io_buffer {
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900439 void (*read) (struct tomoyo_io_buffer *);
Kentaro Takeda95908372009-02-05 17:18:13 +0900440 int (*write) (struct tomoyo_io_buffer *);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900441 int (*poll) (struct file *file, poll_table *wait);
Kentaro Takeda95908372009-02-05 17:18:13 +0900442 /* Exclusive lock for this structure. */
443 struct mutex io_sem;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900444 char __user *read_user_buf;
445 int read_user_buf_avail;
446 struct {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900447 struct list_head *ns;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900448 struct list_head *domain;
449 struct list_head *group;
450 struct list_head *acl;
451 int avail;
452 int step;
453 int query_index;
454 u16 index;
Tetsuo Handa32997142011-06-26 23:19:28 +0900455 u8 acl_group_index;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900456 u8 bit;
457 u8 w_pos;
458 bool eof;
459 bool print_this_domain_only;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900460 bool print_transition_related_only;
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900461 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
462 } r;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900463 struct {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900464 struct tomoyo_policy_namespace *ns;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900465 /* The position currently writing to. */
466 struct tomoyo_domain_info *domain;
467 /* Bytes available for writing. */
468 int avail;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900469 bool is_delete;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900470 } w;
Kentaro Takeda95908372009-02-05 17:18:13 +0900471 /* Buffer for reading. */
472 char *read_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900473 /* Size of read buffer. */
474 int readbuf_size;
475 /* Buffer for writing. */
476 char *write_buf;
Kentaro Takeda95908372009-02-05 17:18:13 +0900477 /* Size of write buffer. */
478 int writebuf_size;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900479 /* Type of this interface. */
480 u8 type;
Tetsuo Handa2e503bb2011-06-26 23:20:55 +0900481 /* Users counter protected by tomoyo_io_buffer_list_lock. */
482 u8 users;
483 /* List for telling GC not to kfree() elements. */
484 struct list_head list;
Kentaro Takeda95908372009-02-05 17:18:13 +0900485};
486
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900487/*
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900488 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
489 * "no_keep_domain" keyword.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900490 */
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900491struct tomoyo_transition_control {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900492 struct tomoyo_acl_head head;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900493 u8 type; /* One of values in "enum tomoyo_transition_type". */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900494 /* True if the domainname is tomoyo_get_last_name(). */
495 bool is_last_name;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900496 const struct tomoyo_path_info *domainname; /* Maybe NULL */
497 const struct tomoyo_path_info *program; /* Maybe NULL */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900498};
499
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900500/* Structure for "aggregator" keyword. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900501struct tomoyo_aggregator {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900502 struct tomoyo_acl_head head;
Tetsuo Handa10843072010-06-03 20:38:03 +0900503 const struct tomoyo_path_info *original_name;
504 const struct tomoyo_path_info *aggregated_name;
Tetsuo Handa10843072010-06-03 20:38:03 +0900505};
506
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900507/* Structure for policy manager. */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900508struct tomoyo_manager {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900509 struct tomoyo_acl_head head;
510 bool is_domain; /* True if manager is a domainname. */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900511 /* A path to program or a domainname. */
512 const struct tomoyo_path_info *manager;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900513};
514
Tetsuo Handa57c25902010-06-03 20:38:44 +0900515struct tomoyo_preference {
516 unsigned int learning_max_entry;
517 bool enforcing_verbose;
518 bool learning_verbose;
519 bool permissive_verbose;
520};
521
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900522/* Structure for /sys/kernel/security/tomnoyo/profile interface. */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900523struct tomoyo_profile {
524 const struct tomoyo_path_info *comment;
525 struct tomoyo_preference *learning;
526 struct tomoyo_preference *permissive;
527 struct tomoyo_preference *enforcing;
528 struct tomoyo_preference preference;
529 u8 default_config;
530 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
Tetsuo Handad5ca1722011-06-26 23:18:21 +0900531 unsigned int pref[TOMOYO_MAX_PREF];
Tetsuo Handa57c25902010-06-03 20:38:44 +0900532};
533
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900534/* Structure for representing YYYY/MM/DD hh/mm/ss. */
535struct tomoyo_time {
536 u16 year;
537 u8 month;
538 u8 day;
539 u8 hour;
540 u8 min;
541 u8 sec;
542};
543
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900544/* Structure for policy namespace. */
545struct tomoyo_policy_namespace {
546 /* Profile table. Memory is allocated as needed. */
547 struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES];
548 /* List of "struct tomoyo_group". */
549 struct list_head group_list[TOMOYO_MAX_GROUP];
550 /* List of policy. */
551 struct list_head policy_list[TOMOYO_MAX_POLICY];
552 /* The global ACL referred by "use_group" keyword. */
553 struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS];
554 /* List for connecting to tomoyo_namespace_list list. */
555 struct list_head namespace_list;
556 /* Profile version. Currently only 20100903 is defined. */
557 unsigned int profile_version;
558 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
559 const char *name;
560};
561
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900562/********** Function prototypes. **********/
563
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900564void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900565bool tomoyo_str_starts(char **src, const char *find);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900566const char *tomoyo_get_exe(void);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900567void tomoyo_normalize_line(unsigned char *buffer);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900568void tomoyo_check_profile(void);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900569int tomoyo_open_control(const u8 type, struct file *file);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900570int tomoyo_close_control(struct tomoyo_io_buffer *head);
Tetsuo Handa0849e3b2010-06-25 12:22:09 +0900571int tomoyo_poll_control(struct file *file, poll_table *wait);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900572int tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900573 const int buffer_len);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900574int tomoyo_write_control(struct tomoyo_io_buffer *head,
575 const char __user *buffer, const int buffer_len);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900576bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900577void tomoyo_warn_oom(const char *function);
Tetsuo Handa484ca792010-07-29 14:29:55 +0900578const struct tomoyo_path_info *
579tomoyo_compare_name_union(const struct tomoyo_path_info *name,
580 const struct tomoyo_name_union *ptr);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900581bool tomoyo_compare_number_union(const unsigned long value,
582 const struct tomoyo_number_union *ptr);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900583int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
584 const u8 index);
Tetsuo Handaf23571e2010-06-24 14:57:16 +0900585void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
Kentaro Takeda95908372009-02-05 17:18:13 +0900586 __attribute__ ((format(printf, 2, 3)));
Tetsuo Handa75093152010-06-16 16:23:55 +0900587bool tomoyo_correct_domain(const unsigned char *domainname);
Tetsuo Handa75093152010-06-16 16:23:55 +0900588bool tomoyo_correct_path(const char *filename);
589bool tomoyo_correct_word(const char *string);
Tetsuo Handa75093152010-06-16 16:23:55 +0900590bool tomoyo_domain_def(const unsigned char *buffer);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900591bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900592 struct tomoyo_name_union *ptr);
Tetsuo Handa484ca792010-07-29 14:29:55 +0900593const struct tomoyo_path_info *
594tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
595 const struct tomoyo_group *group);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900596bool tomoyo_number_matches_group(const unsigned long min,
597 const unsigned long max,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900598 const struct tomoyo_group *group);
Kentaro Takeda95908372009-02-05 17:18:13 +0900599bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
600 const struct tomoyo_path_info *pattern);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900601bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
602 struct tomoyo_number_union *ptr);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900603bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
Kentaro Takeda95908372009-02-05 17:18:13 +0900604bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900605int tomoyo_init_request_info(struct tomoyo_request_info *r,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900606 struct tomoyo_domain_info *domain,
607 const u8 index);
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900608int tomoyo_mount_permission(char *dev_name, struct path *path,
609 const char *type, unsigned long flags,
610 void *data_page);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900611int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
612int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900613 const u8 type);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900614int tomoyo_write_file(struct tomoyo_acl_param *param);
615int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900616int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
617 __attribute__ ((format(printf, 2, 3)));
Kentaro Takeda95908372009-02-05 17:18:13 +0900618struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900619struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900620 const bool transit);
621struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
622 const u8 profile);
623struct tomoyo_policy_namespace *tomoyo_assign_namespace
624(const char *domainname);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900625struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
626 const u8 idx);
Kentaro Takeda95908372009-02-05 17:18:13 +0900627unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
628 const u8 index);
Kentaro Takeda95908372009-02-05 17:18:13 +0900629void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
Kentaro Takeda95908372009-02-05 17:18:13 +0900630void tomoyo_load_policy(const char *filename);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900631void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900632char *tomoyo_encode(const char *str);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900633char *tomoyo_realpath_nofollow(const char *pathname);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900634char *tomoyo_realpath_from_path(struct path *path);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900635bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900636void *tomoyo_commit_ok(void *data, const unsigned int size);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900637const struct tomoyo_path_info *tomoyo_get_name(const char *name);
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900638void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900639int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900640void __init tomoyo_mm_init(void);
Tetsuo Handa05336de2010-06-16 16:20:24 +0900641int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900642 const struct tomoyo_path_info *filename);
643int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
644 struct path *path, const int flag);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900645int tomoyo_path_number_perm(const u8 operation, struct path *path,
646 unsigned long number);
Tetsuo Handa75093152010-06-16 16:23:55 +0900647int tomoyo_mkdev_perm(const u8 operation, struct path *path,
648 const unsigned int mode, unsigned int dev);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900649int tomoyo_path_perm(const u8 operation, struct path *path);
650int tomoyo_path2_perm(const u8 operation, struct path *path1,
651 struct path *path2);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900652int tomoyo_find_next_domain(struct linux_binprm *bprm);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900653void tomoyo_print_ulong(char *buffer, const int buffer_len,
654 const unsigned long value, const u8 type);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900655void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
Tetsuo Handa2e503bb2011-06-26 23:20:55 +0900656void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
Tetsuo Handa847b1732010-02-11 09:43:54 +0900657void tomoyo_memory_free(void *ptr);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900658int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900659 struct tomoyo_acl_param *param,
Tetsuo Handa237ab452010-06-12 20:46:22 +0900660 bool (*check_duplicate) (const struct tomoyo_acl_info
661 *,
662 const struct tomoyo_acl_info
663 *),
664 bool (*merge_duplicate) (struct tomoyo_acl_info *,
665 struct tomoyo_acl_info *,
666 const bool));
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900667int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900668 struct tomoyo_acl_param *param,
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900669 bool (*check_duplicate) (const struct tomoyo_acl_head
670 *,
671 const struct tomoyo_acl_head
672 *));
Tetsuo Handa99a85252010-06-16 16:22:51 +0900673void tomoyo_check_acl(struct tomoyo_request_info *r,
Tetsuo Handa484ca792010-07-29 14:29:55 +0900674 bool (*check_entry) (struct tomoyo_request_info *,
Tetsuo Handa99a85252010-06-16 16:22:51 +0900675 const struct tomoyo_acl_info *));
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900676char *tomoyo_read_token(struct tomoyo_acl_param *param);
677bool tomoyo_permstr(const char *string, const char *keyword);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900678
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900679const char *tomoyo_yesno(const unsigned int value);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900680void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
681 __attribute__ ((format(printf, 2, 3)));
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900682void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
683 va_list args);
684void tomoyo_read_log(struct tomoyo_io_buffer *head);
685int tomoyo_poll_log(struct file *file, poll_table *wait);
686char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
687 va_list args);
688
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900689/********** External variable definitions. **********/
690
691/* Lock for GC. */
692extern struct srcu_struct tomoyo_ss;
693
694/* The list for "struct tomoyo_domain_info". */
695extern struct list_head tomoyo_domain_list;
696
Tetsuo Handa847b1732010-02-11 09:43:54 +0900697extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900698
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900699/* Lock for protecting policy. */
700extern struct mutex tomoyo_policy_lock;
701
702/* Has /sbin/init started? */
703extern bool tomoyo_policy_loaded;
704
705/* The kernel's domain. */
706extern struct tomoyo_domain_info tomoyo_kernel_domain;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900707extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
708extern struct list_head tomoyo_namespace_list;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900709
Tetsuo Handa71c28232010-06-16 16:26:38 +0900710extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
711extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];
712extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION];
713extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION];
714
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900715extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
716extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
717extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
718
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900719extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE];
720extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
721extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900722
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900723/********** Inlined functions. **********/
724
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900725/**
726 * tomoyo_read_lock - Take lock for protecting policy.
727 *
728 * Returns index number for tomoyo_read_unlock().
729 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900730static inline int tomoyo_read_lock(void)
731{
732 return srcu_read_lock(&tomoyo_ss);
733}
734
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900735/**
736 * tomoyo_read_unlock - Release lock for protecting policy.
737 *
738 * @idx: Index number returned by tomoyo_read_lock().
739 *
740 * Returns nothing.
741 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900742static inline void tomoyo_read_unlock(int idx)
743{
744 srcu_read_unlock(&tomoyo_ss, idx);
745}
746
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900747/**
748 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
749 *
750 * @a: Pointer to "struct tomoyo_path_info".
751 * @b: Pointer to "struct tomoyo_path_info".
752 *
753 * Returns true if @a == @b, false otherwise.
754 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900755static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
756 const struct tomoyo_path_info *b)
757{
758 return a->hash != b->hash || strcmp(a->name, b->name);
759}
760
Kentaro Takeda95908372009-02-05 17:18:13 +0900761/**
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900762 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
763 *
764 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
765 *
766 * Returns nothing.
767 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900768static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
769{
770 if (name) {
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900771 struct tomoyo_name *ptr =
772 container_of(name, typeof(*ptr), entry);
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900773 atomic_dec(&ptr->head.users);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900774 }
775}
Kentaro Takeda95908372009-02-05 17:18:13 +0900776
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900777/**
778 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
779 *
780 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
781 *
782 * Returns nothing.
783 */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900784static inline void tomoyo_put_group(struct tomoyo_group *group)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900785{
786 if (group)
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900787 atomic_dec(&group->head.users);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900788}
789
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900790/**
791 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
792 *
793 * Returns pointer to "struct tomoyo_domain_info" for current thread.
794 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900795static inline struct tomoyo_domain_info *tomoyo_domain(void)
796{
797 return current_cred()->security;
798}
Kentaro Takeda95908372009-02-05 17:18:13 +0900799
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900800/**
801 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
802 *
803 * @task: Pointer to "struct task_struct".
804 *
805 * Returns pointer to "struct tomoyo_security" for specified thread.
806 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900807static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
808 *task)
809{
810 return task_cred_xxx(task, security);
811}
Kentaro Takeda95908372009-02-05 17:18:13 +0900812
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900813/**
814 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
815 *
816 * @a: Pointer to "struct tomoyo_name_union".
817 * @b: Pointer to "struct tomoyo_name_union".
818 *
819 * Returns true if @a == @b, false otherwise.
820 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900821static inline bool tomoyo_same_name_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900822(const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900823{
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900824 return a->filename == b->filename && a->group == b->group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900825}
826
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900827/**
828 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
829 *
830 * @a: Pointer to "struct tomoyo_number_union".
831 * @b: Pointer to "struct tomoyo_number_union".
832 *
833 * Returns true if @a == @b, false otherwise.
834 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900835static inline bool tomoyo_same_number_union
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900836(const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900837{
Tetsuo Handab5bc60b2011-06-26 23:16:03 +0900838 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900839 a->group == b->group && a->value_type[0] == b->value_type[0] &&
840 a->value_type[1] == b->value_type[1];
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900841}
842
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900843/**
844 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
845 *
846 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
847 */
848static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void)
849{
850 return tomoyo_domain()->ns;
851}
852
Tetsuo Handaeadd99c2011-06-26 23:18:58 +0900853#if defined(CONFIG_SLOB)
854
855/**
856 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
857 *
858 * @size: Size to be rounded up.
859 *
860 * Returns @size.
861 *
862 * Since SLOB does not round up, this function simply returns @size.
863 */
864static inline int tomoyo_round2(size_t size)
865{
866 return size;
867}
868
869#else
870
871/**
872 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
873 *
874 * @size: Size to be rounded up.
875 *
876 * Returns rounded size.
877 *
878 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
879 * (e.g.) 128 bytes.
880 */
881static inline int tomoyo_round2(size_t size)
882{
883#if PAGE_SIZE == 4096
884 size_t bsize = 32;
885#else
886 size_t bsize = 64;
887#endif
888 if (!size)
889 return 0;
890 while (size > bsize)
891 bsize <<= 1;
892 return bsize;
893}
894
895#endif
896
Kentaro Takeda95908372009-02-05 17:18:13 +0900897/**
898 * list_for_each_cookie - iterate over a list with cookie.
899 * @pos: the &struct list_head to use as a loop cursor.
Kentaro Takeda95908372009-02-05 17:18:13 +0900900 * @head: the head for your list.
Kentaro Takeda95908372009-02-05 17:18:13 +0900901 */
Tetsuo Handa475e6fa2010-06-24 11:28:14 +0900902#define list_for_each_cookie(pos, head) \
903 if (!pos) \
904 pos = srcu_dereference((head)->next, &tomoyo_ss); \
905 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900906
Kentaro Takeda95908372009-02-05 17:18:13 +0900907#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */