common.h 39 KB

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