common.h 38 KB

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