blob: ec3ed488ee30e966f4963fcfb2c7659cf68f69b9 [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 Handacb0abe62010-05-17 10:08:05 +090041enum tomoyo_mode_index {
42 TOMOYO_CONFIG_DISABLED,
43 TOMOYO_CONFIG_LEARNING,
44 TOMOYO_CONFIG_PERMISSIVE,
Tetsuo Handa57c25902010-06-03 20:38:44 +090045 TOMOYO_CONFIG_ENFORCING,
46 TOMOYO_CONFIG_USE_DEFAULT = 255
Tetsuo Handacb0abe62010-05-17 10:08:05 +090047};
48
Tetsuo Handaa230f9e2010-06-17 16:53:24 +090049enum tomoyo_policy_id {
50 TOMOYO_ID_GROUP,
51 TOMOYO_ID_PATH_GROUP,
52 TOMOYO_ID_NUMBER_GROUP,
53 TOMOYO_ID_DOMAIN_INITIALIZER,
54 TOMOYO_ID_DOMAIN_KEEPER,
55 TOMOYO_ID_AGGREGATOR,
56 TOMOYO_ID_ALIAS,
57 TOMOYO_ID_GLOBALLY_READABLE,
58 TOMOYO_ID_PATTERN,
59 TOMOYO_ID_NO_REWRITE,
60 TOMOYO_ID_MANAGER,
61 TOMOYO_ID_NAME,
62 TOMOYO_ID_ACL,
63 TOMOYO_ID_DOMAIN,
64 TOMOYO_MAX_POLICY
65};
66
67enum tomoyo_group_id {
68 TOMOYO_PATH_GROUP,
69 TOMOYO_NUMBER_GROUP,
70 TOMOYO_MAX_GROUP
71};
72
Tetsuo Handa76bb0892010-02-11 09:42:40 +090073/* Keywords for ACLs. */
Tetsuo Handa10843072010-06-03 20:38:03 +090074#define TOMOYO_KEYWORD_AGGREGATOR "aggregator "
Tetsuo Handa76bb0892010-02-11 09:42:40 +090075#define TOMOYO_KEYWORD_ALIAS "alias "
Tetsuo Handa2106ccd2010-05-17 10:10:31 +090076#define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount "
Tetsuo Handa76bb0892010-02-11 09:42:40 +090077#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 "
Tetsuo Handa7762fbf2010-05-10 17:30:26 +090085#define TOMOYO_KEYWORD_PATH_GROUP "path_group "
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090086#define TOMOYO_KEYWORD_NUMBER_GROUP "number_group "
Tetsuo Handa76bb0892010-02-11 09:42:40 +090087#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"
Tetsuo Handa9b244372010-06-03 20:35:53 +090090#define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded"
91#define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed"
Tetsuo Handa76bb0892010-02-11 09:42:40 +090092/* A domain definition starts with <kernel>. */
93#define TOMOYO_ROOT_NAME "<kernel>"
94#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
95
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090096/* 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
101
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900102/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +0900103enum tomoyo_acl_entry_type_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900104 TOMOYO_TYPE_PATH_ACL,
105 TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900106 TOMOYO_TYPE_PATH_NUMBER_ACL,
Tetsuo Handa75093152010-06-16 16:23:55 +0900107 TOMOYO_TYPE_MKDEV_ACL,
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900108 TOMOYO_TYPE_MOUNT_ACL,
Tetsuo Handa084da352010-02-15 15:10:39 +0900109};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900110
111/* Index numbers for File Controls. */
112
113/*
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900114 * 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.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900122 */
123
Tetsuo Handa084da352010-02-15 15:10:39 +0900124enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900125 TOMOYO_TYPE_READ_WRITE,
126 TOMOYO_TYPE_EXECUTE,
127 TOMOYO_TYPE_READ,
128 TOMOYO_TYPE_WRITE,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900129 TOMOYO_TYPE_UNLINK,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900130 TOMOYO_TYPE_RMDIR,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900131 TOMOYO_TYPE_TRUNCATE,
132 TOMOYO_TYPE_SYMLINK,
133 TOMOYO_TYPE_REWRITE,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900134 TOMOYO_TYPE_CHROOT,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900135 TOMOYO_TYPE_UMOUNT,
136 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900137};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900138
Tetsuo Handa237ab452010-06-12 20:46:22 +0900139#define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE))
140
Tetsuo Handa75093152010-06-16 16:23:55 +0900141enum tomoyo_mkdev_acl_index {
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900142 TOMOYO_TYPE_MKBLOCK,
143 TOMOYO_TYPE_MKCHAR,
Tetsuo Handa75093152010-06-16 16:23:55 +0900144 TOMOYO_MAX_MKDEV_OPERATION
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900145};
146
Tetsuo Handa084da352010-02-15 15:10:39 +0900147enum tomoyo_path2_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900148 TOMOYO_TYPE_LINK,
149 TOMOYO_TYPE_RENAME,
150 TOMOYO_TYPE_PIVOT_ROOT,
151 TOMOYO_MAX_PATH2_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900152};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900153
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900154enum tomoyo_path_number_acl_index {
155 TOMOYO_TYPE_CREATE,
156 TOMOYO_TYPE_MKDIR,
157 TOMOYO_TYPE_MKFIFO,
158 TOMOYO_TYPE_MKSOCK,
159 TOMOYO_TYPE_IOCTL,
160 TOMOYO_TYPE_CHMOD,
161 TOMOYO_TYPE_CHOWN,
162 TOMOYO_TYPE_CHGRP,
163 TOMOYO_MAX_PATH_NUMBER_OPERATION
164};
165
Tetsuo Handa084da352010-02-15 15:10:39 +0900166enum tomoyo_securityfs_interface_index {
167 TOMOYO_DOMAINPOLICY,
168 TOMOYO_EXCEPTIONPOLICY,
169 TOMOYO_DOMAIN_STATUS,
170 TOMOYO_PROCESS_STATUS,
171 TOMOYO_MEMINFO,
172 TOMOYO_SELFDOMAIN,
173 TOMOYO_VERSION,
174 TOMOYO_PROFILE,
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900175 TOMOYO_QUERY,
Tetsuo Handa084da352010-02-15 15:10:39 +0900176 TOMOYO_MANAGER
177};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900178
Tetsuo Handa57c25902010-06-03 20:38:44 +0900179enum 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,
203 TOMOYO_MAX_MAC_INDEX
204};
205
206enum tomoyo_mac_category_index {
207 TOMOYO_MAC_CATEGORY_FILE,
208 TOMOYO_MAX_MAC_CATEGORY_INDEX
209};
210
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900211#define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */
212
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900213/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900214
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900215/*
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900216 * tomoyo_acl_head is a structure which is used for holding elements not in
217 * domain policy.
218 * It has following fields.
219 *
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
222 * otherwise.
223 */
224struct tomoyo_acl_head {
225 struct list_head list;
226 bool is_deleted;
227} __packed;
228
229/*
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900230 * tomoyo_request_info is a structure which is used for holding
231 *
232 * (1) Domain information of current process.
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900233 * (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.
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900236 */
237struct tomoyo_request_info {
238 struct tomoyo_domain_info *domain;
Tetsuo Handacf6e9a62010-06-16 16:21:36 +0900239 /* For holding parameters. */
240 union {
241 struct {
242 const struct tomoyo_path_info *filename;
243 u8 operation;
244 } path;
245 struct {
246 const struct tomoyo_path_info *filename1;
247 const struct tomoyo_path_info *filename2;
248 u8 operation;
249 } path2;
250 struct {
251 const struct tomoyo_path_info *filename;
252 unsigned int mode;
253 unsigned int major;
254 unsigned int minor;
255 u8 operation;
256 } mkdev;
257 struct {
258 const struct tomoyo_path_info *filename;
259 unsigned long number;
260 u8 operation;
261 } path_number;
262 struct {
263 const struct tomoyo_path_info *type;
264 const struct tomoyo_path_info *dir;
265 const struct tomoyo_path_info *dev;
266 unsigned long flags;
267 int need_dev;
268 } mount;
269 } param;
270 u8 param_type;
271 bool granted;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900272 u8 retry;
273 u8 profile;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900274 u8 mode; /* One of tomoyo_mode_index . */
Tetsuo Handa57c25902010-06-03 20:38:44 +0900275 u8 type;
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900276};
277
278/*
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900279 * tomoyo_path_info is a structure which is used for holding a string data
280 * used by TOMOYO.
281 * This structure has several fields for supporting pattern matching.
282 *
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
286 * using strcmp().
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 "/",
291 * false otherwise.
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.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900297 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900298struct tomoyo_path_info {
299 const char *name;
300 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900301 u16 const_len; /* = tomoyo_const_part_length(name) */
302 bool is_dir; /* = tomoyo_strendswith(name, "/") */
303 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900304};
305
306/*
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900307 * tomoyo_name_entry is a structure which is used for linking
308 * "struct tomoyo_path_info" into tomoyo_name_list .
Kentaro Takeda95908372009-02-05 17:18:13 +0900309 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900310struct tomoyo_name_entry {
311 struct list_head list;
312 atomic_t users;
313 struct tomoyo_path_info entry;
314};
Kentaro Takeda95908372009-02-05 17:18:13 +0900315
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900316struct tomoyo_name_union {
317 const struct tomoyo_path_info *filename;
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900318 struct tomoyo_group *group;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900319 u8 is_group;
320};
321
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900322struct tomoyo_number_union {
323 unsigned long values[2];
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900324 struct tomoyo_group *group;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900325 u8 min_type;
326 u8 max_type;
327 u8 is_group;
328};
329
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900330/* Structure for "path_group"/"number_group" directive. */
331struct tomoyo_group {
332 struct list_head list;
333 const struct tomoyo_path_info *group_name;
334 struct list_head member_list;
335 atomic_t users;
336};
337
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900338/* Structure for "path_group" directive. */
339struct tomoyo_path_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900340 struct tomoyo_acl_head head;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900341 const struct tomoyo_path_info *member_name;
342};
343
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900344/* Structure for "number_group" directive. */
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900345struct tomoyo_number_group {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900346 struct tomoyo_acl_head head;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900347 struct tomoyo_number_union number;
348};
349
Kentaro Takeda95908372009-02-05 17:18:13 +0900350/*
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900351 * tomoyo_acl_info is a structure which is used for holding
352 *
353 * (1) "list" which is linked to the ->acl_info_list of
354 * "struct tomoyo_domain_info"
Tetsuo Handa237ab452010-06-12 20:46:22 +0900355 * (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.
Kentaro Takeda95908372009-02-05 17:18:13 +0900358 *
359 * Packing "struct tomoyo_acl_info" allows
Tetsuo Handa237ab452010-06-12 20:46:22 +0900360 * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl"
Tetsuo Handa75093152010-06-16 16:23:55 +0900361 * "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed
Tetsuo Handa237ab452010-06-12 20:46:22 +0900362 * "u8" without enlarging their structure size.
Kentaro Takeda95908372009-02-05 17:18:13 +0900363 */
364struct tomoyo_acl_info {
365 struct list_head list;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900366 bool is_deleted;
367 u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */
Kentaro Takeda95908372009-02-05 17:18:13 +0900368} __packed;
369
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900370/*
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.
374 *
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.
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900383 * (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.
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900390 * (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
393 * collection.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900394 *
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).
401 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900402struct 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. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900408 bool is_deleted; /* Delete flag. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900409 bool quota_warned; /* Quota warnning flag. */
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900410 bool ignore_global_allow_read; /* Ignore "allow_read" flag. */
411 bool transition_failed; /* Domain transition failed flag. */
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900412 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900413};
414
Kentaro Takeda95908372009-02-05 17:18:13 +0900415/*
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900416 * tomoyo_path_acl is a structure which is used for holding an
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900417 * entry with one pathname operation (e.g. open(), mkdir()).
418 * It has following fields.
419 *
420 * (1) "head" which is a "struct tomoyo_acl_info".
421 * (2) "perm" which is a bitmask of permitted operations.
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900422 * (3) "name" is the pathname.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900423 *
424 * Directives held by this structure are "allow_read/write", "allow_execute",
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900425 * "allow_read", "allow_write", "allow_unlink", "allow_rmdir",
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900426 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and
427 * "allow_unmount".
Kentaro Takeda95908372009-02-05 17:18:13 +0900428 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900429struct tomoyo_path_acl {
430 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Kentaro Takeda95908372009-02-05 17:18:13 +0900431 u16 perm;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900432 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900433};
434
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900435/*
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900436 * 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.
439 *
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.
444 *
445 * Directives held by this structure are "allow_create", "allow_mkdir",
446 * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown"
447 * and "allow_chgrp".
448 *
449 */
450struct tomoyo_path_number_acl {
451 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
452 u8 perm;
453 struct tomoyo_name_union name;
454 struct tomoyo_number_union number;
455};
456
457/*
Tetsuo Handa75093152010-06-16 16:23:55 +0900458 * tomoyo_mkdev_acl is a structure which is used for holding an
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900459 * entry with one pathname and three numbers operation.
460 * It has following fields.
461 *
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.
467 *
468 * Directives held by this structure are "allow_mkchar", "allow_mkblock".
469 *
470 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900471struct tomoyo_mkdev_acl {
472 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900473 u8 perm;
474 struct tomoyo_name_union name;
475 struct tomoyo_number_union mode;
476 struct tomoyo_number_union major;
477 struct tomoyo_number_union minor;
478};
479
480/*
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900481 * tomoyo_path2_acl is a structure which is used for holding an
Tetsuo Handa937bf612009-12-02 21:09:48 +0900482 * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900483 * It has following fields.
484 *
485 * (1) "head" which is a "struct tomoyo_acl_info".
486 * (2) "perm" which is a bitmask of permitted operations.
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900487 * (3) "name1" is the source/old pathname.
488 * (4) "name2" is the destination/new pathname.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900489 *
Tetsuo Handa937bf612009-12-02 21:09:48 +0900490 * Directives held by this structure are "allow_rename", "allow_link" and
491 * "allow_pivot_root".
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900492 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900493struct tomoyo_path2_acl {
494 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Kentaro Takeda95908372009-02-05 17:18:13 +0900495 u8 perm;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900496 struct tomoyo_name_union name1;
497 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900498};
499
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900500/*
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900501 * tomoyo_mount_acl is a structure which is used for holding an
502 * entry for mount operation.
503 * It has following fields.
504 *
505 * (1) "head" which is a "struct tomoyo_acl_info".
Tetsuo Handa237ab452010-06-12 20:46:22 +0900506 * (2) "dev_name" is the device name.
507 * (3) "dir_name" is the mount point.
508 * (4) "fs_type" is the filesystem type.
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900509 * (5) "flags" is the mount flags.
510 *
Tetsuo Handa237ab452010-06-12 20:46:22 +0900511 * Directive held by this structure is "allow_mount".
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900512 */
513struct tomoyo_mount_acl {
514 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900515 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;
519};
520
521/*
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900522 * 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
525 * cursors.
526 *
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 ).
532 *
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
536 * if seek failed).
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
542 * is appended.
543 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900544struct tomoyo_io_buffer {
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900545 void (*read) (struct tomoyo_io_buffer *);
Kentaro Takeda95908372009-02-05 17:18:13 +0900546 int (*write) (struct tomoyo_io_buffer *);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900547 int (*poll) (struct file *file, poll_table *wait);
Kentaro Takeda95908372009-02-05 17:18:13 +0900548 /* Exclusive lock for this structure. */
549 struct mutex io_sem;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900550 /* Index returned by tomoyo_read_lock(). */
551 int reader_idx;
Kentaro Takeda95908372009-02-05 17:18:13 +0900552 /* 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. */
559 int read_step;
560 /* Buffer for reading. */
561 char *read_buf;
562 /* EOF flag for reading. */
563 bool read_eof;
564 /* Read domain ACL of specified PID? */
565 bool read_single_domain;
566 /* Extra variable for reading. */
567 u8 read_bit;
568 /* Bytes available for reading. */
569 int read_avail;
570 /* Size of read buffer. */
571 int readbuf_size;
572 /* Buffer for writing. */
573 char *write_buf;
574 /* Bytes available for writing. */
575 int write_avail;
576 /* Size of write buffer. */
577 int writebuf_size;
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900578 /* Type of this interface. */
579 u8 type;
Kentaro Takeda95908372009-02-05 17:18:13 +0900580};
581
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900582/*
583 * tomoyo_globally_readable_file_entry is a structure which is used for holding
584 * "allow_read" entries.
585 * It has following fields.
586 *
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900587 * (1) "head" is "struct tomoyo_acl_head".
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900588 * (2) "filename" is a pathname which is allowed to open(O_RDONLY).
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900589 */
590struct tomoyo_globally_readable_file_entry {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900591 struct tomoyo_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900592 const struct tomoyo_path_info *filename;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900593};
594
595/*
596 * tomoyo_pattern_entry is a structure which is used for holding
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900597 * "file_pattern" entries.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900598 * It has following fields.
599 *
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900600 * (1) "head" is "struct tomoyo_acl_head".
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900601 * (2) "pattern" is a pathname pattern which is used for converting pathnames
602 * to pathname patterns during learning mode.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900603 */
604struct tomoyo_pattern_entry {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900605 struct tomoyo_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900606 const struct tomoyo_path_info *pattern;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900607};
608
609/*
610 * tomoyo_no_rewrite_entry is a structure which is used for holding
611 * "deny_rewrite" entries.
612 * It has following fields.
613 *
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900614 * (1) "head" is "struct tomoyo_acl_head".
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900615 * (2) "pattern" is a pathname which is by default not permitted to modify
616 * already existing content.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900617 */
618struct tomoyo_no_rewrite_entry {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900619 struct tomoyo_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900620 const struct tomoyo_path_info *pattern;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900621};
622
623/*
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.
627 *
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900628 * (1) "head" is "struct tomoyo_acl_head".
629 * (2) "is_not" is a bool which is true if "no_initialize_domain", false
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900630 * otherwise.
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900631 * (3) "is_last_name" is a bool which is true if "domainname" is "the last
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900632 * component of a domainname", false otherwise.
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900633 * (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.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900636 */
637struct tomoyo_domain_initializer_entry {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900638 struct tomoyo_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900639 bool is_not; /* True if this entry is "no_initialize_domain". */
640 /* True if the domainname is tomoyo_get_last_name(). */
641 bool is_last_name;
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900642 const struct tomoyo_path_info *domainname; /* This may be NULL */
643 const struct tomoyo_path_info *program;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900644};
645
646/*
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.
650 *
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900651 * (1) "head" is "struct tomoyo_acl_head".
652 * (2) "is_not" is a bool which is true if "no_initialize_domain", false
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900653 * otherwise.
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900654 * (3) "is_last_name" is a bool which is true if "domainname" is "the last
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900655 * component of a domainname", false otherwise.
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900656 * (4) "domainname" which is "a domainname" or "the last component of a
657 * domainname".
658 * (5) "program" which is a program's pathname.
659 * This field is NULL if "from" clause is not specified.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900660 */
661struct tomoyo_domain_keeper_entry {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900662 struct tomoyo_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900663 bool is_not; /* True if this entry is "no_keep_domain". */
664 /* True if the domainname is tomoyo_get_last_name(). */
665 bool is_last_name;
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900666 const struct tomoyo_path_info *domainname;
667 const struct tomoyo_path_info *program; /* This may be NULL */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900668};
669
670/*
Tetsuo Handa10843072010-06-03 20:38:03 +0900671 * tomoyo_aggregator_entry is a structure which is used for holding
672 * "aggregator" entries.
673 * It has following fields.
674 *
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900675 * (1) "head" is "struct tomoyo_acl_head".
Tetsuo Handa10843072010-06-03 20:38:03 +0900676 * (2) "original_name" which is originally requested name.
677 * (3) "aggregated_name" which is name to rewrite.
Tetsuo Handa10843072010-06-03 20:38:03 +0900678 */
679struct tomoyo_aggregator_entry {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900680 struct tomoyo_acl_head head;
Tetsuo Handa10843072010-06-03 20:38:03 +0900681 const struct tomoyo_path_info *original_name;
682 const struct tomoyo_path_info *aggregated_name;
Tetsuo Handa10843072010-06-03 20:38:03 +0900683};
684
685/*
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900686 * tomoyo_alias_entry is a structure which is used for holding "alias" entries.
687 * It has following fields.
688 *
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900689 * (1) "head" is "struct tomoyo_acl_head".
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900690 * (2) "original_name" which is a dereferenced pathname.
691 * (3) "aliased_name" which is a symlink's pathname.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900692 */
693struct tomoyo_alias_entry {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900694 struct tomoyo_acl_head head;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900695 const struct tomoyo_path_info *original_name;
696 const struct tomoyo_path_info *aliased_name;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900697};
698
699/*
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.
704 *
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900705 * (1) "head" is "struct tomoyo_acl_head".
706 * (2) "is_domain" is a bool which is true if "manager" is a domainname, false
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900707 * otherwise.
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900708 * (3) "manager" is a domainname or a program's pathname.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900709 */
710struct tomoyo_policy_manager_entry {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900711 struct tomoyo_acl_head head;
712 bool is_domain; /* True if manager is a domainname. */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900713 /* A path to program or a domainname. */
714 const struct tomoyo_path_info *manager;
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900715};
716
Tetsuo Handa57c25902010-06-03 20:38:44 +0900717struct tomoyo_preference {
718 unsigned int learning_max_entry;
719 bool enforcing_verbose;
720 bool learning_verbose;
721 bool permissive_verbose;
722};
723
724struct 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;
730 u8 default_config;
731 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
732};
733
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900734/********** Function prototypes. **********/
735
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900736extern asmlinkage long sys_getpid(void);
737extern asmlinkage long sys_getppid(void);
738
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900739/* Check whether the given string starts with the given keyword. */
740bool tomoyo_str_starts(char **src, const char *find);
741/* Get tomoyo_realpath() of current process. */
742const char *tomoyo_get_exe(void);
743/* Format string. */
744void tomoyo_normalize_line(unsigned char *buffer);
745/* Print warning or error message on console. */
746void 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. */
749void tomoyo_check_profile(void);
750/* Open operation for /sys/kernel/security/tomoyo/ interface. */
751int tomoyo_open_control(const u8 type, struct file *file);
752/* Close /sys/kernel/security/tomoyo/ interface. */
753int tomoyo_close_control(struct file *file);
754/* Read operation for /sys/kernel/security/tomoyo/ interface. */
755int tomoyo_read_control(struct file *file, char __user *buffer,
756 const int buffer_len);
757/* Write operation for /sys/kernel/security/tomoyo/ interface. */
758int 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. */
761bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
762/* Print out of memory warning message. */
763void tomoyo_warn_oom(const char *function);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900764/* Check whether the given name matches the given name_union. */
765bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
766 const struct tomoyo_name_union *ptr);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900767/* Check whether the given number matches the given number_union. */
768bool tomoyo_compare_number_union(const unsigned long value,
769 const struct tomoyo_number_union *ptr);
Tetsuo Handa57c25902010-06-03 20:38:44 +0900770int tomoyo_get_mode(const u8 profile, const u8 index);
Kentaro Takeda95908372009-02-05 17:18:13 +0900771/* Transactional sprintf() for policy dump. */
772bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
773 __attribute__ ((format(printf, 2, 3)));
774/* Check whether the domainname is correct. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900775bool tomoyo_correct_domain(const unsigned char *domainname);
Kentaro Takeda95908372009-02-05 17:18:13 +0900776/* Check whether the token is correct. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900777bool tomoyo_correct_path(const char *filename);
778bool tomoyo_correct_word(const char *string);
Kentaro Takeda95908372009-02-05 17:18:13 +0900779/* Check whether the token can be a domainname. */
Tetsuo Handa75093152010-06-16 16:23:55 +0900780bool tomoyo_domain_def(const unsigned char *buffer);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900781bool tomoyo_parse_name_union(const char *filename,
782 struct tomoyo_name_union *ptr);
783/* Check whether the given filename matches the given path_group. */
784bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900785 const struct tomoyo_group *group);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900786/* Check whether the given value matches the given number_group. */
787bool tomoyo_number_matches_group(const unsigned long min,
788 const unsigned long max,
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +0900789 const struct tomoyo_group *group);
Kentaro Takeda95908372009-02-05 17:18:13 +0900790/* Check whether the given filename matches the given pattern. */
791bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
792 const struct tomoyo_path_info *pattern);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900793
794bool tomoyo_print_number_union(struct tomoyo_io_buffer *head,
795 const struct tomoyo_number_union *ptr);
796bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900797/* Tokenize a line. */
798bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
Kentaro Takeda95908372009-02-05 17:18:13 +0900799/* Write domain policy violation warning message to console? */
800bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
Kentaro Takeda95908372009-02-05 17:18:13 +0900801/* Get the last component of the given domainname. */
802const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900803/* Fill "struct tomoyo_request_info". */
804int tomoyo_init_request_info(struct tomoyo_request_info *r,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900805 struct tomoyo_domain_info *domain,
806 const u8 index);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900807/* Check permission for mount operation. */
808int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,
809 unsigned long flags, void *data_page);
Tetsuo Handa10843072010-06-03 20:38:03 +0900810/* Create "aggregator" entry in exception policy. */
811int tomoyo_write_aggregator_policy(char *data, const bool is_delete);
Kentaro Takeda95908372009-02-05 17:18:13 +0900812/* Create "alias" entry in exception policy. */
813int tomoyo_write_alias_policy(char *data, const bool is_delete);
814/*
815 * Create "initialize_domain" and "no_initialize_domain" entry
816 * in exception policy.
817 */
818int 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. */
821int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
822 const bool is_delete);
823/*
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.
829 */
830int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
831 const bool is_delete);
832/* Create "allow_read" entry in exception policy. */
833int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
Tetsuo Handa2106ccd2010-05-17 10:10:31 +0900834/* Create "allow_mount" entry in domain policy. */
835int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain,
836 const bool is_delete);
Kentaro Takeda95908372009-02-05 17:18:13 +0900837/* Create "deny_rewrite" entry in exception policy. */
838int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
839/* Create "file_pattern" entry in exception policy. */
840int tomoyo_write_pattern_policy(char *data, const bool is_delete);
Tetsuo Handa7c2ea222010-06-17 16:55:58 +0900841/* Create "path_group"/"number_group" entry in exception policy. */
842int tomoyo_write_group(char *data, const bool is_delete, const u8 type);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900843int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
844 __attribute__ ((format(printf, 2, 3)));
Kentaro Takeda95908372009-02-05 17:18:13 +0900845/* Find a domain by the given name. */
846struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
847/* Find or create a domain by the given name. */
848struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
849 domainname,
850 const u8 profile);
Tetsuo Handa57c25902010-06-03 20:38:44 +0900851struct tomoyo_profile *tomoyo_profile(const u8 profile);
Tetsuo Handa7c2ea222010-06-17 16:55:58 +0900852/*
853 * Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group".
854 */
855struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900856
Kentaro Takeda95908372009-02-05 17:18:13 +0900857/* Check mode for specified functionality. */
858unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
859 const u8 index);
Kentaro Takeda95908372009-02-05 17:18:13 +0900860/* Fill in "struct tomoyo_path_info" members. */
861void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
862/* Run policy loader when /sbin/init starts. */
863void tomoyo_load_policy(const char *filename);
Kentaro Takeda95908372009-02-05 17:18:13 +0900864
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900865void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
866
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900867/* Convert binary string to ascii string. */
Tetsuo Handac8c57e82010-06-03 20:36:43 +0900868char *tomoyo_encode(const char *str);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900869
870/*
871 * Returns realpath(3) of the given pathname but ignores chroot'ed root.
872 * These functions use kzalloc(), so the caller must call kfree()
873 * if these functions didn't return NULL.
874 */
875char *tomoyo_realpath(const char *pathname);
876/*
877 * Same with tomoyo_realpath() except that it doesn't follow the final symlink.
878 */
879char *tomoyo_realpath_nofollow(const char *pathname);
880/* Same with tomoyo_realpath() except that the pathname is already solved. */
881char *tomoyo_realpath_from_path(struct path *path);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900882/* Get patterned pathname. */
883const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900884
885/* Check memory quota. */
886bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900887void *tomoyo_commit_ok(void *data, const unsigned int size);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900888
889/*
890 * Keep the given name on the RAM.
891 * The RAM is shared, so NEVER try to modify or kfree() the returned name.
892 */
893const struct tomoyo_path_info *tomoyo_get_name(const char *name);
894
895/* Check for memory usage. */
Tetsuo Handa8fbe71f2010-06-16 16:29:59 +0900896void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900897
898/* Set memory quota. */
899int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
900
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900901/* Initialize mm related code. */
902void __init tomoyo_mm_init(void);
Tetsuo Handa05336de2010-06-16 16:20:24 +0900903int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900904 const struct tomoyo_path_info *filename);
905int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
906 struct path *path, const int flag);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900907int tomoyo_path_number_perm(const u8 operation, struct path *path,
908 unsigned long number);
Tetsuo Handa75093152010-06-16 16:23:55 +0900909int tomoyo_mkdev_perm(const u8 operation, struct path *path,
910 const unsigned int mode, unsigned int dev);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900911int tomoyo_path_perm(const u8 operation, struct path *path);
912int tomoyo_path2_perm(const u8 operation, struct path *path1,
913 struct path *path2);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900914int tomoyo_find_next_domain(struct linux_binprm *bprm);
915
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900916void tomoyo_print_ulong(char *buffer, const int buffer_len,
917 const unsigned long value, const u8 type);
918
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900919/* Drop refcount on tomoyo_name_union. */
920void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
921
Tetsuo Handa847b1732010-02-11 09:43:54 +0900922/* Run garbage collector. */
923void tomoyo_run_gc(void);
924
925void tomoyo_memory_free(void *ptr);
926
Tetsuo Handa237ab452010-06-12 20:46:22 +0900927int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
928 bool is_delete, struct tomoyo_domain_info *domain,
929 bool (*check_duplicate) (const struct tomoyo_acl_info
930 *,
931 const struct tomoyo_acl_info
932 *),
933 bool (*merge_duplicate) (struct tomoyo_acl_info *,
934 struct tomoyo_acl_info *,
935 const bool));
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900936int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
937 bool is_delete, struct list_head *list,
938 bool (*check_duplicate) (const struct tomoyo_acl_head
939 *,
940 const struct tomoyo_acl_head
941 *));
Tetsuo Handa99a85252010-06-16 16:22:51 +0900942void tomoyo_check_acl(struct tomoyo_request_info *r,
943 bool (*check_entry) (const struct tomoyo_request_info *,
944 const struct tomoyo_acl_info *));
Tetsuo Handa237ab452010-06-12 20:46:22 +0900945
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900946/********** External variable definitions. **********/
947
948/* Lock for GC. */
949extern struct srcu_struct tomoyo_ss;
950
951/* The list for "struct tomoyo_domain_info". */
952extern struct list_head tomoyo_domain_list;
953
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900954extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];
955extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900956extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900957
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900958/* Lock for protecting policy. */
959extern struct mutex tomoyo_policy_lock;
960
961/* Has /sbin/init started? */
962extern bool tomoyo_policy_loaded;
963
964/* The kernel's domain. */
965extern struct tomoyo_domain_info tomoyo_kernel_domain;
966
Tetsuo Handa71c28232010-06-16 16:26:38 +0900967extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
968extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];
969extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION];
970extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION];
971
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900972extern unsigned int tomoyo_quota_for_query;
973extern unsigned int tomoyo_query_memory_size;
974
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900975/********** Inlined functions. **********/
976
977static inline int tomoyo_read_lock(void)
978{
979 return srcu_read_lock(&tomoyo_ss);
980}
981
982static inline void tomoyo_read_unlock(int idx)
983{
984 srcu_read_unlock(&tomoyo_ss, idx);
985}
986
Kentaro Takeda95908372009-02-05 17:18:13 +0900987/* strcmp() for "struct tomoyo_path_info" structure. */
988static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
989 const struct tomoyo_path_info *b)
990{
991 return a->hash != b->hash || strcmp(a->name, b->name);
992}
993
Kentaro Takeda95908372009-02-05 17:18:13 +0900994/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900995 * tomoyo_valid - Check whether the character is a valid char.
Kentaro Takeda95908372009-02-05 17:18:13 +0900996 *
997 * @c: The character to check.
998 *
999 * Returns true if @c is a valid character, false otherwise.
1000 */
Tetsuo Handa75093152010-06-16 16:23:55 +09001001static inline bool tomoyo_valid(const unsigned char c)
Kentaro Takeda95908372009-02-05 17:18:13 +09001002{
1003 return c > ' ' && c < 127;
1004}
1005
1006/**
Tetsuo Handa75093152010-06-16 16:23:55 +09001007 * tomoyo_invalid - Check whether the character is an invalid char.
Kentaro Takeda95908372009-02-05 17:18:13 +09001008 *
1009 * @c: The character to check.
1010 *
1011 * Returns true if @c is an invalid character, false otherwise.
1012 */
Tetsuo Handa75093152010-06-16 16:23:55 +09001013static inline bool tomoyo_invalid(const unsigned char c)
Kentaro Takeda95908372009-02-05 17:18:13 +09001014{
1015 return c && (c <= ' ' || c >= 127);
1016}
1017
Tetsuo Handa76bb0892010-02-11 09:42:40 +09001018static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
1019{
1020 if (name) {
1021 struct tomoyo_name_entry *ptr =
1022 container_of(name, struct tomoyo_name_entry, entry);
1023 atomic_dec(&ptr->users);
1024 }
1025}
Kentaro Takeda95908372009-02-05 17:18:13 +09001026
Tetsuo Handaa98aa4d2010-06-17 16:52:29 +09001027static inline void tomoyo_put_group(struct tomoyo_group *group)
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +09001028{
1029 if (group)
1030 atomic_dec(&group->users);
1031}
1032
Tetsuo Handa76bb0892010-02-11 09:42:40 +09001033static inline struct tomoyo_domain_info *tomoyo_domain(void)
1034{
1035 return current_cred()->security;
1036}
Kentaro Takeda95908372009-02-05 17:18:13 +09001037
Tetsuo Handa76bb0892010-02-11 09:42:40 +09001038static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
1039 *task)
1040{
1041 return task_cred_xxx(task, security);
1042}
Kentaro Takeda95908372009-02-05 17:18:13 +09001043
Tetsuo Handa75093152010-06-16 16:23:55 +09001044static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1,
Tetsuo Handa7762fbf2010-05-10 17:30:26 +09001045 const struct tomoyo_acl_info *p2)
1046{
1047 return p1->type == p2->type;
1048}
1049
Tetsuo Handa75093152010-06-16 16:23:55 +09001050static inline bool tomoyo_same_name_union
Tetsuo Handa7762fbf2010-05-10 17:30:26 +09001051(const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2)
1052{
1053 return p1->filename == p2->filename && p1->group == p2->group &&
1054 p1->is_group == p2->is_group;
1055}
1056
Tetsuo Handa75093152010-06-16 16:23:55 +09001057static inline bool tomoyo_same_number_union
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +09001058(const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2)
1059{
1060 return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1]
1061 && p1->group == p2->group && p1->min_type == p2->min_type &&
1062 p1->max_type == p2->max_type && p1->is_group == p2->is_group;
1063}
1064
Kentaro Takeda95908372009-02-05 17:18:13 +09001065/**
1066 * list_for_each_cookie - iterate over a list with cookie.
1067 * @pos: the &struct list_head to use as a loop cursor.
1068 * @cookie: the &struct list_head to use as a cookie.
1069 * @head: the head for your list.
1070 *
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001071 * Same with list_for_each_rcu() except that this primitive uses @cookie
Kentaro Takeda95908372009-02-05 17:18:13 +09001072 * so that we can continue iteration.
1073 * @cookie must be NULL when iteration starts, and @cookie will become
1074 * NULL when iteration finishes.
1075 */
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001076#define list_for_each_cookie(pos, cookie, head) \
1077 for (({ if (!cookie) \
1078 cookie = head; }), \
1079 pos = rcu_dereference((cookie)->next); \
1080 prefetch(pos->next), pos != (head) || ((cookie) = NULL); \
1081 (cookie) = pos, pos = rcu_dereference(pos->next))
1082
Kentaro Takeda95908372009-02-05 17:18:13 +09001083#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */