common.h 38 KB

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