blob: 91e2bcfd56e341fd1e8687cca2f1a021017673cd [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 Handa084da352010-02-15 15:10:39 +090091};
Tetsuo Handa76bb0892010-02-11 09:42:40 +090092
93/* Index numbers for File Controls. */
94
95/*
96 * TYPE_READ_WRITE_ACL is special. TYPE_READ_WRITE_ACL is automatically set
97 * if both TYPE_READ_ACL and TYPE_WRITE_ACL are set. Both TYPE_READ_ACL and
98 * TYPE_WRITE_ACL are automatically set if TYPE_READ_WRITE_ACL is set.
99 * TYPE_READ_WRITE_ACL is automatically cleared if either TYPE_READ_ACL or
100 * TYPE_WRITE_ACL is cleared. Both TYPE_READ_ACL and TYPE_WRITE_ACL are
101 * automatically cleared if TYPE_READ_WRITE_ACL is cleared.
102 */
103
Tetsuo Handa084da352010-02-15 15:10:39 +0900104enum tomoyo_path_acl_index {
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900105 TOMOYO_TYPE_READ_WRITE,
106 TOMOYO_TYPE_EXECUTE,
107 TOMOYO_TYPE_READ,
108 TOMOYO_TYPE_WRITE,
109 TOMOYO_TYPE_CREATE,
110 TOMOYO_TYPE_UNLINK,
111 TOMOYO_TYPE_MKDIR,
112 TOMOYO_TYPE_RMDIR,
113 TOMOYO_TYPE_MKFIFO,
114 TOMOYO_TYPE_MKSOCK,
115 TOMOYO_TYPE_MKBLOCK,
116 TOMOYO_TYPE_MKCHAR,
117 TOMOYO_TYPE_TRUNCATE,
118 TOMOYO_TYPE_SYMLINK,
119 TOMOYO_TYPE_REWRITE,
120 TOMOYO_TYPE_IOCTL,
121 TOMOYO_TYPE_CHMOD,
122 TOMOYO_TYPE_CHOWN,
123 TOMOYO_TYPE_CHGRP,
124 TOMOYO_TYPE_CHROOT,
125 TOMOYO_TYPE_MOUNT,
126 TOMOYO_TYPE_UMOUNT,
127 TOMOYO_MAX_PATH_OPERATION
Tetsuo Handa084da352010-02-15 15:10:39 +0900128};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900129
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 Handa084da352010-02-15 15:10:39 +0900137enum tomoyo_securityfs_interface_index {
138 TOMOYO_DOMAINPOLICY,
139 TOMOYO_EXCEPTIONPOLICY,
140 TOMOYO_DOMAIN_STATUS,
141 TOMOYO_PROCESS_STATUS,
142 TOMOYO_MEMINFO,
143 TOMOYO_SELFDOMAIN,
144 TOMOYO_VERSION,
145 TOMOYO_PROFILE,
146 TOMOYO_MANAGER
147};
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900148
149/********** Structure definitions. **********/
Kentaro Takeda95908372009-02-05 17:18:13 +0900150
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900151/*
152 * tomoyo_page_buffer is a structure which is used for holding a pathname
153 * obtained from "struct dentry" and "struct vfsmount" pair.
154 * As of now, it is 4096 bytes. If users complain that 4096 bytes is too small
155 * (because TOMOYO escapes non ASCII printable characters using \ooo format),
156 * we will make the buffer larger.
157 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900158struct tomoyo_page_buffer {
159 char buffer[4096];
160};
161
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900162/*
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900163 * tomoyo_request_info is a structure which is used for holding
164 *
165 * (1) Domain information of current process.
166 * (2) Access control mode of the profile.
167 */
168struct tomoyo_request_info {
169 struct tomoyo_domain_info *domain;
170 u8 mode; /* One of tomoyo_mode_index . */
171};
172
173/*
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900174 * tomoyo_path_info is a structure which is used for holding a string data
175 * used by TOMOYO.
176 * This structure has several fields for supporting pattern matching.
177 *
178 * (1) "name" is the '\0' terminated string data.
179 * (2) "hash" is full_name_hash(name, strlen(name)).
180 * This allows tomoyo_pathcmp() to compare by hash before actually compare
181 * using strcmp().
182 * (3) "const_len" is the length of the initial segment of "name" which
183 * consists entirely of non wildcard characters. In other words, the length
184 * which we can compare two strings using strncmp().
185 * (4) "is_dir" is a bool which is true if "name" ends with "/",
186 * false otherwise.
187 * TOMOYO distinguishes directory and non-directory. A directory ends with
188 * "/" and non-directory does not end with "/".
189 * (5) "is_patterned" is a bool which is true if "name" contains wildcard
190 * characters, false otherwise. This allows TOMOYO to use "hash" and
191 * strcmp() for string comparison if "is_patterned" is false.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900192 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900193struct tomoyo_path_info {
194 const char *name;
195 u32 hash; /* = full_name_hash(name, strlen(name)) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900196 u16 const_len; /* = tomoyo_const_part_length(name) */
197 bool is_dir; /* = tomoyo_strendswith(name, "/") */
198 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
Kentaro Takeda95908372009-02-05 17:18:13 +0900199};
200
201/*
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900202 * tomoyo_name_entry is a structure which is used for linking
203 * "struct tomoyo_path_info" into tomoyo_name_list .
Kentaro Takeda95908372009-02-05 17:18:13 +0900204 */
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900205struct tomoyo_name_entry {
206 struct list_head list;
207 atomic_t users;
208 struct tomoyo_path_info entry;
209};
Kentaro Takeda95908372009-02-05 17:18:13 +0900210
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900211/*
212 * tomoyo_path_info_with_data is a structure which is used for holding a
213 * pathname obtained from "struct dentry" and "struct vfsmount" pair.
214 *
215 * "struct tomoyo_path_info_with_data" consists of "struct tomoyo_path_info"
216 * and buffer for the pathname, while "struct tomoyo_page_buffer" consists of
217 * buffer for the pathname only.
218 *
219 * "struct tomoyo_path_info_with_data" is intended to allow TOMOYO to release
220 * both "struct tomoyo_path_info" and buffer for the pathname by single kfree()
221 * so that we don't need to return two pointers to the caller. If the caller
222 * puts "struct tomoyo_path_info" on stack memory, we will be able to remove
223 * "struct tomoyo_path_info_with_data".
224 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900225struct tomoyo_path_info_with_data {
Tetsuo Handa8e2d39a2010-01-26 20:45:27 +0900226 /* Keep "head" first, for this pointer is passed to kfree(). */
Kentaro Takeda95908372009-02-05 17:18:13 +0900227 struct tomoyo_path_info head;
Tetsuo Handaa106cbf2009-03-27 13:12:16 +0900228 char barrier1[16]; /* Safeguard for overrun. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900229 char body[TOMOYO_MAX_PATHNAME_LEN];
230 char barrier2[16]; /* Safeguard for overrun. */
231};
232
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900233struct tomoyo_name_union {
234 const struct tomoyo_path_info *filename;
235 struct tomoyo_path_group *group;
236 u8 is_group;
237};
238
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900239struct tomoyo_number_union {
240 unsigned long values[2];
241 struct tomoyo_number_group *group;
242 u8 min_type;
243 u8 max_type;
244 u8 is_group;
245};
246
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900247/* Structure for "path_group" directive. */
248struct tomoyo_path_group {
249 struct list_head list;
250 const struct tomoyo_path_info *group_name;
251 struct list_head member_list;
252 atomic_t users;
253};
254
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900255/* Structure for "number_group" directive. */
256struct tomoyo_number_group {
257 struct list_head list;
258 const struct tomoyo_path_info *group_name;
259 struct list_head member_list;
260 atomic_t users;
261};
262
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900263/* Structure for "path_group" directive. */
264struct tomoyo_path_group_member {
265 struct list_head list;
266 bool is_deleted;
267 const struct tomoyo_path_info *member_name;
268};
269
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900270/* Structure for "number_group" directive. */
271struct tomoyo_number_group_member {
272 struct list_head list;
273 bool is_deleted;
274 struct tomoyo_number_union number;
275};
276
Kentaro Takeda95908372009-02-05 17:18:13 +0900277/*
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900278 * tomoyo_acl_info is a structure which is used for holding
279 *
280 * (1) "list" which is linked to the ->acl_info_list of
281 * "struct tomoyo_domain_info"
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900282 * (2) "type" which tells type of the entry (either
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900283 * "struct tomoyo_path_acl" or "struct tomoyo_path2_acl").
Kentaro Takeda95908372009-02-05 17:18:13 +0900284 *
285 * Packing "struct tomoyo_acl_info" allows
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900286 * "struct tomoyo_path_acl" to embed "u8" + "u16" and
287 * "struct tomoyo_path2_acl" to embed "u8"
Kentaro Takeda95908372009-02-05 17:18:13 +0900288 * without enlarging their structure size.
289 */
290struct tomoyo_acl_info {
291 struct list_head list;
Kentaro Takeda95908372009-02-05 17:18:13 +0900292 u8 type;
293} __packed;
294
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900295/*
296 * tomoyo_domain_info is a structure which is used for holding permissions
297 * (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
298 * It has following fields.
299 *
300 * (1) "list" which is linked to tomoyo_domain_list .
301 * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info".
302 * (3) "domainname" which holds the name of the domain.
303 * (4) "profile" which remembers profile number assigned to this domain.
304 * (5) "is_deleted" is a bool which is true if this domain is marked as
305 * "deleted", false otherwise.
306 * (6) "quota_warned" is a bool which is used for suppressing warning message
307 * when learning mode learned too much entries.
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900308 * (7) "ignore_global_allow_read" is a bool which is true if this domain
309 * should ignore "allow_read" directive in exception policy.
310 * (8) "transition_failed" is a bool which is set to true when this domain was
311 * unable to create a new domain at tomoyo_find_next_domain() because the
312 * name of the domain to be created was too long or it could not allocate
313 * memory. If set to true, more than one process continued execve()
314 * without domain transition.
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900315 * (9) "users" is an atomic_t that holds how many "struct cred"->security
316 * are referring this "struct tomoyo_domain_info". If is_deleted == true
317 * and users == 0, this struct will be kfree()d upon next garbage
318 * collection.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900319 *
320 * A domain's lifecycle is an analogy of files on / directory.
321 * Multiple domains with the same domainname cannot be created (as with
322 * creating files with the same filename fails with -EEXIST).
323 * If a process reached a domain, that process can reside in that domain after
324 * that domain is marked as "deleted" (as with a process can access an already
325 * open()ed file after that file was unlink()ed).
326 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900327struct tomoyo_domain_info {
328 struct list_head list;
329 struct list_head acl_info_list;
330 /* Name of this domain. Never NULL. */
331 const struct tomoyo_path_info *domainname;
332 u8 profile; /* Profile number to use. */
Tetsuo Handaa0558fc2009-04-06 20:49:14 +0900333 bool is_deleted; /* Delete flag. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900334 bool quota_warned; /* Quota warnning flag. */
Tetsuo Handaea13ddb2010-02-03 06:43:06 +0900335 bool ignore_global_allow_read; /* Ignore "allow_read" flag. */
336 bool transition_failed; /* Domain transition failed flag. */
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900337 atomic_t users; /* Number of referring credentials. */
Kentaro Takeda95908372009-02-05 17:18:13 +0900338};
339
Kentaro Takeda95908372009-02-05 17:18:13 +0900340/*
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900341 * tomoyo_path_acl is a structure which is used for holding an
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900342 * entry with one pathname operation (e.g. open(), mkdir()).
343 * It has following fields.
344 *
345 * (1) "head" which is a "struct tomoyo_acl_info".
346 * (2) "perm" which is a bitmask of permitted operations.
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900347 * (3) "name" is the pathname.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900348 *
349 * Directives held by this structure are "allow_read/write", "allow_execute",
350 * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir",
351 * "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock",
Tetsuo Handa937bf612009-12-02 21:09:48 +0900352 * "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite",
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900353 * "allow_ioctl", "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot",
354 * "allow_mount" and "allow_unmount".
Kentaro Takeda95908372009-02-05 17:18:13 +0900355 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900356struct tomoyo_path_acl {
357 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
Tetsuo Handa937bf612009-12-02 21:09:48 +0900358 u8 perm_high;
Kentaro Takeda95908372009-02-05 17:18:13 +0900359 u16 perm;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900360 struct tomoyo_name_union name;
Kentaro Takeda95908372009-02-05 17:18:13 +0900361};
362
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900363/*
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900364 * tomoyo_path2_acl is a structure which is used for holding an
Tetsuo Handa937bf612009-12-02 21:09:48 +0900365 * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900366 * It has following fields.
367 *
368 * (1) "head" which is a "struct tomoyo_acl_info".
369 * (2) "perm" which is a bitmask of permitted operations.
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900370 * (3) "name1" is the source/old pathname.
371 * (4) "name2" is the destination/new pathname.
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900372 *
Tetsuo Handa937bf612009-12-02 21:09:48 +0900373 * Directives held by this structure are "allow_rename", "allow_link" and
374 * "allow_pivot_root".
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900375 */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900376struct tomoyo_path2_acl {
377 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
Kentaro Takeda95908372009-02-05 17:18:13 +0900378 u8 perm;
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900379 struct tomoyo_name_union name1;
380 struct tomoyo_name_union name2;
Kentaro Takeda95908372009-02-05 17:18:13 +0900381};
382
Tetsuo Handac3fa1092009-06-08 12:37:39 +0900383/*
384 * tomoyo_io_buffer is a structure which is used for reading and modifying
385 * configuration via /sys/kernel/security/tomoyo/ interface.
386 * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as
387 * cursors.
388 *
389 * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of
390 * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info"
391 * entry has a list of "struct tomoyo_acl_info", we need two cursors when
392 * reading (one is for traversing tomoyo_domain_list and the other is for
393 * traversing "struct tomoyo_acl_info"->acl_info_list ).
394 *
395 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
396 * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the
397 * domain with the domainname specified by the rest of that line (NULL is set
398 * if seek failed).
399 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
400 * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that
401 * line (->write_var1 is set to NULL if a domain was deleted).
402 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
403 * neither "select " nor "delete ", an entry or a domain specified by that line
404 * is appended.
405 */
Kentaro Takeda95908372009-02-05 17:18:13 +0900406struct tomoyo_io_buffer {
407 int (*read) (struct tomoyo_io_buffer *);
408 int (*write) (struct tomoyo_io_buffer *);
409 /* Exclusive lock for this structure. */
410 struct mutex io_sem;
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900411 /* Index returned by tomoyo_read_lock(). */
412 int reader_idx;
Kentaro Takeda95908372009-02-05 17:18:13 +0900413 /* The position currently reading from. */
414 struct list_head *read_var1;
415 /* Extra variables for reading. */
416 struct list_head *read_var2;
417 /* The position currently writing to. */
418 struct tomoyo_domain_info *write_var1;
419 /* The step for reading. */
420 int read_step;
421 /* Buffer for reading. */
422 char *read_buf;
423 /* EOF flag for reading. */
424 bool read_eof;
425 /* Read domain ACL of specified PID? */
426 bool read_single_domain;
427 /* Extra variable for reading. */
428 u8 read_bit;
429 /* Bytes available for reading. */
430 int read_avail;
431 /* Size of read buffer. */
432 int readbuf_size;
433 /* Buffer for writing. */
434 char *write_buf;
435 /* Bytes available for writing. */
436 int write_avail;
437 /* Size of write buffer. */
438 int writebuf_size;
439};
440
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900441/*
442 * tomoyo_globally_readable_file_entry is a structure which is used for holding
443 * "allow_read" entries.
444 * It has following fields.
445 *
446 * (1) "list" which is linked to tomoyo_globally_readable_list .
447 * (2) "filename" is a pathname which is allowed to open(O_RDONLY).
448 * (3) "is_deleted" is a bool which is true if marked as deleted, false
449 * otherwise.
450 */
451struct tomoyo_globally_readable_file_entry {
452 struct list_head list;
453 const struct tomoyo_path_info *filename;
454 bool is_deleted;
455};
456
457/*
458 * tomoyo_pattern_entry is a structure which is used for holding
459 * "tomoyo_pattern_list" entries.
460 * It has following fields.
461 *
462 * (1) "list" which is linked to tomoyo_pattern_list .
463 * (2) "pattern" is a pathname pattern which is used for converting pathnames
464 * to pathname patterns during learning mode.
465 * (3) "is_deleted" is a bool which is true if marked as deleted, false
466 * otherwise.
467 */
468struct tomoyo_pattern_entry {
469 struct list_head list;
470 const struct tomoyo_path_info *pattern;
471 bool is_deleted;
472};
473
474/*
475 * tomoyo_no_rewrite_entry is a structure which is used for holding
476 * "deny_rewrite" entries.
477 * It has following fields.
478 *
479 * (1) "list" which is linked to tomoyo_no_rewrite_list .
480 * (2) "pattern" is a pathname which is by default not permitted to modify
481 * already existing content.
482 * (3) "is_deleted" is a bool which is true if marked as deleted, false
483 * otherwise.
484 */
485struct tomoyo_no_rewrite_entry {
486 struct list_head list;
487 const struct tomoyo_path_info *pattern;
488 bool is_deleted;
489};
490
491/*
492 * tomoyo_domain_initializer_entry is a structure which is used for holding
493 * "initialize_domain" and "no_initialize_domain" entries.
494 * It has following fields.
495 *
496 * (1) "list" which is linked to tomoyo_domain_initializer_list .
497 * (2) "domainname" which is "a domainname" or "the last component of a
498 * domainname". This field is NULL if "from" clause is not specified.
499 * (3) "program" which is a program's pathname.
500 * (4) "is_deleted" is a bool which is true if marked as deleted, false
501 * otherwise.
502 * (5) "is_not" is a bool which is true if "no_initialize_domain", false
503 * otherwise.
504 * (6) "is_last_name" is a bool which is true if "domainname" is "the last
505 * component of a domainname", false otherwise.
506 */
507struct tomoyo_domain_initializer_entry {
508 struct list_head list;
509 const struct tomoyo_path_info *domainname; /* This may be NULL */
510 const struct tomoyo_path_info *program;
511 bool is_deleted;
512 bool is_not; /* True if this entry is "no_initialize_domain". */
513 /* True if the domainname is tomoyo_get_last_name(). */
514 bool is_last_name;
515};
516
517/*
518 * tomoyo_domain_keeper_entry is a structure which is used for holding
519 * "keep_domain" and "no_keep_domain" entries.
520 * It has following fields.
521 *
522 * (1) "list" which is linked to tomoyo_domain_keeper_list .
523 * (2) "domainname" which is "a domainname" or "the last component of a
524 * domainname".
525 * (3) "program" which is a program's pathname.
526 * This field is NULL if "from" clause is not specified.
527 * (4) "is_deleted" is a bool which is true if marked as deleted, false
528 * otherwise.
529 * (5) "is_not" is a bool which is true if "no_initialize_domain", false
530 * otherwise.
531 * (6) "is_last_name" is a bool which is true if "domainname" is "the last
532 * component of a domainname", false otherwise.
533 */
534struct tomoyo_domain_keeper_entry {
535 struct list_head list;
536 const struct tomoyo_path_info *domainname;
537 const struct tomoyo_path_info *program; /* This may be NULL */
538 bool is_deleted;
539 bool is_not; /* True if this entry is "no_keep_domain". */
540 /* True if the domainname is tomoyo_get_last_name(). */
541 bool is_last_name;
542};
543
544/*
545 * tomoyo_alias_entry is a structure which is used for holding "alias" entries.
546 * It has following fields.
547 *
548 * (1) "list" which is linked to tomoyo_alias_list .
549 * (2) "original_name" which is a dereferenced pathname.
550 * (3) "aliased_name" which is a symlink's pathname.
551 * (4) "is_deleted" is a bool which is true if marked as deleted, false
552 * otherwise.
553 */
554struct tomoyo_alias_entry {
555 struct list_head list;
556 const struct tomoyo_path_info *original_name;
557 const struct tomoyo_path_info *aliased_name;
558 bool is_deleted;
559};
560
561/*
562 * tomoyo_policy_manager_entry is a structure which is used for holding list of
563 * domainnames or programs which are permitted to modify configuration via
564 * /sys/kernel/security/tomoyo/ interface.
565 * It has following fields.
566 *
567 * (1) "list" which is linked to tomoyo_policy_manager_list .
568 * (2) "manager" is a domainname or a program's pathname.
569 * (3) "is_domain" is a bool which is true if "manager" is a domainname, false
570 * otherwise.
571 * (4) "is_deleted" is a bool which is true if marked as deleted, false
572 * otherwise.
573 */
574struct tomoyo_policy_manager_entry {
575 struct list_head list;
576 /* A path to program or a domainname. */
577 const struct tomoyo_path_info *manager;
578 bool is_domain; /* True if manager is a domainname. */
579 bool is_deleted; /* True if this entry is deleted. */
580};
581
582/********** Function prototypes. **********/
583
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900584/* Check whether the given name matches the given name_union. */
585bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
586 const struct tomoyo_name_union *ptr);
Kentaro Takeda95908372009-02-05 17:18:13 +0900587/* Check whether the domain has too many ACL entries to hold. */
Tetsuo Handacb0abe62010-05-17 10:08:05 +0900588bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
Kentaro Takeda95908372009-02-05 17:18:13 +0900589/* Transactional sprintf() for policy dump. */
590bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
591 __attribute__ ((format(printf, 2, 3)));
592/* Check whether the domainname is correct. */
Tetsuo Handa17080002010-02-16 21:14:48 +0900593bool tomoyo_is_correct_domain(const unsigned char *domainname);
Kentaro Takeda95908372009-02-05 17:18:13 +0900594/* Check whether the token is correct. */
595bool tomoyo_is_correct_path(const char *filename, const s8 start_type,
Tetsuo Handa17080002010-02-16 21:14:48 +0900596 const s8 pattern_type, const s8 end_type);
Kentaro Takeda95908372009-02-05 17:18:13 +0900597/* Check whether the token can be a domainname. */
598bool tomoyo_is_domain_def(const unsigned char *buffer);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900599bool tomoyo_parse_name_union(const char *filename,
600 struct tomoyo_name_union *ptr);
601/* Check whether the given filename matches the given path_group. */
602bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
603 const struct tomoyo_path_group *group,
604 const bool may_use_pattern);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900605/* Check whether the given value matches the given number_group. */
606bool tomoyo_number_matches_group(const unsigned long min,
607 const unsigned long max,
608 const struct tomoyo_number_group *group);
Kentaro Takeda95908372009-02-05 17:18:13 +0900609/* Check whether the given filename matches the given pattern. */
610bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
611 const struct tomoyo_path_info *pattern);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900612
613bool tomoyo_print_number_union(struct tomoyo_io_buffer *head,
614 const struct tomoyo_number_union *ptr);
615bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
616
Kentaro Takeda95908372009-02-05 17:18:13 +0900617/* Read "alias" entry in exception policy. */
618bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head);
619/*
620 * Read "initialize_domain" and "no_initialize_domain" entry
621 * in exception policy.
622 */
623bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head);
624/* Read "keep_domain" and "no_keep_domain" entry in exception policy. */
625bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head);
626/* Read "file_pattern" entry in exception policy. */
627bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900628/* Read "path_group" entry in exception policy. */
629bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900630/* Read "number_group" entry in exception policy. */
631bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head);
Kentaro Takeda95908372009-02-05 17:18:13 +0900632/* Read "allow_read" entry in exception policy. */
633bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head);
634/* Read "deny_rewrite" entry in exception policy. */
635bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900636/* Tokenize a line. */
637bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
Kentaro Takeda95908372009-02-05 17:18:13 +0900638/* Write domain policy violation warning message to console? */
639bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
640/* Convert double path operation to operation name. */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900641const char *tomoyo_path22keyword(const u8 operation);
Kentaro Takeda95908372009-02-05 17:18:13 +0900642/* Get the last component of the given domainname. */
643const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
Kentaro Takeda95908372009-02-05 17:18:13 +0900644/* Convert single path operation to operation name. */
Tetsuo Handa7ef61232010-02-16 08:03:30 +0900645const char *tomoyo_path2keyword(const u8 operation);
Kentaro Takeda95908372009-02-05 17:18:13 +0900646/* Create "alias" entry in exception policy. */
647int tomoyo_write_alias_policy(char *data, const bool is_delete);
648/*
649 * Create "initialize_domain" and "no_initialize_domain" entry
650 * in exception policy.
651 */
652int tomoyo_write_domain_initializer_policy(char *data, const bool is_not,
653 const bool is_delete);
654/* Create "keep_domain" and "no_keep_domain" entry in exception policy. */
655int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
656 const bool is_delete);
657/*
658 * Create "allow_read/write", "allow_execute", "allow_read", "allow_write",
659 * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",
660 * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar",
661 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and
662 * "allow_link" entry in domain policy.
663 */
664int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
665 const bool is_delete);
666/* Create "allow_read" entry in exception policy. */
667int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
668/* Create "deny_rewrite" entry in exception policy. */
669int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
670/* Create "file_pattern" entry in exception policy. */
671int tomoyo_write_pattern_policy(char *data, const bool is_delete);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900672/* Create "path_group" entry in exception policy. */
673int tomoyo_write_path_group_policy(char *data, const bool is_delete);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900674/* Create "number_group" entry in exception policy. */
675int tomoyo_write_number_group_policy(char *data, const bool is_delete);
Kentaro Takeda95908372009-02-05 17:18:13 +0900676/* Find a domain by the given name. */
677struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
678/* Find or create a domain by the given name. */
679struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
680 domainname,
681 const u8 profile);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900682
683/* Allocate memory for "struct tomoyo_path_group". */
684struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900685struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name);
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900686
Kentaro Takeda95908372009-02-05 17:18:13 +0900687/* Check mode for specified functionality. */
688unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
689 const u8 index);
Kentaro Takeda95908372009-02-05 17:18:13 +0900690/* Fill in "struct tomoyo_path_info" members. */
691void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
692/* Run policy loader when /sbin/init starts. */
693void tomoyo_load_policy(const char *filename);
Kentaro Takeda95908372009-02-05 17:18:13 +0900694
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900695void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
696
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900697/* Convert binary string to ascii string. */
698int tomoyo_encode(char *buffer, int buflen, const char *str);
699
700/* Returns realpath(3) of the given pathname but ignores chroot'ed root. */
701int tomoyo_realpath_from_path2(struct path *path, char *newname,
702 int newname_len);
703
704/*
705 * Returns realpath(3) of the given pathname but ignores chroot'ed root.
706 * These functions use kzalloc(), so the caller must call kfree()
707 * if these functions didn't return NULL.
708 */
709char *tomoyo_realpath(const char *pathname);
710/*
711 * Same with tomoyo_realpath() except that it doesn't follow the final symlink.
712 */
713char *tomoyo_realpath_nofollow(const char *pathname);
714/* Same with tomoyo_realpath() except that the pathname is already solved. */
715char *tomoyo_realpath_from_path(struct path *path);
716
717/* Check memory quota. */
718bool tomoyo_memory_ok(void *ptr);
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900719void *tomoyo_commit_ok(void *data, const unsigned int size);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900720
721/*
722 * Keep the given name on the RAM.
723 * The RAM is shared, so NEVER try to modify or kfree() the returned name.
724 */
725const struct tomoyo_path_info *tomoyo_get_name(const char *name);
726
727/* Check for memory usage. */
728int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
729
730/* Set memory quota. */
731int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
732
733/* Initialize realpath related code. */
734void __init tomoyo_realpath_init(void);
735int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
736 const struct tomoyo_path_info *filename);
737int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
738 struct path *path, const int flag);
Tetsuo Handa97d69312010-02-16 09:46:15 +0900739int tomoyo_path_perm(const u8 operation, struct path *path);
740int tomoyo_path2_perm(const u8 operation, struct path *path1,
741 struct path *path2);
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900742int tomoyo_find_next_domain(struct linux_binprm *bprm);
743
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900744/* Drop refcount on tomoyo_name_union. */
745void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
746
Tetsuo Handa847b1732010-02-11 09:43:54 +0900747/* Run garbage collector. */
748void tomoyo_run_gc(void);
749
750void tomoyo_memory_free(void *ptr);
751
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900752/********** External variable definitions. **********/
753
754/* Lock for GC. */
755extern struct srcu_struct tomoyo_ss;
756
757/* The list for "struct tomoyo_domain_info". */
758extern struct list_head tomoyo_domain_list;
759
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900760extern struct list_head tomoyo_path_group_list;
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900761extern struct list_head tomoyo_number_group_list;
Tetsuo Handa847b1732010-02-11 09:43:54 +0900762extern struct list_head tomoyo_domain_initializer_list;
763extern struct list_head tomoyo_domain_keeper_list;
764extern struct list_head tomoyo_alias_list;
765extern struct list_head tomoyo_globally_readable_list;
766extern struct list_head tomoyo_pattern_list;
767extern struct list_head tomoyo_no_rewrite_list;
768extern struct list_head tomoyo_policy_manager_list;
769extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
Tetsuo Handa847b1732010-02-11 09:43:54 +0900770
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900771/* Lock for protecting policy. */
772extern struct mutex tomoyo_policy_lock;
773
774/* Has /sbin/init started? */
775extern bool tomoyo_policy_loaded;
776
777/* The kernel's domain. */
778extern struct tomoyo_domain_info tomoyo_kernel_domain;
779
780/********** Inlined functions. **********/
781
782static inline int tomoyo_read_lock(void)
783{
784 return srcu_read_lock(&tomoyo_ss);
785}
786
787static inline void tomoyo_read_unlock(int idx)
788{
789 srcu_read_unlock(&tomoyo_ss, idx);
790}
791
Kentaro Takeda95908372009-02-05 17:18:13 +0900792/* strcmp() for "struct tomoyo_path_info" structure. */
793static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
794 const struct tomoyo_path_info *b)
795{
796 return a->hash != b->hash || strcmp(a->name, b->name);
797}
798
Kentaro Takeda95908372009-02-05 17:18:13 +0900799/**
800 * tomoyo_is_valid - Check whether the character is a valid char.
801 *
802 * @c: The character to check.
803 *
804 * Returns true if @c is a valid character, false otherwise.
805 */
806static inline bool tomoyo_is_valid(const unsigned char c)
807{
808 return c > ' ' && c < 127;
809}
810
811/**
812 * tomoyo_is_invalid - Check whether the character is an invalid char.
813 *
814 * @c: The character to check.
815 *
816 * Returns true if @c is an invalid character, false otherwise.
817 */
818static inline bool tomoyo_is_invalid(const unsigned char c)
819{
820 return c && (c <= ' ' || c >= 127);
821}
822
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900823static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
824{
825 if (name) {
826 struct tomoyo_name_entry *ptr =
827 container_of(name, struct tomoyo_name_entry, entry);
828 atomic_dec(&ptr->users);
829 }
830}
Kentaro Takeda95908372009-02-05 17:18:13 +0900831
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900832static inline void tomoyo_put_path_group(struct tomoyo_path_group *group)
833{
834 if (group)
835 atomic_dec(&group->users);
836}
837
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900838static inline void tomoyo_put_number_group(struct tomoyo_number_group *group)
839{
840 if (group)
841 atomic_dec(&group->users);
842}
843
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900844static inline struct tomoyo_domain_info *tomoyo_domain(void)
845{
846 return current_cred()->security;
847}
Kentaro Takeda95908372009-02-05 17:18:13 +0900848
Tetsuo Handa76bb0892010-02-11 09:42:40 +0900849static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
850 *task)
851{
852 return task_cred_xxx(task, security);
853}
Kentaro Takeda95908372009-02-05 17:18:13 +0900854
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900855static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1,
856 const struct tomoyo_acl_info *p2)
857{
858 return p1->type == p2->type;
859}
860
861static inline bool tomoyo_is_same_name_union
862(const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2)
863{
864 return p1->filename == p2->filename && p1->group == p2->group &&
865 p1->is_group == p2->is_group;
866}
867
Tetsuo Handa4c3e9e22010-05-17 10:06:58 +0900868static inline bool tomoyo_is_same_number_union
869(const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2)
870{
871 return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1]
872 && p1->group == p2->group && p1->min_type == p2->min_type &&
873 p1->max_type == p2->max_type && p1->is_group == p2->is_group;
874}
875
Tetsuo Handa7762fbf2010-05-10 17:30:26 +0900876static inline bool tomoyo_is_same_path_acl(const struct tomoyo_path_acl *p1,
877 const struct tomoyo_path_acl *p2)
878{
879 return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
880 tomoyo_is_same_name_union(&p1->name, &p2->name);
881}
882
883static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1,
884 const struct tomoyo_path2_acl *p2)
885{
886 return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
887 tomoyo_is_same_name_union(&p1->name1, &p2->name1) &&
888 tomoyo_is_same_name_union(&p1->name2, &p2->name2);
889}
890
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900891static inline bool tomoyo_is_same_domain_initializer_entry
892(const struct tomoyo_domain_initializer_entry *p1,
893 const struct tomoyo_domain_initializer_entry *p2)
894{
895 return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
896 && p1->domainname == p2->domainname
897 && p1->program == p2->program;
898}
899
900static inline bool tomoyo_is_same_domain_keeper_entry
901(const struct tomoyo_domain_keeper_entry *p1,
902 const struct tomoyo_domain_keeper_entry *p2)
903{
904 return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
905 && p1->domainname == p2->domainname
906 && p1->program == p2->program;
907}
908
909static inline bool tomoyo_is_same_alias_entry
910(const struct tomoyo_alias_entry *p1, const struct tomoyo_alias_entry *p2)
911{
912 return p1->original_name == p2->original_name &&
913 p1->aliased_name == p2->aliased_name;
914}
915
Kentaro Takeda95908372009-02-05 17:18:13 +0900916/**
917 * list_for_each_cookie - iterate over a list with cookie.
918 * @pos: the &struct list_head to use as a loop cursor.
919 * @cookie: the &struct list_head to use as a cookie.
920 * @head: the head for your list.
921 *
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900922 * Same with list_for_each_rcu() except that this primitive uses @cookie
Kentaro Takeda95908372009-02-05 17:18:13 +0900923 * so that we can continue iteration.
924 * @cookie must be NULL when iteration starts, and @cookie will become
925 * NULL when iteration finishes.
926 */
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900927#define list_for_each_cookie(pos, cookie, head) \
928 for (({ if (!cookie) \
929 cookie = head; }), \
930 pos = rcu_dereference((cookie)->next); \
931 prefetch(pos->next), pos != (head) || ((cookie) = NULL); \
932 (cookie) = pos, pos = rcu_dereference(pos->next))
933
Kentaro Takeda95908372009-02-05 17:18:13 +0900934#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */