security/tomoyo/gc.c
Source file repositories/reference/linux-study-clean/security/tomoyo/gc.c
File Facts
- System
- Linux kernel
- Corpus path
security/tomoyo/gc.c- Extension
.c- Size
- 17477 bytes
- Lines
- 683
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
common.hlinux/kthread.hlinux/slab.h
Detected Declarations
function Copyrightfunction tomoyo_struct_used_by_io_bufferfunction tomoyo_name_used_by_io_bufferfunction tomoyo_del_transition_controlfunction tomoyo_del_aggregatorfunction tomoyo_del_managerfunction tomoyo_del_aclfunction tomoyo_del_domainfunction tomoyo_del_conditionfunction tomoyo_del_namefunction tomoyo_del_groupfunction tomoyo_del_address_groupfunction tomoyo_collect_memberfunction list_for_each_entry_safefunction tomoyo_collect_aclfunction list_for_each_entry_safefunction tomoyo_collect_entryfunction list_for_each_entry_safefunction list_for_each_entry_safefunction list_for_each_entry_safefunction list_for_each_entry_safefunction tomoyo_gc_threadfunction list_for_each_entry_safefunction tomoyo_notify_gc
Annotated Snippet
switch (i) {
case 0:
id = TOMOYO_ID_PATH_GROUP;
break;
case 1:
id = TOMOYO_ID_NUMBER_GROUP;
break;
default:
id = TOMOYO_ID_ADDRESS_GROUP;
break;
}
list_for_each_entry_safe(group, tmp, list, head.list) {
tomoyo_collect_member(id, &group->member_list);
if (!list_empty(&group->member_list) ||
atomic_read(&group->head.users) > 0)
continue;
atomic_set(&group->head.users,
TOMOYO_GC_IN_PROGRESS);
tomoyo_try_to_gc(TOMOYO_ID_GROUP,
&group->head.list);
}
}
}
for (i = 0; i < TOMOYO_MAX_HASH; i++) {
struct list_head *list = &tomoyo_name_list[i];
struct tomoyo_shared_acl_head *ptr;
struct tomoyo_shared_acl_head *tmp;
list_for_each_entry_safe(ptr, tmp, list, list) {
if (atomic_read(&ptr->users) > 0)
continue;
atomic_set(&ptr->users, TOMOYO_GC_IN_PROGRESS);
tomoyo_try_to_gc(TOMOYO_ID_NAME, &ptr->list);
}
}
mutex_unlock(&tomoyo_policy_lock);
}
/**
* tomoyo_gc_thread - Garbage collector thread function.
*
* @unused: Unused.
*
* Returns 0.
*/
static int tomoyo_gc_thread(void *unused)
{
/* Garbage collector thread is exclusive. */
static DEFINE_MUTEX(tomoyo_gc_mutex);
if (!mutex_trylock(&tomoyo_gc_mutex))
goto out;
tomoyo_collect_entry();
{
struct tomoyo_io_buffer *head;
struct tomoyo_io_buffer *tmp;
spin_lock(&tomoyo_io_buffer_list_lock);
list_for_each_entry_safe(head, tmp, &tomoyo_io_buffer_list,
list) {
if (head->users)
continue;
list_del(&head->list);
/* Safe destruction because no users are left. */
context_unsafe(
kfree(head->read_buf);
kfree(head->write_buf);
);
kfree(head);
}
spin_unlock(&tomoyo_io_buffer_list_lock);
}
mutex_unlock(&tomoyo_gc_mutex);
out:
/* This acts as do_exit(0). */
return 0;
}
/**
* tomoyo_notify_gc - Register/unregister /sys/kernel/security/tomoyo/ users.
*
* @head: Pointer to "struct tomoyo_io_buffer".
* @is_register: True if register, false if unregister.
*
* Returns nothing.
*/
void tomoyo_notify_gc(struct tomoyo_io_buffer *head, const bool is_register)
{
bool is_write = false;
Annotation
- Immediate include surface: `common.h`, `linux/kthread.h`, `linux/slab.h`.
- Detected declarations: `function Copyright`, `function tomoyo_struct_used_by_io_buffer`, `function tomoyo_name_used_by_io_buffer`, `function tomoyo_del_transition_control`, `function tomoyo_del_aggregator`, `function tomoyo_del_manager`, `function tomoyo_del_acl`, `function tomoyo_del_domain`, `function tomoyo_del_condition`, `function tomoyo_del_name`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.