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