]> bbs.cooldavid.org Git - net-next-2.6.git/blame - security/tomoyo/common.h
TOMOYO: Add pathname aggregation support.
[net-next-2.6.git] / security / tomoyo / common.h
CommitLineData
9590837b
KT
1/*
2 * security/tomoyo/common.h
3 *
76bb0895 4 * Header file for TOMOYO.
9590837b 5 *
76bb0895 6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
9590837b
KT
7 */
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>
76bb0895 22#include <linux/cred.h>
17fcfbd9 23#include <linux/poll.h>
76bb0895
TH
24struct linux_binprm;
25
26/********** 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
c8c57e84 36#define TOMOYO_EXEC_TMPSIZE 4096
76bb0895
TH
37
38/* Profile number is an integer between 0 and 255. */
39#define TOMOYO_MAX_PROFILES 256
40
cb0abe6a
TH
41enum tomoyo_mode_index {
42 TOMOYO_CONFIG_DISABLED,
43 TOMOYO_CONFIG_LEARNING,
44 TOMOYO_CONFIG_PERMISSIVE,
45 TOMOYO_CONFIG_ENFORCING
46};
47
76bb0895 48/* Keywords for ACLs. */
1084307c 49#define TOMOYO_KEYWORD_AGGREGATOR "aggregator "
76bb0895 50#define TOMOYO_KEYWORD_ALIAS "alias "
2106ccd9 51#define TOMOYO_KEYWORD_ALLOW_MOUNT "allow_mount "
76bb0895
TH
52#define TOMOYO_KEYWORD_ALLOW_READ "allow_read "
53#define TOMOYO_KEYWORD_DELETE "delete "
54#define TOMOYO_KEYWORD_DENY_REWRITE "deny_rewrite "
55#define TOMOYO_KEYWORD_FILE_PATTERN "file_pattern "
56#define TOMOYO_KEYWORD_INITIALIZE_DOMAIN "initialize_domain "
57#define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain "
58#define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain "
59#define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain "
7762fbff 60#define TOMOYO_KEYWORD_PATH_GROUP "path_group "
4c3e9e2d 61#define TOMOYO_KEYWORD_NUMBER_GROUP "number_group "
76bb0895
TH
62#define TOMOYO_KEYWORD_SELECT "select "
63#define TOMOYO_KEYWORD_USE_PROFILE "use_profile "
64#define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read"
9b244373
TH
65#define TOMOYO_KEYWORD_QUOTA_EXCEEDED "quota_exceeded"
66#define TOMOYO_KEYWORD_TRANSITION_FAILED "transition_failed"
76bb0895
TH
67/* A domain definition starts with <kernel>. */
68#define TOMOYO_ROOT_NAME "<kernel>"
69#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
70
4c3e9e2d
TH
71/* Value type definition. */
72#define TOMOYO_VALUE_TYPE_INVALID 0
73#define TOMOYO_VALUE_TYPE_DECIMAL 1
74#define TOMOYO_VALUE_TYPE_OCTAL 2
75#define TOMOYO_VALUE_TYPE_HEXADECIMAL 3
76
76bb0895 77/* Index numbers for Access Controls. */
084da356
TH
78enum tomoyo_mac_index {
79 TOMOYO_MAC_FOR_FILE, /* domain_policy.conf */
80 TOMOYO_MAX_ACCEPT_ENTRY,
81 TOMOYO_VERBOSE,
82 TOMOYO_MAX_CONTROL_INDEX
83};
76bb0895
TH
84
85/* Index numbers for Access Controls. */
084da356 86enum tomoyo_acl_entry_type_index {
7ef61233
TH
87 TOMOYO_TYPE_PATH_ACL,
88 TOMOYO_TYPE_PATH2_ACL,
a1f9bb6a
TH
89 TOMOYO_TYPE_PATH_NUMBER_ACL,
90 TOMOYO_TYPE_PATH_NUMBER3_ACL,
2106ccd9 91 TOMOYO_TYPE_MOUNT_ACL,
084da356 92};
76bb0895
TH
93
94/* Index numbers for File Controls. */
95
96/*
a1f9bb6a
TH
97 * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically
98 * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set.
99 * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if
100 * TOMOYO_TYPE_READ_WRITE is set.
101 * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ
102 * or TOMOYO_TYPE_WRITE is cleared.
103 * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if
104 * TOMOYO_TYPE_READ_WRITE is cleared.
76bb0895
TH
105 */
106
084da356 107enum tomoyo_path_acl_index {
7ef61233
TH
108 TOMOYO_TYPE_READ_WRITE,
109 TOMOYO_TYPE_EXECUTE,
110 TOMOYO_TYPE_READ,
111 TOMOYO_TYPE_WRITE,
7ef61233 112 TOMOYO_TYPE_UNLINK,
7ef61233 113 TOMOYO_TYPE_RMDIR,
7ef61233
TH
114 TOMOYO_TYPE_TRUNCATE,
115 TOMOYO_TYPE_SYMLINK,
116 TOMOYO_TYPE_REWRITE,
7ef61233 117 TOMOYO_TYPE_CHROOT,
7ef61233
TH
118 TOMOYO_TYPE_UMOUNT,
119 TOMOYO_MAX_PATH_OPERATION
084da356
TH
120};
121
a1f9bb6a
TH
122enum tomoyo_path_number3_acl_index {
123 TOMOYO_TYPE_MKBLOCK,
124 TOMOYO_TYPE_MKCHAR,
125 TOMOYO_MAX_PATH_NUMBER3_OPERATION
126};
127
084da356 128enum tomoyo_path2_acl_index {
7ef61233
TH
129 TOMOYO_TYPE_LINK,
130 TOMOYO_TYPE_RENAME,
131 TOMOYO_TYPE_PIVOT_ROOT,
132 TOMOYO_MAX_PATH2_OPERATION
084da356
TH
133};
134
a1f9bb6a
TH
135enum tomoyo_path_number_acl_index {
136 TOMOYO_TYPE_CREATE,
137 TOMOYO_TYPE_MKDIR,
138 TOMOYO_TYPE_MKFIFO,
139 TOMOYO_TYPE_MKSOCK,
140 TOMOYO_TYPE_IOCTL,
141 TOMOYO_TYPE_CHMOD,
142 TOMOYO_TYPE_CHOWN,
143 TOMOYO_TYPE_CHGRP,
144 TOMOYO_MAX_PATH_NUMBER_OPERATION
145};
146
084da356
TH
147enum tomoyo_securityfs_interface_index {
148 TOMOYO_DOMAINPOLICY,
149 TOMOYO_EXCEPTIONPOLICY,
150 TOMOYO_DOMAIN_STATUS,
151 TOMOYO_PROCESS_STATUS,
152 TOMOYO_MEMINFO,
153 TOMOYO_SELFDOMAIN,
154 TOMOYO_VERSION,
155 TOMOYO_PROFILE,
17fcfbd9 156 TOMOYO_QUERY,
084da356
TH
157 TOMOYO_MANAGER
158};
9590837b 159
17fcfbd9
TH
160#define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */
161
76bb0895 162/********** Structure definitions. **********/
9590837b 163
cb0abe6a
TH
164/*
165 * tomoyo_request_info is a structure which is used for holding
166 *
167 * (1) Domain information of current process.
17fcfbd9
TH
168 * (2) How many retries are made for this request.
169 * (3) Profile number used for this request.
170 * (4) Access control mode of the profile.
cb0abe6a
TH
171 */
172struct tomoyo_request_info {
173 struct tomoyo_domain_info *domain;
17fcfbd9
TH
174 u8 retry;
175 u8 profile;
cb0abe6a
TH
176 u8 mode; /* One of tomoyo_mode_index . */
177};
178
c3fa109a
TH
179/*
180 * tomoyo_path_info is a structure which is used for holding a string data
181 * used by TOMOYO.
182 * This structure has several fields for supporting pattern matching.
183 *
184 * (1) "name" is the '\0' terminated string data.
185 * (2) "hash" is full_name_hash(name, strlen(name)).
186 * This allows tomoyo_pathcmp() to compare by hash before actually compare
187 * using strcmp().
188 * (3) "const_len" is the length of the initial segment of "name" which
189 * consists entirely of non wildcard characters. In other words, the length
190 * which we can compare two strings using strncmp().
191 * (4) "is_dir" is a bool which is true if "name" ends with "/",
192 * false otherwise.
193 * TOMOYO distinguishes directory and non-directory. A directory ends with
194 * "/" and non-directory does not end with "/".
195 * (5) "is_patterned" is a bool which is true if "name" contains wildcard
196 * characters, false otherwise. This allows TOMOYO to use "hash" and
197 * strcmp() for string comparison if "is_patterned" is false.
c3fa109a 198 */
9590837b
KT
199struct tomoyo_path_info {
200 const char *name;
201 u32 hash; /* = full_name_hash(name, strlen(name)) */
9590837b
KT
202 u16 const_len; /* = tomoyo_const_part_length(name) */
203 bool is_dir; /* = tomoyo_strendswith(name, "/") */
204 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
9590837b
KT
205};
206
207/*
76bb0895
TH
208 * tomoyo_name_entry is a structure which is used for linking
209 * "struct tomoyo_path_info" into tomoyo_name_list .
9590837b 210 */
76bb0895
TH
211struct tomoyo_name_entry {
212 struct list_head list;
213 atomic_t users;
214 struct tomoyo_path_info entry;
215};
9590837b 216
7762fbff
TH
217struct tomoyo_name_union {
218 const struct tomoyo_path_info *filename;
219 struct tomoyo_path_group *group;
220 u8 is_group;
221};
222
4c3e9e2d
TH
223struct tomoyo_number_union {
224 unsigned long values[2];
225 struct tomoyo_number_group *group;
226 u8 min_type;
227 u8 max_type;
228 u8 is_group;
229};
230
7762fbff
TH
231/* Structure for "path_group" directive. */
232struct tomoyo_path_group {
233 struct list_head list;
234 const struct tomoyo_path_info *group_name;
235 struct list_head member_list;
236 atomic_t users;
237};
238
4c3e9e2d
TH
239/* Structure for "number_group" directive. */
240struct tomoyo_number_group {
241 struct list_head list;
242 const struct tomoyo_path_info *group_name;
243 struct list_head member_list;
244 atomic_t users;
245};
246
7762fbff
TH
247/* Structure for "path_group" directive. */
248struct tomoyo_path_group_member {
249 struct list_head list;
250 bool is_deleted;
251 const struct tomoyo_path_info *member_name;
252};
253
4c3e9e2d
TH
254/* Structure for "number_group" directive. */
255struct tomoyo_number_group_member {
256 struct list_head list;
257 bool is_deleted;
258 struct tomoyo_number_union number;
259};
260
9590837b 261/*
c3fa109a
TH
262 * tomoyo_acl_info is a structure which is used for holding
263 *
264 * (1) "list" which is linked to the ->acl_info_list of
265 * "struct tomoyo_domain_info"
ea13ddba 266 * (2) "type" which tells type of the entry (either
7ef61233 267 * "struct tomoyo_path_acl" or "struct tomoyo_path2_acl").
9590837b
KT
268 *
269 * Packing "struct tomoyo_acl_info" allows
7ef61233
TH
270 * "struct tomoyo_path_acl" to embed "u8" + "u16" and
271 * "struct tomoyo_path2_acl" to embed "u8"
9590837b
KT
272 * without enlarging their structure size.
273 */
274struct tomoyo_acl_info {
275 struct list_head list;
9590837b
KT
276 u8 type;
277} __packed;
278
c3fa109a
TH
279/*
280 * tomoyo_domain_info is a structure which is used for holding permissions
281 * (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
282 * It has following fields.
283 *
284 * (1) "list" which is linked to tomoyo_domain_list .
285 * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info".
286 * (3) "domainname" which holds the name of the domain.
287 * (4) "profile" which remembers profile number assigned to this domain.
288 * (5) "is_deleted" is a bool which is true if this domain is marked as
289 * "deleted", false otherwise.
290 * (6) "quota_warned" is a bool which is used for suppressing warning message
291 * when learning mode learned too much entries.
ea13ddba
TH
292 * (7) "ignore_global_allow_read" is a bool which is true if this domain
293 * should ignore "allow_read" directive in exception policy.
294 * (8) "transition_failed" is a bool which is set to true when this domain was
295 * unable to create a new domain at tomoyo_find_next_domain() because the
296 * name of the domain to be created was too long or it could not allocate
297 * memory. If set to true, more than one process continued execve()
298 * without domain transition.
ec8e6a4e
TH
299 * (9) "users" is an atomic_t that holds how many "struct cred"->security
300 * are referring this "struct tomoyo_domain_info". If is_deleted == true
301 * and users == 0, this struct will be kfree()d upon next garbage
302 * collection.
c3fa109a
TH
303 *
304 * A domain's lifecycle is an analogy of files on / directory.
305 * Multiple domains with the same domainname cannot be created (as with
306 * creating files with the same filename fails with -EEXIST).
307 * If a process reached a domain, that process can reside in that domain after
308 * that domain is marked as "deleted" (as with a process can access an already
309 * open()ed file after that file was unlink()ed).
310 */
9590837b
KT
311struct tomoyo_domain_info {
312 struct list_head list;
313 struct list_head acl_info_list;
314 /* Name of this domain. Never NULL. */
315 const struct tomoyo_path_info *domainname;
316 u8 profile; /* Profile number to use. */
a0558fc3 317 bool is_deleted; /* Delete flag. */
9590837b 318 bool quota_warned; /* Quota warnning flag. */
ea13ddba
TH
319 bool ignore_global_allow_read; /* Ignore "allow_read" flag. */
320 bool transition_failed; /* Domain transition failed flag. */
ec8e6a4e 321 atomic_t users; /* Number of referring credentials. */
9590837b
KT
322};
323
9590837b 324/*
7ef61233 325 * tomoyo_path_acl is a structure which is used for holding an
c3fa109a
TH
326 * entry with one pathname operation (e.g. open(), mkdir()).
327 * It has following fields.
328 *
329 * (1) "head" which is a "struct tomoyo_acl_info".
330 * (2) "perm" which is a bitmask of permitted operations.
7762fbff 331 * (3) "name" is the pathname.
c3fa109a
TH
332 *
333 * Directives held by this structure are "allow_read/write", "allow_execute",
a1f9bb6a 334 * "allow_read", "allow_write", "allow_unlink", "allow_rmdir",
2106ccd9
TH
335 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and
336 * "allow_unmount".
9590837b 337 */
7ef61233
TH
338struct tomoyo_path_acl {
339 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
9590837b 340 u16 perm;
7762fbff 341 struct tomoyo_name_union name;
9590837b
KT
342};
343
a1f9bb6a
TH
344/*
345 * tomoyo_path_number_acl is a structure which is used for holding an
346 * entry with one pathname and one number operation.
347 * It has following fields.
348 *
349 * (1) "head" which is a "struct tomoyo_acl_info".
350 * (2) "perm" which is a bitmask of permitted operations.
351 * (3) "name" is the pathname.
352 * (4) "number" is the numeric value.
353 *
354 * Directives held by this structure are "allow_create", "allow_mkdir",
355 * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown"
356 * and "allow_chgrp".
357 *
358 */
359struct tomoyo_path_number_acl {
360 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
361 u8 perm;
362 struct tomoyo_name_union name;
363 struct tomoyo_number_union number;
364};
365
366/*
367 * tomoyo_path_number3_acl is a structure which is used for holding an
368 * entry with one pathname and three numbers operation.
369 * It has following fields.
370 *
371 * (1) "head" which is a "struct tomoyo_acl_info".
372 * (2) "perm" which is a bitmask of permitted operations.
373 * (3) "mode" is the create mode.
374 * (4) "major" is the major number of device node.
375 * (5) "minor" is the minor number of device node.
376 *
377 * Directives held by this structure are "allow_mkchar", "allow_mkblock".
378 *
379 */
380struct tomoyo_path_number3_acl {
381 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER3_ACL */
382 u8 perm;
383 struct tomoyo_name_union name;
384 struct tomoyo_number_union mode;
385 struct tomoyo_number_union major;
386 struct tomoyo_number_union minor;
387};
388
c3fa109a 389/*
7ef61233 390 * tomoyo_path2_acl is a structure which is used for holding an
937bf613 391 * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
c3fa109a
TH
392 * It has following fields.
393 *
394 * (1) "head" which is a "struct tomoyo_acl_info".
395 * (2) "perm" which is a bitmask of permitted operations.
7762fbff
TH
396 * (3) "name1" is the source/old pathname.
397 * (4) "name2" is the destination/new pathname.
c3fa109a 398 *
937bf613
TH
399 * Directives held by this structure are "allow_rename", "allow_link" and
400 * "allow_pivot_root".
c3fa109a 401 */
7ef61233
TH
402struct tomoyo_path2_acl {
403 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
9590837b 404 u8 perm;
7762fbff
TH
405 struct tomoyo_name_union name1;
406 struct tomoyo_name_union name2;
9590837b
KT
407};
408
2106ccd9
TH
409/*
410 * tomoyo_mount_acl is a structure which is used for holding an
411 * entry for mount operation.
412 * It has following fields.
413 *
414 * (1) "head" which is a "struct tomoyo_acl_info".
415 * (2) "is_deleted" is boolean.
416 * (3) "dev_name" is the device name.
417 * (4) "dir_name" is the mount point.
418 * (5) "flags" is the mount flags.
419 *
420 * Directives held by this structure are "allow_rename", "allow_link" and
421 * "allow_pivot_root".
422 */
423struct tomoyo_mount_acl {
424 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
425 bool is_deleted;
426 struct tomoyo_name_union dev_name;
427 struct tomoyo_name_union dir_name;
428 struct tomoyo_name_union fs_type;
429 struct tomoyo_number_union flags;
430};
431
c3fa109a
TH
432/*
433 * tomoyo_io_buffer is a structure which is used for reading and modifying
434 * configuration via /sys/kernel/security/tomoyo/ interface.
435 * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as
436 * cursors.
437 *
438 * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of
439 * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info"
440 * entry has a list of "struct tomoyo_acl_info", we need two cursors when
441 * reading (one is for traversing tomoyo_domain_list and the other is for
442 * traversing "struct tomoyo_acl_info"->acl_info_list ).
443 *
444 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
445 * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the
446 * domain with the domainname specified by the rest of that line (NULL is set
447 * if seek failed).
448 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
449 * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that
450 * line (->write_var1 is set to NULL if a domain was deleted).
451 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
452 * neither "select " nor "delete ", an entry or a domain specified by that line
453 * is appended.
454 */
9590837b
KT
455struct tomoyo_io_buffer {
456 int (*read) (struct tomoyo_io_buffer *);
457 int (*write) (struct tomoyo_io_buffer *);
17fcfbd9 458 int (*poll) (struct file *file, poll_table *wait);
9590837b
KT
459 /* Exclusive lock for this structure. */
460 struct mutex io_sem;
fdb8ebb7
TH
461 /* Index returned by tomoyo_read_lock(). */
462 int reader_idx;
9590837b
KT
463 /* The position currently reading from. */
464 struct list_head *read_var1;
465 /* Extra variables for reading. */
466 struct list_head *read_var2;
467 /* The position currently writing to. */
468 struct tomoyo_domain_info *write_var1;
469 /* The step for reading. */
470 int read_step;
471 /* Buffer for reading. */
472 char *read_buf;
473 /* EOF flag for reading. */
474 bool read_eof;
475 /* Read domain ACL of specified PID? */
476 bool read_single_domain;
477 /* Extra variable for reading. */
478 u8 read_bit;
479 /* Bytes available for reading. */
480 int read_avail;
481 /* Size of read buffer. */
482 int readbuf_size;
483 /* Buffer for writing. */
484 char *write_buf;
485 /* Bytes available for writing. */
486 int write_avail;
487 /* Size of write buffer. */
488 int writebuf_size;
17fcfbd9
TH
489 /* Type of this interface. */
490 u8 type;
9590837b
KT
491};
492
76bb0895
TH
493/*
494 * tomoyo_globally_readable_file_entry is a structure which is used for holding
495 * "allow_read" entries.
496 * It has following fields.
497 *
498 * (1) "list" which is linked to tomoyo_globally_readable_list .
499 * (2) "filename" is a pathname which is allowed to open(O_RDONLY).
500 * (3) "is_deleted" is a bool which is true if marked as deleted, false
501 * otherwise.
502 */
503struct tomoyo_globally_readable_file_entry {
504 struct list_head list;
505 const struct tomoyo_path_info *filename;
506 bool is_deleted;
507};
508
509/*
510 * tomoyo_pattern_entry is a structure which is used for holding
511 * "tomoyo_pattern_list" entries.
512 * It has following fields.
513 *
514 * (1) "list" which is linked to tomoyo_pattern_list .
515 * (2) "pattern" is a pathname pattern which is used for converting pathnames
516 * to pathname patterns during learning mode.
517 * (3) "is_deleted" is a bool which is true if marked as deleted, false
518 * otherwise.
519 */
520struct tomoyo_pattern_entry {
521 struct list_head list;
522 const struct tomoyo_path_info *pattern;
523 bool is_deleted;
524};
525
526/*
527 * tomoyo_no_rewrite_entry is a structure which is used for holding
528 * "deny_rewrite" entries.
529 * It has following fields.
530 *
531 * (1) "list" which is linked to tomoyo_no_rewrite_list .
532 * (2) "pattern" is a pathname which is by default not permitted to modify
533 * already existing content.
534 * (3) "is_deleted" is a bool which is true if marked as deleted, false
535 * otherwise.
536 */
537struct tomoyo_no_rewrite_entry {
538 struct list_head list;
539 const struct tomoyo_path_info *pattern;
540 bool is_deleted;
541};
542
543/*
544 * tomoyo_domain_initializer_entry is a structure which is used for holding
545 * "initialize_domain" and "no_initialize_domain" entries.
546 * It has following fields.
547 *
548 * (1) "list" which is linked to tomoyo_domain_initializer_list .
549 * (2) "domainname" which is "a domainname" or "the last component of a
550 * domainname". This field is NULL if "from" clause is not specified.
551 * (3) "program" which is a program's pathname.
552 * (4) "is_deleted" is a bool which is true if marked as deleted, false
553 * otherwise.
554 * (5) "is_not" is a bool which is true if "no_initialize_domain", false
555 * otherwise.
556 * (6) "is_last_name" is a bool which is true if "domainname" is "the last
557 * component of a domainname", false otherwise.
558 */
559struct tomoyo_domain_initializer_entry {
560 struct list_head list;
561 const struct tomoyo_path_info *domainname; /* This may be NULL */
562 const struct tomoyo_path_info *program;
563 bool is_deleted;
564 bool is_not; /* True if this entry is "no_initialize_domain". */
565 /* True if the domainname is tomoyo_get_last_name(). */
566 bool is_last_name;
567};
568
569/*
570 * tomoyo_domain_keeper_entry is a structure which is used for holding
571 * "keep_domain" and "no_keep_domain" entries.
572 * It has following fields.
573 *
574 * (1) "list" which is linked to tomoyo_domain_keeper_list .
575 * (2) "domainname" which is "a domainname" or "the last component of a
576 * domainname".
577 * (3) "program" which is a program's pathname.
578 * This field is NULL if "from" clause is not specified.
579 * (4) "is_deleted" is a bool which is true if marked as deleted, false
580 * otherwise.
581 * (5) "is_not" is a bool which is true if "no_initialize_domain", false
582 * otherwise.
583 * (6) "is_last_name" is a bool which is true if "domainname" is "the last
584 * component of a domainname", false otherwise.
585 */
586struct tomoyo_domain_keeper_entry {
587 struct list_head list;
588 const struct tomoyo_path_info *domainname;
589 const struct tomoyo_path_info *program; /* This may be NULL */
590 bool is_deleted;
591 bool is_not; /* True if this entry is "no_keep_domain". */
592 /* True if the domainname is tomoyo_get_last_name(). */
593 bool is_last_name;
594};
595
1084307c
TH
596/*
597 * tomoyo_aggregator_entry is a structure which is used for holding
598 * "aggregator" entries.
599 * It has following fields.
600 *
601 * (1) "list" which is linked to tomoyo_aggregator_list .
602 * (2) "original_name" which is originally requested name.
603 * (3) "aggregated_name" which is name to rewrite.
604 * (4) "is_deleted" is a bool which is true if marked as deleted, false
605 * otherwise.
606 */
607struct tomoyo_aggregator_entry {
608 struct list_head list;
609 const struct tomoyo_path_info *original_name;
610 const struct tomoyo_path_info *aggregated_name;
611 bool is_deleted;
612};
613
76bb0895
TH
614/*
615 * tomoyo_alias_entry is a structure which is used for holding "alias" entries.
616 * It has following fields.
617 *
618 * (1) "list" which is linked to tomoyo_alias_list .
619 * (2) "original_name" which is a dereferenced pathname.
620 * (3) "aliased_name" which is a symlink's pathname.
621 * (4) "is_deleted" is a bool which is true if marked as deleted, false
622 * otherwise.
623 */
624struct tomoyo_alias_entry {
625 struct list_head list;
626 const struct tomoyo_path_info *original_name;
627 const struct tomoyo_path_info *aliased_name;
628 bool is_deleted;
629};
630
631/*
632 * tomoyo_policy_manager_entry is a structure which is used for holding list of
633 * domainnames or programs which are permitted to modify configuration via
634 * /sys/kernel/security/tomoyo/ interface.
635 * It has following fields.
636 *
637 * (1) "list" which is linked to tomoyo_policy_manager_list .
638 * (2) "manager" is a domainname or a program's pathname.
639 * (3) "is_domain" is a bool which is true if "manager" is a domainname, false
640 * otherwise.
641 * (4) "is_deleted" is a bool which is true if marked as deleted, false
642 * otherwise.
643 */
644struct tomoyo_policy_manager_entry {
645 struct list_head list;
646 /* A path to program or a domainname. */
647 const struct tomoyo_path_info *manager;
648 bool is_domain; /* True if manager is a domainname. */
649 bool is_deleted; /* True if this entry is deleted. */
650};
651
652/********** Function prototypes. **********/
653
17fcfbd9
TH
654extern asmlinkage long sys_getpid(void);
655extern asmlinkage long sys_getppid(void);
656
c3ef1500
TH
657/* Check whether the given string starts with the given keyword. */
658bool tomoyo_str_starts(char **src, const char *find);
659/* Get tomoyo_realpath() of current process. */
660const char *tomoyo_get_exe(void);
661/* Format string. */
662void tomoyo_normalize_line(unsigned char *buffer);
663/* Print warning or error message on console. */
664void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...)
665 __attribute__ ((format(printf, 2, 3)));
666/* Check all profiles currently assigned to domains are defined. */
667void tomoyo_check_profile(void);
668/* Open operation for /sys/kernel/security/tomoyo/ interface. */
669int tomoyo_open_control(const u8 type, struct file *file);
670/* Close /sys/kernel/security/tomoyo/ interface. */
671int tomoyo_close_control(struct file *file);
672/* Read operation for /sys/kernel/security/tomoyo/ interface. */
673int tomoyo_read_control(struct file *file, char __user *buffer,
674 const int buffer_len);
675/* Write operation for /sys/kernel/security/tomoyo/ interface. */
676int tomoyo_write_control(struct file *file, const char __user *buffer,
677 const int buffer_len);
678/* Check whether the domain has too many ACL entries to hold. */
679bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
680/* Print out of memory warning message. */
681void tomoyo_warn_oom(const char *function);
7762fbff
TH
682/* Check whether the given name matches the given name_union. */
683bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
684 const struct tomoyo_name_union *ptr);
2106ccd9
TH
685/* Check whether the given number matches the given number_union. */
686bool tomoyo_compare_number_union(const unsigned long value,
687 const struct tomoyo_number_union *ptr);
9590837b
KT
688/* Transactional sprintf() for policy dump. */
689bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
690 __attribute__ ((format(printf, 2, 3)));
691/* Check whether the domainname is correct. */
17080008 692bool tomoyo_is_correct_domain(const unsigned char *domainname);
9590837b 693/* Check whether the token is correct. */
3f629636
TH
694bool tomoyo_is_correct_path(const char *filename);
695bool tomoyo_is_correct_word(const char *string);
9590837b
KT
696/* Check whether the token can be a domainname. */
697bool tomoyo_is_domain_def(const unsigned char *buffer);
7762fbff
TH
698bool tomoyo_parse_name_union(const char *filename,
699 struct tomoyo_name_union *ptr);
700/* Check whether the given filename matches the given path_group. */
701bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
3f629636 702 const struct tomoyo_path_group *group);
4c3e9e2d
TH
703/* Check whether the given value matches the given number_group. */
704bool tomoyo_number_matches_group(const unsigned long min,
705 const unsigned long max,
706 const struct tomoyo_number_group *group);
9590837b
KT
707/* Check whether the given filename matches the given pattern. */
708bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
709 const struct tomoyo_path_info *pattern);
4c3e9e2d
TH
710
711bool tomoyo_print_number_union(struct tomoyo_io_buffer *head,
712 const struct tomoyo_number_union *ptr);
713bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
714
1084307c
TH
715/* Read "aggregator" entry in exception policy. */
716bool tomoyo_read_aggregator_policy(struct tomoyo_io_buffer *head);
9590837b
KT
717/* Read "alias" entry in exception policy. */
718bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head);
719/*
720 * Read "initialize_domain" and "no_initialize_domain" entry
721 * in exception policy.
722 */
723bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head);
724/* Read "keep_domain" and "no_keep_domain" entry in exception policy. */
725bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head);
726/* Read "file_pattern" entry in exception policy. */
727bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head);
7762fbff
TH
728/* Read "path_group" entry in exception policy. */
729bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head);
4c3e9e2d
TH
730/* Read "number_group" entry in exception policy. */
731bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head);
9590837b
KT
732/* Read "allow_read" entry in exception policy. */
733bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head);
734/* Read "deny_rewrite" entry in exception policy. */
735bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head);
7762fbff
TH
736/* Tokenize a line. */
737bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
9590837b
KT
738/* Write domain policy violation warning message to console? */
739bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
740/* Convert double path operation to operation name. */
7ef61233 741const char *tomoyo_path22keyword(const u8 operation);
a1f9bb6a
TH
742const char *tomoyo_path_number2keyword(const u8 operation);
743const char *tomoyo_path_number32keyword(const u8 operation);
9590837b
KT
744/* Get the last component of the given domainname. */
745const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
9590837b 746/* Convert single path operation to operation name. */
7ef61233 747const char *tomoyo_path2keyword(const u8 operation);
2106ccd9
TH
748/* Fill "struct tomoyo_request_info". */
749int tomoyo_init_request_info(struct tomoyo_request_info *r,
750 struct tomoyo_domain_info *domain);
751/* Check permission for mount operation. */
752int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,
753 unsigned long flags, void *data_page);
1084307c
TH
754/* Create "aggregator" entry in exception policy. */
755int tomoyo_write_aggregator_policy(char *data, const bool is_delete);
9590837b
KT
756/* Create "alias" entry in exception policy. */
757int tomoyo_write_alias_policy(char *data, const bool is_delete);
758/*
759 * Create "initialize_domain" and "no_initialize_domain" entry
760 * in exception policy.
761 */
762int tomoyo_write_domain_initializer_policy(char *data, const bool is_not,
763 const bool is_delete);
764/* Create "keep_domain" and "no_keep_domain" entry in exception policy. */
765int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
766 const bool is_delete);
767/*
768 * Create "allow_read/write", "allow_execute", "allow_read", "allow_write",
769 * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",
770 * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar",
771 * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and
772 * "allow_link" entry in domain policy.
773 */
774int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
775 const bool is_delete);
776/* Create "allow_read" entry in exception policy. */
777int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
2106ccd9
TH
778/* Create "allow_mount" entry in domain policy. */
779int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain,
780 const bool is_delete);
9590837b
KT
781/* Create "deny_rewrite" entry in exception policy. */
782int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
783/* Create "file_pattern" entry in exception policy. */
784int tomoyo_write_pattern_policy(char *data, const bool is_delete);
7762fbff
TH
785/* Create "path_group" entry in exception policy. */
786int tomoyo_write_path_group_policy(char *data, const bool is_delete);
17fcfbd9
TH
787int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
788 __attribute__ ((format(printf, 2, 3)));
4c3e9e2d
TH
789/* Create "number_group" entry in exception policy. */
790int tomoyo_write_number_group_policy(char *data, const bool is_delete);
9590837b
KT
791/* Find a domain by the given name. */
792struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
793/* Find or create a domain by the given name. */
794struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
795 domainname,
796 const u8 profile);
7762fbff
TH
797/* Allocate memory for "struct tomoyo_path_group". */
798struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
4c3e9e2d 799struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name);
7762fbff 800
9590837b
KT
801/* Check mode for specified functionality. */
802unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
803 const u8 index);
9590837b
KT
804/* Fill in "struct tomoyo_path_info" members. */
805void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
806/* Run policy loader when /sbin/init starts. */
807void tomoyo_load_policy(const char *filename);
9590837b 808
4c3e9e2d
TH
809void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
810
76bb0895 811/* Convert binary string to ascii string. */
c8c57e84 812char *tomoyo_encode(const char *str);
76bb0895
TH
813
814/*
815 * Returns realpath(3) of the given pathname but ignores chroot'ed root.
816 * These functions use kzalloc(), so the caller must call kfree()
817 * if these functions didn't return NULL.
818 */
819char *tomoyo_realpath(const char *pathname);
820/*
821 * Same with tomoyo_realpath() except that it doesn't follow the final symlink.
822 */
823char *tomoyo_realpath_nofollow(const char *pathname);
824/* Same with tomoyo_realpath() except that the pathname is already solved. */
825char *tomoyo_realpath_from_path(struct path *path);
17fcfbd9
TH
826/* Get patterned pathname. */
827const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename);
76bb0895
TH
828
829/* Check memory quota. */
830bool tomoyo_memory_ok(void *ptr);
9e4b50e9 831void *tomoyo_commit_ok(void *data, const unsigned int size);
76bb0895
TH
832
833/*
834 * Keep the given name on the RAM.
835 * The RAM is shared, so NEVER try to modify or kfree() the returned name.
836 */
837const struct tomoyo_path_info *tomoyo_get_name(const char *name);
838
839/* Check for memory usage. */
840int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
841
842/* Set memory quota. */
843int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
844
c3ef1500
TH
845/* Initialize mm related code. */
846void __init tomoyo_mm_init(void);
76bb0895
TH
847int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
848 const struct tomoyo_path_info *filename);
849int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
850 struct path *path, const int flag);
a1f9bb6a
TH
851int tomoyo_path_number_perm(const u8 operation, struct path *path,
852 unsigned long number);
853int tomoyo_path_number3_perm(const u8 operation, struct path *path,
854 const unsigned int mode, unsigned int dev);
97d6931e
TH
855int tomoyo_path_perm(const u8 operation, struct path *path);
856int tomoyo_path2_perm(const u8 operation, struct path *path1,
857 struct path *path2);
76bb0895
TH
858int tomoyo_find_next_domain(struct linux_binprm *bprm);
859
a1f9bb6a
TH
860void tomoyo_print_ulong(char *buffer, const int buffer_len,
861 const unsigned long value, const u8 type);
862
7762fbff
TH
863/* Drop refcount on tomoyo_name_union. */
864void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
865
847b173e
TH
866/* Run garbage collector. */
867void tomoyo_run_gc(void);
868
869void tomoyo_memory_free(void *ptr);
870
76bb0895
TH
871/********** External variable definitions. **********/
872
873/* Lock for GC. */
874extern struct srcu_struct tomoyo_ss;
875
876/* The list for "struct tomoyo_domain_info". */
877extern struct list_head tomoyo_domain_list;
878
7762fbff 879extern struct list_head tomoyo_path_group_list;
4c3e9e2d 880extern struct list_head tomoyo_number_group_list;
847b173e
TH
881extern struct list_head tomoyo_domain_initializer_list;
882extern struct list_head tomoyo_domain_keeper_list;
1084307c 883extern struct list_head tomoyo_aggregator_list;
847b173e
TH
884extern struct list_head tomoyo_alias_list;
885extern struct list_head tomoyo_globally_readable_list;
886extern struct list_head tomoyo_pattern_list;
887extern struct list_head tomoyo_no_rewrite_list;
888extern struct list_head tomoyo_policy_manager_list;
889extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
847b173e 890
76bb0895
TH
891/* Lock for protecting policy. */
892extern struct mutex tomoyo_policy_lock;
893
894/* Has /sbin/init started? */
895extern bool tomoyo_policy_loaded;
896
897/* The kernel's domain. */
898extern struct tomoyo_domain_info tomoyo_kernel_domain;
899
17fcfbd9
TH
900extern unsigned int tomoyo_quota_for_query;
901extern unsigned int tomoyo_query_memory_size;
902
76bb0895
TH
903/********** Inlined functions. **********/
904
905static inline int tomoyo_read_lock(void)
906{
907 return srcu_read_lock(&tomoyo_ss);
908}
909
910static inline void tomoyo_read_unlock(int idx)
911{
912 srcu_read_unlock(&tomoyo_ss, idx);
913}
914
9590837b
KT
915/* strcmp() for "struct tomoyo_path_info" structure. */
916static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
917 const struct tomoyo_path_info *b)
918{
919 return a->hash != b->hash || strcmp(a->name, b->name);
920}
921
9590837b
KT
922/**
923 * tomoyo_is_valid - Check whether the character is a valid char.
924 *
925 * @c: The character to check.
926 *
927 * Returns true if @c is a valid character, false otherwise.
928 */
929static inline bool tomoyo_is_valid(const unsigned char c)
930{
931 return c > ' ' && c < 127;
932}
933
934/**
935 * tomoyo_is_invalid - Check whether the character is an invalid char.
936 *
937 * @c: The character to check.
938 *
939 * Returns true if @c is an invalid character, false otherwise.
940 */
941static inline bool tomoyo_is_invalid(const unsigned char c)
942{
943 return c && (c <= ' ' || c >= 127);
944}
945
76bb0895
TH
946static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
947{
948 if (name) {
949 struct tomoyo_name_entry *ptr =
950 container_of(name, struct tomoyo_name_entry, entry);
951 atomic_dec(&ptr->users);
952 }
953}
9590837b 954
7762fbff
TH
955static inline void tomoyo_put_path_group(struct tomoyo_path_group *group)
956{
957 if (group)
958 atomic_dec(&group->users);
959}
960
4c3e9e2d
TH
961static inline void tomoyo_put_number_group(struct tomoyo_number_group *group)
962{
963 if (group)
964 atomic_dec(&group->users);
965}
966
76bb0895
TH
967static inline struct tomoyo_domain_info *tomoyo_domain(void)
968{
969 return current_cred()->security;
970}
9590837b 971
76bb0895
TH
972static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
973 *task)
974{
975 return task_cred_xxx(task, security);
976}
9590837b 977
7762fbff
TH
978static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1,
979 const struct tomoyo_acl_info *p2)
980{
981 return p1->type == p2->type;
982}
983
984static inline bool tomoyo_is_same_name_union
985(const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2)
986{
987 return p1->filename == p2->filename && p1->group == p2->group &&
988 p1->is_group == p2->is_group;
989}
990
4c3e9e2d
TH
991static inline bool tomoyo_is_same_number_union
992(const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2)
993{
994 return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1]
995 && p1->group == p2->group && p1->min_type == p2->min_type &&
996 p1->max_type == p2->max_type && p1->is_group == p2->is_group;
997}
998
7762fbff
TH
999static inline bool tomoyo_is_same_path_acl(const struct tomoyo_path_acl *p1,
1000 const struct tomoyo_path_acl *p2)
1001{
1002 return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
1003 tomoyo_is_same_name_union(&p1->name, &p2->name);
1004}
1005
a1f9bb6a
TH
1006static inline bool tomoyo_is_same_path_number3_acl
1007(const struct tomoyo_path_number3_acl *p1,
1008 const struct tomoyo_path_number3_acl *p2)
1009{
1010 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
1011 && tomoyo_is_same_name_union(&p1->name, &p2->name)
1012 && tomoyo_is_same_number_union(&p1->mode, &p2->mode)
1013 && tomoyo_is_same_number_union(&p1->major, &p2->major)
1014 && tomoyo_is_same_number_union(&p1->minor, &p2->minor);
1015}
1016
1017
7762fbff
TH
1018static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1,
1019 const struct tomoyo_path2_acl *p2)
1020{
1021 return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
1022 tomoyo_is_same_name_union(&p1->name1, &p2->name1) &&
1023 tomoyo_is_same_name_union(&p1->name2, &p2->name2);
1024}
1025
a1f9bb6a
TH
1026static inline bool tomoyo_is_same_path_number_acl
1027(const struct tomoyo_path_number_acl *p1,
1028 const struct tomoyo_path_number_acl *p2)
1029{
1030 return tomoyo_is_same_acl_head(&p1->head, &p2->head)
1031 && tomoyo_is_same_name_union(&p1->name, &p2->name)
1032 && tomoyo_is_same_number_union(&p1->number, &p2->number);
1033}
1034
2106ccd9
TH
1035static inline bool tomoyo_is_same_mount_acl(const struct tomoyo_mount_acl *p1,
1036 const struct tomoyo_mount_acl *p2)
1037{
1038 return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
1039 tomoyo_is_same_name_union(&p1->dev_name, &p2->dev_name) &&
1040 tomoyo_is_same_name_union(&p1->dir_name, &p2->dir_name) &&
1041 tomoyo_is_same_name_union(&p1->fs_type, &p2->fs_type) &&
1042 tomoyo_is_same_number_union(&p1->flags, &p2->flags);
1043}
1044
9e4b50e9
TH
1045static inline bool tomoyo_is_same_domain_initializer_entry
1046(const struct tomoyo_domain_initializer_entry *p1,
1047 const struct tomoyo_domain_initializer_entry *p2)
1048{
1049 return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
1050 && p1->domainname == p2->domainname
1051 && p1->program == p2->program;
1052}
1053
1054static inline bool tomoyo_is_same_domain_keeper_entry
1055(const struct tomoyo_domain_keeper_entry *p1,
1056 const struct tomoyo_domain_keeper_entry *p2)
1057{
1058 return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
1059 && p1->domainname == p2->domainname
1060 && p1->program == p2->program;
1061}
1062
1084307c
TH
1063static inline bool tomoyo_is_same_aggregator_entry
1064(const struct tomoyo_aggregator_entry *p1,
1065 const struct tomoyo_aggregator_entry *p2)
1066{
1067 return p1->original_name == p2->original_name &&
1068 p1->aggregated_name == p2->aggregated_name;
1069}
1070
9e4b50e9
TH
1071static inline bool tomoyo_is_same_alias_entry
1072(const struct tomoyo_alias_entry *p1, const struct tomoyo_alias_entry *p2)
1073{
1074 return p1->original_name == p2->original_name &&
1075 p1->aliased_name == p2->aliased_name;
1076}
1077
9590837b
KT
1078/**
1079 * list_for_each_cookie - iterate over a list with cookie.
1080 * @pos: the &struct list_head to use as a loop cursor.
1081 * @cookie: the &struct list_head to use as a cookie.
1082 * @head: the head for your list.
1083 *
fdb8ebb7 1084 * Same with list_for_each_rcu() except that this primitive uses @cookie
9590837b
KT
1085 * so that we can continue iteration.
1086 * @cookie must be NULL when iteration starts, and @cookie will become
1087 * NULL when iteration finishes.
1088 */
fdb8ebb7
TH
1089#define list_for_each_cookie(pos, cookie, head) \
1090 for (({ if (!cookie) \
1091 cookie = head; }), \
1092 pos = rcu_dereference((cookie)->next); \
1093 prefetch(pos->next), pos != (head) || ((cookie) = NULL); \
1094 (cookie) = pos, pos = rcu_dereference(pos->next))
1095
9590837b 1096#endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */