2 * security/tomoyo/common.c
4 * Common functions for TOMOYO.
6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
9 #include <linux/uaccess.h>
10 #include <linux/slab.h>
11 #include <linux/security.h>
14 /* String table for operation mode. */
15 const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE] = {
16 [TOMOYO_CONFIG_DISABLED] = "disabled",
17 [TOMOYO_CONFIG_LEARNING] = "learning",
18 [TOMOYO_CONFIG_PERMISSIVE] = "permissive",
19 [TOMOYO_CONFIG_ENFORCING] = "enforcing"
22 /* String table for /sys/kernel/security/tomoyo/profile */
23 const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX
24 + TOMOYO_MAX_MAC_CATEGORY_INDEX] = {
25 [TOMOYO_MAC_FILE_EXECUTE] = "execute",
26 [TOMOYO_MAC_FILE_OPEN] = "open",
27 [TOMOYO_MAC_FILE_CREATE] = "create",
28 [TOMOYO_MAC_FILE_UNLINK] = "unlink",
29 [TOMOYO_MAC_FILE_GETATTR] = "getattr",
30 [TOMOYO_MAC_FILE_MKDIR] = "mkdir",
31 [TOMOYO_MAC_FILE_RMDIR] = "rmdir",
32 [TOMOYO_MAC_FILE_MKFIFO] = "mkfifo",
33 [TOMOYO_MAC_FILE_MKSOCK] = "mksock",
34 [TOMOYO_MAC_FILE_TRUNCATE] = "truncate",
35 [TOMOYO_MAC_FILE_SYMLINK] = "symlink",
36 [TOMOYO_MAC_FILE_MKBLOCK] = "mkblock",
37 [TOMOYO_MAC_FILE_MKCHAR] = "mkchar",
38 [TOMOYO_MAC_FILE_LINK] = "link",
39 [TOMOYO_MAC_FILE_RENAME] = "rename",
40 [TOMOYO_MAC_FILE_CHMOD] = "chmod",
41 [TOMOYO_MAC_FILE_CHOWN] = "chown",
42 [TOMOYO_MAC_FILE_CHGRP] = "chgrp",
43 [TOMOYO_MAC_FILE_IOCTL] = "ioctl",
44 [TOMOYO_MAC_FILE_CHROOT] = "chroot",
45 [TOMOYO_MAC_FILE_MOUNT] = "mount",
46 [TOMOYO_MAC_FILE_UMOUNT] = "unmount",
47 [TOMOYO_MAC_FILE_PIVOT_ROOT] = "pivot_root",
48 [TOMOYO_MAX_MAC_INDEX + TOMOYO_MAC_CATEGORY_FILE] = "file",
51 /* String table for conditions. */
52 const char * const tomoyo_condition_keyword[TOMOYO_MAX_CONDITION_KEYWORD] = {
53 [TOMOYO_TASK_UID] = "task.uid",
54 [TOMOYO_TASK_EUID] = "task.euid",
55 [TOMOYO_TASK_SUID] = "task.suid",
56 [TOMOYO_TASK_FSUID] = "task.fsuid",
57 [TOMOYO_TASK_GID] = "task.gid",
58 [TOMOYO_TASK_EGID] = "task.egid",
59 [TOMOYO_TASK_SGID] = "task.sgid",
60 [TOMOYO_TASK_FSGID] = "task.fsgid",
61 [TOMOYO_TASK_PID] = "task.pid",
62 [TOMOYO_TASK_PPID] = "task.ppid",
65 /* String table for PREFERENCE keyword. */
66 static const char * const tomoyo_pref_keywords[TOMOYO_MAX_PREF] = {
67 [TOMOYO_PREF_MAX_AUDIT_LOG] = "max_audit_log",
68 [TOMOYO_PREF_MAX_LEARNING_ENTRY] = "max_learning_entry",
71 /* String table for path operation. */
72 const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = {
73 [TOMOYO_TYPE_EXECUTE] = "execute",
74 [TOMOYO_TYPE_READ] = "read",
75 [TOMOYO_TYPE_WRITE] = "write",
76 [TOMOYO_TYPE_APPEND] = "append",
77 [TOMOYO_TYPE_UNLINK] = "unlink",
78 [TOMOYO_TYPE_GETATTR] = "getattr",
79 [TOMOYO_TYPE_RMDIR] = "rmdir",
80 [TOMOYO_TYPE_TRUNCATE] = "truncate",
81 [TOMOYO_TYPE_SYMLINK] = "symlink",
82 [TOMOYO_TYPE_CHROOT] = "chroot",
83 [TOMOYO_TYPE_UMOUNT] = "unmount",
86 /* String table for categories. */
87 static const char * const tomoyo_category_keywords
88 [TOMOYO_MAX_MAC_CATEGORY_INDEX] = {
89 [TOMOYO_MAC_CATEGORY_FILE] = "file",
92 /* Permit policy management by non-root user? */
93 static bool tomoyo_manage_by_non_root;
95 /* Utility functions. */
98 * tomoyo_yesno - Return "yes" or "no".
100 * @value: Bool value.
102 const char *tomoyo_yesno(const unsigned int value)
104 return value ? "yes" : "no";
108 * tomoyo_addprintf - strncat()-like-snprintf().
110 * @buffer: Buffer to write to. Must be '\0'-terminated.
111 * @len: Size of @buffer.
112 * @fmt: The printf()'s format string, followed by parameters.
116 static void tomoyo_addprintf(char *buffer, int len, const char *fmt, ...)
119 const int pos = strlen(buffer);
121 vsnprintf(buffer + pos, len - pos - 1, fmt, args);
126 * tomoyo_flush - Flush queued string to userspace's buffer.
128 * @head: Pointer to "struct tomoyo_io_buffer".
130 * Returns true if all data was flushed, false otherwise.
132 static bool tomoyo_flush(struct tomoyo_io_buffer *head)
134 while (head->r.w_pos) {
135 const char *w = head->r.w[0];
136 size_t len = strlen(w);
138 if (len > head->read_user_buf_avail)
139 len = head->read_user_buf_avail;
142 if (copy_to_user(head->read_user_buf, w, len))
144 head->read_user_buf_avail -= len;
145 head->read_user_buf += len;
151 /* Add '\0' for audit logs and query. */
153 if (!head->read_user_buf_avail ||
154 copy_to_user(head->read_user_buf, "", 1))
156 head->read_user_buf_avail--;
157 head->read_user_buf++;
160 for (len = 0; len < head->r.w_pos; len++)
161 head->r.w[len] = head->r.w[len + 1];
168 * tomoyo_set_string - Queue string to "struct tomoyo_io_buffer" structure.
170 * @head: Pointer to "struct tomoyo_io_buffer".
171 * @string: String to print.
173 * Note that @string has to be kept valid until @head is kfree()d.
174 * This means that char[] allocated on stack memory cannot be passed to
175 * this function. Use tomoyo_io_printf() for char[] allocated on stack memory.
177 static void tomoyo_set_string(struct tomoyo_io_buffer *head, const char *string)
179 if (head->r.w_pos < TOMOYO_MAX_IO_READ_QUEUE) {
180 head->r.w[head->r.w_pos++] = string;
187 * tomoyo_io_printf - printf() to "struct tomoyo_io_buffer" structure.
189 * @head: Pointer to "struct tomoyo_io_buffer".
190 * @fmt: The printf()'s format string, followed by parameters.
192 void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
196 size_t pos = head->r.avail;
197 int size = head->readbuf_size - pos;
201 len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1;
203 if (pos + len >= head->readbuf_size) {
207 head->r.avail += len;
208 tomoyo_set_string(head, head->read_buf + pos);
212 * tomoyo_set_space - Put a space to "struct tomoyo_io_buffer" structure.
214 * @head: Pointer to "struct tomoyo_io_buffer".
218 static void tomoyo_set_space(struct tomoyo_io_buffer *head)
220 tomoyo_set_string(head, " ");
224 * tomoyo_set_lf - Put a line feed to "struct tomoyo_io_buffer" structure.
226 * @head: Pointer to "struct tomoyo_io_buffer".
230 static bool tomoyo_set_lf(struct tomoyo_io_buffer *head)
232 tomoyo_set_string(head, "\n");
233 return !head->r.w_pos;
237 * tomoyo_set_slash - Put a shash to "struct tomoyo_io_buffer" structure.
239 * @head: Pointer to "struct tomoyo_io_buffer".
243 static void tomoyo_set_slash(struct tomoyo_io_buffer *head)
245 tomoyo_set_string(head, "/");
248 /* List of namespaces. */
249 LIST_HEAD(tomoyo_namespace_list);
250 /* True if namespace other than tomoyo_kernel_namespace is defined. */
251 static bool tomoyo_namespace_enabled;
254 * tomoyo_init_policy_namespace - Initialize namespace.
256 * @ns: Pointer to "struct tomoyo_policy_namespace".
260 void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns)
263 for (idx = 0; idx < TOMOYO_MAX_ACL_GROUPS; idx++)
264 INIT_LIST_HEAD(&ns->acl_group[idx]);
265 for (idx = 0; idx < TOMOYO_MAX_GROUP; idx++)
266 INIT_LIST_HEAD(&ns->group_list[idx]);
267 for (idx = 0; idx < TOMOYO_MAX_POLICY; idx++)
268 INIT_LIST_HEAD(&ns->policy_list[idx]);
269 ns->profile_version = 20100903;
270 tomoyo_namespace_enabled = !list_empty(&tomoyo_namespace_list);
271 list_add_tail_rcu(&ns->namespace_list, &tomoyo_namespace_list);
275 * tomoyo_print_namespace - Print namespace header.
277 * @head: Pointer to "struct tomoyo_io_buffer".
281 static void tomoyo_print_namespace(struct tomoyo_io_buffer *head)
283 if (!tomoyo_namespace_enabled)
285 tomoyo_set_string(head,
286 container_of(head->r.ns,
287 struct tomoyo_policy_namespace,
288 namespace_list)->name);
289 tomoyo_set_space(head);
293 * tomoyo_print_name_union - Print a tomoyo_name_union.
295 * @head: Pointer to "struct tomoyo_io_buffer".
296 * @ptr: Pointer to "struct tomoyo_name_union".
298 static void tomoyo_print_name_union(struct tomoyo_io_buffer *head,
299 const struct tomoyo_name_union *ptr)
301 tomoyo_set_space(head);
303 tomoyo_set_string(head, "@");
304 tomoyo_set_string(head, ptr->group->group_name->name);
306 tomoyo_set_string(head, ptr->filename->name);
311 * tomoyo_print_number_union_nospace - Print a tomoyo_number_union without a space.
313 * @head: Pointer to "struct tomoyo_io_buffer".
314 * @ptr: Pointer to "struct tomoyo_number_union".
318 static void tomoyo_print_number_union_nospace
319 (struct tomoyo_io_buffer *head, const struct tomoyo_number_union *ptr)
322 tomoyo_set_string(head, "@");
323 tomoyo_set_string(head, ptr->group->group_name->name);
326 unsigned long min = ptr->values[0];
327 const unsigned long max = ptr->values[1];
328 u8 min_type = ptr->value_type[0];
329 const u8 max_type = ptr->value_type[1];
332 for (i = 0; i < 2; i++) {
334 case TOMOYO_VALUE_TYPE_HEXADECIMAL:
335 tomoyo_addprintf(buffer, sizeof(buffer),
338 case TOMOYO_VALUE_TYPE_OCTAL:
339 tomoyo_addprintf(buffer, sizeof(buffer),
343 tomoyo_addprintf(buffer, sizeof(buffer), "%lu",
347 if (min == max && min_type == max_type)
349 tomoyo_addprintf(buffer, sizeof(buffer), "-");
353 tomoyo_io_printf(head, "%s", buffer);
358 * tomoyo_print_number_union - Print a tomoyo_number_union.
360 * @head: Pointer to "struct tomoyo_io_buffer".
361 * @ptr: Pointer to "struct tomoyo_number_union".
365 static void tomoyo_print_number_union(struct tomoyo_io_buffer *head,
366 const struct tomoyo_number_union *ptr)
368 tomoyo_set_space(head);
369 tomoyo_print_number_union_nospace(head, ptr);
373 * tomoyo_assign_profile - Create a new profile.
375 * @ns: Pointer to "struct tomoyo_policy_namespace".
376 * @profile: Profile number to create.
378 * Returns pointer to "struct tomoyo_profile" on success, NULL otherwise.
380 static struct tomoyo_profile *tomoyo_assign_profile
381 (struct tomoyo_policy_namespace *ns, const unsigned int profile)
383 struct tomoyo_profile *ptr;
384 struct tomoyo_profile *entry;
385 if (profile >= TOMOYO_MAX_PROFILES)
387 ptr = ns->profile_ptr[profile];
390 entry = kzalloc(sizeof(*entry), GFP_NOFS);
391 if (mutex_lock_interruptible(&tomoyo_policy_lock))
393 ptr = ns->profile_ptr[profile];
394 if (!ptr && tomoyo_memory_ok(entry)) {
396 ptr->default_config = TOMOYO_CONFIG_DISABLED |
397 TOMOYO_CONFIG_WANT_GRANT_LOG |
398 TOMOYO_CONFIG_WANT_REJECT_LOG;
399 memset(ptr->config, TOMOYO_CONFIG_USE_DEFAULT,
400 sizeof(ptr->config));
401 ptr->pref[TOMOYO_PREF_MAX_AUDIT_LOG] = 1024;
402 ptr->pref[TOMOYO_PREF_MAX_LEARNING_ENTRY] = 2048;
403 mb(); /* Avoid out-of-order execution. */
404 ns->profile_ptr[profile] = ptr;
407 mutex_unlock(&tomoyo_policy_lock);
414 * tomoyo_profile - Find a profile.
416 * @ns: Pointer to "struct tomoyo_policy_namespace".
417 * @profile: Profile number to find.
419 * Returns pointer to "struct tomoyo_profile".
421 struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
424 static struct tomoyo_profile tomoyo_null_profile;
425 struct tomoyo_profile *ptr = ns->profile_ptr[profile];
427 ptr = &tomoyo_null_profile;
432 * tomoyo_find_yesno - Find values for specified keyword.
434 * @string: String to check.
435 * @find: Name of keyword.
437 * Returns 1 if "@find=yes" was found, 0 if "@find=no" was found, -1 otherwise.
439 static s8 tomoyo_find_yesno(const char *string, const char *find)
441 const char *cp = strstr(string, find);
444 if (!strncmp(cp, "=yes", 4))
446 else if (!strncmp(cp, "=no", 3))
453 * tomoyo_set_uint - Set value for specified preference.
455 * @i: Pointer to "unsigned int".
456 * @string: String to check.
457 * @find: Name of keyword.
461 static void tomoyo_set_uint(unsigned int *i, const char *string,
464 const char *cp = strstr(string, find);
466 sscanf(cp + strlen(find), "=%u", i);
470 * tomoyo_set_mode - Set mode for specified profile.
472 * @name: Name of functionality.
473 * @value: Mode for @name.
474 * @profile: Pointer to "struct tomoyo_profile".
476 * Returns 0 on success, negative value otherwise.
478 static int tomoyo_set_mode(char *name, const char *value,
479 struct tomoyo_profile *profile)
483 if (!strcmp(name, "CONFIG")) {
484 i = TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX;
485 config = profile->default_config;
486 } else if (tomoyo_str_starts(&name, "CONFIG::")) {
488 for (i = 0; i < TOMOYO_MAX_MAC_INDEX
489 + TOMOYO_MAX_MAC_CATEGORY_INDEX; i++) {
491 if (i < TOMOYO_MAX_MAC_INDEX) {
492 const u8 c = tomoyo_index2category[i];
493 const char *category =
494 tomoyo_category_keywords[c];
495 len = strlen(category);
496 if (strncmp(name, category, len) ||
497 name[len++] != ':' || name[len++] != ':')
500 if (strcmp(name + len, tomoyo_mac_keywords[i]))
502 config = profile->config[i];
505 if (i == TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX)
510 if (strstr(value, "use_default")) {
511 config = TOMOYO_CONFIG_USE_DEFAULT;
514 for (mode = 0; mode < 4; mode++)
515 if (strstr(value, tomoyo_mode[mode]))
517 * Update lower 3 bits in order to distinguish
518 * 'config' from 'TOMOYO_CONFIG_USE_DEAFULT'.
520 config = (config & ~7) | mode;
521 if (config != TOMOYO_CONFIG_USE_DEFAULT) {
522 switch (tomoyo_find_yesno(value, "grant_log")) {
524 config |= TOMOYO_CONFIG_WANT_GRANT_LOG;
527 config &= ~TOMOYO_CONFIG_WANT_GRANT_LOG;
530 switch (tomoyo_find_yesno(value, "reject_log")) {
532 config |= TOMOYO_CONFIG_WANT_REJECT_LOG;
535 config &= ~TOMOYO_CONFIG_WANT_REJECT_LOG;
540 if (i < TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX)
541 profile->config[i] = config;
542 else if (config != TOMOYO_CONFIG_USE_DEFAULT)
543 profile->default_config = config;
548 * tomoyo_write_profile - Write profile table.
550 * @head: Pointer to "struct tomoyo_io_buffer".
552 * Returns 0 on success, negative value otherwise.
554 static int tomoyo_write_profile(struct tomoyo_io_buffer *head)
556 char *data = head->write_buf;
559 struct tomoyo_profile *profile;
560 if (sscanf(data, "PROFILE_VERSION=%u", &head->w.ns->profile_version)
563 i = simple_strtoul(data, &cp, 10);
567 profile = tomoyo_assign_profile(head->w.ns, i);
570 cp = strchr(data, '=');
574 if (!strcmp(data, "COMMENT")) {
575 static DEFINE_SPINLOCK(lock);
576 const struct tomoyo_path_info *new_comment
577 = tomoyo_get_name(cp);
578 const struct tomoyo_path_info *old_comment;
582 old_comment = profile->comment;
583 profile->comment = new_comment;
585 tomoyo_put_name(old_comment);
588 if (!strcmp(data, "PREFERENCE")) {
589 for (i = 0; i < TOMOYO_MAX_PREF; i++)
590 tomoyo_set_uint(&profile->pref[i], cp,
591 tomoyo_pref_keywords[i]);
594 return tomoyo_set_mode(data, cp, profile);
598 * tomoyo_print_config - Print mode for specified functionality.
600 * @head: Pointer to "struct tomoyo_io_buffer".
601 * @config: Mode for that functionality.
605 * Caller prints functionality's name.
607 static void tomoyo_print_config(struct tomoyo_io_buffer *head, const u8 config)
609 tomoyo_io_printf(head, "={ mode=%s grant_log=%s reject_log=%s }\n",
610 tomoyo_mode[config & 3],
611 tomoyo_yesno(config & TOMOYO_CONFIG_WANT_GRANT_LOG),
612 tomoyo_yesno(config & TOMOYO_CONFIG_WANT_REJECT_LOG));
616 * tomoyo_read_profile - Read profile table.
618 * @head: Pointer to "struct tomoyo_io_buffer".
622 static void tomoyo_read_profile(struct tomoyo_io_buffer *head)
625 struct tomoyo_policy_namespace *ns =
626 container_of(head->r.ns, typeof(*ns), namespace_list);
627 const struct tomoyo_profile *profile;
631 index = head->r.index;
632 profile = ns->profile_ptr[index];
633 switch (head->r.step) {
635 tomoyo_print_namespace(head);
636 tomoyo_io_printf(head, "PROFILE_VERSION=%u\n",
637 ns->profile_version);
641 for ( ; head->r.index < TOMOYO_MAX_PROFILES;
643 if (ns->profile_ptr[head->r.index])
645 if (head->r.index == TOMOYO_MAX_PROFILES)
652 const struct tomoyo_path_info *comment =
654 tomoyo_print_namespace(head);
655 tomoyo_io_printf(head, "%u-COMMENT=", index);
656 tomoyo_set_string(head, comment ? comment->name : "");
658 tomoyo_io_printf(head, "%u-PREFERENCE={ ", index);
659 for (i = 0; i < TOMOYO_MAX_PREF; i++)
660 tomoyo_io_printf(head, "%s=%u ",
661 tomoyo_pref_keywords[i],
663 tomoyo_set_string(head, "}\n");
669 tomoyo_print_namespace(head);
670 tomoyo_io_printf(head, "%u-%s", index, "CONFIG");
671 tomoyo_print_config(head, profile->default_config);
677 for ( ; head->r.bit < TOMOYO_MAX_MAC_INDEX
678 + TOMOYO_MAX_MAC_CATEGORY_INDEX; head->r.bit++) {
679 const u8 i = head->r.bit;
680 const u8 config = profile->config[i];
681 if (config == TOMOYO_CONFIG_USE_DEFAULT)
683 tomoyo_print_namespace(head);
684 if (i < TOMOYO_MAX_MAC_INDEX)
685 tomoyo_io_printf(head, "%u-CONFIG::%s::%s",
687 tomoyo_category_keywords
688 [tomoyo_index2category[i]],
689 tomoyo_mac_keywords[i]);
691 tomoyo_io_printf(head, "%u-CONFIG::%s", index,
692 tomoyo_mac_keywords[i]);
693 tomoyo_print_config(head, config);
697 if (head->r.bit == TOMOYO_MAX_MAC_INDEX
698 + TOMOYO_MAX_MAC_CATEGORY_INDEX) {
704 if (tomoyo_flush(head))
708 static bool tomoyo_same_manager(const struct tomoyo_acl_head *a,
709 const struct tomoyo_acl_head *b)
711 return container_of(a, struct tomoyo_manager, head)->manager ==
712 container_of(b, struct tomoyo_manager, head)->manager;
716 * tomoyo_update_manager_entry - Add a manager entry.
718 * @manager: The path to manager or the domainnamme.
719 * @is_delete: True if it is a delete request.
721 * Returns 0 on success, negative value otherwise.
723 * Caller holds tomoyo_read_lock().
725 static int tomoyo_update_manager_entry(const char *manager,
726 const bool is_delete)
728 struct tomoyo_manager e = { };
729 struct tomoyo_acl_param param = {
730 /* .ns = &tomoyo_kernel_namespace, */
731 .is_delete = is_delete,
732 .list = &tomoyo_kernel_namespace.
733 policy_list[TOMOYO_ID_MANAGER],
735 int error = is_delete ? -ENOENT : -ENOMEM;
736 if (tomoyo_domain_def(manager)) {
737 if (!tomoyo_correct_domain(manager))
741 if (!tomoyo_correct_path(manager))
744 e.manager = tomoyo_get_name(manager);
746 error = tomoyo_update_policy(&e.head, sizeof(e), ¶m,
747 tomoyo_same_manager);
748 tomoyo_put_name(e.manager);
754 * tomoyo_write_manager - Write manager policy.
756 * @head: Pointer to "struct tomoyo_io_buffer".
758 * Returns 0 on success, negative value otherwise.
760 * Caller holds tomoyo_read_lock().
762 static int tomoyo_write_manager(struct tomoyo_io_buffer *head)
764 char *data = head->write_buf;
766 if (!strcmp(data, "manage_by_non_root")) {
767 tomoyo_manage_by_non_root = !head->w.is_delete;
770 return tomoyo_update_manager_entry(data, head->w.is_delete);
774 * tomoyo_read_manager - Read manager policy.
776 * @head: Pointer to "struct tomoyo_io_buffer".
778 * Caller holds tomoyo_read_lock().
780 static void tomoyo_read_manager(struct tomoyo_io_buffer *head)
784 list_for_each_cookie(head->r.acl, &tomoyo_kernel_namespace.
785 policy_list[TOMOYO_ID_MANAGER]) {
786 struct tomoyo_manager *ptr =
787 list_entry(head->r.acl, typeof(*ptr), head.list);
788 if (ptr->head.is_deleted)
790 if (!tomoyo_flush(head))
792 tomoyo_set_string(head, ptr->manager->name);
799 * tomoyo_manager - Check whether the current process is a policy manager.
801 * Returns true if the current process is permitted to modify policy
802 * via /sys/kernel/security/tomoyo/ interface.
804 * Caller holds tomoyo_read_lock().
806 static bool tomoyo_manager(void)
808 struct tomoyo_manager *ptr;
810 const struct task_struct *task = current;
811 const struct tomoyo_path_info *domainname = tomoyo_domain()->domainname;
814 if (!tomoyo_policy_loaded)
816 if (!tomoyo_manage_by_non_root && (task->cred->uid || task->cred->euid))
818 list_for_each_entry_rcu(ptr, &tomoyo_kernel_namespace.
819 policy_list[TOMOYO_ID_MANAGER], head.list) {
820 if (!ptr->head.is_deleted && ptr->is_domain
821 && !tomoyo_pathcmp(domainname, ptr->manager)) {
828 exe = tomoyo_get_exe();
831 list_for_each_entry_rcu(ptr, &tomoyo_kernel_namespace.
832 policy_list[TOMOYO_ID_MANAGER], head.list) {
833 if (!ptr->head.is_deleted && !ptr->is_domain
834 && !strcmp(exe, ptr->manager->name)) {
839 if (!found) { /* Reduce error messages. */
840 static pid_t last_pid;
841 const pid_t pid = current->pid;
842 if (last_pid != pid) {
843 printk(KERN_WARNING "%s ( %s ) is not permitted to "
844 "update policies.\n", domainname->name, exe);
853 * tomoyo_select_domain - Parse select command.
855 * @head: Pointer to "struct tomoyo_io_buffer".
856 * @data: String to parse.
858 * Returns true on success, false otherwise.
860 * Caller holds tomoyo_read_lock().
862 static bool tomoyo_select_domain(struct tomoyo_io_buffer *head,
866 struct tomoyo_domain_info *domain = NULL;
867 bool global_pid = false;
868 if (strncmp(data, "select ", 7))
871 if (sscanf(data, "pid=%u", &pid) == 1 ||
872 (global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) {
873 struct task_struct *p;
875 read_lock(&tasklist_lock);
877 p = find_task_by_pid_ns(pid, &init_pid_ns);
879 p = find_task_by_vpid(pid);
881 domain = tomoyo_real_domain(p);
882 read_unlock(&tasklist_lock);
884 } else if (!strncmp(data, "domain=", 7)) {
885 if (tomoyo_domain_def(data + 7))
886 domain = tomoyo_find_domain(data + 7);
889 head->w.domain = domain;
890 /* Accessing read_buf is safe because head->io_sem is held. */
892 return true; /* Do nothing if open(O_WRONLY). */
893 memset(&head->r, 0, sizeof(head->r));
894 head->r.print_this_domain_only = true;
896 head->r.domain = &domain->list;
899 tomoyo_io_printf(head, "# select %s\n", data);
900 if (domain && domain->is_deleted)
901 tomoyo_io_printf(head, "# This is a deleted domain.\n");
906 * tomoyo_delete_domain - Delete a domain.
908 * @domainname: The name of domain.
912 * Caller holds tomoyo_read_lock().
914 static int tomoyo_delete_domain(char *domainname)
916 struct tomoyo_domain_info *domain;
917 struct tomoyo_path_info name;
919 name.name = domainname;
920 tomoyo_fill_path_info(&name);
921 if (mutex_lock_interruptible(&tomoyo_policy_lock))
923 /* Is there an active domain? */
924 list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
925 /* Never delete tomoyo_kernel_domain */
926 if (domain == &tomoyo_kernel_domain)
928 if (domain->is_deleted ||
929 tomoyo_pathcmp(domain->domainname, &name))
931 domain->is_deleted = true;
934 mutex_unlock(&tomoyo_policy_lock);
939 * tomoyo_write_domain2 - Write domain policy.
941 * @ns: Pointer to "struct tomoyo_policy_namespace".
942 * @list: Pointer to "struct list_head".
943 * @data: Policy to be interpreted.
944 * @is_delete: True if it is a delete request.
946 * Returns 0 on success, negative value otherwise.
948 * Caller holds tomoyo_read_lock().
950 static int tomoyo_write_domain2(struct tomoyo_policy_namespace *ns,
951 struct list_head *list, char *data,
952 const bool is_delete)
954 struct tomoyo_acl_param param = {
958 .is_delete = is_delete,
960 static const struct {
962 int (*write) (struct tomoyo_acl_param *);
963 } tomoyo_callback[1] = {
964 { "file ", tomoyo_write_file },
967 for (i = 0; i < 1; i++) {
968 if (!tomoyo_str_starts(¶m.data,
969 tomoyo_callback[i].keyword))
971 return tomoyo_callback[i].write(¶m);
976 /* String table for domain flags. */
977 const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS] = {
978 [TOMOYO_DIF_QUOTA_WARNED] = "quota_exceeded\n",
979 [TOMOYO_DIF_TRANSITION_FAILED] = "transition_failed\n",
983 * tomoyo_write_domain - Write domain policy.
985 * @head: Pointer to "struct tomoyo_io_buffer".
987 * Returns 0 on success, negative value otherwise.
989 * Caller holds tomoyo_read_lock().
991 static int tomoyo_write_domain(struct tomoyo_io_buffer *head)
993 char *data = head->write_buf;
994 struct tomoyo_policy_namespace *ns;
995 struct tomoyo_domain_info *domain = head->w.domain;
996 const bool is_delete = head->w.is_delete;
997 bool is_select = !is_delete && tomoyo_str_starts(&data, "select ");
998 unsigned int profile;
1002 tomoyo_delete_domain(data);
1004 domain = tomoyo_find_domain(data);
1006 domain = tomoyo_assign_domain(data, false);
1007 head->w.domain = domain;
1013 if (sscanf(data, "use_profile %u", &profile) == 1
1014 && profile < TOMOYO_MAX_PROFILES) {
1015 if (!tomoyo_policy_loaded || ns->profile_ptr[profile])
1016 domain->profile = (u8) profile;
1019 if (sscanf(data, "use_group %u\n", &profile) == 1
1020 && profile < TOMOYO_MAX_ACL_GROUPS) {
1022 domain->group = (u8) profile;
1025 for (profile = 0; profile < TOMOYO_MAX_DOMAIN_INFO_FLAGS; profile++) {
1026 const char *cp = tomoyo_dif[profile];
1027 if (strncmp(data, cp, strlen(cp) - 1))
1029 domain->flags[profile] = !is_delete;
1032 return tomoyo_write_domain2(ns, &domain->acl_info_list, data,
1037 * tomoyo_print_condition - Print condition part.
1039 * @head: Pointer to "struct tomoyo_io_buffer".
1040 * @cond: Pointer to "struct tomoyo_condition".
1042 * Returns true on success, false otherwise.
1044 static bool tomoyo_print_condition(struct tomoyo_io_buffer *head,
1045 const struct tomoyo_condition *cond)
1047 switch (head->r.cond_step) {
1049 head->r.cond_index = 0;
1050 head->r.cond_step++;
1054 const u16 condc = cond->condc;
1055 const struct tomoyo_condition_element *condp =
1056 (typeof(condp)) (cond + 1);
1057 const struct tomoyo_number_union *numbers_p =
1058 (typeof(numbers_p)) (condp + condc);
1060 for (skip = 0; skip < head->r.cond_index; skip++) {
1061 const u8 left = condp->left;
1062 const u8 right = condp->right;
1065 case TOMOYO_NUMBER_UNION:
1070 case TOMOYO_NUMBER_UNION:
1075 while (head->r.cond_index < condc) {
1076 const u8 match = condp->equals;
1077 const u8 left = condp->left;
1078 const u8 right = condp->right;
1079 if (!tomoyo_flush(head))
1082 head->r.cond_index++;
1083 tomoyo_set_space(head);
1085 case TOMOYO_NUMBER_UNION:
1086 tomoyo_print_number_union_nospace
1087 (head, numbers_p++);
1090 tomoyo_set_string(head,
1091 tomoyo_condition_keyword[left]);
1094 tomoyo_set_string(head, match ? "=" : "!=");
1096 case TOMOYO_NUMBER_UNION:
1097 tomoyo_print_number_union_nospace
1098 (head, numbers_p++);
1101 tomoyo_set_string(head,
1102 tomoyo_condition_keyword[right]);
1107 head->r.cond_step++;
1110 if (!tomoyo_flush(head))
1112 head->r.cond_step++;
1115 tomoyo_set_lf(head);
1122 * tomoyo_set_group - Print "acl_group " header keyword and category name.
1124 * @head: Pointer to "struct tomoyo_io_buffer".
1125 * @category: Category name.
1129 static void tomoyo_set_group(struct tomoyo_io_buffer *head,
1130 const char *category)
1132 if (head->type == TOMOYO_EXCEPTIONPOLICY) {
1133 tomoyo_print_namespace(head);
1134 tomoyo_io_printf(head, "acl_group %u ",
1135 head->r.acl_group_index);
1137 tomoyo_set_string(head, category);
1141 * tomoyo_print_entry - Print an ACL entry.
1143 * @head: Pointer to "struct tomoyo_io_buffer".
1144 * @acl: Pointer to an ACL entry.
1146 * Returns true on success, false otherwise.
1148 static bool tomoyo_print_entry(struct tomoyo_io_buffer *head,
1149 struct tomoyo_acl_info *acl)
1151 const u8 acl_type = acl->type;
1155 if (head->r.print_cond_part)
1156 goto print_cond_part;
1157 if (acl->is_deleted)
1159 if (!tomoyo_flush(head))
1161 else if (acl_type == TOMOYO_TYPE_PATH_ACL) {
1162 struct tomoyo_path_acl *ptr =
1163 container_of(acl, typeof(*ptr), head);
1164 const u16 perm = ptr->perm;
1165 for (bit = 0; bit < TOMOYO_MAX_PATH_OPERATION; bit++) {
1166 if (!(perm & (1 << bit)))
1168 if (head->r.print_transition_related_only &&
1169 bit != TOMOYO_TYPE_EXECUTE)
1172 tomoyo_set_group(head, "file ");
1175 tomoyo_set_slash(head);
1177 tomoyo_set_string(head, tomoyo_path_keyword[bit]);
1181 tomoyo_print_name_union(head, &ptr->name);
1182 } else if (head->r.print_transition_related_only) {
1184 } else if (acl_type == TOMOYO_TYPE_PATH2_ACL) {
1185 struct tomoyo_path2_acl *ptr =
1186 container_of(acl, typeof(*ptr), head);
1187 const u8 perm = ptr->perm;
1188 for (bit = 0; bit < TOMOYO_MAX_PATH2_OPERATION; bit++) {
1189 if (!(perm & (1 << bit)))
1192 tomoyo_set_group(head, "file ");
1195 tomoyo_set_slash(head);
1197 tomoyo_set_string(head, tomoyo_mac_keywords
1198 [tomoyo_pp2mac[bit]]);
1202 tomoyo_print_name_union(head, &ptr->name1);
1203 tomoyo_print_name_union(head, &ptr->name2);
1204 } else if (acl_type == TOMOYO_TYPE_PATH_NUMBER_ACL) {
1205 struct tomoyo_path_number_acl *ptr =
1206 container_of(acl, typeof(*ptr), head);
1207 const u8 perm = ptr->perm;
1208 for (bit = 0; bit < TOMOYO_MAX_PATH_NUMBER_OPERATION; bit++) {
1209 if (!(perm & (1 << bit)))
1212 tomoyo_set_group(head, "file ");
1215 tomoyo_set_slash(head);
1217 tomoyo_set_string(head, tomoyo_mac_keywords
1218 [tomoyo_pn2mac[bit]]);
1222 tomoyo_print_name_union(head, &ptr->name);
1223 tomoyo_print_number_union(head, &ptr->number);
1224 } else if (acl_type == TOMOYO_TYPE_MKDEV_ACL) {
1225 struct tomoyo_mkdev_acl *ptr =
1226 container_of(acl, typeof(*ptr), head);
1227 const u8 perm = ptr->perm;
1228 for (bit = 0; bit < TOMOYO_MAX_MKDEV_OPERATION; bit++) {
1229 if (!(perm & (1 << bit)))
1232 tomoyo_set_group(head, "file ");
1235 tomoyo_set_slash(head);
1237 tomoyo_set_string(head, tomoyo_mac_keywords
1238 [tomoyo_pnnn2mac[bit]]);
1242 tomoyo_print_name_union(head, &ptr->name);
1243 tomoyo_print_number_union(head, &ptr->mode);
1244 tomoyo_print_number_union(head, &ptr->major);
1245 tomoyo_print_number_union(head, &ptr->minor);
1246 } else if (acl_type == TOMOYO_TYPE_MOUNT_ACL) {
1247 struct tomoyo_mount_acl *ptr =
1248 container_of(acl, typeof(*ptr), head);
1249 tomoyo_set_group(head, "file mount");
1250 tomoyo_print_name_union(head, &ptr->dev_name);
1251 tomoyo_print_name_union(head, &ptr->dir_name);
1252 tomoyo_print_name_union(head, &ptr->fs_type);
1253 tomoyo_print_number_union(head, &ptr->flags);
1256 head->r.print_cond_part = true;
1257 head->r.cond_step = 0;
1258 if (!tomoyo_flush(head))
1261 if (!tomoyo_print_condition(head, acl->cond))
1263 head->r.print_cond_part = false;
1265 tomoyo_set_lf(head);
1271 * tomoyo_read_domain2 - Read domain policy.
1273 * @head: Pointer to "struct tomoyo_io_buffer".
1274 * @list: Pointer to "struct list_head".
1276 * Caller holds tomoyo_read_lock().
1278 * Returns true on success, false otherwise.
1280 static bool tomoyo_read_domain2(struct tomoyo_io_buffer *head,
1281 struct list_head *list)
1283 list_for_each_cookie(head->r.acl, list) {
1284 struct tomoyo_acl_info *ptr =
1285 list_entry(head->r.acl, typeof(*ptr), list);
1286 if (!tomoyo_print_entry(head, ptr))
1294 * tomoyo_read_domain - Read domain policy.
1296 * @head: Pointer to "struct tomoyo_io_buffer".
1298 * Caller holds tomoyo_read_lock().
1300 static void tomoyo_read_domain(struct tomoyo_io_buffer *head)
1304 list_for_each_cookie(head->r.domain, &tomoyo_domain_list) {
1305 struct tomoyo_domain_info *domain =
1306 list_entry(head->r.domain, typeof(*domain), list);
1307 switch (head->r.step) {
1310 if (domain->is_deleted &&
1311 !head->r.print_this_domain_only)
1313 /* Print domainname and flags. */
1314 tomoyo_set_string(head, domain->domainname->name);
1315 tomoyo_set_lf(head);
1316 tomoyo_io_printf(head, "use_profile %u\n",
1318 tomoyo_io_printf(head, "use_group %u\n",
1320 for (i = 0; i < TOMOYO_MAX_DOMAIN_INFO_FLAGS; i++)
1321 if (domain->flags[i])
1322 tomoyo_set_string(head, tomoyo_dif[i]);
1324 tomoyo_set_lf(head);
1327 if (!tomoyo_read_domain2(head, &domain->acl_info_list))
1330 if (!tomoyo_set_lf(head))
1335 if (head->r.print_this_domain_only)
1344 * tomoyo_write_pid: Specify PID to obtain domainname.
1346 * @head: Pointer to "struct tomoyo_io_buffer".
1350 static int tomoyo_write_pid(struct tomoyo_io_buffer *head)
1352 head->r.eof = false;
1357 * tomoyo_read_pid - Get domainname of the specified PID.
1359 * @head: Pointer to "struct tomoyo_io_buffer".
1361 * Returns the domainname which the specified PID is in on success,
1362 * empty string otherwise.
1363 * The PID is specified by tomoyo_write_pid() so that the user can obtain
1364 * using read()/write() interface rather than sysctl() interface.
1366 static void tomoyo_read_pid(struct tomoyo_io_buffer *head)
1368 char *buf = head->write_buf;
1369 bool global_pid = false;
1371 struct task_struct *p;
1372 struct tomoyo_domain_info *domain = NULL;
1374 /* Accessing write_buf is safe because head->io_sem is held. */
1377 return; /* Do nothing if open(O_RDONLY). */
1379 if (head->r.w_pos || head->r.eof)
1382 if (tomoyo_str_starts(&buf, "global-pid "))
1384 pid = (unsigned int) simple_strtoul(buf, NULL, 10);
1386 read_lock(&tasklist_lock);
1388 p = find_task_by_pid_ns(pid, &init_pid_ns);
1390 p = find_task_by_vpid(pid);
1392 domain = tomoyo_real_domain(p);
1393 read_unlock(&tasklist_lock);
1397 tomoyo_io_printf(head, "%u %u ", pid, domain->profile);
1398 tomoyo_set_string(head, domain->domainname->name);
1401 static const char *tomoyo_transition_type[TOMOYO_MAX_TRANSITION_TYPE] = {
1402 [TOMOYO_TRANSITION_CONTROL_NO_RESET] = "no_reset_domain ",
1403 [TOMOYO_TRANSITION_CONTROL_RESET] = "reset_domain ",
1404 [TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE] = "no_initialize_domain ",
1405 [TOMOYO_TRANSITION_CONTROL_INITIALIZE] = "initialize_domain ",
1406 [TOMOYO_TRANSITION_CONTROL_NO_KEEP] = "no_keep_domain ",
1407 [TOMOYO_TRANSITION_CONTROL_KEEP] = "keep_domain ",
1410 static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = {
1411 [TOMOYO_PATH_GROUP] = "path_group ",
1412 [TOMOYO_NUMBER_GROUP] = "number_group ",
1416 * tomoyo_write_exception - Write exception policy.
1418 * @head: Pointer to "struct tomoyo_io_buffer".
1420 * Returns 0 on success, negative value otherwise.
1422 * Caller holds tomoyo_read_lock().
1424 static int tomoyo_write_exception(struct tomoyo_io_buffer *head)
1426 const bool is_delete = head->w.is_delete;
1427 struct tomoyo_acl_param param = {
1429 .is_delete = is_delete,
1430 .data = head->write_buf,
1433 if (tomoyo_str_starts(¶m.data, "aggregator "))
1434 return tomoyo_write_aggregator(¶m);
1435 for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++)
1436 if (tomoyo_str_starts(¶m.data, tomoyo_transition_type[i]))
1437 return tomoyo_write_transition_control(¶m, i);
1438 for (i = 0; i < TOMOYO_MAX_GROUP; i++)
1439 if (tomoyo_str_starts(¶m.data, tomoyo_group_name[i]))
1440 return tomoyo_write_group(¶m, i);
1441 if (tomoyo_str_starts(¶m.data, "acl_group ")) {
1444 group = simple_strtoul(param.data, &data, 10);
1445 if (group < TOMOYO_MAX_ACL_GROUPS && *data++ == ' ')
1446 return tomoyo_write_domain2
1447 (head->w.ns, &head->w.ns->acl_group[group],
1454 * tomoyo_read_group - Read "struct tomoyo_path_group"/"struct tomoyo_number_group" list.
1456 * @head: Pointer to "struct tomoyo_io_buffer".
1457 * @idx: Index number.
1459 * Returns true on success, false otherwise.
1461 * Caller holds tomoyo_read_lock().
1463 static bool tomoyo_read_group(struct tomoyo_io_buffer *head, const int idx)
1465 struct tomoyo_policy_namespace *ns =
1466 container_of(head->r.ns, typeof(*ns), namespace_list);
1467 struct list_head *list = &ns->group_list[idx];
1468 list_for_each_cookie(head->r.group, list) {
1469 struct tomoyo_group *group =
1470 list_entry(head->r.group, typeof(*group), head.list);
1471 list_for_each_cookie(head->r.acl, &group->member_list) {
1472 struct tomoyo_acl_head *ptr =
1473 list_entry(head->r.acl, typeof(*ptr), list);
1474 if (ptr->is_deleted)
1476 if (!tomoyo_flush(head))
1478 tomoyo_print_namespace(head);
1479 tomoyo_set_string(head, tomoyo_group_name[idx]);
1480 tomoyo_set_string(head, group->group_name->name);
1481 if (idx == TOMOYO_PATH_GROUP) {
1482 tomoyo_set_space(head);
1483 tomoyo_set_string(head, container_of
1484 (ptr, struct tomoyo_path_group,
1485 head)->member_name->name);
1486 } else if (idx == TOMOYO_NUMBER_GROUP) {
1487 tomoyo_print_number_union(head, &container_of
1489 struct tomoyo_number_group,
1492 tomoyo_set_lf(head);
1496 head->r.group = NULL;
1501 * tomoyo_read_policy - Read "struct tomoyo_..._entry" list.
1503 * @head: Pointer to "struct tomoyo_io_buffer".
1504 * @idx: Index number.
1506 * Returns true on success, false otherwise.
1508 * Caller holds tomoyo_read_lock().
1510 static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx)
1512 struct tomoyo_policy_namespace *ns =
1513 container_of(head->r.ns, typeof(*ns), namespace_list);
1514 struct list_head *list = &ns->policy_list[idx];
1515 list_for_each_cookie(head->r.acl, list) {
1516 struct tomoyo_acl_head *acl =
1517 container_of(head->r.acl, typeof(*acl), list);
1518 if (acl->is_deleted)
1520 if (!tomoyo_flush(head))
1523 case TOMOYO_ID_TRANSITION_CONTROL:
1525 struct tomoyo_transition_control *ptr =
1526 container_of(acl, typeof(*ptr), head);
1527 tomoyo_print_namespace(head);
1528 tomoyo_set_string(head, tomoyo_transition_type
1530 tomoyo_set_string(head, ptr->program ?
1531 ptr->program->name : "any");
1532 tomoyo_set_string(head, " from ");
1533 tomoyo_set_string(head, ptr->domainname ?
1534 ptr->domainname->name :
1538 case TOMOYO_ID_AGGREGATOR:
1540 struct tomoyo_aggregator *ptr =
1541 container_of(acl, typeof(*ptr), head);
1542 tomoyo_print_namespace(head);
1543 tomoyo_set_string(head, "aggregator ");
1544 tomoyo_set_string(head,
1545 ptr->original_name->name);
1546 tomoyo_set_space(head);
1547 tomoyo_set_string(head,
1548 ptr->aggregated_name->name);
1554 tomoyo_set_lf(head);
1561 * tomoyo_read_exception - Read exception policy.
1563 * @head: Pointer to "struct tomoyo_io_buffer".
1565 * Caller holds tomoyo_read_lock().
1567 static void tomoyo_read_exception(struct tomoyo_io_buffer *head)
1569 struct tomoyo_policy_namespace *ns =
1570 container_of(head->r.ns, typeof(*ns), namespace_list);
1573 while (head->r.step < TOMOYO_MAX_POLICY &&
1574 tomoyo_read_policy(head, head->r.step))
1576 if (head->r.step < TOMOYO_MAX_POLICY)
1578 while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP &&
1579 tomoyo_read_group(head, head->r.step - TOMOYO_MAX_POLICY))
1581 if (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP)
1583 while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP
1584 + TOMOYO_MAX_ACL_GROUPS) {
1585 head->r.acl_group_index = head->r.step - TOMOYO_MAX_POLICY
1587 if (!tomoyo_read_domain2(head, &ns->acl_group
1588 [head->r.acl_group_index]))
1595 /* Wait queue for kernel -> userspace notification. */
1596 static DECLARE_WAIT_QUEUE_HEAD(tomoyo_query_wait);
1597 /* Wait queue for userspace -> kernel notification. */
1598 static DECLARE_WAIT_QUEUE_HEAD(tomoyo_answer_wait);
1600 /* Structure for query. */
1601 struct tomoyo_query {
1602 struct list_head list;
1605 unsigned int serial;
1611 /* The list for "struct tomoyo_query". */
1612 static LIST_HEAD(tomoyo_query_list);
1614 /* Lock for manipulating tomoyo_query_list. */
1615 static DEFINE_SPINLOCK(tomoyo_query_list_lock);
1618 * Number of "struct file" referring /sys/kernel/security/tomoyo/query
1621 static atomic_t tomoyo_query_observers = ATOMIC_INIT(0);
1624 * tomoyo_add_entry - Add an ACL to current thread's domain. Used by learning mode.
1626 * @domain: Pointer to "struct tomoyo_domain_info".
1627 * @header: Lines containing ACL.
1631 static void tomoyo_add_entry(struct tomoyo_domain_info *domain, char *header)
1634 char *cp = strchr(header, '\n');
1638 cp = strchr(cp + 1, '\n');
1642 len = strlen(cp) + 1;
1643 buffer = kmalloc(len, GFP_NOFS);
1646 snprintf(buffer, len - 1, "%s", cp);
1647 tomoyo_normalize_line(buffer);
1648 if (!tomoyo_write_domain2(domain->ns, &domain->acl_info_list, buffer,
1650 tomoyo_update_stat(TOMOYO_STAT_POLICY_UPDATES);
1655 * tomoyo_supervisor - Ask for the supervisor's decision.
1657 * @r: Pointer to "struct tomoyo_request_info".
1658 * @fmt: The printf()'s format string, followed by parameters.
1660 * Returns 0 if the supervisor decided to permit the access request which
1661 * violated the policy in enforcing mode, TOMOYO_RETRY_REQUEST if the
1662 * supervisor decided to retry the access request which violated the policy in
1663 * enforcing mode, 0 if it is not in enforcing mode, -EPERM otherwise.
1665 int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
1670 static unsigned int tomoyo_serial;
1671 struct tomoyo_query entry = { };
1672 bool quota_exceeded = false;
1673 va_start(args, fmt);
1674 len = vsnprintf((char *) &len, 1, fmt, args) + 1;
1676 /* Write /sys/kernel/security/tomoyo/audit. */
1677 va_start(args, fmt);
1678 tomoyo_write_log2(r, len, fmt, args);
1680 /* Nothing more to do if granted. */
1684 tomoyo_update_stat(r->mode);
1686 case TOMOYO_CONFIG_ENFORCING:
1688 if (atomic_read(&tomoyo_query_observers))
1691 case TOMOYO_CONFIG_LEARNING:
1693 /* Check max_learning_entry parameter. */
1694 if (tomoyo_domain_quota_is_ok(r))
1701 va_start(args, fmt);
1702 entry.query = tomoyo_init_log(r, len, fmt, args);
1706 entry.query_len = strlen(entry.query) + 1;
1708 tomoyo_add_entry(r->domain, entry.query);
1711 len = tomoyo_round2(entry.query_len);
1712 spin_lock(&tomoyo_query_list_lock);
1713 if (tomoyo_memory_quota[TOMOYO_MEMORY_QUERY] &&
1714 tomoyo_memory_used[TOMOYO_MEMORY_QUERY] + len
1715 >= tomoyo_memory_quota[TOMOYO_MEMORY_QUERY]) {
1716 quota_exceeded = true;
1718 entry.serial = tomoyo_serial++;
1719 entry.retry = r->retry;
1720 tomoyo_memory_used[TOMOYO_MEMORY_QUERY] += len;
1721 list_add_tail(&entry.list, &tomoyo_query_list);
1723 spin_unlock(&tomoyo_query_list_lock);
1726 /* Give 10 seconds for supervisor's opinion. */
1727 while (entry.timer < 10) {
1728 wake_up_all(&tomoyo_query_wait);
1729 if (wait_event_interruptible_timeout
1730 (tomoyo_answer_wait, entry.answer ||
1731 !atomic_read(&tomoyo_query_observers), HZ))
1736 spin_lock(&tomoyo_query_list_lock);
1737 list_del(&entry.list);
1738 tomoyo_memory_used[TOMOYO_MEMORY_QUERY] -= len;
1739 spin_unlock(&tomoyo_query_list_lock);
1740 switch (entry.answer) {
1741 case 3: /* Asked to retry by administrator. */
1742 error = TOMOYO_RETRY_REQUEST;
1746 /* Granted by administrator. */
1750 /* Timed out or rejected by administrator. */
1759 * tomoyo_poll_query - poll() for /sys/kernel/security/tomoyo/query.
1761 * @file: Pointer to "struct file".
1762 * @wait: Pointer to "poll_table".
1764 * Returns POLLIN | POLLRDNORM when ready to read, 0 otherwise.
1766 * Waits for access requests which violated policy in enforcing mode.
1768 static int tomoyo_poll_query(struct file *file, poll_table *wait)
1770 struct list_head *tmp;
1773 for (i = 0; i < 2; i++) {
1774 spin_lock(&tomoyo_query_list_lock);
1775 list_for_each(tmp, &tomoyo_query_list) {
1776 struct tomoyo_query *ptr =
1777 list_entry(tmp, typeof(*ptr), list);
1783 spin_unlock(&tomoyo_query_list_lock);
1785 return POLLIN | POLLRDNORM;
1788 poll_wait(file, &tomoyo_query_wait, wait);
1794 * tomoyo_read_query - Read access requests which violated policy in enforcing mode.
1796 * @head: Pointer to "struct tomoyo_io_buffer".
1798 static void tomoyo_read_query(struct tomoyo_io_buffer *head)
1800 struct list_head *tmp;
1801 unsigned int pos = 0;
1806 if (head->read_buf) {
1807 kfree(head->read_buf);
1808 head->read_buf = NULL;
1810 spin_lock(&tomoyo_query_list_lock);
1811 list_for_each(tmp, &tomoyo_query_list) {
1812 struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list);
1815 if (pos++ != head->r.query_index)
1817 len = ptr->query_len;
1820 spin_unlock(&tomoyo_query_list_lock);
1822 head->r.query_index = 0;
1825 buf = kzalloc(len + 32, GFP_NOFS);
1829 spin_lock(&tomoyo_query_list_lock);
1830 list_for_each(tmp, &tomoyo_query_list) {
1831 struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list);
1834 if (pos++ != head->r.query_index)
1837 * Some query can be skipped because tomoyo_query_list
1838 * can change, but I don't care.
1840 if (len == ptr->query_len)
1841 snprintf(buf, len + 31, "Q%u-%hu\n%s", ptr->serial,
1842 ptr->retry, ptr->query);
1845 spin_unlock(&tomoyo_query_list_lock);
1847 head->read_buf = buf;
1848 head->r.w[head->r.w_pos++] = buf;
1849 head->r.query_index++;
1856 * tomoyo_write_answer - Write the supervisor's decision.
1858 * @head: Pointer to "struct tomoyo_io_buffer".
1860 * Returns 0 on success, -EINVAL otherwise.
1862 static int tomoyo_write_answer(struct tomoyo_io_buffer *head)
1864 char *data = head->write_buf;
1865 struct list_head *tmp;
1866 unsigned int serial;
1867 unsigned int answer;
1868 spin_lock(&tomoyo_query_list_lock);
1869 list_for_each(tmp, &tomoyo_query_list) {
1870 struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list);
1873 spin_unlock(&tomoyo_query_list_lock);
1874 if (sscanf(data, "A%u=%u", &serial, &answer) != 2)
1876 spin_lock(&tomoyo_query_list_lock);
1877 list_for_each(tmp, &tomoyo_query_list) {
1878 struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list);
1879 if (ptr->serial != serial)
1882 ptr->answer = answer;
1885 spin_unlock(&tomoyo_query_list_lock);
1890 * tomoyo_read_version: Get version.
1892 * @head: Pointer to "struct tomoyo_io_buffer".
1894 * Returns version information.
1896 static void tomoyo_read_version(struct tomoyo_io_buffer *head)
1899 tomoyo_io_printf(head, "2.4.0");
1905 * tomoyo_read_self_domain - Get the current process's domainname.
1907 * @head: Pointer to "struct tomoyo_io_buffer".
1909 * Returns the current process's domainname.
1911 static void tomoyo_read_self_domain(struct tomoyo_io_buffer *head)
1915 * tomoyo_domain()->domainname != NULL
1916 * because every process belongs to a domain and
1917 * the domain's name cannot be NULL.
1919 tomoyo_io_printf(head, "%s", tomoyo_domain()->domainname->name);
1924 /* String table for /sys/kernel/security/tomoyo/stat interface. */
1925 static const char * const tomoyo_policy_headers[TOMOYO_MAX_POLICY_STAT] = {
1926 [TOMOYO_STAT_POLICY_UPDATES] = "update:",
1927 [TOMOYO_STAT_POLICY_LEARNING] = "violation in learning mode:",
1928 [TOMOYO_STAT_POLICY_PERMISSIVE] = "violation in permissive mode:",
1929 [TOMOYO_STAT_POLICY_ENFORCING] = "violation in enforcing mode:",
1932 /* String table for /sys/kernel/security/tomoyo/stat interface. */
1933 static const char * const tomoyo_memory_headers[TOMOYO_MAX_MEMORY_STAT] = {
1934 [TOMOYO_MEMORY_POLICY] = "policy:",
1935 [TOMOYO_MEMORY_AUDIT] = "audit log:",
1936 [TOMOYO_MEMORY_QUERY] = "query message:",
1939 /* Timestamp counter for last updated. */
1940 static unsigned int tomoyo_stat_updated[TOMOYO_MAX_POLICY_STAT];
1941 /* Counter for number of updates. */
1942 static unsigned int tomoyo_stat_modified[TOMOYO_MAX_POLICY_STAT];
1945 * tomoyo_update_stat - Update statistic counters.
1947 * @index: Index for policy type.
1951 void tomoyo_update_stat(const u8 index)
1954 do_gettimeofday(&tv);
1956 * I don't use atomic operations because race condition is not fatal.
1958 tomoyo_stat_updated[index]++;
1959 tomoyo_stat_modified[index] = tv.tv_sec;
1963 * tomoyo_read_stat - Read statistic data.
1965 * @head: Pointer to "struct tomoyo_io_buffer".
1969 static void tomoyo_read_stat(struct tomoyo_io_buffer *head)
1972 unsigned int total = 0;
1975 for (i = 0; i < TOMOYO_MAX_POLICY_STAT; i++) {
1976 tomoyo_io_printf(head, "Policy %-30s %10u",
1977 tomoyo_policy_headers[i],
1978 tomoyo_stat_updated[i]);
1979 if (tomoyo_stat_modified[i]) {
1980 struct tomoyo_time stamp;
1981 tomoyo_convert_time(tomoyo_stat_modified[i], &stamp);
1982 tomoyo_io_printf(head, " (Last: %04u/%02u/%02u "
1984 stamp.year, stamp.month, stamp.day,
1985 stamp.hour, stamp.min, stamp.sec);
1987 tomoyo_set_lf(head);
1989 for (i = 0; i < TOMOYO_MAX_MEMORY_STAT; i++) {
1990 unsigned int used = tomoyo_memory_used[i];
1992 tomoyo_io_printf(head, "Memory used by %-22s %10u",
1993 tomoyo_memory_headers[i], used);
1994 used = tomoyo_memory_quota[i];
1996 tomoyo_io_printf(head, " (Quota: %10u)", used);
1997 tomoyo_set_lf(head);
1999 tomoyo_io_printf(head, "Total memory used: %10u\n",
2005 * tomoyo_write_stat - Set memory quota.
2007 * @head: Pointer to "struct tomoyo_io_buffer".
2011 static int tomoyo_write_stat(struct tomoyo_io_buffer *head)
2013 char *data = head->write_buf;
2015 if (tomoyo_str_starts(&data, "Memory used by "))
2016 for (i = 0; i < TOMOYO_MAX_MEMORY_STAT; i++)
2017 if (tomoyo_str_starts(&data, tomoyo_memory_headers[i]))
2018 sscanf(data, "%u", &tomoyo_memory_quota[i]);
2023 * tomoyo_open_control - open() for /sys/kernel/security/tomoyo/ interface.
2025 * @type: Type of interface.
2026 * @file: Pointer to "struct file".
2028 * Returns 0 on success, negative value otherwise.
2030 int tomoyo_open_control(const u8 type, struct file *file)
2032 struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS);
2036 mutex_init(&head->io_sem);
2039 case TOMOYO_DOMAINPOLICY:
2040 /* /sys/kernel/security/tomoyo/domain_policy */
2041 head->write = tomoyo_write_domain;
2042 head->read = tomoyo_read_domain;
2044 case TOMOYO_EXCEPTIONPOLICY:
2045 /* /sys/kernel/security/tomoyo/exception_policy */
2046 head->write = tomoyo_write_exception;
2047 head->read = tomoyo_read_exception;
2050 /* /sys/kernel/security/tomoyo/audit */
2051 head->poll = tomoyo_poll_log;
2052 head->read = tomoyo_read_log;
2054 case TOMOYO_SELFDOMAIN:
2055 /* /sys/kernel/security/tomoyo/self_domain */
2056 head->read = tomoyo_read_self_domain;
2058 case TOMOYO_PROCESS_STATUS:
2059 /* /sys/kernel/security/tomoyo/.process_status */
2060 head->write = tomoyo_write_pid;
2061 head->read = tomoyo_read_pid;
2063 case TOMOYO_VERSION:
2064 /* /sys/kernel/security/tomoyo/version */
2065 head->read = tomoyo_read_version;
2066 head->readbuf_size = 128;
2069 /* /sys/kernel/security/tomoyo/stat */
2070 head->write = tomoyo_write_stat;
2071 head->read = tomoyo_read_stat;
2072 head->readbuf_size = 1024;
2074 case TOMOYO_PROFILE:
2075 /* /sys/kernel/security/tomoyo/profile */
2076 head->write = tomoyo_write_profile;
2077 head->read = tomoyo_read_profile;
2079 case TOMOYO_QUERY: /* /sys/kernel/security/tomoyo/query */
2080 head->poll = tomoyo_poll_query;
2081 head->write = tomoyo_write_answer;
2082 head->read = tomoyo_read_query;
2084 case TOMOYO_MANAGER:
2085 /* /sys/kernel/security/tomoyo/manager */
2086 head->write = tomoyo_write_manager;
2087 head->read = tomoyo_read_manager;
2090 if (!(file->f_mode & FMODE_READ)) {
2092 * No need to allocate read_buf since it is not opened
2097 } else if (!head->poll) {
2098 /* Don't allocate read_buf for poll() access. */
2099 if (!head->readbuf_size)
2100 head->readbuf_size = 4096 * 2;
2101 head->read_buf = kzalloc(head->readbuf_size, GFP_NOFS);
2102 if (!head->read_buf) {
2107 if (!(file->f_mode & FMODE_WRITE)) {
2109 * No need to allocate write_buf since it is not opened
2113 } else if (head->write) {
2114 head->writebuf_size = 4096 * 2;
2115 head->write_buf = kzalloc(head->writebuf_size, GFP_NOFS);
2116 if (!head->write_buf) {
2117 kfree(head->read_buf);
2123 * If the file is /sys/kernel/security/tomoyo/query , increment the
2125 * The obserber counter is used by tomoyo_supervisor() to see if
2126 * there is some process monitoring /sys/kernel/security/tomoyo/query.
2128 if (type == TOMOYO_QUERY)
2129 atomic_inc(&tomoyo_query_observers);
2130 file->private_data = head;
2131 tomoyo_notify_gc(head, true);
2136 * tomoyo_poll_control - poll() for /sys/kernel/security/tomoyo/ interface.
2138 * @file: Pointer to "struct file".
2139 * @wait: Pointer to "poll_table".
2141 * Waits for read readiness.
2142 * /sys/kernel/security/tomoyo/query is handled by /usr/sbin/tomoyo-queryd and
2143 * /sys/kernel/security/tomoyo/audit is handled by /usr/sbin/tomoyo-auditd.
2145 int tomoyo_poll_control(struct file *file, poll_table *wait)
2147 struct tomoyo_io_buffer *head = file->private_data;
2150 return head->poll(file, wait);
2154 * tomoyo_set_namespace_cursor - Set namespace to read.
2156 * @head: Pointer to "struct tomoyo_io_buffer".
2160 static inline void tomoyo_set_namespace_cursor(struct tomoyo_io_buffer *head)
2162 struct list_head *ns;
2163 if (head->type != TOMOYO_EXCEPTIONPOLICY &&
2164 head->type != TOMOYO_PROFILE)
2167 * If this is the first read, or reading previous namespace finished
2168 * and has more namespaces to read, update the namespace cursor.
2171 if (!ns || (head->r.eof && ns->next != &tomoyo_namespace_list)) {
2172 /* Clearing is OK because tomoyo_flush() returned true. */
2173 memset(&head->r, 0, sizeof(head->r));
2174 head->r.ns = ns ? ns->next : tomoyo_namespace_list.next;
2179 * tomoyo_has_more_namespace - Check for unread namespaces.
2181 * @head: Pointer to "struct tomoyo_io_buffer".
2183 * Returns true if we have more entries to print, false otherwise.
2185 static inline bool tomoyo_has_more_namespace(struct tomoyo_io_buffer *head)
2187 return (head->type == TOMOYO_EXCEPTIONPOLICY ||
2188 head->type == TOMOYO_PROFILE) && head->r.eof &&
2189 head->r.ns->next != &tomoyo_namespace_list;
2193 * tomoyo_read_control - read() for /sys/kernel/security/tomoyo/ interface.
2195 * @head: Pointer to "struct tomoyo_io_buffer".
2196 * @buffer: Poiner to buffer to write to.
2197 * @buffer_len: Size of @buffer.
2199 * Returns bytes read on success, negative value otherwise.
2201 ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
2202 const int buffer_len)
2209 if (mutex_lock_interruptible(&head->io_sem))
2211 head->read_user_buf = buffer;
2212 head->read_user_buf_avail = buffer_len;
2213 idx = tomoyo_read_lock();
2214 if (tomoyo_flush(head))
2215 /* Call the policy handler. */
2217 tomoyo_set_namespace_cursor(head);
2219 } while (tomoyo_flush(head) &&
2220 tomoyo_has_more_namespace(head));
2221 tomoyo_read_unlock(idx);
2222 len = head->read_user_buf - buffer;
2223 mutex_unlock(&head->io_sem);
2228 * tomoyo_parse_policy - Parse a policy line.
2230 * @head: Poiter to "struct tomoyo_io_buffer".
2231 * @line: Line to parse.
2233 * Returns 0 on success, negative value otherwise.
2235 * Caller holds tomoyo_read_lock().
2237 static int tomoyo_parse_policy(struct tomoyo_io_buffer *head, char *line)
2239 /* Delete request? */
2240 head->w.is_delete = !strncmp(line, "delete ", 7);
2241 if (head->w.is_delete)
2242 memmove(line, line + 7, strlen(line + 7) + 1);
2243 /* Selecting namespace to update. */
2244 if (head->type == TOMOYO_EXCEPTIONPOLICY ||
2245 head->type == TOMOYO_PROFILE) {
2247 char *cp = strchr(line, ' ');
2250 head->w.ns = tomoyo_assign_namespace(line);
2251 memmove(line, cp, strlen(cp) + 1);
2255 head->w.ns = &tomoyo_kernel_namespace;
2256 /* Don't allow updating if namespace is invalid. */
2260 /* Do the update. */
2261 return head->write(head);
2265 * tomoyo_write_control - write() for /sys/kernel/security/tomoyo/ interface.
2267 * @head: Pointer to "struct tomoyo_io_buffer".
2268 * @buffer: Pointer to buffer to read from.
2269 * @buffer_len: Size of @buffer.
2271 * Returns @buffer_len on success, negative value otherwise.
2273 ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
2274 const char __user *buffer, const int buffer_len)
2276 int error = buffer_len;
2277 size_t avail_len = buffer_len;
2278 char *cp0 = head->write_buf;
2282 if (!access_ok(VERIFY_READ, buffer, buffer_len))
2284 if (mutex_lock_interruptible(&head->io_sem))
2286 idx = tomoyo_read_lock();
2287 /* Read a line and dispatch it to the policy handler. */
2288 while (avail_len > 0) {
2290 if (head->w.avail >= head->writebuf_size - 1) {
2291 const int len = head->writebuf_size * 2;
2292 char *cp = kzalloc(len, GFP_NOFS);
2297 memmove(cp, cp0, head->w.avail);
2299 head->write_buf = cp;
2301 head->writebuf_size = len;
2303 if (get_user(c, buffer)) {
2309 cp0[head->w.avail++] = c;
2312 cp0[head->w.avail - 1] = '\0';
2314 tomoyo_normalize_line(cp0);
2315 if (!strcmp(cp0, "reset")) {
2316 head->w.ns = &tomoyo_kernel_namespace;
2317 head->w.domain = NULL;
2318 memset(&head->r, 0, sizeof(head->r));
2321 /* Don't allow updating policies by non manager programs. */
2322 switch (head->type) {
2323 case TOMOYO_PROCESS_STATUS:
2324 /* This does not write anything. */
2326 case TOMOYO_DOMAINPOLICY:
2327 if (tomoyo_select_domain(head, cp0))
2330 case TOMOYO_EXCEPTIONPOLICY:
2331 if (!strcmp(cp0, "select transition_only")) {
2332 head->r.print_transition_related_only = true;
2337 if (!tomoyo_manager()) {
2342 switch (tomoyo_parse_policy(head, cp0)) {
2347 switch (head->type) {
2348 case TOMOYO_DOMAINPOLICY:
2349 case TOMOYO_EXCEPTIONPOLICY:
2351 case TOMOYO_PROFILE:
2352 case TOMOYO_MANAGER:
2353 tomoyo_update_stat(TOMOYO_STAT_POLICY_UPDATES);
2362 tomoyo_read_unlock(idx);
2363 mutex_unlock(&head->io_sem);
2368 * tomoyo_close_control - close() for /sys/kernel/security/tomoyo/ interface.
2370 * @head: Pointer to "struct tomoyo_io_buffer".
2374 int tomoyo_close_control(struct tomoyo_io_buffer *head)
2377 * If the file is /sys/kernel/security/tomoyo/query , decrement the
2380 if (head->type == TOMOYO_QUERY &&
2381 atomic_dec_and_test(&tomoyo_query_observers))
2382 wake_up_all(&tomoyo_answer_wait);
2383 tomoyo_notify_gc(head, false);
2388 * tomoyo_check_profile - Check all profiles currently assigned to domains are defined.
2390 void tomoyo_check_profile(void)
2392 struct tomoyo_domain_info *domain;
2393 const int idx = tomoyo_read_lock();
2394 tomoyo_policy_loaded = true;
2395 printk(KERN_INFO "TOMOYO: 2.4.0\n");
2396 list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
2397 const u8 profile = domain->profile;
2398 const struct tomoyo_policy_namespace *ns = domain->ns;
2399 if (ns->profile_version != 20100903)
2401 "Profile version %u is not supported.\n",
2402 ns->profile_version);
2403 else if (!ns->profile_ptr[profile])
2405 "Profile %u (used by '%s') is not defined.\n",
2406 profile, domain->domainname->name);
2410 "Userland tools for TOMOYO 2.4 must be installed and "
2411 "policy must be initialized.\n");
2412 printk(KERN_ERR "Please see http://tomoyo.sourceforge.jp/2.4/ "
2413 "for more information.\n");
2416 tomoyo_read_unlock(idx);
2417 printk(KERN_INFO "Mandatory Access Control activated.\n");
2421 * tomoyo_load_builtin_policy - Load built-in policy.
2425 void __init tomoyo_load_builtin_policy(void)
2428 * This include file is manually created and contains built-in policy
2429 * named "tomoyo_builtin_profile", "tomoyo_builtin_exception_policy",
2430 * "tomoyo_builtin_domain_policy", "tomoyo_builtin_manager",
2431 * "tomoyo_builtin_stat" in the form of "static char [] __initdata".
2433 #include "builtin-policy.h"
2435 const int idx = tomoyo_read_lock();
2436 for (i = 0; i < 5; i++) {
2437 struct tomoyo_io_buffer head = { };
2441 start = tomoyo_builtin_profile;
2442 head.type = TOMOYO_PROFILE;
2443 head.write = tomoyo_write_profile;
2446 start = tomoyo_builtin_exception_policy;
2447 head.type = TOMOYO_EXCEPTIONPOLICY;
2448 head.write = tomoyo_write_exception;
2451 start = tomoyo_builtin_domain_policy;
2452 head.type = TOMOYO_DOMAINPOLICY;
2453 head.write = tomoyo_write_domain;
2456 start = tomoyo_builtin_manager;
2457 head.type = TOMOYO_MANAGER;
2458 head.write = tomoyo_write_manager;
2461 start = tomoyo_builtin_stat;
2462 head.type = TOMOYO_STAT;
2463 head.write = tomoyo_write_stat;
2467 char *end = strchr(start, '\n');
2471 tomoyo_normalize_line(start);
2472 head.write_buf = start;
2473 tomoyo_parse_policy(&head, start);
2477 tomoyo_read_unlock(idx);
2478 #ifdef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
2479 tomoyo_check_profile();