kernel/seccomp.c
Source file repositories/reference/linux-study-clean/kernel/seccomp.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/seccomp.c- Extension
.c- Size
- 67497 bytes
- Lines
- 2570
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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 participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/refcount.hlinux/audit.hlinux/compat.hlinux/coredump.hlinux/kmemleak.hlinux/nospec.hlinux/prctl.hlinux/sched.hlinux/sched/task_stack.hlinux/seccomp.hlinux/slab.hlinux/syscalls.hlinux/sysctl.hasm/syscall.hlinux/file.hlinux/filter.hlinux/pid.hlinux/ptrace.hlinux/capability.hlinux/uaccess.hlinux/anon_inodes.hlinux/lockdep.h
Detected Declarations
syscall seccompstruct seccomp_knotifstruct seccomp_kaddfdstruct notificationstruct action_cachestruct action_cachestruct seccomp_filterstruct seccomp_log_nameenum notify_statefunction seccomp_cache_check_allowfunction seccomp_cache_preparefunction populate_seccomp_datafunction filterfunction seccomp_cache_check_allow_bitmapfunction seccomp_cache_check_allowfunction seccomp_run_filtersfunction seccomp_may_assign_modefunction arch_seccomp_spec_mitigatefunction is_ancestorfunction seccomp_can_sync_threadsfunction seccomp_filter_freefunction __seccomp_filter_orphanfunction __put_seccomp_filterfunction __seccomp_filter_releasefunction seccomp_filter_releasefunction seccomp_can_sync_threadsfunction seccomp_prepare_user_filterfunction seccomp_uprobe_exceptionfunction seccomp_is_const_allowfunction seccomp_cache_prepare_bitmapfunction seccomp_cache_preparefunction seccomp_attach_filterfunction __get_seccomp_filterfunction get_seccomp_filterfunction seccomp_logfunction __secure_computing_strictfunction secure_computing_strictfunction __secure_computingfunction seccomp_next_notify_idfunction seccomp_handle_addfdfunction should_sleep_killablefunction seccomp_do_user_notificationfunction __seccomp_filterfunction __seccomp_filterfunction __secure_computingfunction prctl_get_seccompfunction seccomp_set_mode_strictfunction seccomp_notify_free
Annotated Snippet
SYSCALL_DEFINE3(seccomp, unsigned int, op, unsigned int, flags,
void __user *, uargs)
{
return do_seccomp(op, flags, uargs);
}
/**
* prctl_set_seccomp: configures current->seccomp.mode
* @seccomp_mode: requested mode to use
* @filter: optional struct sock_fprog for use with SECCOMP_MODE_FILTER
*
* Returns 0 on success or -EINVAL on failure.
*/
long prctl_set_seccomp(unsigned long seccomp_mode, void __user *filter)
{
unsigned int op;
void __user *uargs;
switch (seccomp_mode) {
case SECCOMP_MODE_STRICT:
op = SECCOMP_SET_MODE_STRICT;
/*
* Setting strict mode through prctl always ignored filter,
* so make sure it is always NULL here to pass the internal
* check in do_seccomp().
*/
uargs = NULL;
break;
case SECCOMP_MODE_FILTER:
op = SECCOMP_SET_MODE_FILTER;
uargs = filter;
break;
default:
return -EINVAL;
}
/* prctl interface doesn't have flags, so they are always zero. */
return do_seccomp(op, 0, uargs);
}
#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
static struct seccomp_filter *get_nth_filter(struct task_struct *task,
unsigned long filter_off)
{
struct seccomp_filter *orig, *filter;
unsigned long count;
/*
* Note: this is only correct because the caller should be the (ptrace)
* tracer of the task, otherwise lock_task_sighand is needed.
*/
spin_lock_irq(&task->sighand->siglock);
if (task->seccomp.mode != SECCOMP_MODE_FILTER) {
spin_unlock_irq(&task->sighand->siglock);
return ERR_PTR(-EINVAL);
}
orig = task->seccomp.filter;
__get_seccomp_filter(orig);
spin_unlock_irq(&task->sighand->siglock);
count = 0;
for (filter = orig; filter; filter = filter->prev)
count++;
if (filter_off >= count) {
filter = ERR_PTR(-ENOENT);
goto out;
}
count -= filter_off;
for (filter = orig; filter && count > 1; filter = filter->prev)
count--;
if (WARN_ON(count != 1 || !filter)) {
filter = ERR_PTR(-ENOENT);
goto out;
}
__get_seccomp_filter(filter);
out:
__put_seccomp_filter(orig);
return filter;
}
long seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
void __user *data)
{
Annotation
- Immediate include surface: `linux/refcount.h`, `linux/audit.h`, `linux/compat.h`, `linux/coredump.h`, `linux/kmemleak.h`, `linux/nospec.h`, `linux/prctl.h`, `linux/sched.h`.
- Detected declarations: `syscall seccomp`, `struct seccomp_knotif`, `struct seccomp_kaddfd`, `struct notification`, `struct action_cache`, `struct action_cache`, `struct seccomp_filter`, `struct seccomp_log_name`, `enum notify_state`, `function seccomp_cache_check_allow`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.