TOMOYO: Allow using UID/GID etc. of current thread as conditions.
[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 #include <linux/binfmts.h>
25 #include <linux/highmem.h>
26
27 /********** Constants definitions. **********/
28
29 /*
30 * TOMOYO uses this hash only when appending a string into the string
31 * table. Frequency of appending strings is very low. So we don't need
32 * large (e.g. 64k) hash size. 256 will be sufficient.
33 */
34 #define TOMOYO_HASH_BITS 8
35 #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
36
37 #define TOMOYO_EXEC_TMPSIZE 4096
38
39 /* Profile number is an integer between 0 and 255. */
40 #define TOMOYO_MAX_PROFILES 256
41
42 /* Group number is an integer between 0 and 255. */
43 #define TOMOYO_MAX_ACL_GROUPS 256
44
45 /* Index numbers for "struct tomoyo_condition". */
46 enum tomoyo_conditions_index {
47 TOMOYO_TASK_UID, /* current_uid() */
48 TOMOYO_TASK_EUID, /* current_euid() */
49 TOMOYO_TASK_SUID, /* current_suid() */
50 TOMOYO_TASK_FSUID, /* current_fsuid() */
51 TOMOYO_TASK_GID, /* current_gid() */
52 TOMOYO_TASK_EGID, /* current_egid() */
53 TOMOYO_TASK_SGID, /* current_sgid() */
54 TOMOYO_TASK_FSGID, /* current_fsgid() */
55 TOMOYO_TASK_PID, /* sys_getpid() */
56 TOMOYO_TASK_PPID, /* sys_getppid() */
57 TOMOYO_MAX_CONDITION_KEYWORD,
58 TOMOYO_NUMBER_UNION,
59 };
60
61 /* Index numbers for operation mode. */
62 enum tomoyo_mode_index {
63 TOMOYO_CONFIG_DISABLED,
64 TOMOYO_CONFIG_LEARNING,
65 TOMOYO_CONFIG_PERMISSIVE,
66 TOMOYO_CONFIG_ENFORCING,
67 TOMOYO_CONFIG_MAX_MODE,
68 TOMOYO_CONFIG_WANT_REJECT_LOG = 64,
69 TOMOYO_CONFIG_WANT_GRANT_LOG = 128,
70 TOMOYO_CONFIG_USE_DEFAULT = 255,
71 };
72
73 /* Index numbers for entry type. */
74 enum tomoyo_policy_id {
75 TOMOYO_ID_GROUP,
76 TOMOYO_ID_PATH_GROUP,
77 TOMOYO_ID_NUMBER_GROUP,
78 TOMOYO_ID_TRANSITION_CONTROL,
79 TOMOYO_ID_AGGREGATOR,
80 TOMOYO_ID_MANAGER,
81 TOMOYO_ID_CONDITION,
82 TOMOYO_ID_NAME,
83 TOMOYO_ID_ACL,
84 TOMOYO_ID_DOMAIN,
85 TOMOYO_MAX_POLICY
86 };
87
88 /* Index numbers for domain's attributes. */
89 enum tomoyo_domain_info_flags_index {
90 /* Quota warnning flag. */
91 TOMOYO_DIF_QUOTA_WARNED,
92 /*
93 * This domain was unable to create a new domain at
94 * tomoyo_find_next_domain() because the name of the domain to be
95 * created was too long or it could not allocate memory.
96 * More than one process continued execve() without domain transition.
97 */
98 TOMOYO_DIF_TRANSITION_FAILED,
99 TOMOYO_MAX_DOMAIN_INFO_FLAGS
100 };
101
102 /* Index numbers for group entries. */
103 enum tomoyo_group_id {
104 TOMOYO_PATH_GROUP,
105 TOMOYO_NUMBER_GROUP,
106 TOMOYO_MAX_GROUP
107 };
108
109 /* Index numbers for type of numeric values. */
110 enum tomoyo_value_type {
111 TOMOYO_VALUE_TYPE_INVALID,
112 TOMOYO_VALUE_TYPE_DECIMAL,
113 TOMOYO_VALUE_TYPE_OCTAL,
114 TOMOYO_VALUE_TYPE_HEXADECIMAL,
115 };
116
117 /* Index numbers for domain transition control keywords. */
118 enum tomoyo_transition_type {
119 /* Do not change this order, */
120 TOMOYO_TRANSITION_CONTROL_NO_RESET,
121 TOMOYO_TRANSITION_CONTROL_RESET,
122 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
123 TOMOYO_TRANSITION_CONTROL_INITIALIZE,
124 TOMOYO_TRANSITION_CONTROL_NO_KEEP,
125 TOMOYO_TRANSITION_CONTROL_KEEP,
126 TOMOYO_MAX_TRANSITION_TYPE
127 };
128
129 /* Index numbers for Access Controls. */
130 enum tomoyo_acl_entry_type_index {
131 TOMOYO_TYPE_PATH_ACL,
132 TOMOYO_TYPE_PATH2_ACL,
133 TOMOYO_TYPE_PATH_NUMBER_ACL,
134 TOMOYO_TYPE_MKDEV_ACL,
135 TOMOYO_TYPE_MOUNT_ACL,
136 };
137
138 /* Index numbers for access controls with one pathname. */
139 enum tomoyo_path_acl_index {
140 TOMOYO_TYPE_EXECUTE,
141 TOMOYO_TYPE_READ,
142 TOMOYO_TYPE_WRITE,
143 TOMOYO_TYPE_APPEND,
144 TOMOYO_TYPE_UNLINK,
145 TOMOYO_TYPE_GETATTR,
146 TOMOYO_TYPE_RMDIR,
147 TOMOYO_TYPE_TRUNCATE,
148 TOMOYO_TYPE_SYMLINK,
149 TOMOYO_TYPE_CHROOT,
150 TOMOYO_TYPE_UMOUNT,
151 TOMOYO_MAX_PATH_OPERATION
152 };
153
154 /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
155 enum tomoyo_memory_stat_type {
156 TOMOYO_MEMORY_POLICY,
157 TOMOYO_MEMORY_AUDIT,
158 TOMOYO_MEMORY_QUERY,
159 TOMOYO_MAX_MEMORY_STAT
160 };
161
162 enum tomoyo_mkdev_acl_index {
163 TOMOYO_TYPE_MKBLOCK,
164 TOMOYO_TYPE_MKCHAR,
165 TOMOYO_MAX_MKDEV_OPERATION
166 };
167
168 /* Index numbers for access controls with two pathnames. */
169 enum tomoyo_path2_acl_index {
170 TOMOYO_TYPE_LINK,
171 TOMOYO_TYPE_RENAME,
172 TOMOYO_TYPE_PIVOT_ROOT,
173 TOMOYO_MAX_PATH2_OPERATION
174 };
175
176 /* Index numbers for access controls with one pathname and one number. */
177 enum tomoyo_path_number_acl_index {
178 TOMOYO_TYPE_CREATE,
179 TOMOYO_TYPE_MKDIR,
180 TOMOYO_TYPE_MKFIFO,
181 TOMOYO_TYPE_MKSOCK,
182 TOMOYO_TYPE_IOCTL,
183 TOMOYO_TYPE_CHMOD,
184 TOMOYO_TYPE_CHOWN,
185 TOMOYO_TYPE_CHGRP,
186 TOMOYO_MAX_PATH_NUMBER_OPERATION
187 };
188
189 /* Index numbers for /sys/kernel/security/tomoyo/ interfaces. */
190 enum tomoyo_securityfs_interface_index {
191 TOMOYO_DOMAINPOLICY,
192 TOMOYO_EXCEPTIONPOLICY,
193 TOMOYO_PROCESS_STATUS,
194 TOMOYO_STAT,
195 TOMOYO_SELFDOMAIN,
196 TOMOYO_AUDIT,
197 TOMOYO_VERSION,
198 TOMOYO_PROFILE,
199 TOMOYO_QUERY,
200 TOMOYO_MANAGER
201 };
202
203 /* Index numbers for special mount operations. */
204 enum tomoyo_special_mount {
205 TOMOYO_MOUNT_BIND, /* mount --bind /source /dest */
206 TOMOYO_MOUNT_MOVE, /* mount --move /old /new */
207 TOMOYO_MOUNT_REMOUNT, /* mount -o remount /dir */
208 TOMOYO_MOUNT_MAKE_UNBINDABLE, /* mount --make-unbindable /dir */
209 TOMOYO_MOUNT_MAKE_PRIVATE, /* mount --make-private /dir */
210 TOMOYO_MOUNT_MAKE_SLAVE, /* mount --make-slave /dir */
211 TOMOYO_MOUNT_MAKE_SHARED, /* mount --make-shared /dir */
212 TOMOYO_MAX_SPECIAL_MOUNT
213 };
214
215 /* Index numbers for functionality. */
216 enum tomoyo_mac_index {
217 TOMOYO_MAC_FILE_EXECUTE,
218 TOMOYO_MAC_FILE_OPEN,
219 TOMOYO_MAC_FILE_CREATE,
220 TOMOYO_MAC_FILE_UNLINK,
221 TOMOYO_MAC_FILE_GETATTR,
222 TOMOYO_MAC_FILE_MKDIR,
223 TOMOYO_MAC_FILE_RMDIR,
224 TOMOYO_MAC_FILE_MKFIFO,
225 TOMOYO_MAC_FILE_MKSOCK,
226 TOMOYO_MAC_FILE_TRUNCATE,
227 TOMOYO_MAC_FILE_SYMLINK,
228 TOMOYO_MAC_FILE_MKBLOCK,
229 TOMOYO_MAC_FILE_MKCHAR,
230 TOMOYO_MAC_FILE_LINK,
231 TOMOYO_MAC_FILE_RENAME,
232 TOMOYO_MAC_FILE_CHMOD,
233 TOMOYO_MAC_FILE_CHOWN,
234 TOMOYO_MAC_FILE_CHGRP,
235 TOMOYO_MAC_FILE_IOCTL,
236 TOMOYO_MAC_FILE_CHROOT,
237 TOMOYO_MAC_FILE_MOUNT,
238 TOMOYO_MAC_FILE_UMOUNT,
239 TOMOYO_MAC_FILE_PIVOT_ROOT,
240 TOMOYO_MAX_MAC_INDEX
241 };
242
243 /* Index numbers for category of functionality. */
244 enum tomoyo_mac_category_index {
245 TOMOYO_MAC_CATEGORY_FILE,
246 TOMOYO_MAX_MAC_CATEGORY_INDEX
247 };
248
249 /*
250 * Retry this request. Returned by tomoyo_supervisor() if policy violation has
251 * occurred in enforcing mode and the userspace daemon decided to retry.
252 *
253 * We must choose a positive value in order to distinguish "granted" (which is
254 * 0) and "rejected" (which is a negative value) and "retry".
255 */
256 #define TOMOYO_RETRY_REQUEST 1
257
258 /* Index numbers for /sys/kernel/security/tomoyo/stat interface. */
259 enum tomoyo_policy_stat_type {
260 /* Do not change this order. */
261 TOMOYO_STAT_POLICY_UPDATES,
262 TOMOYO_STAT_POLICY_LEARNING, /* == TOMOYO_CONFIG_LEARNING */
263 TOMOYO_STAT_POLICY_PERMISSIVE, /* == TOMOYO_CONFIG_PERMISSIVE */
264 TOMOYO_STAT_POLICY_ENFORCING, /* == TOMOYO_CONFIG_ENFORCING */
265 TOMOYO_MAX_POLICY_STAT
266 };
267
268 /* Index numbers for profile's PREFERENCE values. */
269 enum tomoyo_pref_index {
270 TOMOYO_PREF_MAX_AUDIT_LOG,
271 TOMOYO_PREF_MAX_LEARNING_ENTRY,
272 TOMOYO_MAX_PREF
273 };
274
275 /********** Structure definitions. **********/
276
277 /* Common header for holding ACL entries. */
278 struct tomoyo_acl_head {
279 struct list_head list;
280 bool is_deleted;
281 } __packed;
282
283 /* Common header for shared entries. */
284 struct tomoyo_shared_acl_head {
285 struct list_head list;
286 atomic_t users;
287 } __packed;
288
289 struct tomoyo_policy_namespace;
290
291 /* Structure for request info. */
292 struct tomoyo_request_info {
293 struct tomoyo_domain_info *domain;
294 /* For holding parameters. */
295 union {
296 struct {
297 const struct tomoyo_path_info *filename;
298 /* For using wildcards at tomoyo_find_next_domain(). */
299 const struct tomoyo_path_info *matched_path;
300 /* One of values in "enum tomoyo_path_acl_index". */
301 u8 operation;
302 } path;
303 struct {
304 const struct tomoyo_path_info *filename1;
305 const struct tomoyo_path_info *filename2;
306 /* One of values in "enum tomoyo_path2_acl_index". */
307 u8 operation;
308 } path2;
309 struct {
310 const struct tomoyo_path_info *filename;
311 unsigned int mode;
312 unsigned int major;
313 unsigned int minor;
314 /* One of values in "enum tomoyo_mkdev_acl_index". */
315 u8 operation;
316 } mkdev;
317 struct {
318 const struct tomoyo_path_info *filename;
319 unsigned long number;
320 /*
321 * One of values in
322 * "enum tomoyo_path_number_acl_index".
323 */
324 u8 operation;
325 } path_number;
326 struct {
327 const struct tomoyo_path_info *type;
328 const struct tomoyo_path_info *dir;
329 const struct tomoyo_path_info *dev;
330 unsigned long flags;
331 int need_dev;
332 } mount;
333 } param;
334 u8 param_type;
335 bool granted;
336 u8 retry;
337 u8 profile;
338 u8 mode; /* One of tomoyo_mode_index . */
339 u8 type;
340 };
341
342 /* Structure for holding a token. */
343 struct tomoyo_path_info {
344 const char *name;
345 u32 hash; /* = full_name_hash(name, strlen(name)) */
346 u16 const_len; /* = tomoyo_const_part_length(name) */
347 bool is_dir; /* = tomoyo_strendswith(name, "/") */
348 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
349 };
350
351 /* Structure for holding string data. */
352 struct tomoyo_name {
353 struct tomoyo_shared_acl_head head;
354 struct tomoyo_path_info entry;
355 };
356
357 /* Structure for holding a word. */
358 struct tomoyo_name_union {
359 /* Either @filename or @group is NULL. */
360 const struct tomoyo_path_info *filename;
361 struct tomoyo_group *group;
362 };
363
364 /* Structure for holding a number. */
365 struct tomoyo_number_union {
366 unsigned long values[2];
367 struct tomoyo_group *group; /* Maybe NULL. */
368 /* One of values in "enum tomoyo_value_type". */
369 u8 value_type[2];
370 };
371
372 /* Structure for "path_group"/"number_group" directive. */
373 struct tomoyo_group {
374 struct tomoyo_shared_acl_head head;
375 const struct tomoyo_path_info *group_name;
376 struct list_head member_list;
377 };
378
379 /* Structure for "path_group" directive. */
380 struct tomoyo_path_group {
381 struct tomoyo_acl_head head;
382 const struct tomoyo_path_info *member_name;
383 };
384
385 /* Structure for "number_group" directive. */
386 struct tomoyo_number_group {
387 struct tomoyo_acl_head head;
388 struct tomoyo_number_union number;
389 };
390
391 /* Structure for entries which follows "struct tomoyo_condition". */
392 struct tomoyo_condition_element {
393 /* Left hand operand. */
394 u8 left;
395 /* Right hand operand. */
396 u8 right;
397 /* Equation operator. True if equals or overlaps, false otherwise. */
398 bool equals;
399 };
400
401 /* Structure for optional arguments. */
402 struct tomoyo_condition {
403 struct tomoyo_shared_acl_head head;
404 u32 size; /* Memory size allocated for this entry. */
405 u16 condc; /* Number of conditions in this struct. */
406 u16 numbers_count; /* Number of "struct tomoyo_number_union values". */
407 /*
408 * struct tomoyo_condition_element condition[condc];
409 * struct tomoyo_number_union values[numbers_count];
410 */
411 };
412
413 /* Common header for individual entries. */
414 struct tomoyo_acl_info {
415 struct list_head list;
416 struct tomoyo_condition *cond; /* Maybe NULL. */
417 bool is_deleted;
418 u8 type; /* One of values in "enum tomoyo_acl_entry_type_index". */
419 } __packed;
420
421 /* Structure for domain information. */
422 struct tomoyo_domain_info {
423 struct list_head list;
424 struct list_head acl_info_list;
425 /* Name of this domain. Never NULL. */
426 const struct tomoyo_path_info *domainname;
427 /* Namespace for this domain. Never NULL. */
428 struct tomoyo_policy_namespace *ns;
429 u8 profile; /* Profile number to use. */
430 u8 group; /* Group number to use. */
431 bool is_deleted; /* Delete flag. */
432 bool flags[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
433 atomic_t users; /* Number of referring credentials. */
434 };
435
436 /*
437 * Structure for "file execute", "file read", "file write", "file append",
438 * "file unlink", "file getattr", "file rmdir", "file truncate",
439 * "file symlink", "file chroot" and "file unmount" directive.
440 */
441 struct tomoyo_path_acl {
442 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
443 u16 perm; /* Bitmask of values in "enum tomoyo_path_acl_index". */
444 struct tomoyo_name_union name;
445 };
446
447 /*
448 * Structure for "file create", "file mkdir", "file mkfifo", "file mksock",
449 * "file ioctl", "file chmod", "file chown" and "file chgrp" directive.
450 */
451 struct tomoyo_path_number_acl {
452 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
453 /* Bitmask of values in "enum tomoyo_path_number_acl_index". */
454 u8 perm;
455 struct tomoyo_name_union name;
456 struct tomoyo_number_union number;
457 };
458
459 /* Structure for "file mkblock" and "file mkchar" directive. */
460 struct tomoyo_mkdev_acl {
461 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
462 u8 perm; /* Bitmask of values in "enum tomoyo_mkdev_acl_index". */
463 struct tomoyo_name_union name;
464 struct tomoyo_number_union mode;
465 struct tomoyo_number_union major;
466 struct tomoyo_number_union minor;
467 };
468
469 /*
470 * Structure for "file rename", "file link" and "file pivot_root" directive.
471 */
472 struct tomoyo_path2_acl {
473 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
474 u8 perm; /* Bitmask of values in "enum tomoyo_path2_acl_index". */
475 struct tomoyo_name_union name1;
476 struct tomoyo_name_union name2;
477 };
478
479 /* Structure for "file mount" directive. */
480 struct tomoyo_mount_acl {
481 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
482 struct tomoyo_name_union dev_name;
483 struct tomoyo_name_union dir_name;
484 struct tomoyo_name_union fs_type;
485 struct tomoyo_number_union flags;
486 };
487
488 /* Structure for holding a line from /sys/kernel/security/tomoyo/ interface. */
489 struct tomoyo_acl_param {
490 char *data;
491 struct list_head *list;
492 struct tomoyo_policy_namespace *ns;
493 bool is_delete;
494 };
495
496 #define TOMOYO_MAX_IO_READ_QUEUE 64
497
498 /*
499 * Structure for reading/writing policy via /sys/kernel/security/tomoyo
500 * interfaces.
501 */
502 struct tomoyo_io_buffer {
503 void (*read) (struct tomoyo_io_buffer *);
504 int (*write) (struct tomoyo_io_buffer *);
505 int (*poll) (struct file *file, poll_table *wait);
506 /* Exclusive lock for this structure. */
507 struct mutex io_sem;
508 char __user *read_user_buf;
509 size_t read_user_buf_avail;
510 struct {
511 struct list_head *ns;
512 struct list_head *domain;
513 struct list_head *group;
514 struct list_head *acl;
515 size_t avail;
516 unsigned int step;
517 unsigned int query_index;
518 u16 index;
519 u16 cond_index;
520 u8 acl_group_index;
521 u8 cond_step;
522 u8 bit;
523 u8 w_pos;
524 bool eof;
525 bool print_this_domain_only;
526 bool print_transition_related_only;
527 bool print_cond_part;
528 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
529 } r;
530 struct {
531 struct tomoyo_policy_namespace *ns;
532 /* The position currently writing to. */
533 struct tomoyo_domain_info *domain;
534 /* Bytes available for writing. */
535 size_t avail;
536 bool is_delete;
537 } w;
538 /* Buffer for reading. */
539 char *read_buf;
540 /* Size of read buffer. */
541 size_t readbuf_size;
542 /* Buffer for writing. */
543 char *write_buf;
544 /* Size of write buffer. */
545 size_t writebuf_size;
546 /* Type of this interface. */
547 enum tomoyo_securityfs_interface_index type;
548 /* Users counter protected by tomoyo_io_buffer_list_lock. */
549 u8 users;
550 /* List for telling GC not to kfree() elements. */
551 struct list_head list;
552 };
553
554 /*
555 * Structure for "initialize_domain"/"no_initialize_domain"/"keep_domain"/
556 * "no_keep_domain" keyword.
557 */
558 struct tomoyo_transition_control {
559 struct tomoyo_acl_head head;
560 u8 type; /* One of values in "enum tomoyo_transition_type". */
561 /* True if the domainname is tomoyo_get_last_name(). */
562 bool is_last_name;
563 const struct tomoyo_path_info *domainname; /* Maybe NULL */
564 const struct tomoyo_path_info *program; /* Maybe NULL */
565 };
566
567 /* Structure for "aggregator" keyword. */
568 struct tomoyo_aggregator {
569 struct tomoyo_acl_head head;
570 const struct tomoyo_path_info *original_name;
571 const struct tomoyo_path_info *aggregated_name;
572 };
573
574 /* Structure for policy manager. */
575 struct tomoyo_manager {
576 struct tomoyo_acl_head head;
577 bool is_domain; /* True if manager is a domainname. */
578 /* A path to program or a domainname. */
579 const struct tomoyo_path_info *manager;
580 };
581
582 struct tomoyo_preference {
583 unsigned int learning_max_entry;
584 bool enforcing_verbose;
585 bool learning_verbose;
586 bool permissive_verbose;
587 };
588
589 /* Structure for /sys/kernel/security/tomnoyo/profile interface. */
590 struct tomoyo_profile {
591 const struct tomoyo_path_info *comment;
592 struct tomoyo_preference *learning;
593 struct tomoyo_preference *permissive;
594 struct tomoyo_preference *enforcing;
595 struct tomoyo_preference preference;
596 u8 default_config;
597 u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
598 unsigned int pref[TOMOYO_MAX_PREF];
599 };
600
601 /* Structure for representing YYYY/MM/DD hh/mm/ss. */
602 struct tomoyo_time {
603 u16 year;
604 u8 month;
605 u8 day;
606 u8 hour;
607 u8 min;
608 u8 sec;
609 };
610
611 /* Structure for policy namespace. */
612 struct tomoyo_policy_namespace {
613 /* Profile table. Memory is allocated as needed. */
614 struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES];
615 /* List of "struct tomoyo_group". */
616 struct list_head group_list[TOMOYO_MAX_GROUP];
617 /* List of policy. */
618 struct list_head policy_list[TOMOYO_MAX_POLICY];
619 /* The global ACL referred by "use_group" keyword. */
620 struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS];
621 /* List for connecting to tomoyo_namespace_list list. */
622 struct list_head namespace_list;
623 /* Profile version. Currently only 20100903 is defined. */
624 unsigned int profile_version;
625 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
626 const char *name;
627 };
628
629 /********** Function prototypes. **********/
630
631 bool tomoyo_compare_number_union(const unsigned long value,
632 const struct tomoyo_number_union *ptr);
633 bool tomoyo_condition(struct tomoyo_request_info *r,
634 const struct tomoyo_condition *cond);
635 bool tomoyo_correct_domain(const unsigned char *domainname);
636 bool tomoyo_correct_path(const char *filename);
637 bool tomoyo_correct_word(const char *string);
638 bool tomoyo_domain_def(const unsigned char *buffer);
639 bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
640 bool tomoyo_memory_ok(void *ptr);
641 bool tomoyo_number_matches_group(const unsigned long min,
642 const unsigned long max,
643 const struct tomoyo_group *group);
644 bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
645 struct tomoyo_name_union *ptr);
646 bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
647 struct tomoyo_number_union *ptr);
648 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
649 const struct tomoyo_path_info *pattern);
650 bool tomoyo_permstr(const char *string, const char *keyword);
651 bool tomoyo_str_starts(char **src, const char *find);
652 char *tomoyo_encode(const char *str);
653 char *tomoyo_init_log(struct tomoyo_request_info *r, int len, const char *fmt,
654 va_list args);
655 char *tomoyo_read_token(struct tomoyo_acl_param *param);
656 char *tomoyo_realpath_from_path(struct path *path);
657 char *tomoyo_realpath_nofollow(const char *pathname);
658 const char *tomoyo_get_exe(void);
659 const char *tomoyo_yesno(const unsigned int value);
660 const struct tomoyo_path_info *tomoyo_compare_name_union
661 (const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr);
662 const struct tomoyo_path_info *tomoyo_get_name(const char *name);
663 const struct tomoyo_path_info *tomoyo_path_matches_group
664 (const struct tomoyo_path_info *pathname, const struct tomoyo_group *group);
665 int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
666 struct path *path, const int flag);
667 int tomoyo_close_control(struct tomoyo_io_buffer *head);
668 int tomoyo_find_next_domain(struct linux_binprm *bprm);
669 int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
670 const u8 index);
671 int tomoyo_init_request_info(struct tomoyo_request_info *r,
672 struct tomoyo_domain_info *domain,
673 const u8 index);
674 int tomoyo_mkdev_perm(const u8 operation, struct path *path,
675 const unsigned int mode, unsigned int dev);
676 int tomoyo_mount_permission(char *dev_name, struct path *path,
677 const char *type, unsigned long flags,
678 void *data_page);
679 int tomoyo_open_control(const u8 type, struct file *file);
680 int tomoyo_path2_perm(const u8 operation, struct path *path1,
681 struct path *path2);
682 int tomoyo_path_number_perm(const u8 operation, struct path *path,
683 unsigned long number);
684 int tomoyo_path_perm(const u8 operation, struct path *path);
685 int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
686 const struct tomoyo_path_info *filename);
687 int tomoyo_poll_control(struct file *file, poll_table *wait);
688 int tomoyo_poll_log(struct file *file, poll_table *wait);
689 int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
690 __printf(2, 3);
691 int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
692 struct tomoyo_acl_param *param,
693 bool (*check_duplicate)
694 (const struct tomoyo_acl_info *,
695 const struct tomoyo_acl_info *),
696 bool (*merge_duplicate)
697 (struct tomoyo_acl_info *, struct tomoyo_acl_info *,
698 const bool));
699 int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
700 struct tomoyo_acl_param *param,
701 bool (*check_duplicate)
702 (const struct tomoyo_acl_head *,
703 const struct tomoyo_acl_head *));
704 int tomoyo_write_aggregator(struct tomoyo_acl_param *param);
705 int tomoyo_write_file(struct tomoyo_acl_param *param);
706 int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type);
707 int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
708 const u8 type);
709 ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
710 const int buffer_len);
711 ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
712 const char __user *buffer, const int buffer_len);
713 struct tomoyo_condition *tomoyo_get_condition(struct tomoyo_acl_param *param);
714 struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
715 const bool transit);
716 struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
717 struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
718 const u8 idx);
719 struct tomoyo_policy_namespace *tomoyo_assign_namespace
720 (const char *domainname);
721 struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
722 const u8 profile);
723 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
724 const u8 index);
725 u8 tomoyo_parse_ulong(unsigned long *result, char **str);
726 void *tomoyo_commit_ok(void *data, const unsigned int size);
727 void __init tomoyo_load_builtin_policy(void);
728 void __init tomoyo_mm_init(void);
729 void tomoyo_check_acl(struct tomoyo_request_info *r,
730 bool (*check_entry) (struct tomoyo_request_info *,
731 const struct tomoyo_acl_info *));
732 void tomoyo_check_profile(void);
733 void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp);
734 void tomoyo_del_condition(struct list_head *element);
735 void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
736 void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
737 void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
738 __printf(2, 3);
739 void tomoyo_load_policy(const char *filename);
740 void tomoyo_memory_free(void *ptr);
741 void tomoyo_normalize_line(unsigned char *buffer);
742 void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register);
743 void tomoyo_print_ulong(char *buffer, const int buffer_len,
744 const unsigned long value, const u8 type);
745 void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
746 void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
747 void tomoyo_read_log(struct tomoyo_io_buffer *head);
748 void tomoyo_update_stat(const u8 index);
749 void tomoyo_warn_oom(const char *function);
750 void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
751 __printf(2, 3);
752 void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
753 va_list args);
754
755 /********** External variable definitions. **********/
756
757 extern bool tomoyo_policy_loaded;
758 extern const char * const tomoyo_condition_keyword
759 [TOMOYO_MAX_CONDITION_KEYWORD];
760 extern const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS];
761 extern const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX
762 + TOMOYO_MAX_MAC_CATEGORY_INDEX];
763 extern const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE];
764 extern const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
765 extern const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX];
766 extern const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION];
767 extern const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION];
768 extern const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION];
769 extern struct list_head tomoyo_condition_list;
770 extern struct list_head tomoyo_domain_list;
771 extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
772 extern struct list_head tomoyo_namespace_list;
773 extern struct mutex tomoyo_policy_lock;
774 extern struct srcu_struct tomoyo_ss;
775 extern struct tomoyo_domain_info tomoyo_kernel_domain;
776 extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
777 extern unsigned int tomoyo_memory_quota[TOMOYO_MAX_MEMORY_STAT];
778 extern unsigned int tomoyo_memory_used[TOMOYO_MAX_MEMORY_STAT];
779
780 /********** Inlined functions. **********/
781
782 /**
783 * tomoyo_read_lock - Take lock for protecting policy.
784 *
785 * Returns index number for tomoyo_read_unlock().
786 */
787 static inline int tomoyo_read_lock(void)
788 {
789 return srcu_read_lock(&tomoyo_ss);
790 }
791
792 /**
793 * tomoyo_read_unlock - Release lock for protecting policy.
794 *
795 * @idx: Index number returned by tomoyo_read_lock().
796 *
797 * Returns nothing.
798 */
799 static inline void tomoyo_read_unlock(int idx)
800 {
801 srcu_read_unlock(&tomoyo_ss, idx);
802 }
803
804 /**
805 * tomoyo_sys_getppid - Copy of getppid().
806 *
807 * Returns parent process's PID.
808 *
809 * Alpha does not have getppid() defined. To be able to build this module on
810 * Alpha, I have to copy getppid() from kernel/timer.c.
811 */
812 static inline pid_t tomoyo_sys_getppid(void)
813 {
814 pid_t pid;
815 rcu_read_lock();
816 pid = task_tgid_vnr(current->real_parent);
817 rcu_read_unlock();
818 return pid;
819 }
820
821 /**
822 * tomoyo_sys_getpid - Copy of getpid().
823 *
824 * Returns current thread's PID.
825 *
826 * Alpha does not have getpid() defined. To be able to build this module on
827 * Alpha, I have to copy getpid() from kernel/timer.c.
828 */
829 static inline pid_t tomoyo_sys_getpid(void)
830 {
831 return task_tgid_vnr(current);
832 }
833
834 /**
835 * tomoyo_pathcmp - strcmp() for "struct tomoyo_path_info" structure.
836 *
837 * @a: Pointer to "struct tomoyo_path_info".
838 * @b: Pointer to "struct tomoyo_path_info".
839 *
840 * Returns true if @a == @b, false otherwise.
841 */
842 static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
843 const struct tomoyo_path_info *b)
844 {
845 return a->hash != b->hash || strcmp(a->name, b->name);
846 }
847
848 /**
849 * tomoyo_put_name - Drop reference on "struct tomoyo_name".
850 *
851 * @name: Pointer to "struct tomoyo_path_info". Maybe NULL.
852 *
853 * Returns nothing.
854 */
855 static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
856 {
857 if (name) {
858 struct tomoyo_name *ptr =
859 container_of(name, typeof(*ptr), entry);
860 atomic_dec(&ptr->head.users);
861 }
862 }
863
864 /**
865 * tomoyo_put_condition - Drop reference on "struct tomoyo_condition".
866 *
867 * @cond: Pointer to "struct tomoyo_condition". Maybe NULL.
868 *
869 * Returns nothing.
870 */
871 static inline void tomoyo_put_condition(struct tomoyo_condition *cond)
872 {
873 if (cond)
874 atomic_dec(&cond->head.users);
875 }
876
877 /**
878 * tomoyo_put_group - Drop reference on "struct tomoyo_group".
879 *
880 * @group: Pointer to "struct tomoyo_group". Maybe NULL.
881 *
882 * Returns nothing.
883 */
884 static inline void tomoyo_put_group(struct tomoyo_group *group)
885 {
886 if (group)
887 atomic_dec(&group->head.users);
888 }
889
890 /**
891 * tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
892 *
893 * Returns pointer to "struct tomoyo_domain_info" for current thread.
894 */
895 static inline struct tomoyo_domain_info *tomoyo_domain(void)
896 {
897 return current_cred()->security;
898 }
899
900 /**
901 * tomoyo_real_domain - Get "struct tomoyo_domain_info" for specified thread.
902 *
903 * @task: Pointer to "struct task_struct".
904 *
905 * Returns pointer to "struct tomoyo_security" for specified thread.
906 */
907 static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
908 *task)
909 {
910 return task_cred_xxx(task, security);
911 }
912
913 /**
914 * tomoyo_same_name_union - Check for duplicated "struct tomoyo_name_union" entry.
915 *
916 * @a: Pointer to "struct tomoyo_name_union".
917 * @b: Pointer to "struct tomoyo_name_union".
918 *
919 * Returns true if @a == @b, false otherwise.
920 */
921 static inline bool tomoyo_same_name_union
922 (const struct tomoyo_name_union *a, const struct tomoyo_name_union *b)
923 {
924 return a->filename == b->filename && a->group == b->group;
925 }
926
927 /**
928 * tomoyo_same_number_union - Check for duplicated "struct tomoyo_number_union" entry.
929 *
930 * @a: Pointer to "struct tomoyo_number_union".
931 * @b: Pointer to "struct tomoyo_number_union".
932 *
933 * Returns true if @a == @b, false otherwise.
934 */
935 static inline bool tomoyo_same_number_union
936 (const struct tomoyo_number_union *a, const struct tomoyo_number_union *b)
937 {
938 return a->values[0] == b->values[0] && a->values[1] == b->values[1] &&
939 a->group == b->group && a->value_type[0] == b->value_type[0] &&
940 a->value_type[1] == b->value_type[1];
941 }
942
943 /**
944 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
945 *
946 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
947 */
948 static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void)
949 {
950 return tomoyo_domain()->ns;
951 }
952
953 #if defined(CONFIG_SLOB)
954
955 /**
956 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
957 *
958 * @size: Size to be rounded up.
959 *
960 * Returns @size.
961 *
962 * Since SLOB does not round up, this function simply returns @size.
963 */
964 static inline int tomoyo_round2(size_t size)
965 {
966 return size;
967 }
968
969 #else
970
971 /**
972 * tomoyo_round2 - Round up to power of 2 for calculating memory usage.
973 *
974 * @size: Size to be rounded up.
975 *
976 * Returns rounded size.
977 *
978 * Strictly speaking, SLAB may be able to allocate (e.g.) 96 bytes instead of
979 * (e.g.) 128 bytes.
980 */
981 static inline int tomoyo_round2(size_t size)
982 {
983 #if PAGE_SIZE == 4096
984 size_t bsize = 32;
985 #else
986 size_t bsize = 64;
987 #endif
988 if (!size)
989 return 0;
990 while (size > bsize)
991 bsize <<= 1;
992 return bsize;
993 }
994
995 #endif
996
997 /**
998 * list_for_each_cookie - iterate over a list with cookie.
999 * @pos: the &struct list_head to use as a loop cursor.
1000 * @head: the head for your list.
1001 */
1002 #define list_for_each_cookie(pos, head) \
1003 if (!pos) \
1004 pos = srcu_dereference((head)->next, &tomoyo_ss); \
1005 for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
1006
1007 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */
This page took 0.051831 seconds and 6 git commands to generate.