common.h 37 KB

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