security/tomoyo/tomoyo.c
Source file repositories/reference/linux-study-clean/security/tomoyo/tomoyo.c
File Facts
- System
- Linux kernel
- Corpus path
security/tomoyo/tomoyo.c- Extension
.c- Size
- 16609 bytes
- Lines
- 622
- 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
linux/lsm_hooks.huapi/linux/lsm.hcommon.h
Detected Declarations
function Copyrightfunction tomoyo_cred_preparefunction tomoyo_bprm_committed_credsfunction tomoyo_bprm_creds_for_execfunction tomoyo_bprm_check_securityfunction execvefunction tomoyo_inode_getattrfunction tomoyo_path_truncatefunction tomoyo_file_truncatefunction tomoyo_path_unlinkfunction tomoyo_path_mkdirfunction tomoyo_path_rmdirfunction tomoyo_path_symlinkfunction tomoyo_path_mknodfunction tomoyo_path_linkfunction tomoyo_path_renamefunction tomoyo_file_fcntlfunction tomoyo_file_openfunction tomoyo_file_ioctlfunction tomoyo_path_chmodfunction tomoyo_path_chownfunction tomoyo_path_chrootfunction tomoyo_sb_mountfunction tomoyo_sb_umountfunction tomoyo_sb_pivotrootfunction tomoyo_socket_listenfunction tomoyo_socket_connectfunction tomoyo_socket_bindfunction tomoyo_socket_sendmsgfunction tomoyo_task_allocfunction tomoyo_task_freefunction tomoyo_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* security/tomoyo/tomoyo.c
*
* Copyright (C) 2005-2011 NTT DATA CORPORATION
*/
#include <linux/lsm_hooks.h>
#include <uapi/linux/lsm.h>
#include "common.h"
/**
* tomoyo_domain - Get "struct tomoyo_domain_info" for current thread.
*
* Returns pointer to "struct tomoyo_domain_info" for current thread.
*/
struct tomoyo_domain_info *tomoyo_domain(void)
{
struct tomoyo_task *s = tomoyo_task(current);
if (s->old_domain_info && !current->in_execve) {
atomic_dec(&s->old_domain_info->users);
s->old_domain_info = NULL;
}
return s->domain_info;
}
/**
* tomoyo_cred_prepare - Target for security_prepare_creds().
*
* @new: Pointer to "struct cred".
* @old: Pointer to "struct cred".
* @gfp: Memory allocation flags.
*
* Returns 0.
*/
static int tomoyo_cred_prepare(struct cred *new, const struct cred *old,
gfp_t gfp)
{
/* Restore old_domain_info saved by previous execve() request. */
struct tomoyo_task *s = tomoyo_task(current);
if (s->old_domain_info && !current->in_execve) {
atomic_dec(&s->domain_info->users);
s->domain_info = s->old_domain_info;
s->old_domain_info = NULL;
}
return 0;
}
/**
* tomoyo_bprm_committed_creds - Target for security_bprm_committed_creds().
*
* @bprm: Pointer to "struct linux_binprm".
*/
static void tomoyo_bprm_committed_creds(const struct linux_binprm *bprm)
{
/* Clear old_domain_info saved by execve() request. */
struct tomoyo_task *s = tomoyo_task(current);
atomic_dec(&s->old_domain_info->users);
s->old_domain_info = NULL;
}
#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER
/**
* tomoyo_bprm_creds_for_exec - Target for security_bprm_creds_for_exec().
*
* @bprm: Pointer to "struct linux_binprm".
*
* Returns 0.
*/
static int tomoyo_bprm_creds_for_exec(struct linux_binprm *bprm)
{
/*
* Load policy if /sbin/tomoyo-init exists and /sbin/init is requested
* for the first time.
*/
if (!tomoyo_policy_loaded)
tomoyo_load_policy(bprm->filename);
return 0;
}
#endif
/**
* tomoyo_bprm_check_security - Target for security_bprm_check().
*
* @bprm: Pointer to "struct linux_binprm".
*
* Returns 0 on success, negative value otherwise.
Annotation
- Immediate include surface: `linux/lsm_hooks.h`, `uapi/linux/lsm.h`, `common.h`.
- Detected declarations: `function Copyright`, `function tomoyo_cred_prepare`, `function tomoyo_bprm_committed_creds`, `function tomoyo_bprm_creds_for_exec`, `function tomoyo_bprm_check_security`, `function execve`, `function tomoyo_inode_getattr`, `function tomoyo_path_truncate`, `function tomoyo_file_truncate`, `function tomoyo_path_unlink`.
- 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.