security/yama/yama_lsm.c
Source file repositories/reference/linux-study-clean/security/yama/yama_lsm.c
File Facts
- System
- Linux kernel
- Corpus path
security/yama/yama_lsm.c- Extension
.c- Size
- 12090 bytes
- Lines
- 482
- 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/sysctl.hlinux/ptrace.hlinux/prctl.hlinux/ratelimit.hlinux/workqueue.hlinux/string_helpers.hlinux/task_work.hlinux/sched.hlinux/spinlock.huapi/linux/lsm.h
Detected Declarations
struct ptrace_relationstruct access_report_infofunction __report_accessfunction report_accessfunction yama_relation_cleanupfunction yama_ptracer_addfunction yama_ptracer_delfunction yama_task_freefunction yama_task_prctlfunction task_is_descendantfunction ptracer_exception_foundfunction yama_ptrace_access_checkfunction yama_ptrace_tracemefunction yama_dointvec_minmaxfunction yama_init_sysctlfunction yama_init_sysctl
Annotated Snippet
struct ptrace_relation {
struct task_struct *tracer;
struct task_struct *tracee;
bool invalid;
struct list_head node;
struct rcu_head rcu;
};
static LIST_HEAD(ptracer_relations);
static DEFINE_SPINLOCK(ptracer_relations_lock);
static void yama_relation_cleanup(struct work_struct *work);
static DECLARE_WORK(yama_relation_work, yama_relation_cleanup);
struct access_report_info {
struct callback_head work;
const char *access;
struct task_struct *target;
struct task_struct *agent;
};
static void __report_access(struct callback_head *work)
{
struct access_report_info *info =
container_of(work, struct access_report_info, work);
char *target_cmd, *agent_cmd;
target_cmd = kstrdup_quotable_cmdline(info->target, GFP_KERNEL);
agent_cmd = kstrdup_quotable_cmdline(info->agent, GFP_KERNEL);
pr_notice_ratelimited(
"ptrace %s of \"%s\"[%d] was attempted by \"%s\"[%d]\n",
info->access, target_cmd, info->target->pid, agent_cmd,
info->agent->pid);
kfree(agent_cmd);
kfree(target_cmd);
put_task_struct(info->agent);
put_task_struct(info->target);
kfree(info);
}
/* defers execution because cmdline access can sleep */
static void report_access(const char *access, struct task_struct *target,
struct task_struct *agent)
{
struct access_report_info *info;
assert_spin_locked(&target->alloc_lock); /* for target->comm */
if (current->flags & PF_KTHREAD) {
/* I don't think kthreads call task_work_run() before exiting.
* Imagine angry ranting about procfs here.
*/
pr_notice_ratelimited(
"ptrace %s of \"%s\"[%d] was attempted by \"%s\"[%d]\n",
access, target->comm, target->pid, agent->comm, agent->pid);
return;
}
info = kmalloc_obj(*info, GFP_ATOMIC);
if (!info)
return;
init_task_work(&info->work, __report_access);
get_task_struct(target);
get_task_struct(agent);
info->access = access;
info->target = target;
info->agent = agent;
if (task_work_add(current, &info->work, TWA_RESUME) == 0)
return; /* success */
WARN(1, "report_access called from exiting task");
put_task_struct(target);
put_task_struct(agent);
kfree(info);
}
/**
* yama_relation_cleanup - remove invalid entries from the relation list
* @work: unused
*
*/
static void yama_relation_cleanup(struct work_struct *work)
{
struct ptrace_relation *relation;
spin_lock(&ptracer_relations_lock);
rcu_read_lock();
Annotation
- Immediate include surface: `linux/lsm_hooks.h`, `linux/sysctl.h`, `linux/ptrace.h`, `linux/prctl.h`, `linux/ratelimit.h`, `linux/workqueue.h`, `linux/string_helpers.h`, `linux/task_work.h`.
- Detected declarations: `struct ptrace_relation`, `struct access_report_info`, `function __report_access`, `function report_access`, `function yama_relation_cleanup`, `function yama_ptracer_add`, `function yama_ptracer_del`, `function yama_task_free`, `function yama_task_prctl`, `function task_is_descendant`.
- 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.