common.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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. /* Index numbers for operation mode. */
  35. enum tomoyo_mode_index {
  36. TOMOYO_CONFIG_DISABLED,
  37. TOMOYO_CONFIG_LEARNING,
  38. TOMOYO_CONFIG_PERMISSIVE,
  39. TOMOYO_CONFIG_ENFORCING,
  40. TOMOYO_CONFIG_USE_DEFAULT = 255
  41. };
  42. /* Index numbers for entry type. */
  43. enum tomoyo_policy_id {
  44. TOMOYO_ID_GROUP,
  45. TOMOYO_ID_PATH_GROUP,
  46. TOMOYO_ID_NUMBER_GROUP,
  47. TOMOYO_ID_TRANSITION_CONTROL,
  48. TOMOYO_ID_AGGREGATOR,
  49. TOMOYO_ID_MANAGER,
  50. TOMOYO_ID_NAME,
  51. TOMOYO_ID_ACL,
  52. TOMOYO_ID_DOMAIN,
  53. TOMOYO_MAX_POLICY
  54. };
  55. /* Index numbers for group entries. */
  56. enum tomoyo_group_id {
  57. TOMOYO_PATH_GROUP,
  58. TOMOYO_NUMBER_GROUP,
  59. TOMOYO_MAX_GROUP
  60. };
  61. /* A domain definition starts with <kernel>. */
  62. #define TOMOYO_ROOT_NAME "<kernel>"
  63. #define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
  64. /* Index numbers for type of numeric values. */
  65. enum tomoyo_value_type {
  66. TOMOYO_VALUE_TYPE_INVALID,
  67. TOMOYO_VALUE_TYPE_DECIMAL,
  68. TOMOYO_VALUE_TYPE_OCTAL,
  69. TOMOYO_VALUE_TYPE_HEXADECIMAL,
  70. };
  71. /* Index numbers for domain transition control keywords. */
  72. enum tomoyo_transition_type {
  73. /* Do not change this order, */
  74. TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
  75. TOMOYO_TRANSITION_CONTROL_INITIALIZE,
  76. TOMOYO_TRANSITION_CONTROL_NO_KEEP,
  77. TOMOYO_TRANSITION_CONTROL_KEEP,
  78. TOMOYO_MAX_TRANSITION_TYPE
  79. };
  80. /* Index numbers for Access Controls. */
  81. enum tomoyo_acl_entry_type_index {
  82. TOMOYO_TYPE_PATH_ACL,
  83. TOMOYO_TYPE_PATH2_ACL,
  84. TOMOYO_TYPE_PATH_NUMBER_ACL,
  85. TOMOYO_TYPE_MKDEV_ACL,
  86. TOMOYO_TYPE_MOUNT_ACL,
  87. };
  88. /* Index numbers for access controls with one pathname. */
  89. enum tomoyo_path_acl_index {
  90. TOMOYO_TYPE_EXECUTE,
  91. TOMOYO_TYPE_READ,
  92. TOMOYO_TYPE_WRITE,
  93. TOMOYO_TYPE_APPEND,
  94. TOMOYO_TYPE_UNLINK,
  95. TOMOYO_TYPE_GETATTR,
  96. TOMOYO_TYPE_RMDIR,
  97. TOMOYO_TYPE_TRUNCATE,
  98. TOMOYO_TYPE_SYMLINK,
  99. TOMOYO_TYPE_CHROOT,
  100. TOMOYO_TYPE_UMOUNT,
  101. TOMOYO_MAX_PATH_OPERATION
  102. };
  103. enum tomoyo_mkdev_acl_index {
  104. TOMOYO_TYPE_MKBLOCK,
  105. TOMOYO_TYPE_MKCHAR,
  106. TOMOYO_MAX_MKDEV_OPERATION
  107. };
  108. /* Index numbers for access controls with two pathnames. */
  109. enum tomoyo_path2_acl_index {
  110. TOMOYO_TYPE_LINK,
  111. TOMOYO_TYPE_RENAME,
  112. TOMOYO_TYPE_PIVOT_ROOT,
  113. TOMOYO_MAX_PATH2_OPERATION
  114. };
  115. /* Index numbers for access controls with one pathname and one number. */
  116. enum tomoyo_path_number_acl_index {
  117. TOMOYO_TYPE_CREATE,
  118. TOMOYO_TYPE_MKDIR,
  119. TOMOYO_TYPE_MKFIFO,
  120. TOMOYO_TYPE_MKSOCK,
  121. TOMOYO_TYPE_IOCTL,
  122. TOMOYO_TYPE_CHMOD,
  123. TOMOYO_TYPE_CHOWN,
  124. TOMOYO_TYPE_CHGRP,
  125. TOMOYO_MAX_PATH_NUMBER_OPERATION
  126. };
  127. /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
  128. enum tomoyo_securityfs_interface_index {
  129. TOMOYO_DOMAINPOLICY,
  130. TOMOYO_EXCEPTIONPOLICY,
  131. TOMOYO_DOMAIN_STATUS,
  132. TOMOYO_PROCESS_STATUS,
  133. TOMOYO_MEMINFO,
  134. TOMOYO_SELFDOMAIN,
  135. TOMOYO_VERSION,
  136. TOMOYO_PROFILE,
  137. TOMOYO_QUERY,
  138. TOMOYO_MANAGER
  139. };
  140. /* Index numbers for special mount operations. */
  141. enum tomoyo_special_mount {
  142. TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */
  143. TOMOYO_MOUNT_MOVE, /* mount --move /old /new */
  144. TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */
  145. TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
  146. TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */
  147. TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */
  148. TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */
  149. TOMOYO_MAX_SPECIAL_MOUNT
  150. };
  151. /* Index numbers for functionality. */
  152. enum tomoyo_mac_index {
  153. TOMOYO_MAC_FILE_EXECUTE,
  154. TOMOYO_MAC_FILE_OPEN,
  155. TOMOYO_MAC_FILE_CREATE,
  156. TOMOYO_MAC_FILE_UNLINK,
  157. TOMOYO_MAC_FILE_GETATTR,
  158. TOMOYO_MAC_FILE_MKDIR,
  159. TOMOYO_MAC_FILE_RMDIR,
  160. TOMOYO_MAC_FILE_MKFIFO,
  161. TOMOYO_MAC_FILE_MKSOCK,
  162. TOMOYO_MAC_FILE_TRUNCATE,
  163. TOMOYO_MAC_FILE_SYMLINK,
  164. TOMOYO_MAC_FILE_MKBLOCK,
  165. TOMOYO_MAC_FILE_MKCHAR,
  166. TOMOYO_MAC_FILE_LINK,
  167. TOMOYO_MAC_FILE_RENAME,
  168. TOMOYO_MAC_FILE_CHMOD,
  169. TOMOYO_MAC_FILE_CHOWN,
  170. TOMOYO_MAC_FILE_CHGRP,
  171. TOMOYO_MAC_FILE_IOCTL,
  172. TOMOYO_MAC_FILE_CHROOT,
  173. TOMOYO_MAC_FILE_MOUNT,
  174. TOMOYO_MAC_FILE_UMOUNT,
  175. TOMOYO_MAC_FILE_PIVOT_ROOT,
  176. TOMOYO_MAX_MAC_INDEX
  177. };
  178. /* Index numbers for category of functionality. */
  179. enum tomoyo_mac_category_index {
  180. TOMOYO_MAC_CATEGORY_FILE,
  181. TOMOYO_MAX_MAC_CATEGORY_INDEX
  182. };
  183. /*
  184. * Retry this request. Returned by tomoyo_supervisor() if policy violation has
  185. * occurred in enforcing mode and the userspace daemon decided to retry.
  186. *
  187. * We must choose a positive value in order to distinguish "granted" (which is
  188. * 0) and "rejected" (which is a negative value) and "retry".
  189. */
  190. #define TOMOYO_RETRY_REQUEST 1
  191. /********** Structure definitions. **********/
  192. /* Common header for holding ACL entries. */
  193. struct tomoyo_acl_head {
  194. struct list_head list;
  195. bool is_deleted;
  196. } __packed;
  197. /* Common header for shared entries. */
  198. struct tomoyo_shared_acl_head {
  199. struct list_head list;
  200. atomic_t users;
  201. } __packed;
  202. /* Structure for request info. */
  203. struct tomoyo_request_info {
  204. struct tomoyo_domain_info *domain;
  205. /* For holding parameters. */
  206. union {
  207. struct {
  208. const struct tomoyo_path_info *filename;
  209. /* For using wildcards at tomoyo_find_next_domain(). */
  210. const struct tomoyo_path_info *matched_path;
  211. /* One of values in "enum tomoyo_path_acl_index". */
  212. u8 operation;
  213. } path;
  214. struct {
  215. const struct tomoyo_path_info *filename1;
  216. const struct tomoyo_path_info *filename2;
  217. /* One of values in "enum tomoyo_path2_acl_index". */
  218. u8 operation;
  219. } path2;
  220. struct {
  221. const struct tomoyo_path_info *filename;
  222. unsigned int mode;
  223. unsigned int major;
  224. unsigned int minor;
  225. /* One of values in "enum tomoyo_mkdev_acl_index". */
  226. u8 operation;
  227. } mkdev;
  228. struct {
  229. const struct tomoyo_path_info *filename;
  230. unsigned long number;
  231. /*
  232. * One of values in
  233. * "enum tomoyo_path_number_acl_index".
  234. */
  235. u8 operation;
  236. } path_number;
  237. struct {
  238. const struct tomoyo_path_info *type;
  239. const struct tomoyo_path_info *dir;
  240. const struct tomoyo_path_info *dev;
  241. unsigned long flags;
  242. int need_dev;
  243. } mount;
  244. } param;
  245. u8 param_type;
  246. bool granted;
  247. u8 retry;
  248. u8 profile;
  249. u8 mode; /* One of tomoyo_mode_index . */
  250. u8 type;
  251. };
  252. /* Structure for holding a token. */
  253. struct tomoyo_path_info {
  254. const char *name;
  255. u32 hash; /* = full_name_hash(name, strlen(name)) */
  256. u16 const_len; /* = tomoyo_const_part_length(name) */
  257. bool is_dir; /* = tomoyo_strendswith(name, "/") */
  258. bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
  259. };
  260. /* Structure for holding string data. */
  261. struct tomoyo_name {
  262. struct tomoyo_shared_acl_head head;
  263. struct tomoyo_path_info entry;
  264. };
  265. /* Structure for holding a word. */
  266. struct tomoyo_name_union {
  267. /* Either @filename or @group is NULL. */
  268. const struct tomoyo_path_info *filename;
  269. struct tomoyo_group *group;
  270. };
  271. /* Structure for holding a number. */
  272. struct tomoyo_number_union {
  273. unsigned long values[2];
  274. struct tomoyo_group *group; /* Maybe NULL. */
  275. /* One of values in "enum tomoyo_value_type". */
  276. u8 value_type[2];
  277. };
  278. /* Structure for "path_group"/"number_group" directive. */
  279. struct tomoyo_group {
  280. struct tomoyo_shared_acl_head head;
  281. const struct tomoyo_path_info *group_name;
  282. struct list_head member_list;
  283. };
  284. /* Structure for "path_group" directive. */
  285. struct tomoyo_path_group {
  286. struct tomoyo_acl_head head;
  287. const struct tomoyo_path_info *member_name;
  288. };
  289. /* Structure for "number_group" directive. */
  290. struct tomoyo_number_group {
  291. struct tomoyo_acl_head head;
  292. struct tomoyo_number_union number;
  293. };
  294. /* Common header for individual entries. */
  295. struct tomoyo_acl_info {
  296. struct list_head list;
  297. bool is_deleted;
  298. u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
  299. } __packed;
  300. /* Structure for domain information. */
  301. struct tomoyo_domain_info {
  302. struct list_head list;
  303. struct list_head acl_info_list;
  304. /* Name of this domain. Never NULL. */
  305. const struct tomoyo_path_info *domainname;
  306. u8 profile; /* Profile number to use. */
  307. bool is_deleted; /* Delete flag. */
  308. bool quota_warned; /* Quota warnning flag. */
  309. bool transition_failed; /* Domain transition failed flag. */
  310. atomic_t users; /* Number of referring credentials. */
  311. };
  312. /*
  313. * Structure for "file execute", "file read", "file write", "file append",
  314. * "file unlink", "file getattr", "file rmdir", "file truncate",
  315. * "file symlink", "file chroot" and "file unmount" directive.
  316. */
  317. struct tomoyo_path_acl {
  318. struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
  319. u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
  320. struct tomoyo_name_union name;
  321. };
  322. /*
  323. * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
  324. * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
  325. */
  326. struct tomoyo_path_number_acl {
  327. struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
  328. /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
  329. u8 perm;
  330. struct tomoyo_name_union name;
  331. struct tomoyo_number_union number;
  332. };
  333. /* Structure for "file mkblock" and "file mkchar" directive. */
  334. struct tomoyo_mkdev_acl {
  335. struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
  336. u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
  337. struct tomoyo_name_union name;
  338. struct tomoyo_number_union mode;
  339. struct tomoyo_number_union major;
  340. struct tomoyo_number_union minor;
  341. };
  342. /*
  343. * Structure for "file rename", "file link" and "file pivot_root" directive.
  344. */
  345. struct tomoyo_path2_acl {
  346. struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
  347. u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
  348. struct tomoyo_name_union name1;
  349. struct tomoyo_name_union name2;
  350. };
  351. /* Structure for "file mount" directive. */
  352. struct tomoyo_mount_acl {
  353. struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
  354. struct tomoyo_name_union dev_name;
  355. struct tomoyo_name_union dir_name;
  356. struct tomoyo_name_union fs_type;
  357. struct tomoyo_number_union flags;
  358. };
  359. /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
  360. struct tomoyo_acl_param {
  361. char *data;
  362. struct list_head *list;
  363. bool is_delete;
  364. };
  365. #define TOMOYO_MAX_IO_READ_QUEUE 64
  366. /*
  367. * Structure for reading/writing policy via /sys/kernel/security/tomoyo
  368. * interfaces.
  369. */
  370. struct tomoyo_io_buffer {
  371. void (*read) (struct tomoyo_io_buffer *);
  372. int (*write) (struct tomoyo_io_buffer *);
  373. int (*poll) (struct file *file, poll_table *wait);
  374. /* Exclusive lock for this structure. */
  375. struct mutex io_sem;
  376. /* Index returned by tomoyo_read_lock(). */
  377. int reader_idx;
  378. char __user *read_user_buf;
  379. int read_user_buf_avail;
  380. struct {
  381. struct list_head *domain;
  382. struct list_head *group;
  383. struct list_head *acl;
  384. int avail;
  385. int step;
  386. int query_index;
  387. u16 index;
  388. u8 bit;
  389. u8 w_pos;
  390. bool eof;
  391. bool print_this_domain_only;
  392. bool print_execute_only;
  393. const char *w[TOMOYO_MAX_IO_READ_QUEUE];
  394. } r;
  395. struct {
  396. /* The position currently writing to. */
  397. struct tomoyo_domain_info *domain;
  398. /* Bytes available for writing. */
  399. int avail;
  400. } w;
  401. /* Buffer for reading. */
  402. char *read_buf;
  403. /* Size of read buffer. */
  404. int readbuf_size;
  405. /* Buffer for writing. */
  406. char *write_buf;
  407. /* Size of write buffer. */
  408. int writebuf_size;
  409. /* Type of this interface. */
  410. u8 type;
  411. };
  412. /*
  413. * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
  414. * "no_keep_domain" keyword.
  415. */
  416. struct tomoyo_transition_control {
  417. struct tomoyo_acl_head head;
  418. u8 type; /* One of values in "enum tomoyo_transition_type". */
  419. /* True if the domainname is tomoyo_get_last_name(). */
  420. bool is_last_name;
  421. const struct tomoyo_path_info *domainname; /* Maybe NULL */
  422. const struct tomoyo_path_info *program; /* Maybe NULL */
  423. };
  424. /* Structure for "aggregator" keyword. */
  425. struct tomoyo_aggregator {
  426. struct tomoyo_acl_head head;
  427. const struct tomoyo_path_info *original_name;
  428. const struct tomoyo_path_info *aggregated_name;
  429. };
  430. /* Structure for policy manager. */
  431. struct tomoyo_manager {
  432. struct tomoyo_acl_head head;
  433. bool is_domain; /* True if manager is a domainname. */
  434. /* A path to program or a domainname. */
  435. const struct tomoyo_path_info *manager;
  436. };
  437. struct tomoyo_preference {
  438. unsigned int learning_max_entry;
  439. bool enforcing_verbose;
  440. bool learning_verbose;
  441. bool permissive_verbose;
  442. };
  443. /* Structure for /sys/kernel/security/tomnoyo/profile interface. */
  444. struct tomoyo_profile {
  445. const struct tomoyo_path_info *comment;
  446. struct tomoyo_preference *learning;
  447. struct tomoyo_preference *permissive;
  448. struct tomoyo_preference *enforcing;
  449. struct tomoyo_preference preference;
  450. u8 default_config;
  451. u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
  452. };
  453. /********** Function prototypes. **********/
  454. bool tomoyo_str_starts(char **src, const char *find);
  455. const char *tomoyo_get_exe(void);
  456. void tomoyo_normalize_line(unsigned char *buffer);
  457. void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...)
  458. __attribute__ ((format(printf, 2, 3)));
  459. void tomoyo_check_profile(void);
  460. int tomoyo_open_control(const u8 type, struct file *file);
  461. int tomoyo_close_control(struct tomoyo_io_buffer *head);
  462. int tomoyo_poll_control(struct file *file, poll_table *wait);
  463. int tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
  464. const int buffer_len);
  465. int tomoyo_write_control(struct tomoyo_io_buffer *head,
  466. const char __user *buffer, const int buffer_len);
  467. bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
  468. void tomoyo_warn_oom(const char *function);
  469. const struct tomoyo_path_info *
  470. tomoyo_compare_name_union(const struct tomoyo_path_info *name,
  471. const struct tomoyo_name_union *ptr);
  472. bool tomoyo_compare_number_union(const unsigned long value,
  473. const struct tomoyo_number_union *ptr);
  474. int tomoyo_get_mode(const u8 profile, const u8 index);
  475. void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
  476. __attribute__ ((format(printf, 2, 3)));
  477. bool tomoyo_correct_domain(const unsigned char *domainname);
  478. bool tomoyo_correct_path(const char *filename);
  479. bool tomoyo_correct_word(const char *string);
  480. bool tomoyo_domain_def(const unsigned char *buffer);
  481. bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
  482. struct tomoyo_name_union *ptr);
  483. const struct tomoyo_path_info *
  484. tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
  485. const struct tomoyo_group *group);
  486. bool tomoyo_number_matches_group(const unsigned long min,
  487. const unsigned long max,
  488. const struct tomoyo_group *group);
  489. bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
  490. const struct tomoyo_path_info *pattern);
  491. bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
  492. struct tomoyo_number_union *ptr);
  493. bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
  494. bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
  495. int tomoyo_init_request_info(struct tomoyo_request_info *r,
  496. struct tomoyo_domain_info *domain,
  497. const u8 index);
  498. int tomoyo_mount_permission(char *dev_name, struct path *path,
  499. const char *type, unsigned long flags,
  500. void *data_page);
  501. int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
  502. int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
  503. const u8 type);
  504. int tomoyo_write_file(struct tomoyo_acl_param *param);
  505. int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
  506. int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
  507. __attribute__ ((format(printf, 2, 3)));
  508. struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
  509. struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
  510. const u8 profile);
  511. struct tomoyo_profile *tomoyo_profile(const u8 profile);
  512. struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
  513. const u8 idx);
  514. unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
  515. const u8 index);
  516. void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
  517. void tomoyo_load_policy(const char *filename);
  518. void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
  519. char *tomoyo_encode(const char *str);
  520. char *tomoyo_realpath_nofollow(const char *pathname);
  521. char *tomoyo_realpath_from_path(struct path *path);
  522. bool tomoyo_memory_ok(void *ptr);
  523. void *tomoyo_commit_ok(void *data, const unsigned int size);
  524. const struct tomoyo_path_info *tomoyo_get_name(const char *name);
  525. void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
  526. int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
  527. void __init tomoyo_mm_init(void);
  528. int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
  529. const struct tomoyo_path_info *filename);
  530. int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
  531. struct path *path, const int flag);
  532. int tomoyo_path_number_perm(const u8 operation, struct path *path,
  533. unsigned long number);
  534. int tomoyo_mkdev_perm(const u8 operation, struct path *path,
  535. const unsigned int mode, unsigned int dev);
  536. int tomoyo_path_perm(const u8 operation, struct path *path);
  537. int tomoyo_path2_perm(const u8 operation, struct path *path1,
  538. struct path *path2);
  539. int tomoyo_find_next_domain(struct linux_binprm *bprm);
  540. void tomoyo_print_ulong(char *buffer, const int buffer_len,
  541. const unsigned long value, const u8 type);
  542. void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
  543. void tomoyo_run_gc(void);
  544. void tomoyo_memory_free(void *ptr);
  545. int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
  546. struct tomoyo_acl_param *param,
  547. bool (*check_duplicate) (const struct tomoyo_acl_info
  548. *,
  549. const struct tomoyo_acl_info
  550. *),
  551. bool (*merge_duplicate) (struct tomoyo_acl_info *,
  552. struct tomoyo_acl_info *,
  553. const bool));
  554. int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
  555. struct tomoyo_acl_param *param,
  556. bool (*check_duplicate) (const struct tomoyo_acl_head
  557. *,
  558. const struct tomoyo_acl_head
  559. *));
  560. void tomoyo_check_acl(struct tomoyo_request_info *r,
  561. bool (*check_entry) (struct tomoyo_request_info *,
  562. const struct tomoyo_acl_info *));
  563. char *tomoyo_read_token(struct tomoyo_acl_param *param);
  564. bool tomoyo_permstr(const char *string, const char *keyword);
  565. /********** External variable definitions. **********/
  566. /* Lock for GC. */
  567. extern struct srcu_struct tomoyo_ss;
  568. /* The list for "struct tomoyo_domain_info". */
  569. extern struct list_head tomoyo_domain_list;
  570. extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];
  571. extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];
  572. extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
  573. /* Lock for protecting policy. */
  574. extern struct mutex tomoyo_policy_lock;
  575. /* Has /sbin/init started? */
  576. extern bool tomoyo_policy_loaded;
  577. /* The kernel's domain. */
  578. extern struct tomoyo_domain_info tomoyo_kernel_domain;
  579. extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
  580. extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];
  581. extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION];
  582. extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION];
  583. extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
  584. extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
  585. extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
  586. extern unsigned int tomoyo_quota_for_query;
  587. extern unsigned int tomoyo_query_memory_size;
  588. /********** Inlined functions. **********/
  589. /**
  590. * tomoyo_read_lock - Take lock for protecting policy.
  591. *
  592. * Returns index number for tomoyo_read_unlock().
  593. */
  594. static inline int tomoyo_read_lock(void)
  595. {
  596. return srcu_read_lock(&tomoyo_ss);
  597. }
  598. /**
  599. * tomoyo_read_unlock - Release lock for protecting policy.
  600. *
  601. * @idx: Index number returned by tomoyo_read_lock().
  602. *
  603. * Returns nothing.
  604. */
  605. static inline void tomoyo_read_unlock(int idx)
  606. {
  607. srcu_read_unlock(&tomoyo_ss, idx);
  608. }
  609. /**
  610. * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
  611. *
  612. * @a: Pointer to "struct tomoyo_path_info".
  613. * @b: Pointer to "struct tomoyo_path_info".
  614. *
  615. * Returns true if @a == @b, false otherwise.
  616. */
  617. static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
  618. const struct tomoyo_path_info *b)
  619. {
  620. return a->hash != b->hash || strcmp(a->name, b->name);
  621. }
  622. /**
  623. * tomoyo_put_name - Drop reference on "struct tomoyo_name".
  624. *
  625. * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
  626. *
  627. * Returns nothing.
  628. */
  629. static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
  630. {
  631. if (name) {
  632. struct tomoyo_name *ptr =
  633. container_of(name, typeof(*ptr), entry);
  634. atomic_dec(&ptr->head.users);
  635. }
  636. }
  637. /**
  638. * tomoyo_put_group - Drop reference on "struct tomoyo_group".
  639. *
  640. * @group: Pointer to "struct tomoyo_group". Maybe NULL.
  641. *
  642. * Returns nothing.
  643. */
  644. static inline void tomoyo_put_group(struct tomoyo_group *group)
  645. {
  646. if (group)
  647. atomic_dec(&group->head.users);
  648. }
  649. /**
  650. * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
  651. *
  652. * Returns pointer to "struct tomoyo_domain_info" for current thread.
  653. */
  654. static inline struct tomoyo_domain_info *tomoyo_domain(void)
  655. {
  656. return current_cred()->security;
  657. }
  658. /**
  659. * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
  660. *
  661. * @task: Pointer to "struct task_struct".
  662. *
  663. * Returns pointer to "struct tomoyo_security" for specified thread.
  664. */
  665. static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
  666. *task)
  667. {
  668. return task_cred_xxx(task, security);
  669. }
  670. /**
  671. * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
  672. *
  673. * @a: Pointer to "struct tomoyo_name_union".
  674. * @b: Pointer to "struct tomoyo_name_union".
  675. *
  676. * Returns true if @a == @b, false otherwise.
  677. */
  678. static inline bool tomoyo_same_name_union
  679. (const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
  680. {
  681. return a->filename == b->filename && a->group == b->group;
  682. }
  683. /**
  684. * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
  685. *
  686. * @a: Pointer to "struct tomoyo_number_union".
  687. * @b: Pointer to "struct tomoyo_number_union".
  688. *
  689. * Returns true if @a == @b, false otherwise.
  690. */
  691. static inline bool tomoyo_same_number_union
  692. (const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
  693. {
  694. return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
  695. a->group == b->group && a->value_type[0] == b->value_type[0] &&
  696. a->value_type[1] == b->value_type[1];
  697. }
  698. /**
  699. * list_for_each_cookie - iterate over a list with cookie.
  700. * @pos: the &struct list_head to use as a loop cursor.
  701. * @head: the head for your list.
  702. */
  703. #define list_for_each_cookie(pos, head) \
  704. if (!pos) \
  705. pos = srcu_dereference((head)->next, &tomoyo_ss); \
  706. for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
  707. #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */