security/landlock/task.c
Source file repositories/reference/linux-study-clean/security/landlock/task.c
File Facts
- System
- Linux kernel
- Corpus path
security/landlock/task.c- Extension
.c- Size
- 12355 bytes
- Lines
- 464
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/current.hlinux/cleanup.hlinux/cred.hlinux/errno.hlinux/kernel.hlinux/lsm_audit.hlinux/lsm_hooks.hlinux/rcupdate.hlinux/sched.hlinux/sched/signal.hnet/af_unix.hnet/sock.haudit.hcommon.hcred.hdomain.hfs.hruleset.hsetup.htask.h
Detected Declarations
function domain_scope_lefunction domain_ptracefunction hook_ptrace_access_checkfunction scoped_guardfunction landlock_log_denialfunction hook_ptrace_tracemefunction hook_ptrace_access_checkfunction domain_is_scopedfunction sock_is_scopedfunction is_abstract_socketfunction hook_unix_stream_connectfunction landlock_log_denialfunction hook_unix_may_sendfunction landlock_log_denialfunction hook_task_killfunction scoped_guardfunction landlock_log_denialfunction hook_file_send_sigiotaskfunction scoped_guardfunction landlock_log_denialfunction landlock_add_task_hooks
Annotated Snippet
landlock_log_denial(parent_subject, &(struct landlock_request) {
.type = LANDLOCK_REQUEST_PTRACE,
.audit = {
.type = LSM_AUDIT_DATA_TASK,
.u.tsk = child,
},
.layer_plus_one = parent_subject->domain->num_layers,
});
return err;
}
/**
* hook_ptrace_traceme - Determines whether another process may trace the
* current one
*
* @parent: Task proposed to be the tracer.
*
* If the parent has Landlock rules, then the current task must have the same
* or more rules. Else denied.
*
* Return: 0 if permission is granted, -errno if denied.
*/
static int hook_ptrace_traceme(struct task_struct *const parent)
{
const struct landlock_cred_security *parent_subject;
const struct landlock_ruleset *child_dom;
int err;
child_dom = landlock_get_current_domain();
guard(rcu)();
parent_subject = landlock_cred(__task_cred(parent));
err = domain_ptrace(parent_subject->domain, child_dom);
if (!err)
return 0;
/*
* For the ptrace_traceme case, we log the domain which is the cause of
* the denial, which means the parent domain instead of the current
* domain. This may look unusual because the ptrace_traceme action is a
* request to be traced, but the semantic is consistent with
* hook_ptrace_access_check().
*/
landlock_log_denial(parent_subject, &(struct landlock_request) {
.type = LANDLOCK_REQUEST_PTRACE,
.audit = {
.type = LSM_AUDIT_DATA_TASK,
.u.tsk = current,
},
.layer_plus_one = parent_subject->domain->num_layers,
});
return err;
}
/**
* domain_is_scoped - Check if an interaction from a client/sender to a
* server/receiver should be restricted based on scope controls.
*
* @client: IPC sender domain.
* @server: IPC receiver domain.
* @scope: The scope restriction criteria.
*
* Return: True if @server is in a different domain from @client and @client
* is scoped to access @server (i.e. access should be denied), false otherwise.
*/
static bool domain_is_scoped(const struct landlock_ruleset *const client,
const struct landlock_ruleset *const server,
access_mask_t scope)
{
int client_layer, server_layer;
const struct landlock_hierarchy *client_walker, *server_walker;
/* Quick return if client has no domain */
if (WARN_ON_ONCE(!client))
return false;
client_layer = client->num_layers - 1;
client_walker = client->hierarchy;
/*
* client_layer must be able to represent all numbers from
* LANDLOCK_MAX_NUM_LAYERS - 1 to -1 for the loop below to terminate.
* (It must be large enough, and it must be signed.)
*/
BUILD_BUG_ON(!is_signed_type(typeof(client_layer)));
BUILD_BUG_ON(LANDLOCK_MAX_NUM_LAYERS - 1 >
type_max(typeof(client_layer)));
server_layer = server ? (server->num_layers - 1) : -1;
Annotation
- Immediate include surface: `asm/current.h`, `linux/cleanup.h`, `linux/cred.h`, `linux/errno.h`, `linux/kernel.h`, `linux/lsm_audit.h`, `linux/lsm_hooks.h`, `linux/rcupdate.h`.
- Detected declarations: `function domain_scope_le`, `function domain_ptrace`, `function hook_ptrace_access_check`, `function scoped_guard`, `function landlock_log_denial`, `function hook_ptrace_traceme`, `function hook_ptrace_access_check`, `function domain_is_scoped`, `function sock_is_scoped`, `function is_abstract_socket`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source implementation candidate.
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.