]> git.karo-electronics.de Git - mv-sheeva.git/blob - security/tomoyo/common.h
c777c594a00b1b9d6e17a3b5ffd9704b896e4a85
[mv-sheeva.git] / security / tomoyo / common.h
1 /*
2  * security/tomoyo/common.h
3  *
4  * Header file for TOMOYO.
5  *
6  * Copyright (C) 2005-2010  NTT DATA CORPORATION
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>
22 #include <linux/cred.h>
23 #include <linux/poll.h>
24 struct 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
36 #define TOMOYO_EXEC_TMPSIZE     4096
37
38 /* Profile number is an integer between 0 and 255. */
39 #define TOMOYO_MAX_PROFILES 256
40
41 enum tomoyo_mode_index {
42         TOMOYO_CONFIG_DISABLED,
43         TOMOYO_CONFIG_LEARNING,
44         TOMOYO_CONFIG_PERMISSIVE,
45         TOMOYO_CONFIG_ENFORCING,
46         TOMOYO_CONFIG_USE_DEFAULT = 255
47 };
48
49 /* Keywords for ACLs. */
50 #define TOMOYO_KEYWORD_AGGREGATOR                "aggregator "
51 #define TOMOYO_KEYWORD_ALIAS                     "alias "
52 #define TOMOYO_KEYWORD_ALLOW_MOUNT               "allow_mount "
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 "
61 #define TOMOYO_KEYWORD_PATH_GROUP                "path_group "
62 #define TOMOYO_KEYWORD_NUMBER_GROUP              "number_group "
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"
66 #define TOMOYO_KEYWORD_QUOTA_EXCEEDED            "quota_exceeded"
67 #define TOMOYO_KEYWORD_TRANSITION_FAILED         "transition_failed"
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
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
78 /* Index numbers for Access Controls. */
79 enum tomoyo_acl_entry_type_index {
80         TOMOYO_TYPE_PATH_ACL,
81         TOMOYO_TYPE_PATH2_ACL,
82         TOMOYO_TYPE_PATH_NUMBER_ACL,
83         TOMOYO_TYPE_PATH_NUMBER3_ACL,
84         TOMOYO_TYPE_MOUNT_ACL,
85 };
86
87 /* Index numbers for File Controls. */
88
89 /*
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.
98  */
99
100 enum tomoyo_path_acl_index {
101         TOMOYO_TYPE_READ_WRITE,
102         TOMOYO_TYPE_EXECUTE,
103         TOMOYO_TYPE_READ,
104         TOMOYO_TYPE_WRITE,
105         TOMOYO_TYPE_UNLINK,
106         TOMOYO_TYPE_RMDIR,
107         TOMOYO_TYPE_TRUNCATE,
108         TOMOYO_TYPE_SYMLINK,
109         TOMOYO_TYPE_REWRITE,
110         TOMOYO_TYPE_CHROOT,
111         TOMOYO_TYPE_UMOUNT,
112         TOMOYO_MAX_PATH_OPERATION
113 };
114
115 enum tomoyo_path_number3_acl_index {
116         TOMOYO_TYPE_MKBLOCK,
117         TOMOYO_TYPE_MKCHAR,
118         TOMOYO_MAX_PATH_NUMBER3_OPERATION
119 };
120
121 enum tomoyo_path2_acl_index {
122         TOMOYO_TYPE_LINK,
123         TOMOYO_TYPE_RENAME,
124         TOMOYO_TYPE_PIVOT_ROOT,
125         TOMOYO_MAX_PATH2_OPERATION
126 };
127
128 enum 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
140 enum 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,
149         TOMOYO_QUERY,
150         TOMOYO_MANAGER
151 };
152
153 enum 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
180 enum tomoyo_mac_category_index {
181         TOMOYO_MAC_CATEGORY_FILE,
182         TOMOYO_MAX_MAC_CATEGORY_INDEX
183 };
184
185 #define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */
186
187 /********** Structure definitions. **********/
188
189 /*
190  * tomoyo_request_info is a structure which is used for holding
191  *
192  * (1) Domain information of current process.
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.
196  */
197 struct tomoyo_request_info {
198         struct tomoyo_domain_info *domain;
199         u8 retry;
200         u8 profile;
201         u8 mode; /* One of tomoyo_mode_index . */
202         u8 type;
203 };
204
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.
224  */
225 struct tomoyo_path_info {
226         const char *name;
227         u32 hash;          /* = full_name_hash(name, strlen(name)) */
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) */
231 };
232
233 /*
234  * tomoyo_name_entry is a structure which is used for linking
235  * "struct tomoyo_path_info" into tomoyo_name_list .
236  */
237 struct tomoyo_name_entry {
238         struct list_head list;
239         atomic_t users;
240         struct tomoyo_path_info entry;
241 };
242
243 struct tomoyo_name_union {
244         const struct tomoyo_path_info *filename;
245         struct tomoyo_path_group *group;
246         u8 is_group;
247 };
248
249 struct 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
257 /* Structure for "path_group" directive. */
258 struct 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
265 /* Structure for "number_group" directive. */
266 struct 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
273 /* Structure for "path_group" directive. */
274 struct tomoyo_path_group_member {
275         struct list_head list;
276         bool is_deleted;
277         const struct tomoyo_path_info *member_name;
278 };
279
280 /* Structure for "number_group" directive. */
281 struct tomoyo_number_group_member {
282         struct list_head list;
283         bool is_deleted;
284         struct tomoyo_number_union number;
285 };
286
287 /*
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"
292  *  (2) "type" which tells type of the entry (either
293  *      "struct tomoyo_path_acl" or "struct tomoyo_path2_acl").
294  *
295  * Packing "struct tomoyo_acl_info" allows
296  * "struct tomoyo_path_acl" to embed "u8" + "u16" and
297  * "struct tomoyo_path2_acl" to embed "u8"
298  * without enlarging their structure size.
299  */
300 struct tomoyo_acl_info {
301         struct list_head list;
302         u8 type;
303 } __packed;
304
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.
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.
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.
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  */
337 struct 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. */
343         bool is_deleted;   /* Delete flag.           */
344         bool quota_warned; /* Quota warnning flag.   */
345         bool ignore_global_allow_read; /* Ignore "allow_read" flag. */
346         bool transition_failed; /* Domain transition failed flag. */
347         atomic_t users; /* Number of referring credentials. */
348 };
349
350 /*
351  * tomoyo_path_acl is a structure which is used for holding an
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.
357  *  (3) "name" is the pathname.
358  *
359  * Directives held by this structure are "allow_read/write", "allow_execute",
360  * "allow_read", "allow_write", "allow_unlink", "allow_rmdir",
361  * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and
362  * "allow_unmount".
363  */
364 struct tomoyo_path_acl {
365         struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
366         u16 perm;
367         struct tomoyo_name_union name;
368 };
369
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  */
385 struct 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  */
406 struct 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
415 /*
416  * tomoyo_path2_acl is a structure which is used for holding an
417  * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
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.
422  *  (3) "name1" is the source/old pathname.
423  *  (4) "name2" is the destination/new pathname.
424  *
425  * Directives held by this structure are "allow_rename", "allow_link" and
426  * "allow_pivot_root".
427  */
428 struct tomoyo_path2_acl {
429         struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
430         u8 perm;
431         struct tomoyo_name_union name1;
432         struct tomoyo_name_union name2;
433 };
434
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  */
449 struct 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
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  */
481 struct tomoyo_io_buffer {
482         int (*read) (struct tomoyo_io_buffer *);
483         int (*write) (struct tomoyo_io_buffer *);
484         int (*poll) (struct file *file, poll_table *wait);
485         /* Exclusive lock for this structure.   */
486         struct mutex io_sem;
487         /* Index returned by tomoyo_read_lock(). */
488         int reader_idx;
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;
515         /* Type of this interface.              */
516         u8 type;
517 };
518
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  */
529 struct 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  */
546 struct 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  */
563 struct 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  */
585 struct 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  */
612 struct 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
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  */
633 struct 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
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  */
650 struct 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  */
670 struct 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
678 struct tomoyo_preference {
679         unsigned int learning_max_entry;
680         bool enforcing_verbose;
681         bool learning_verbose;
682         bool permissive_verbose;
683 };
684
685 struct 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
695 /********** Function prototypes. **********/
696
697 extern asmlinkage long sys_getpid(void);
698 extern asmlinkage long sys_getppid(void);
699
700 /* Check whether the given string starts with the given keyword. */
701 bool tomoyo_str_starts(char **src, const char *find);
702 /* Get tomoyo_realpath() of current process. */
703 const char *tomoyo_get_exe(void);
704 /* Format string. */
705 void tomoyo_normalize_line(unsigned char *buffer);
706 /* Print warning or error message on console. */
707 void 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. */
710 void tomoyo_check_profile(void);
711 /* Open operation for /sys/kernel/security/tomoyo/ interface. */
712 int tomoyo_open_control(const u8 type, struct file *file);
713 /* Close /sys/kernel/security/tomoyo/ interface. */
714 int tomoyo_close_control(struct file *file);
715 /* Read operation for /sys/kernel/security/tomoyo/ interface. */
716 int tomoyo_read_control(struct file *file, char __user *buffer,
717                         const int buffer_len);
718 /* Write operation for /sys/kernel/security/tomoyo/ interface. */
719 int 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. */
722 bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
723 /* Print out of memory warning message. */
724 void tomoyo_warn_oom(const char *function);
725 /* Check whether the given name matches the given name_union. */
726 bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
727                                const struct tomoyo_name_union *ptr);
728 /* Check whether the given number matches the given number_union. */
729 bool tomoyo_compare_number_union(const unsigned long value,
730                                  const struct tomoyo_number_union *ptr);
731 int tomoyo_get_mode(const u8 profile, const u8 index);
732 /* Transactional sprintf() for policy dump. */
733 bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
734         __attribute__ ((format(printf, 2, 3)));
735 /* Check whether the domainname is correct. */
736 bool tomoyo_is_correct_domain(const unsigned char *domainname);
737 /* Check whether the token is correct. */
738 bool tomoyo_is_correct_path(const char *filename);
739 bool tomoyo_is_correct_word(const char *string);
740 /* Check whether the token can be a domainname. */
741 bool tomoyo_is_domain_def(const unsigned char *buffer);
742 bool tomoyo_parse_name_union(const char *filename,
743                              struct tomoyo_name_union *ptr);
744 /* Check whether the given filename matches the given path_group. */
745 bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
746                                const struct tomoyo_path_group *group);
747 /* Check whether the given value matches the given number_group. */
748 bool tomoyo_number_matches_group(const unsigned long min,
749                                  const unsigned long max,
750                                  const struct tomoyo_number_group *group);
751 /* Check whether the given filename matches the given pattern. */
752 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
753                                  const struct tomoyo_path_info *pattern);
754
755 bool tomoyo_print_number_union(struct tomoyo_io_buffer *head,
756                                const struct tomoyo_number_union *ptr);
757 bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
758
759 /* Read "aggregator" entry in exception policy. */
760 bool tomoyo_read_aggregator_policy(struct tomoyo_io_buffer *head);
761 /* Read "alias" entry in exception policy. */
762 bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head);
763 /*
764  * Read "initialize_domain" and "no_initialize_domain" entry
765  * in exception policy.
766  */
767 bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head);
768 /* Read "keep_domain" and "no_keep_domain" entry in exception policy. */
769 bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head);
770 /* Read "file_pattern" entry in exception policy. */
771 bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head);
772 /* Read "path_group" entry in exception policy. */
773 bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head);
774 /* Read "number_group" entry in exception policy. */
775 bool tomoyo_read_number_group_policy(struct tomoyo_io_buffer *head);
776 /* Read "allow_read" entry in exception policy. */
777 bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head);
778 /* Read "deny_rewrite" entry in exception policy. */
779 bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head);
780 /* Tokenize a line. */
781 bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
782 /* Write domain policy violation warning message to console? */
783 bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
784 /* Convert double path operation to operation name. */
785 const char *tomoyo_path22keyword(const u8 operation);
786 const char *tomoyo_path_number2keyword(const u8 operation);
787 const char *tomoyo_path_number32keyword(const u8 operation);
788 /* Get the last component of the given domainname. */
789 const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
790 /* Convert single path operation to operation name. */
791 const char *tomoyo_path2keyword(const u8 operation);
792 /* Fill "struct tomoyo_request_info". */
793 int tomoyo_init_request_info(struct tomoyo_request_info *r,
794                              struct tomoyo_domain_info *domain,
795                              const u8 index);
796 /* Check permission for mount operation. */
797 int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,
798                             unsigned long flags, void *data_page);
799 /* Create "aggregator" entry in exception policy. */
800 int tomoyo_write_aggregator_policy(char *data, const bool is_delete);
801 /* Create "alias" entry in exception policy. */
802 int 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  */
807 int 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. */
810 int 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  */
819 int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
820                              const bool is_delete);
821 /* Create "allow_read" entry in exception policy. */
822 int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
823 /* Create "allow_mount" entry in domain policy. */
824 int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain,
825                               const bool is_delete);
826 /* Create "deny_rewrite" entry in exception policy. */
827 int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
828 /* Create "file_pattern" entry in exception policy. */
829 int tomoyo_write_pattern_policy(char *data, const bool is_delete);
830 /* Create "path_group" entry in exception policy. */
831 int tomoyo_write_path_group_policy(char *data, const bool is_delete);
832 int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
833      __attribute__ ((format(printf, 2, 3)));
834 /* Create "number_group" entry in exception policy. */
835 int tomoyo_write_number_group_policy(char *data, const bool is_delete);
836 /* Find a domain by the given name. */
837 struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
838 /* Find or create a domain by the given name. */
839 struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
840                                                             domainname,
841                                                             const u8 profile);
842 struct tomoyo_profile *tomoyo_profile(const u8 profile);
843 /* Allocate memory for "struct tomoyo_path_group". */
844 struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
845 struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name);
846
847 /* Check mode for specified functionality. */
848 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
849                                 const u8 index);
850 /* Fill in "struct tomoyo_path_info" members. */
851 void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
852 /* Run policy loader when /sbin/init starts. */
853 void tomoyo_load_policy(const char *filename);
854
855 void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
856
857 /* Convert binary string to ascii string. */
858 char *tomoyo_encode(const char *str);
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  */
865 char *tomoyo_realpath(const char *pathname);
866 /*
867  * Same with tomoyo_realpath() except that it doesn't follow the final symlink.
868  */
869 char *tomoyo_realpath_nofollow(const char *pathname);
870 /* Same with tomoyo_realpath() except that the pathname is already solved. */
871 char *tomoyo_realpath_from_path(struct path *path);
872 /* Get patterned pathname. */
873 const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename);
874
875 /* Check memory quota. */
876 bool tomoyo_memory_ok(void *ptr);
877 void *tomoyo_commit_ok(void *data, const unsigned int size);
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  */
883 const struct tomoyo_path_info *tomoyo_get_name(const char *name);
884
885 /* Check for memory usage. */
886 int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
887
888 /* Set memory quota. */
889 int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
890
891 /* Initialize mm related code. */
892 void __init tomoyo_mm_init(void);
893 int tomoyo_check_exec_perm(struct tomoyo_request_info *r,
894                            const struct tomoyo_path_info *filename);
895 int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
896                                  struct path *path, const int flag);
897 int tomoyo_path_number_perm(const u8 operation, struct path *path,
898                             unsigned long number);
899 int tomoyo_path_number3_perm(const u8 operation, struct path *path,
900                              const unsigned int mode, unsigned int dev);
901 int tomoyo_path_perm(const u8 operation, struct path *path);
902 int tomoyo_path2_perm(const u8 operation, struct path *path1,
903                       struct path *path2);
904 int tomoyo_find_next_domain(struct linux_binprm *bprm);
905
906 void tomoyo_print_ulong(char *buffer, const int buffer_len,
907                         const unsigned long value, const u8 type);
908
909 /* Drop refcount on tomoyo_name_union. */
910 void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
911
912 /* Run garbage collector. */
913 void tomoyo_run_gc(void);
914
915 void tomoyo_memory_free(void *ptr);
916
917 /********** External variable definitions. **********/
918
919 /* Lock for GC. */
920 extern struct srcu_struct tomoyo_ss;
921
922 /* The list for "struct tomoyo_domain_info". */
923 extern struct list_head tomoyo_domain_list;
924
925 extern struct list_head tomoyo_path_group_list;
926 extern struct list_head tomoyo_number_group_list;
927 extern struct list_head tomoyo_domain_initializer_list;
928 extern struct list_head tomoyo_domain_keeper_list;
929 extern struct list_head tomoyo_aggregator_list;
930 extern struct list_head tomoyo_alias_list;
931 extern struct list_head tomoyo_globally_readable_list;
932 extern struct list_head tomoyo_pattern_list;
933 extern struct list_head tomoyo_no_rewrite_list;
934 extern struct list_head tomoyo_policy_manager_list;
935 extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
936
937 /* Lock for protecting policy. */
938 extern struct mutex tomoyo_policy_lock;
939
940 /* Has /sbin/init started? */
941 extern bool tomoyo_policy_loaded;
942
943 /* The kernel's domain. */
944 extern struct tomoyo_domain_info tomoyo_kernel_domain;
945
946 extern unsigned int tomoyo_quota_for_query;
947 extern unsigned int tomoyo_query_memory_size;
948
949 /********** Inlined functions. **********/
950
951 static inline int tomoyo_read_lock(void)
952 {
953         return srcu_read_lock(&tomoyo_ss);
954 }
955
956 static inline void tomoyo_read_unlock(int idx)
957 {
958         srcu_read_unlock(&tomoyo_ss, idx);
959 }
960
961 /* strcmp() for "struct tomoyo_path_info" structure. */
962 static 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
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  */
975 static 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  */
987 static inline bool tomoyo_is_invalid(const unsigned char c)
988 {
989         return c && (c <= ' ' || c >= 127);
990 }
991
992 static 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 }
1000
1001 static inline void tomoyo_put_path_group(struct tomoyo_path_group *group)
1002 {
1003         if (group)
1004                 atomic_dec(&group->users);
1005 }
1006
1007 static inline void tomoyo_put_number_group(struct tomoyo_number_group *group)
1008 {
1009         if (group)
1010                 atomic_dec(&group->users);
1011 }
1012
1013 static inline struct tomoyo_domain_info *tomoyo_domain(void)
1014 {
1015         return current_cred()->security;
1016 }
1017
1018 static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
1019                                                             *task)
1020 {
1021         return task_cred_xxx(task, security);
1022 }
1023
1024 static 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
1030 static 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
1037 static 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
1045 static 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
1052 static 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
1064 static 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
1072 static 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
1081 static 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
1091 static 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
1100 static 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
1109 static 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
1117 static 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
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  *
1130  * Same with list_for_each_rcu() except that this primitive uses @cookie
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  */
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
1142 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */