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