Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

seccomp(2)

FieldValue
Numbers (x64 / i386 / arm64-generic / arm32)317 / 354 / 277 / 383 (cached kernel tables; hub agrees)
Since (kernel)3.17 (man VERSIONS: “The seccomp() system call first appeared in Linux 3.17”; hub agrees). Per-arch BPF filter support per the man page: x86-64 / i386 / x32 since 3.5, ARM and s390 since 3.8, MIPS 3.16, ARM-64 3.19, PowerPC and Tile 4.3
Man pageman2/seccomp.2 (local cache, dated 2021-08-27)
glibc wrapperNone; call via syscall(SYS_seccomp, operation, flags, args) (man page; nm -D on glibc 2.41 shows no seccomp symbol). libseccomp is the recommended front end (man NOTES)
Aliases coverednone (prctl PR_SET_SECCOMP is an equivalent interface, see below)
Ledger IDSC-seccomp

Purpose

seccomp() operates on the Secure Computing (seccomp) state of the calling process: it installs the hard-coded strict filter or a caller-supplied BPF filter program that inspects every system call and returns a verdict, or it queries action support and notification sizes. Background reading in this book (architecture, threat model, libseccomp programming – not duplicated here): kernel security overview and userspace programming guide.

Synopsis

#include <linux/seccomp.h>
int syscall(SYS_seccomp, unsigned int operation, unsigned int flags,
            void *args);

Arguments and behavior

OperationValueBehavior (man page)
SECCOMP_SET_MODE_STRICT0Only read(2), write(2), _exit(2) (not exit_group) and sigreturn(2) allowed; anything else kills the thread. Needs CONFIG_SECCOMP. flags must be 0, args NULL. Equals prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT)
SECCOMP_SET_MODE_FILTER1args points to struct sock_fprog (BPF program). Needs CONFIG_SECCOMP_FILTER and either CAP_SYS_ADMIN or the no_new_privs bit (prctl(PR_SET_NO_NEW_PRIVS, 1)), else EACCES. Equals prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, args) when flags is 0
SECCOMP_GET_ACTION_AVAIL2 (4.14)args points to a u32 action; tests kernel support
SECCOMP_GET_NOTIF_SIZES3 (5.0)args points to struct seccomp_notif_sizes

Mode constants (linux/seccomp.h): SECCOMP_MODE_DISABLED 0, SECCOMP_MODE_STRICT 1, SECCOMP_MODE_FILTER 2.

Return value and errors

0 on success; on SECCOMP_FILTER_FLAG_TSYNC failure the return value is the ID of the first thread that could not synchronize; otherwise -1 with errno: EACCES, EBUSY (a NEW_LISTENER filter already installed), EFAULT, EINVAL (unknown operation; invalid flags; invalid or oversized filter program – more than BPF_MAXINSNS 4096 instructions), ENOMEM (total filters would exceed MAX_INSNS_PER_PATH 32768 instructions), EOPNOTSUPP, ESRCH.

Flags and constants

Filter flags for SECCOMP_SET_MODE_FILTER (installed linux/seccomp.h; since values from the cached man page where documented):

FlagValueSince
SECCOMP_FILTER_FLAG_TSYNC1UL << 0initial (no since given in man)
SECCOMP_FILTER_FLAG_LOG1UL << 14.14
SECCOMP_FILTER_FLAG_SPEC_ALLOW1UL << 24.17
SECCOMP_FILTER_FLAG_NEW_LISTENER1UL << 35.0 (returns a supervisor fd for SECCOMP_RET_USER_NOTIF; at most one such filter per thread)
SECCOMP_FILTER_FLAG_TSYNC_ESRCH1UL << 4header-sourced only; not in the cached man page; since unverified
SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV1UL << 5header-sourced only; since unverified

Filter return actions, in decreasing order of precedence (man page; values from linux/seccomp.h):

ActionValueSinceEffect
SECCOMP_RET_KILL_PROCESS0x80000000U4.14terminate whole process as though by SIGSYS; syscall not run
SECCOMP_RET_KILL_THREAD (= SECCOMP_RET_KILL)0x00000000Uoriginalterminate the calling thread; unsafe for multithreaded processes
SECCOMP_RET_TRAP0x00030000Uoriginalthread-directed SIGSYS, si_code = SYS_SECCOMP
SECCOMP_RET_ERRNO0x00050000Uoriginalreturn SECCOMP_RET_DATA as errno without running the call
SECCOMP_RET_USER_NOTIF0x7fc00000U5.0forward to the supervisor fd; ENOSYS if none attached
SECCOMP_RET_TRACE0x7ff00000Uoriginalnotify a ptrace tracer (PTRACE_O_TRACESECCOMP); ENOSYS without one
SECCOMP_RET_LOG0x7ffc0000U4.14log, then execute the syscall
SECCOMP_RET_ALLOW0x7fff0000Uoriginalexecute the syscall

Masks: SECCOMP_RET_ACTION_FULL 0xffff0000U, SECCOMP_RET_ACTION 0x7fff0000U, SECCOMP_RET_DATA 0x0000ffffU. An unknown action is treated as SECCOMP_RET_KILL_PROCESS (since 4.14) or SECCOMP_RET_KILL_THREAD (4.13 and earlier). All filters run, most recently installed first; the highest-precedence action wins.

Security and notes

The no_new_privs requirement prevents an unprivileged process from filtering setuid-root execution into a trap (man page explains the setuid scenario). /proc/sys/kernel/seccomp/actions_avail and actions_logged (4.14) expose and control audit logging of actions. Filters are inherited across fork/clone when allowed, and preserved across execve(2) when allowed; further filters may be added only if prctl(2)/seccomp(2) are still allowed by the current filter. Before 5.4, x32-range syscall numbers must be denied explicitly by policies.

References

  • Cached man page: source-cache/man-pages-sparse/man2/seccomp.2; companion seccomp_unotify.2 in the cache
  • Headers: installed /usr/include/linux/seccomp.h
  • Book cross-links (background): src/linux/kernel/security/seccomp.md, src/linux/sysprog/seccomp.md
  • Online: https://man7.org/linux/man-pages/man2/seccomp.2.html