/* The list for "struct tomoyo_io_buffer". */ static LIST_HEAD(tomoyo_io_buffer_list); /* Lock for protecting tomoyo_io_buffer_list. */ static DEFINE_SPINLOCK(tomoyo_io_buffer_list_lock);
/** * tomoyo_struct_used_by_io_buffer - Check whether the list element is used by /sys/kernel/security/tomoyo/ users or not. * * @element: Pointer to "struct list_head". * * Returns true if @element is used by /sys/kernel/security/tomoyo/ users, * false otherwise.
*/ staticbool tomoyo_struct_used_by_io_buffer(conststruct list_head *element)
{ struct tomoyo_io_buffer *head; bool in_use = false;
spin_lock(&tomoyo_io_buffer_list_lock);
list_for_each_entry(head, &tomoyo_io_buffer_list, list) {
head->users++;
spin_unlock(&tomoyo_io_buffer_list_lock);
mutex_lock(&head->io_sem); if (head->r.domain == element || head->r.group == element ||
head->r.acl == element || &head->w.domain->list == element)
in_use = true;
mutex_unlock(&head->io_sem);
spin_lock(&tomoyo_io_buffer_list_lock);
head->users--; if (in_use) break;
}
spin_unlock(&tomoyo_io_buffer_list_lock); return in_use;
}
/** * tomoyo_name_used_by_io_buffer - Check whether the string is used by /sys/kernel/security/tomoyo/ users or not. * * @string: String to check. * * Returns true if @string is used by /sys/kernel/security/tomoyo/ users, * false otherwise.
*/ staticbool tomoyo_name_used_by_io_buffer(constchar *string)
{ struct tomoyo_io_buffer *head; const size_t size = strlen(string) + 1; bool in_use = false;
spin_lock(&tomoyo_io_buffer_list_lock);
list_for_each_entry(head, &tomoyo_io_buffer_list, list) { int i;
head->users++;
spin_unlock(&tomoyo_io_buffer_list_lock);
mutex_lock(&head->io_sem); for (i = 0; i < TOMOYO_MAX_IO_READ_QUEUE; i++) { constchar *w = head->r.w[i];
if (w < string || w > string + size) continue;
in_use = true; break;
}
mutex_unlock(&head->io_sem);
spin_lock(&tomoyo_io_buffer_list_lock);
head->users--; if (in_use) break;
}
spin_unlock(&tomoyo_io_buffer_list_lock); return in_use;
}
/* * Since this domain is referenced from neither * "struct tomoyo_io_buffer" nor "struct cred"->security, we can delete * elements without checking for is_deleted flag.
*/
list_for_each_entry_safe(acl, tmp, &domain->acl_info_list, list) {
tomoyo_del_acl(&acl->list);
tomoyo_memory_free(acl);
}
tomoyo_put_name(domain->domainname);
}
for (i = 0; i < numbers_count; i++)
tomoyo_put_number_union(numbers_p++); for (i = 0; i < names_count; i++)
tomoyo_put_name_union(names_p++); for (i = 0; i < argc; argv++, i++)
tomoyo_put_name(argv->value); for (i = 0; i < envc; envp++, i++) {
tomoyo_put_name(envp->name);
tomoyo_put_name(envp->value);
}
}
/** * tomoyo_del_name - Delete members in "struct tomoyo_name". * * @element: Pointer to "struct list_head". * * Returns nothing.
*/ staticinlinevoid tomoyo_del_name(struct list_head *element)
{ /* Nothing to do. */
}
/** * tomoyo_del_address_group - Delete members in "struct tomoyo_address_group". * * @element: Pointer to "struct list_head". * * Returns nothing.
*/ staticinlinevoid tomoyo_del_address_group(struct list_head *element)
{ /* Nothing to do. */
}
/** * tomoyo_del_number_group - Delete members in "struct tomoyo_number_group". * * @element: Pointer to "struct list_head". * * Returns nothing.
*/ staticinlinevoid tomoyo_del_number_group(struct list_head *element)
{ /* Nothing to do. */
}
/** * tomoyo_try_to_gc - Try to kfree() an entry. * * @type: One of values in "enum tomoyo_policy_id". * @element: Pointer to "struct list_head". * * Returns nothing. * * Caller holds tomoyo_policy_lock mutex.
*/ staticvoid tomoyo_try_to_gc(constenum tomoyo_policy_id type, struct list_head *element)
{ /* * __list_del_entry() guarantees that the list element became no longer * reachable from the list which the element was originally on (e.g. * tomoyo_domain_list). Also, synchronize_srcu() guarantees that the * list element became no longer referenced by syscall users.
*/
__list_del_entry(element);
mutex_unlock(&tomoyo_policy_lock);
synchronize_srcu(&tomoyo_ss); /* * However, there are two users which may still be using the list * element. We need to defer until both users forget this element. * * Don't kfree() until "struct tomoyo_io_buffer"->r.{domain,group,acl} * and "struct tomoyo_io_buffer"->w.domain forget this element.
*/ if (tomoyo_struct_used_by_io_buffer(element)) goto reinject; switch (type) { case TOMOYO_ID_TRANSITION_CONTROL:
tomoyo_del_transition_control(element); break; case TOMOYO_ID_MANAGER:
tomoyo_del_manager(element); break; case TOMOYO_ID_AGGREGATOR:
tomoyo_del_aggregator(element); break; case TOMOYO_ID_GROUP:
tomoyo_del_group(element); break; case TOMOYO_ID_PATH_GROUP:
tomoyo_del_path_group(element); break; case TOMOYO_ID_ADDRESS_GROUP:
tomoyo_del_address_group(element); break; case TOMOYO_ID_NUMBER_GROUP:
tomoyo_del_number_group(element); break; case TOMOYO_ID_CONDITION:
tomoyo_del_condition(element); break; case TOMOYO_ID_NAME: /* * Don't kfree() until all "struct tomoyo_io_buffer"->r.w[] * forget this element.
*/ if (tomoyo_name_used_by_io_buffer
(container_of(element, typeof(struct tomoyo_name),
head.list)->entry.name)) goto reinject;
tomoyo_del_name(element); break; case TOMOYO_ID_ACL:
tomoyo_del_acl(element); break; case TOMOYO_ID_DOMAIN: /* * Don't kfree() until all "struct cred"->security forget this * element.
*/ if (atomic_read(&container_of
(element, typeof(struct tomoyo_domain_info),
list)->users)) goto reinject; break; case TOMOYO_MAX_POLICY: break;
}
mutex_lock(&tomoyo_policy_lock); if (type == TOMOYO_ID_DOMAIN)
tomoyo_del_domain(element);
tomoyo_memory_free(element); return;
reinject: /* * We can safely reinject this element here because * (1) Appending list elements and removing list elements are protected * by tomoyo_policy_lock mutex. * (2) Only this function removes list elements and this function is * exclusively executed by tomoyo_gc_mutex mutex. * are true.
*/
mutex_lock(&tomoyo_policy_lock);
list_add_rcu(element, element->prev);
}
/** * tomoyo_collect_member - Delete elements with "struct tomoyo_acl_head". * * @id: One of values in "enum tomoyo_policy_id". * @member_list: Pointer to "struct list_head". * * Returns nothing.
*/ staticvoid tomoyo_collect_member(constenum tomoyo_policy_id id, struct list_head *member_list)
{ struct tomoyo_acl_head *member; struct tomoyo_acl_head *tmp;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.