common.h 38 KB

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