blob: 565a1c11da53d729756cd34cb6565a7857f2cd29 [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>
23struct linux_binprm;
Kentaro Takeda95908372009-02-05 17:18:13 +090024
Tetsuo Handa76bb0892010-02-11 09:42:40 +090025/********** Constants definitions. **********/
26
27/*
28 * TOMOYO uses this hash only when appending a string into the string
29 * table. Frequency of appending strings is very low. So we don't need
30 * large (e.g. 64k) hash size. 256 will be sufficient.
31 */
32#define TOMOYO_HASH_BITS 8
33#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
34
35/*
36 * This is the max length of a token.
37 *
38 * A token consists of only ASCII printable characters.
39 * Non printable characters in a token is represented in \ooo style
40 * octal string. Thus, \ itself is represented as \\.
41 */
42#define TOMOYO_MAX_PATHNAME_LEN 4000
43
44/* Profile number is an integer between 0 and 255. */
45#define TOMOYO_MAX_PROFILES 256
46
Tetsuo Handacb0abe62010-05-17 10:08:05 +090047enum tomoyo_mode_index {
48 TOMOYO_CONFIG_DISABLED,
49 TOMOYO_CONFIG_LEARNING,
50 TOMOYO_CONFIG_PERMISSIVE,
51 TOMOYO_CONFIG_ENFORCING
52};
53
Tetsuo Handa76bb0892010-02-11 09:42:40 +090054/* Keywords for ACLs. */
55#define TOMOYO_KEYWORD_ALIAS "alias "
56#define TOMOYO_KEYWORD_ALLOW_READ "allow_read "
57#define TOMOYO_KEYWORD_DELETE "delete "
58#define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite "
59#define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern "
60#define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain "
61#define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain "
62#define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain "
63#define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain "
Tetsuo Handa7762fbf2010-05-10 17:30:26 +090064#define TOMOYO_KEYWORD_PATH_GROUP "path_group "
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090065#define TOMOYO_KEYWORD_NUMBER_GROUP "number_group "
Tetsuo Handa76bb0892010-02-11 09:42:40 +090066#define TOMOYO_KEYWORD_SELECT "select "
67#define TOMOYO_KEYWORD_USE_PROFILE "use_profile "
68#define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read"
69/* A domain definition starts with <kernel>. */
70#define TOMOYO_ROOT_NAME "<kernel>"
71#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
72
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +090073/* Value type definition. */
74#define TOMOYO_VALUE_TYPE_INVALID 0
75#define TOMOYO_VALUE_TYPE_DECIMAL 1
76#define TOMOYO_VALUE_TYPE_OCTAL 2
77#define TOMOYO_VALUE_TYPE_HEXADECIMAL 3
78
Tetsuo Handa76bb0892010-02-11 09:42:40 +090079/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +090080enum tomoyo_mac_index {
81 TOMOYO_MAC_FOR_FILE, /* domain_policy.conf */
82 TOMOYO_MAX_ACCEPT_ENTRY,
83 TOMOYO_VERBOSE,
84 TOMOYO_MAX_CONTROL_INDEX
85};
Tetsuo Handa76bb0892010-02-11 09:42:40 +090086
87/* Index numbers for Access Controls. */
Tetsuo Handa084da352010-02-15 15:10:39 +090088enum tomoyo_acl_entry_type_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +090089 TOMOYO_TYPE_PATH_ACL,
90 TOMOYO_TYPE_PATH2_ACL,
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090091 TOMOYO_TYPE_PATH_NUMBER_ACL,
92 TOMOYO_TYPE_PATH_NUMBER3_ACL,
Tetsuo Handa084da352010-02-15 15:10:39 +090093};
Tetsuo Handa76bb0892010-02-11 09:42:40 +090094
95/* Index numbers for File Controls. */
96
97/*
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +090098 * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically
99 * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set.
100 * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if
101 * TOMOYO_TYPE_READ_WRITE is set.
102 * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ
103 * or TOMOYO_TYPE_WRITE is cleared.
104 * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if
105 * TOMOYO_TYPE_READ_WRITE is cleared.
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900106 */
107
Tetsuo Handa084da352010-02-15 15:10:39 +0900108enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900109 TOMOYO_TYPE_READ_WRITE,
110 TOMOYO_TYPE_EXECUTE,
111 TOMOYO_TYPE_READ,
112 TOMOYO_TYPE_WRITE,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900113 TOMOYO_TYPE_UNLINK,
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,
117 TOMOYO_TYPE_REWRITE,
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900118 TOMOYO_TYPE_CHROOT,
119 TOMOYO_TYPE_MOUNT,
120 TOMOYO_TYPE_UMOUNT,
121 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900122};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900123
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900124enum tomoyo_path_number3_acl_index {
125 TOMOYO_TYPE_MKBLOCK,
126 TOMOYO_TYPE_MKCHAR,
127 TOMOYO_MAX_PATH_NUMBER3_OPERATION
128};
129
Tetsuo Handa084da352010-02-15 15:10:39 +0900130enum tomoyo_path2_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900131 TOMOYO_TYPE_LINK,
132 TOMOYO_TYPE_RENAME,
133 TOMOYO_TYPE_PIVOT_ROOT,
134 TOMOYO_MAX_PATH2_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900135};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900136
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900137enum tomoyo_path_number_acl_index {
138 TOMOYO_TYPE_CREATE,
139 TOMOYO_TYPE_MKDIR,
140 TOMOYO_TYPE_MKFIFO,
141 TOMOYO_TYPE_MKSOCK,
142 TOMOYO_TYPE_IOCTL,
143 TOMOYO_TYPE_CHMOD,
144 TOMOYO_TYPE_CHOWN,
145 TOMOYO_TYPE_CHGRP,
146 TOMOYO_MAX_PATH_NUMBER_OPERATION
147};
148
Tetsuo Handa084da352010-02-15 15:10:39 +0900149enum tomoyo_securityfs_interface_index {
150 TOMOYO_DOMAINPOLICY,
151 TOMOYO_EXCEPTIONPOLICY,
152 TOMOYO_DOMAIN_STATUS,
153 TOMOYO_PROCESS_STATUS,
154 TOMOYO_MEMINFO,
155 TOMOYO_SELFDOMAIN,
156 TOMOYO_VERSION,
157 TOMOYO_PROFILE,
158 TOMOYO_MANAGER
159};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900160
161/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900162
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900163/*
164 * tomoyo_page_buffer is a structure which is used for holding a pathname
165 * obtained from "struct dentry" and "struct vfsmount" pair.
166 * As of now, it is 4096 bytes. If users complain that 4096 bytes is too small
167 * (because TOMOYO escapes non ASCII printable characters using \ooo format),
168 * we will make the buffer larger.
169 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900170struct tomoyo_page_buffer {
171 char buffer[4096];
172};
173
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900174/*
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900175 * tomoyo_request_info is a structure which is used for holding
176 *
177 * (1) Domain information of current process.
178 * (2) Access control mode of the profile.
179 */
180struct tomoyo_request_info {
181 struct tomoyo_domain_info *domain;
182 u8 mode; /* One of tomoyo_mode_index . */
183};
184
185/*
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900186 * tomoyo_path_info is a structure which is used for holding a string data
187 * used by TOMOYO.
188 * This structure has several fields for supporting pattern matching.
189 *
190 * (1) "name" is the '\0' terminated string data.
191 * (2) "hash" is full_name_hash(name, strlen(name)).
192 * This allows tomoyo_pathcmp() to compare by hash before actually compare
193 * using strcmp().
194 * (3) "const_len" is the length of the initial segment of "name" which
195 * consists entirely of non wildcard characters. In other words, the length
196 * which we can compare two strings using strncmp().
197 * (4) "is_dir" is a bool which is true if "name" ends with "/",
198 * false otherwise.
199 * TOMOYO distinguishes directory and non-directory. A directory ends with
200 * "/" and non-directory does not end with "/".
201 * (5) "is_patterned" is a bool which is true if "name" contains wildcard
202 * characters, false otherwise. This allows TOMOYO to use "hash" and
203 * strcmp() for string comparison if "is_patterned" is false.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900204 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900205struct tomoyo_path_info {
206 const char *name;
207 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900208 u16 const_len; /* = tomoyo_const_part_length(name) */
209 bool is_dir; /* = tomoyo_strendswith(name, "/") */
210 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900211};
212
213/*
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900214 * tomoyo_name_entry is a structure which is used for linking
215 * "struct tomoyo_path_info" into tomoyo_name_list .
Kentaro Takeda95908372009-02-05 17:18:13 +0900216 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900217struct tomoyo_name_entry {
218 struct list_head list;
219 atomic_t users;
220 struct tomoyo_path_info entry;
221};
Kentaro Takeda95908372009-02-05 17:18:13 +0900222
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900223/*
224 * tomoyo_path_info_with_data is a structure which is used for holding a
225 * pathname obtained from "struct dentry" and "struct vfsmount" pair.
226 *
227 * "struct tomoyo_path_info_with_data" consists of "struct tomoyo_path_info"
228 * and buffer for the pathname, while "struct tomoyo_page_buffer" consists of
229 * buffer for the pathname only.
230 *
231 * "struct tomoyo_path_info_with_data" is intended to allow TOMOYO to release
232 * both "struct tomoyo_path_info" and buffer for the pathname by single kfree()
233 * so that we don't need to return two pointers to the caller. If the caller
234 * puts "struct tomoyo_path_info" on stack memory, we will be able to remove
235 * "struct tomoyo_path_info_with_data".
236 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900237struct tomoyo_path_info_with_data {
Tetsuo Handa8e2d39a2010-01-26 20:45:27 +0900238 /* Keep "head" first, for this pointer is passed to kfree(). */
Kentaro Takeda95908372009-02-05 17:18:13 +0900239 struct tomoyo_path_info head;
Tetsuo Handaa106cbf2009-03-27 13:12:16 +0900240 char barrier1[16]; /* Safeguard for overrun. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900241 char body[TOMOYO_MAX_PATHNAME_LEN];
242 char barrier2[16]; /* Safeguard for overrun. */
243};
244
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900245struct tomoyo_name_union {
246 const struct tomoyo_path_info *filename;
247 struct tomoyo_path_group *group;
248 u8 is_group;
249};
250
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900251struct tomoyo_number_union {
252 unsigned long values[2];
253 struct tomoyo_number_group *group;
254 u8 min_type;
255 u8 max_type;
256 u8 is_group;
257};
258
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900259/* Structure for "path_group" directive. */
260struct tomoyo_path_group {
261 struct list_head list;
262 const struct tomoyo_path_info *group_name;
263 struct list_head member_list;
264 atomic_t users;
265};
266
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900267/* Structure for "number_group" directive. */
268struct tomoyo_number_group {
269 struct list_head list;
270 const struct tomoyo_path_info *group_name;
271 struct list_head member_list;
272 atomic_t users;
273};
274
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900275/* Structure for "path_group" directive. */
276struct tomoyo_path_group_member {
277 struct list_head list;
278 bool is_deleted;
279 const struct tomoyo_path_info *member_name;
280};
281
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900282/* Structure for "number_group" directive. */
283struct tomoyo_number_group_member {
284 struct list_head list;
285 bool is_deleted;
286 struct tomoyo_number_union number;
287};
288
Kentaro Takeda95908372009-02-05 17:18:13 +0900289/*
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900290 * tomoyo_acl_info is a structure which is used for holding
291 *
292 * (1) "list" which is linked to the ->acl_info_list of
293 * "struct tomoyo_domain_info"
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900294 * (2) "type" which tells type of the entry (either
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900295 * "struct tomoyo_path_acl" or "struct tomoyo_path2_acl").
Kentaro Takeda95908372009-02-05 17:18:13 +0900296 *
297 * Packing "struct tomoyo_acl_info" allows
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900298 * "struct tomoyo_path_acl" to embed "u8" + "u16" and
299 * "struct tomoyo_path2_acl" to embed "u8"
Kentaro Takeda95908372009-02-05 17:18:13 +0900300 * without enlarging their structure size.
301 */
302struct tomoyo_acl_info {
303 struct list_head list;
Kentaro Takeda95908372009-02-05 17:18:13 +0900304 u8 type;
305} __packed;
306
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900307/*
308 * tomoyo_domain_info is a structure which is used for holding permissions
309 * (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
310 * It has following fields.
311 *
312 * (1) "list" which is linked to tomoyo_domain_list .
313 * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info".
314 * (3) "domainname" which holds the name of the domain.
315 * (4) "profile" which remembers profile number assigned to this domain.
316 * (5) "is_deleted" is a bool which is true if this domain is marked as
317 * "deleted", false otherwise.
318 * (6) "quota_warned" is a bool which is used for suppressing warning message
319 * when learning mode learned too much entries.
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900320 * (7) "ignore_global_allow_read" is a bool which is true if this domain
321 * should ignore "allow_read" directive in exception policy.
322 * (8) "transition_failed" is a bool which is set to true when this domain was
323 * unable to create a new domain at tomoyo_find_next_domain() because the
324 * name of the domain to be created was too long or it could not allocate
325 * memory. If set to true, more than one process continued execve()
326 * without domain transition.
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900327 * (9) "users" is an atomic_t that holds how many "struct cred"->security
328 * are referring this "struct tomoyo_domain_info". If is_deleted == true
329 * and users == 0, this struct will be kfree()d upon next garbage
330 * collection.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900331 *
332 * A domain's lifecycle is an analogy of files on / directory.
333 * Multiple domains with the same domainname cannot be created (as with
334 * creating files with the same filename fails with -EEXIST).
335 * If a process reached a domain, that process can reside in that domain after
336 * that domain is marked as "deleted" (as with a process can access an already
337 * open()ed file after that file was unlink()ed).
338 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900339struct tomoyo_domain_info {
340 struct list_head list;
341 struct list_head acl_info_list;
342 /* Name of this domain. Never NULL. */
343 const struct tomoyo_path_info *domainname;
344 u8 profile; /* Profile number to use. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900345 bool is_deleted; /* Delete flag. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900346 bool quota_warned; /* Quota warnning flag. */
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900347 bool ignore_global_allow_read; /* Ignore "allow_read" flag. */
348 bool transition_failed; /* Domain transition failed flag. */
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900349 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900350};
351
Kentaro Takeda95908372009-02-05 17:18:13 +0900352/*
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900353 * tomoyo_path_acl is a structure which is used for holding an
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900354 * entry with one pathname operation (e.g. open(), mkdir()).
355 * It has following fields.
356 *
357 * (1) "head" which is a "struct tomoyo_acl_info".
358 * (2) "perm" which is a bitmask of permitted operations.
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900359 * (3) "name" is the pathname.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900360 *
361 * Directives held by this structure are "allow_read/write", "allow_execute",
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900362 * "allow_read", "allow_write", "allow_unlink", "allow_rmdir",
363 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot",
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900364 * "allow_mount" and "allow_unmount".
Kentaro Takeda95908372009-02-05 17:18:13 +0900365 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900366struct tomoyo_path_acl {
367 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Kentaro Takeda95908372009-02-05 17:18:13 +0900368 u16 perm;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900369 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900370};
371
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900372/*
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900373 * tomoyo_path_number_acl is a structure which is used for holding an
374 * entry with one pathname and one number operation.
375 * It has following fields.
376 *
377 * (1) "head" which is a "struct tomoyo_acl_info".
378 * (2) "perm" which is a bitmask of permitted operations.
379 * (3) "name" is the pathname.
380 * (4) "number" is the numeric value.
381 *
382 * Directives held by this structure are "allow_create", "allow_mkdir",
383 * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown"
384 * and "allow_chgrp".
385 *
386 */
387struct tomoyo_path_number_acl {
388 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
389 u8 perm;
390 struct tomoyo_name_union name;
391 struct tomoyo_number_union number;
392};
393
394/*
395 * tomoyo_path_number3_acl is a structure which is used for holding an
396 * entry with one pathname and three numbers operation.
397 * It has following fields.
398 *
399 * (1) "head" which is a "struct tomoyo_acl_info".
400 * (2) "perm" which is a bitmask of permitted operations.
401 * (3) "mode" is the create mode.
402 * (4) "major" is the major number of device node.
403 * (5) "minor" is the minor number of device node.
404 *
405 * Directives held by this structure are "allow_mkchar", "allow_mkblock".
406 *
407 */
408struct tomoyo_path_number3_acl {
409 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER3_ACL */
410 u8 perm;
411 struct tomoyo_name_union name;
412 struct tomoyo_number_union mode;
413 struct tomoyo_number_union major;
414 struct tomoyo_number_union minor;
415};
416
417/*
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900418 * tomoyo_path2_acl is a structure which is used for holding an
Tetsuo Handa937bf612009-12-02 21:09:48 +0900419 * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900420 * It has following fields.
421 *
422 * (1) "head" which is a "struct tomoyo_acl_info".
423 * (2) "perm" which is a bitmask of permitted operations.
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900424 * (3) "name1" is the source/old pathname.
425 * (4) "name2" is the destination/new pathname.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900426 *
Tetsuo Handa937bf612009-12-02 21:09:48 +0900427 * Directives held by this structure are "allow_rename", "allow_link" and
428 * "allow_pivot_root".
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900429 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900430struct tomoyo_path2_acl {
431 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Kentaro Takeda95908372009-02-05 17:18:13 +0900432 u8 perm;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900433 struct tomoyo_name_union name1;
434 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900435};
436
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900437/*
438 * tomoyo_io_buffer is a structure which is used for reading and modifying
439 * configuration via /sys/kernel/security/tomoyo/ interface.
440 * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as
441 * cursors.
442 *
443 * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of
444 * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info"
445 * entry has a list of "struct tomoyo_acl_info", we need two cursors when
446 * reading (one is for traversing tomoyo_domain_list and the other is for
447 * traversing "struct tomoyo_acl_info"->acl_info_list ).
448 *
449 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
450 * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the
451 * domain with the domainname specified by the rest of that line (NULL is set
452 * if seek failed).
453 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
454 * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that
455 * line (->write_var1 is set to NULL if a domain was deleted).
456 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
457 * neither "select " nor "delete ", an entry or a domain specified by that line
458 * is appended.
459 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900460struct tomoyo_io_buffer {
461 int (*read) (struct tomoyo_io_buffer *);
462 int (*write) (struct tomoyo_io_buffer *);
463 /* Exclusive lock for this structure. */
464 struct mutex io_sem;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900465 /* Index returned by tomoyo_read_lock(). */
466 int reader_idx;
Kentaro Takeda95908372009-02-05 17:18:13 +0900467 /* The position currently reading from. */
468 struct list_head *read_var1;
469 /* Extra variables for reading. */
470 struct list_head *read_var2;
471 /* The position currently writing to. */
472 struct tomoyo_domain_info *write_var1;
473 /* The step for reading. */
474 int read_step;
475 /* Buffer for reading. */
476 char *read_buf;
477 /* EOF flag for reading. */
478 bool read_eof;
479 /* Read domain ACL of specified PID? */
480 bool read_single_domain;
481 /* Extra variable for reading. */
482 u8 read_bit;
483 /* Bytes available for reading. */
484 int read_avail;
485 /* Size of read buffer. */
486 int readbuf_size;
487 /* Buffer for writing. */
488 char *write_buf;
489 /* Bytes available for writing. */
490 int write_avail;
491 /* Size of write buffer. */
492 int writebuf_size;
493};
494
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900495/*
496 * tomoyo_globally_readable_file_entry is a structure which is used for holding
497 * "allow_read" entries.
498 * It has following fields.
499 *
500 * (1) "list" which is linked to tomoyo_globally_readable_list .
501 * (2) "filename" is a pathname which is allowed to open(O_RDONLY).
502 * (3) "is_deleted" is a bool which is true if marked as deleted, false
503 * otherwise.
504 */
505struct tomoyo_globally_readable_file_entry {
506 struct list_head list;
507 const struct tomoyo_path_info *filename;
508 bool is_deleted;
509};
510
511/*
512 * tomoyo_pattern_entry is a structure which is used for holding
513 * "tomoyo_pattern_list" entries.
514 * It has following fields.
515 *
516 * (1) "list" which is linked to tomoyo_pattern_list .
517 * (2) "pattern" is a pathname pattern which is used for converting pathnames
518 * to pathname patterns during learning mode.
519 * (3) "is_deleted" is a bool which is true if marked as deleted, false
520 * otherwise.
521 */
522struct tomoyo_pattern_entry {
523 struct list_head list;
524 const struct tomoyo_path_info *pattern;
525 bool is_deleted;
526};
527
528/*
529 * tomoyo_no_rewrite_entry is a structure which is used for holding
530 * "deny_rewrite" entries.
531 * It has following fields.
532 *
533 * (1) "list" which is linked to tomoyo_no_rewrite_list .
534 * (2) "pattern" is a pathname which is by default not permitted to modify
535 * already existing content.
536 * (3) "is_deleted" is a bool which is true if marked as deleted, false
537 * otherwise.
538 */
539struct tomoyo_no_rewrite_entry {
540 struct list_head list;
541 const struct tomoyo_path_info *pattern;
542 bool is_deleted;
543};
544
545/*
546 * tomoyo_domain_initializer_entry is a structure which is used for holding
547 * "initialize_domain" and "no_initialize_domain" entries.
548 * It has following fields.
549 *
550 * (1) "list" which is linked to tomoyo_domain_initializer_list .
551 * (2) "domainname" which is "a domainname" or "the last component of a
552 * domainname". This field is NULL if "from" clause is not specified.
553 * (3) "program" which is a program's pathname.
554 * (4) "is_deleted" is a bool which is true if marked as deleted, false
555 * otherwise.
556 * (5) "is_not" is a bool which is true if "no_initialize_domain", false
557 * otherwise.
558 * (6) "is_last_name" is a bool which is true if "domainname" is "the last
559 * component of a domainname", false otherwise.
560 */
561struct tomoyo_domain_initializer_entry {
562 struct list_head list;
563 const struct tomoyo_path_info *domainname; /* This may be NULL */
564 const struct tomoyo_path_info *program;
565 bool is_deleted;
566 bool is_not; /* True if this entry is "no_initialize_domain". */
567 /* True if the domainname is tomoyo_get_last_name(). */
568 bool is_last_name;
569};
570
571/*
572 * tomoyo_domain_keeper_entry is a structure which is used for holding
573 * "keep_domain" and "no_keep_domain" entries.
574 * It has following fields.
575 *
576 * (1) "list" which is linked to tomoyo_domain_keeper_list .
577 * (2) "domainname" which is "a domainname" or "the last component of a
578 * domainname".
579 * (3) "program" which is a program's pathname.
580 * This field is NULL if "from" clause is not specified.
581 * (4) "is_deleted" is a bool which is true if marked as deleted, false
582 * otherwise.
583 * (5) "is_not" is a bool which is true if "no_initialize_domain", false
584 * otherwise.
585 * (6) "is_last_name" is a bool which is true if "domainname" is "the last
586 * component of a domainname", false otherwise.
587 */
588struct tomoyo_domain_keeper_entry {
589 struct list_head list;
590 const struct tomoyo_path_info *domainname;
591 const struct tomoyo_path_info *program; /* This may be NULL */
592 bool is_deleted;
593 bool is_not; /* True if this entry is "no_keep_domain". */
594 /* True if the domainname is tomoyo_get_last_name(). */
595 bool is_last_name;
596};
597
598/*
599 * tomoyo_alias_entry is a structure which is used for holding "alias" entries.
600 * It has following fields.
601 *
602 * (1) "list" which is linked to tomoyo_alias_list .
603 * (2) "original_name" which is a dereferenced pathname.
604 * (3) "aliased_name" which is a symlink's pathname.
605 * (4) "is_deleted" is a bool which is true if marked as deleted, false
606 * otherwise.
607 */
608struct tomoyo_alias_entry {
609 struct list_head list;
610 const struct tomoyo_path_info *original_name;
611 const struct tomoyo_path_info *aliased_name;
612 bool is_deleted;
613};
614
615/*
616 * tomoyo_policy_manager_entry is a structure which is used for holding list of
617 * domainnames or programs which are permitted to modify configuration via
618 * /sys/kernel/security/tomoyo/ interface.
619 * It has following fields.
620 *
621 * (1) "list" which is linked to tomoyo_policy_manager_list .
622 * (2) "manager" is a domainname or a program's pathname.
623 * (3) "is_domain" is a bool which is true if "manager" is a domainname, false
624 * otherwise.
625 * (4) "is_deleted" is a bool which is true if marked as deleted, false
626 * otherwise.
627 */
628struct tomoyo_policy_manager_entry {
629 struct list_head list;
630 /* A path to program or a domainname. */
631 const struct tomoyo_path_info *manager;
632 bool is_domain; /* True if manager is a domainname. */
633 bool is_deleted; /* True if this entry is deleted. */
634};
635
636/********** Function prototypes. **********/
637
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900638/* Check whether the given name matches the given name_union. */
639bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
640 const struct tomoyo_name_union *ptr);
Kentaro Takeda95908372009-02-05 17:18:13 +0900641/* Check whether the domain has too many ACL entries to hold. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900642bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
Kentaro Takeda95908372009-02-05 17:18:13 +0900643/* Transactional sprintf() for policy dump. */
644bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
645 __attribute__ ((format(printf, 2, 3)));
646/* Check whether the domainname is correct. */
Tetsuo Handa17080002010-02-16 21:14:48 +0900647bool tomoyo_is_correct_domain(const unsigned char *domainname);
Kentaro Takeda95908372009-02-05 17:18:13 +0900648/* Check whether the token is correct. */
649bool tomoyo_is_correct_path(const char *filename, const s8 start_type,
Tetsuo Handa17080002010-02-16 21:14:48 +0900650 const s8 pattern_type, const s8 end_type);
Kentaro Takeda95908372009-02-05 17:18:13 +0900651/* Check whether the token can be a domainname. */
652bool tomoyo_is_domain_def(const unsigned char *buffer);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900653bool tomoyo_parse_name_union(const char *filename,
654 struct tomoyo_name_union *ptr);
655/* Check whether the given filename matches the given path_group. */
656bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
657 const struct tomoyo_path_group *group,
658 const bool may_use_pattern);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900659/* Check whether the given value matches the given number_group. */
660bool tomoyo_number_matches_group(const unsigned long min,
661 const unsigned long max,
662 const struct tomoyo_number_group *group);
Kentaro Takeda95908372009-02-05 17:18:13 +0900663/* Check whether the given filename matches the given pattern. */
664bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
665 const struct tomoyo_path_info *pattern);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900666
667bool tomoyo_print_number_union(struct tomoyo_io_buffer *head,
668 const struct tomoyo_number_union *ptr);
669bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
670
Kentaro Takeda95908372009-02-05 17:18:13 +0900671/* Read "alias" entry in exception policy. */
672bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head);
673/*
674 * Read "initialize_domain" and "no_initialize_domain" entry
675 * in exception policy.
676 */
677bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head);
678/* Read "keep_domain" and "no_keep_domain" entry in exception policy. */
679bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head);
680/* Read "file_pattern" entry in exception policy. */
681bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900682/* Read "path_group" entry in exception policy. */
683bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900684/* Read "number_group" entry in exception policy. */
685bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head);
Kentaro Takeda95908372009-02-05 17:18:13 +0900686/* Read "allow_read" entry in exception policy. */
687bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head);
688/* Read "deny_rewrite" entry in exception policy. */
689bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900690/* Tokenize a line. */
691bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
Kentaro Takeda95908372009-02-05 17:18:13 +0900692/* Write domain policy violation warning message to console? */
693bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
694/* Convert double path operation to operation name. */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900695const char *tomoyo_path22keyword(const u8 operation);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900696const char *tomoyo_path_number2keyword(const u8 operation);
697const char *tomoyo_path_number32keyword(const u8 operation);
Kentaro Takeda95908372009-02-05 17:18:13 +0900698/* Get the last component of the given domainname. */
699const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
Kentaro Takeda95908372009-02-05 17:18:13 +0900700/* Convert single path operation to operation name. */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900701const char *tomoyo_path2keyword(const u8 operation);
Kentaro Takeda95908372009-02-05 17:18:13 +0900702/* Create "alias" entry in exception policy. */
703int tomoyo_write_alias_policy(char *data, const bool is_delete);
704/*
705 * Create "initialize_domain" and "no_initialize_domain" entry
706 * in exception policy.
707 */
708int tomoyo_write_domain_initializer_policy(char *data, const bool is_not,
709 const bool is_delete);
710/* Create "keep_domain" and "no_keep_domain" entry in exception policy. */
711int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
712 const bool is_delete);
713/*
714 * Create "allow_read/write", "allow_execute", "allow_read", "allow_write",
715 * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",
716 * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar",
717 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and
718 * "allow_link" entry in domain policy.
719 */
720int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
721 const bool is_delete);
722/* Create "allow_read" entry in exception policy. */
723int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
724/* Create "deny_rewrite" entry in exception policy. */
725int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
726/* Create "file_pattern" entry in exception policy. */
727int tomoyo_write_pattern_policy(char *data, const bool is_delete);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900728/* Create "path_group" entry in exception policy. */
729int tomoyo_write_path_group_policy(char *data, const bool is_delete);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900730/* Create "number_group" entry in exception policy. */
731int tomoyo_write_number_group_policy(char *data, const bool is_delete);
Kentaro Takeda95908372009-02-05 17:18:13 +0900732/* Find a domain by the given name. */
733struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
734/* Find or create a domain by the given name. */
735struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
736 domainname,
737 const u8 profile);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900738
739/* Allocate memory for "struct tomoyo_path_group". */
740struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900741struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900742
Kentaro Takeda95908372009-02-05 17:18:13 +0900743/* Check mode for specified functionality. */
744unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
745 const u8 index);
Kentaro Takeda95908372009-02-05 17:18:13 +0900746/* Fill in "struct tomoyo_path_info" members. */
747void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
748/* Run policy loader when /sbin/init starts. */
749void tomoyo_load_policy(const char *filename);
Kentaro Takeda95908372009-02-05 17:18:13 +0900750
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900751void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
752
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900753/* Convert binary string to ascii string. */
754int tomoyo_encode(char *buffer, int buflen, const char *str);
755
756/* Returns realpath(3) of the given pathname but ignores chroot'ed root. */
757int tomoyo_realpath_from_path2(struct path *path, char *newname,
758 int newname_len);
759
760/*
761 * Returns realpath(3) of the given pathname but ignores chroot'ed root.
762 * These functions use kzalloc(), so the caller must call kfree()
763 * if these functions didn't return NULL.
764 */
765char *tomoyo_realpath(const char *pathname);
766/*
767 * Same with tomoyo_realpath() except that it doesn't follow the final symlink.
768 */
769char *tomoyo_realpath_nofollow(const char *pathname);
770/* Same with tomoyo_realpath() except that the pathname is already solved. */
771char *tomoyo_realpath_from_path(struct path *path);
772
773/* Check memory quota. */
774bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900775void *tomoyo_commit_ok(void *data, const unsigned int size);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900776
777/*
778 * Keep the given name on the RAM.
779 * The RAM is shared, so NEVER try to modify or kfree() the returned name.
780 */
781const struct tomoyo_path_info *tomoyo_get_name(const char *name);
782
783/* Check for memory usage. */
784int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
785
786/* Set memory quota. */
787int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
788
789/* Initialize realpath related code. */
790void __init tomoyo_realpath_init(void);
791int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
792 const struct tomoyo_path_info *filename);
793int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
794 struct path *path, const int flag);
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900795int tomoyo_path_number_perm(const u8 operation, struct path *path,
796 unsigned long number);
797int tomoyo_path_number3_perm(const u8 operation, struct path *path,
798 const unsigned int mode, unsigned int dev);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900799int tomoyo_path_perm(const u8 operation, struct path *path);
800int tomoyo_path2_perm(const u8 operation, struct path *path1,
801 struct path *path2);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900802int tomoyo_find_next_domain(struct linux_binprm *bprm);
803
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900804void tomoyo_print_ulong(char *buffer, const int buffer_len,
805 const unsigned long value, const u8 type);
806
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900807/* Drop refcount on tomoyo_name_union. */
808void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
809
Tetsuo Handa847b1732010-02-11 09:43:54 +0900810/* Run garbage collector. */
811void tomoyo_run_gc(void);
812
813void tomoyo_memory_free(void *ptr);
814
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900815/********** External variable definitions. **********/
816
817/* Lock for GC. */
818extern struct srcu_struct tomoyo_ss;
819
820/* The list for "struct tomoyo_domain_info". */
821extern struct list_head tomoyo_domain_list;
822
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900823extern struct list_head tomoyo_path_group_list;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900824extern struct list_head tomoyo_number_group_list;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900825extern struct list_head tomoyo_domain_initializer_list;
826extern struct list_head tomoyo_domain_keeper_list;
827extern struct list_head tomoyo_alias_list;
828extern struct list_head tomoyo_globally_readable_list;
829extern struct list_head tomoyo_pattern_list;
830extern struct list_head tomoyo_no_rewrite_list;
831extern struct list_head tomoyo_policy_manager_list;
832extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900833
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900834/* Lock for protecting policy. */
835extern struct mutex tomoyo_policy_lock;
836
837/* Has /sbin/init started? */
838extern bool tomoyo_policy_loaded;
839
840/* The kernel's domain. */
841extern struct tomoyo_domain_info tomoyo_kernel_domain;
842
843/********** Inlined functions. **********/
844
845static inline int tomoyo_read_lock(void)
846{
847 return srcu_read_lock(&tomoyo_ss);
848}
849
850static inline void tomoyo_read_unlock(int idx)
851{
852 srcu_read_unlock(&tomoyo_ss, idx);
853}
854
Kentaro Takeda95908372009-02-05 17:18:13 +0900855/* strcmp() for "struct tomoyo_path_info" structure. */
856static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
857 const struct tomoyo_path_info *b)
858{
859 return a->hash != b->hash || strcmp(a->name, b->name);
860}
861
Kentaro Takeda95908372009-02-05 17:18:13 +0900862/**
863 * tomoyo_is_valid - Check whether the character is a valid char.
864 *
865 * @c: The character to check.
866 *
867 * Returns true if @c is a valid character, false otherwise.
868 */
869static inline bool tomoyo_is_valid(const unsigned char c)
870{
871 return c > ' ' && c < 127;
872}
873
874/**
875 * tomoyo_is_invalid - Check whether the character is an invalid char.
876 *
877 * @c: The character to check.
878 *
879 * Returns true if @c is an invalid character, false otherwise.
880 */
881static inline bool tomoyo_is_invalid(const unsigned char c)
882{
883 return c && (c <= ' ' || c >= 127);
884}
885
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900886static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
887{
888 if (name) {
889 struct tomoyo_name_entry *ptr =
890 container_of(name, struct tomoyo_name_entry, entry);
891 atomic_dec(&ptr->users);
892 }
893}
Kentaro Takeda95908372009-02-05 17:18:13 +0900894
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900895static inline void tomoyo_put_path_group(struct tomoyo_path_group *group)
896{
897 if (group)
898 atomic_dec(&group->users);
899}
900
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900901static inline void tomoyo_put_number_group(struct tomoyo_number_group *group)
902{
903 if (group)
904 atomic_dec(&group->users);
905}
906
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900907static inline struct tomoyo_domain_info *tomoyo_domain(void)
908{
909 return current_cred()->security;
910}
Kentaro Takeda95908372009-02-05 17:18:13 +0900911
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900912static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
913 *task)
914{
915 return task_cred_xxx(task, security);
916}
Kentaro Takeda95908372009-02-05 17:18:13 +0900917
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900918static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1,
919 const struct tomoyo_acl_info *p2)
920{
921 return p1->type == p2->type;
922}
923
924static inline bool tomoyo_is_same_name_union
925(const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2)
926{
927 return p1->filename == p2->filename && p1->group == p2->group &&
928 p1->is_group == p2->is_group;
929}
930
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900931static inline bool tomoyo_is_same_number_union
932(const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2)
933{
934 return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1]
935 && p1->group == p2->group && p1->min_type == p2->min_type &&
936 p1->max_type == p2->max_type && p1->is_group == p2->is_group;
937}
938
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900939static inline bool tomoyo_is_same_path_acl(const struct tomoyo_path_acl *p1,
940 const struct tomoyo_path_acl *p2)
941{
942 return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
943 tomoyo_is_same_name_union(&p1->name, &p2->name);
944}
945
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900946static inline bool tomoyo_is_same_path_number3_acl
947(const struct tomoyo_path_number3_acl *p1,
948 const struct tomoyo_path_number3_acl *p2)
949{
950 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
951 && tomoyo_is_same_name_union(&p1->name, &p2->name)
952 && tomoyo_is_same_number_union(&p1->mode, &p2->mode)
953 && tomoyo_is_same_number_union(&p1->major, &p2->major)
954 && tomoyo_is_same_number_union(&p1->minor, &p2->minor);
955}
956
957
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900958static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1,
959 const struct tomoyo_path2_acl *p2)
960{
961 return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
962 tomoyo_is_same_name_union(&p1->name1, &p2->name1) &&
963 tomoyo_is_same_name_union(&p1->name2, &p2->name2);
964}
965
Tetsuo Handaa1f9bb62010-05-17 10:09:15 +0900966static inline bool tomoyo_is_same_path_number_acl
967(const struct tomoyo_path_number_acl *p1,
968 const struct tomoyo_path_number_acl *p2)
969{
970 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
971 && tomoyo_is_same_name_union(&p1->name, &p2->name)
972 && tomoyo_is_same_number_union(&p1->number, &p2->number);
973}
974
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900975static inline bool tomoyo_is_same_domain_initializer_entry
976(const struct tomoyo_domain_initializer_entry *p1,
977 const struct tomoyo_domain_initializer_entry *p2)
978{
979 return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
980 && p1->domainname == p2->domainname
981 && p1->program == p2->program;
982}
983
984static inline bool tomoyo_is_same_domain_keeper_entry
985(const struct tomoyo_domain_keeper_entry *p1,
986 const struct tomoyo_domain_keeper_entry *p2)
987{
988 return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
989 && p1->domainname == p2->domainname
990 && p1->program == p2->program;
991}
992
993static inline bool tomoyo_is_same_alias_entry
994(const struct tomoyo_alias_entry *p1, const struct tomoyo_alias_entry *p2)
995{
996 return p1->original_name == p2->original_name &&
997 p1->aliased_name == p2->aliased_name;
998}
999
Kentaro Takeda95908372009-02-05 17:18:13 +09001000/**
1001 * list_for_each_cookie - iterate over a list with cookie.
1002 * @pos: the &struct list_head to use as a loop cursor.
1003 * @cookie: the &struct list_head to use as a cookie.
1004 * @head: the head for your list.
1005 *
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001006 * Same with list_for_each_rcu() except that this primitive uses @cookie
Kentaro Takeda95908372009-02-05 17:18:13 +09001007 * so that we can continue iteration.
1008 * @cookie must be NULL when iteration starts, and @cookie will become
1009 * NULL when iteration finishes.
1010 */
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +09001011#define list_for_each_cookie(pos, cookie, head) \
1012 for (({ if (!cookie) \
1013 cookie = head; }), \
1014 pos = rcu_dereference((cookie)->next); \
1015 prefetch(pos->next), pos != (head) || ((cookie) = NULL); \
1016 (cookie) = pos, pos = rcu_dereference(pos->next))
1017
Kentaro Takeda95908372009-02-05 17:18:13 +09001018#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */