common.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  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. /* Get the last component of the given domainname. */
  753. const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
  754. /* Fill "struct tomoyo_request_info". */
  755. int tomoyo_init_request_info(struct tomoyo_request_info *r,
  756. struct tomoyo_domain_info *domain,
  757. const u8 index);
  758. /* Check permission for mount operation. */
  759. int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,
  760. unsigned long flags, void *data_page);
  761. /* Create "aggregator" entry in exception policy. */
  762. int tomoyo_write_aggregator_policy(char *data, const bool is_delete);
  763. /* Create "alias" entry in exception policy. */
  764. int tomoyo_write_alias_policy(char *data, const bool is_delete);
  765. /*
  766. * Create "initialize_domain" and "no_initialize_domain" entry
  767. * in exception policy.
  768. */
  769. int tomoyo_write_domain_initializer_policy(char *data, const bool is_not,
  770. const bool is_delete);
  771. /* Create "keep_domain" and "no_keep_domain" entry in exception policy. */
  772. int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
  773. const bool is_delete);
  774. /*
  775. * Create "allow_read/write", "allow_execute", "allow_read", "allow_write",
  776. * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",
  777. * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar",
  778. * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and
  779. * "allow_link" entry in domain policy.
  780. */
  781. int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
  782. const bool is_delete);
  783. /* Create "allow_read" entry in exception policy. */
  784. int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
  785. /* Create "allow_mount" entry in domain policy. */
  786. int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain,
  787. const bool is_delete);
  788. /* Create "deny_rewrite" entry in exception policy. */
  789. int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
  790. /* Create "file_pattern" entry in exception policy. */
  791. int tomoyo_write_pattern_policy(char *data, const bool is_delete);
  792. /* Create "path_group" entry in exception policy. */
  793. int tomoyo_write_path_group_policy(char *data, const bool is_delete);
  794. int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
  795. __attribute__ ((format(printf, 2, 3)));
  796. /* Create "number_group" entry in exception policy. */
  797. int tomoyo_write_number_group_policy(char *data, const bool is_delete);
  798. /* Find a domain by the given name. */
  799. struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
  800. /* Find or create a domain by the given name. */
  801. struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
  802. domainname,
  803. const u8 profile);
  804. struct tomoyo_profile *tomoyo_profile(const u8 profile);
  805. /* Allocate memory for "struct tomoyo_path_group". */
  806. struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
  807. struct tomoyo_number_group *tomoyo_get_number_group(const char *group_name);
  808. /* Check mode for specified functionality. */
  809. unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
  810. const u8 index);
  811. /* Fill in "struct tomoyo_path_info" members. */
  812. void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
  813. /* Run policy loader when /sbin/init starts. */
  814. void tomoyo_load_policy(const char *filename);
  815. void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
  816. /* Convert binary string to ascii string. */
  817. char *tomoyo_encode(const char *str);
  818. /*
  819. * Returns realpath(3) of the given pathname but ignores chroot'ed root.
  820. * These functions use kzalloc(), so the caller must call kfree()
  821. * if these functions didn't return NULL.
  822. */
  823. char *tomoyo_realpath(const char *pathname);
  824. /*
  825. * Same with tomoyo_realpath() except that it doesn't follow the final symlink.
  826. */
  827. char *tomoyo_realpath_nofollow(const char *pathname);
  828. /* Same with tomoyo_realpath() except that the pathname is already solved. */
  829. char *tomoyo_realpath_from_path(struct path *path);
  830. /* Get patterned pathname. */
  831. const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename);
  832. /* Check memory quota. */
  833. bool tomoyo_memory_ok(void *ptr);
  834. void *tomoyo_commit_ok(void *data, const unsigned int size);
  835. /*
  836. * Keep the given name on the RAM.
  837. * The RAM is shared, so NEVER try to modify or kfree() the returned name.
  838. */
  839. const struct tomoyo_path_info *tomoyo_get_name(const char *name);
  840. /* Check for memory usage. */
  841. int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
  842. /* Set memory quota. */
  843. int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
  844. /* Initialize mm related code. */
  845. void __init tomoyo_mm_init(void);
  846. int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
  847. const struct tomoyo_path_info *filename);
  848. int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
  849. struct path *path, const int flag);
  850. int tomoyo_path_number_perm(const u8 operation, struct path *path,
  851. unsigned long number);
  852. int tomoyo_mkdev_perm(const u8 operation, struct path *path,
  853. const unsigned int mode, unsigned int dev);
  854. int tomoyo_path_perm(const u8 operation, struct path *path);
  855. int tomoyo_path2_perm(const u8 operation, struct path *path1,
  856. struct path *path2);
  857. int tomoyo_find_next_domain(struct linux_binprm *bprm);
  858. void tomoyo_print_ulong(char *buffer, const int buffer_len,
  859. const unsigned long value, const u8 type);
  860. /* Drop refcount on tomoyo_name_union. */
  861. void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
  862. /* Run garbage collector. */
  863. void tomoyo_run_gc(void);
  864. void tomoyo_memory_free(void *ptr);
  865. int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
  866. bool is_delete, struct tomoyo_domain_info *domain,
  867. bool (*check_duplicate) (const struct tomoyo_acl_info
  868. *,
  869. const struct tomoyo_acl_info
  870. *),
  871. bool (*merge_duplicate) (struct tomoyo_acl_info *,
  872. struct tomoyo_acl_info *,
  873. const bool));
  874. int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
  875. bool is_delete, struct list_head *list,
  876. bool (*check_duplicate) (const struct tomoyo_acl_head
  877. *,
  878. const struct tomoyo_acl_head
  879. *));
  880. void tomoyo_check_acl(struct tomoyo_request_info *r,
  881. bool (*check_entry) (const struct tomoyo_request_info *,
  882. const struct tomoyo_acl_info *));
  883. /********** External variable definitions. **********/
  884. /* Lock for GC. */
  885. extern struct srcu_struct tomoyo_ss;
  886. /* The list for "struct tomoyo_domain_info". */
  887. extern struct list_head tomoyo_domain_list;
  888. extern struct list_head tomoyo_path_group_list;
  889. extern struct list_head tomoyo_number_group_list;
  890. extern struct list_head tomoyo_domain_initializer_list;
  891. extern struct list_head tomoyo_domain_keeper_list;
  892. extern struct list_head tomoyo_aggregator_list;
  893. extern struct list_head tomoyo_alias_list;
  894. extern struct list_head tomoyo_globally_readable_list;
  895. extern struct list_head tomoyo_pattern_list;
  896. extern struct list_head tomoyo_no_rewrite_list;
  897. extern struct list_head tomoyo_policy_manager_list;
  898. extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
  899. /* Lock for protecting policy. */
  900. extern struct mutex tomoyo_policy_lock;
  901. /* Has /sbin/init started? */
  902. extern bool tomoyo_policy_loaded;
  903. /* The kernel's domain. */
  904. extern struct tomoyo_domain_info tomoyo_kernel_domain;
  905. extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
  906. extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];
  907. extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION];
  908. extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION];
  909. extern unsigned int tomoyo_quota_for_query;
  910. extern unsigned int tomoyo_query_memory_size;
  911. /********** Inlined functions. **********/
  912. static inline int tomoyo_read_lock(void)
  913. {
  914. return srcu_read_lock(&tomoyo_ss);
  915. }
  916. static inline void tomoyo_read_unlock(int idx)
  917. {
  918. srcu_read_unlock(&tomoyo_ss, idx);
  919. }
  920. /* strcmp() for "struct tomoyo_path_info" structure. */
  921. static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
  922. const struct tomoyo_path_info *b)
  923. {
  924. return a->hash != b->hash || strcmp(a->name, b->name);
  925. }
  926. /**
  927. * tomoyo_valid - Check whether the character is a valid char.
  928. *
  929. * @c: The character to check.
  930. *
  931. * Returns true if @c is a valid character, false otherwise.
  932. */
  933. static inline bool tomoyo_valid(const unsigned char c)
  934. {
  935. return c > ' ' && c < 127;
  936. }
  937. /**
  938. * tomoyo_invalid - Check whether the character is an invalid char.
  939. *
  940. * @c: The character to check.
  941. *
  942. * Returns true if @c is an invalid character, false otherwise.
  943. */
  944. static inline bool tomoyo_invalid(const unsigned char c)
  945. {
  946. return c && (c <= ' ' || c >= 127);
  947. }
  948. static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
  949. {
  950. if (name) {
  951. struct tomoyo_name_entry *ptr =
  952. container_of(name, struct tomoyo_name_entry, entry);
  953. atomic_dec(&ptr->users);
  954. }
  955. }
  956. static inline void tomoyo_put_path_group(struct tomoyo_path_group *group)
  957. {
  958. if (group)
  959. atomic_dec(&group->users);
  960. }
  961. static inline void tomoyo_put_number_group(struct tomoyo_number_group *group)
  962. {
  963. if (group)
  964. atomic_dec(&group->users);
  965. }
  966. static inline struct tomoyo_domain_info *tomoyo_domain(void)
  967. {
  968. return current_cred()->security;
  969. }
  970. static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
  971. *task)
  972. {
  973. return task_cred_xxx(task, security);
  974. }
  975. static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1,
  976. const struct tomoyo_acl_info *p2)
  977. {
  978. return p1->type == p2->type;
  979. }
  980. static inline bool tomoyo_same_name_union
  981. (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2)
  982. {
  983. return p1->filename == p2->filename && p1->group == p2->group &&
  984. p1->is_group == p2->is_group;
  985. }
  986. static inline bool tomoyo_same_number_union
  987. (const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2)
  988. {
  989. return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1]
  990. && p1->group == p2->group && p1->min_type == p2->min_type &&
  991. p1->max_type == p2->max_type && p1->is_group == p2->is_group;
  992. }
  993. /**
  994. * list_for_each_cookie - iterate over a list with cookie.
  995. * @pos: the &struct list_head to use as a loop cursor.
  996. * @cookie: the &struct list_head to use as a cookie.
  997. * @head: the head for your list.
  998. *
  999. * Same with list_for_each_rcu() except that this primitive uses @cookie
  1000. * so that we can continue iteration.
  1001. * @cookie must be NULL when iteration starts, and @cookie will become
  1002. * NULL when iteration finishes.
  1003. */
  1004. #define list_for_each_cookie(pos, cookie, head) \
  1005. for (({ if (!cookie) \
  1006. cookie = head; }), \
  1007. pos = rcu_dereference((cookie)->next); \
  1008. prefetch(pos->next), pos != (head) || ((cookie) = NULL); \
  1009. (cookie) = pos, pos = rcu_dereference(pos->next))
  1010. #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */