security/apparmor/lsm.c
Source file repositories/reference/linux-study-clean/security/apparmor/lsm.c
File Facts
- System
- Linux kernel
- Corpus path
security/apparmor/lsm.c- Extension
.c- Size
- 70141 bytes
- Lines
- 2575
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/lsm_hooks.hlinux/moduleparam.hlinux/mm.hlinux/mman.hlinux/mount.hlinux/namei.hlinux/ptrace.hlinux/ctype.hlinux/sysctl.hlinux/sysfs.hlinux/audit.hlinux/user_namespace.hlinux/netfilter_ipv4.hlinux/netfilter_ipv6.hlinux/zstd.hnet/sock.huapi/linux/mount.huapi/linux/lsm.hinclude/af_unix.hinclude/apparmor.hinclude/apparmorfs.hinclude/audit.hinclude/capability.hinclude/cred.hinclude/crypto.hinclude/file.hinclude/ipc.hinclude/net.hinclude/path.hinclude/label.hinclude/policy.hinclude/policy_ns.h
Detected Declarations
struct aa_local_cachefunction apparmor_cred_freefunction apparmor_cred_alloc_blankfunction apparmor_cred_preparefunction apparmor_cred_transferfunction apparmor_task_freefunction apparmor_task_allocfunction apparmor_ptrace_access_checkfunction apparmor_ptrace_tracemefunction apparmor_capgetfunction label_for_each_confinedfunction apparmor_capablefunction common_permfunction common_perm_condfunction common_perm_dir_dentryfunction common_perm_rmfunction common_perm_createfunction apparmor_path_unlinkfunction apparmor_path_mkdirfunction apparmor_path_rmdirfunction apparmor_path_mknodfunction apparmor_path_truncatefunction apparmor_file_truncatefunction apparmor_path_symlinkfunction apparmor_path_linkfunction apparmor_path_renamefunction apparmor_path_chmodfunction apparmor_path_chownfunction apparmor_inode_getattrfunction apparmor_file_openfunction apparmor_file_alloc_securityfunction apparmor_file_free_securityfunction common_file_permfunction apparmor_file_receivefunction apparmor_file_permissionfunction apparmor_file_lockfunction common_mmapfunction apparmor_mmap_filefunction apparmor_file_mprotectfunction audit_uring_cbfunction profile_uringfunction apparmor_uring_override_credsfunction apparmor_uring_sqpollfunction apparmor_sb_mountfunction apparmor_move_mountfunction apparmor_sb_umountfunction apparmor_sb_pivotrootfunction apparmor_getselfattr
Annotated Snippet
struct aa_local_cache {
unsigned int hold;
unsigned int count;
struct list_head head;
};
#define RESERVE_COUNT 2
static int reserve_count = RESERVE_COUNT;
static int buffer_count;
static LIST_HEAD(aa_global_buffers);
static DEFINE_SPINLOCK(aa_buffers_lock);
static DEFINE_PER_CPU(struct aa_local_cache, aa_local_buffers);
/*
* LSM hook functions
*/
/*
* put the associated labels
*/
static void apparmor_cred_free(struct cred *cred)
{
aa_put_label(cred_label(cred));
set_cred_label(cred, NULL);
}
/*
* allocate the apparmor part of blank credentials
*/
static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp)
{
set_cred_label(cred, NULL);
return 0;
}
/*
* prepare new cred label for modification by prepare_cred block
*/
static int apparmor_cred_prepare(struct cred *new, const struct cred *old,
gfp_t gfp)
{
set_cred_label(new, aa_get_newest_label(cred_label(old)));
return 0;
}
/*
* transfer the apparmor data to a blank set of creds
*/
static void apparmor_cred_transfer(struct cred *new, const struct cred *old)
{
set_cred_label(new, aa_get_newest_label(cred_label(old)));
}
static void apparmor_task_free(struct task_struct *task)
{
aa_free_task_ctx(task_ctx(task));
}
static int apparmor_task_alloc(struct task_struct *task,
u64 clone_flags)
{
struct aa_task_ctx *new = task_ctx(task);
aa_dup_task_ctx(new, task_ctx(current));
return 0;
}
static int apparmor_ptrace_access_check(struct task_struct *child,
unsigned int mode)
{
struct aa_label *tracer, *tracee;
const struct cred *cred;
int error;
bool needput;
cred = get_task_cred(child);
tracee = cred_label(cred); /* ref count on cred */
tracer = __begin_current_label_crit_section(&needput);
error = aa_may_ptrace(current_cred(), tracer, cred, tracee,
(mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
: AA_PTRACE_TRACE);
__end_current_label_crit_section(tracer, needput);
put_cred(cred);
return error;
}
Annotation
- Immediate include surface: `linux/lsm_hooks.h`, `linux/moduleparam.h`, `linux/mm.h`, `linux/mman.h`, `linux/mount.h`, `linux/namei.h`, `linux/ptrace.h`, `linux/ctype.h`.
- Detected declarations: `struct aa_local_cache`, `function apparmor_cred_free`, `function apparmor_cred_alloc_blank`, `function apparmor_cred_prepare`, `function apparmor_cred_transfer`, `function apparmor_task_free`, `function apparmor_task_alloc`, `function apparmor_ptrace_access_check`, `function apparmor_ptrace_traceme`, `function apparmor_capget`.
- 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.