Part of the accepted-design index.
See the usage guide for operations and verification for contributor commands and environments.
The package accepts a small constant-operand subset of classic BPF rather than a syscall-name policy language, eBPF framework, or unrestricted instruction set. Absolute word loads, constant masking, forward comparisons/jumps, and constant results express syscall and scalar-argument checks while keeping validation bounded and independent of kernel mutation. Excluding scratch state, indirect reads, computed return actions, and a compiler avoids a verifier or language whose policy semantics would need a separate security contract. Unknown actions and ignored input data are rejected explicitly.
Construction copies to maintained x/sys/unix.SockFilter values, and loading uses its syscall number and SockFprog layout. Linux retains an installed program independently of the Go value. The immutable filter can be constructed once and shared. Each attachment is a new stacking operation with kernel-owned lifetime.
Explicit architecture labelling makes the caller’s syscall-number convention visible. Accepting only the current amd64 or arm64 ABI avoids silently interpreting another architecture’s numbers. A mandatory prefix kills other audit architectures; amd64 additionally rejects x32’s syscall bit because audit architecture alone does not distinguish it. Caller jumps stay inside their own forward-only body and cannot reach or bypass that prefix. Resetting the accumulator afterward preserves the usual zero-initialized classic-BPF body semantics.
This deliberately excludes multi-ABI policies and cross-architecture exec. An unrestricted raw-program entrypoint would let callers omit this essential check and make validation claims much weaker. The fixed body bound reserves the largest prefix within the 4096-instruction kernel limit, giving the same public size limit on both supported architectures. ABI fields, actions, and TSYNC behavior are checked against Linux 7.0 UAPI and its implementation; seccomp(2) explains x32 and argument-width pitfalls.
A zero synchronization value is invalid. A thread-local default could leave a multithreaded Go caller believing its process was restricted; automatic TSYNC would make otherwise local code change every runtime thread. Explicit CallingThread and AllThreads expose that choice without enumerating Go threads or using private runtime hooks. TSYNC’s positive refusing TID has its own error type, preserving information that an errno-only wrapper would lose. Failed synchronization never falls back to local attachment.
No-new-privileges is an explicit loading option rather than an undocumented prerequisite or unconditional side effect. Keeping its prctl separate inside Load lets callers with an existing bit or appropriate capability avoid that operation. It also means a successful prctl followed by failed loading cannot roll back the bit. The API documents this partial state, requires caller-owned thread affinity, and offers no scoped callback or restoration promise. Kernel TSYNC handles process-wide filter consistency; application policy coordination remains external.
The package leaves Go syscall policy, signal disposition, ptrace supervision, and process startup to their existing owners. A complete sandbox or runtime-compatible allow-list would require application-specific decisions far beyond filter loading. Real restrictions therefore run only in bounded child fixtures during verification, including deliberate fatal actions, thread-tree conflicts, and inherited policy after exec.
Listen attaches a Notify filter and returns an owned resource. Requiring this explicit path avoids installing a Notify filter without a listener, which would make its matching syscalls return ENOSYS. The normal TSYNC contract reports a positive refusing thread ID. Linux also uses positive values for new listener descriptors, and combining these flags would require switching to TSYNC_ESRCH and discarding that distinction. Calling-thread loading lets a dedicated setup goroutine pass the filter to a workload via standard process start while an unrestricted goroutine supervises it. Linux 7.0 seccomp implementation.
The existing pure-Go loader and x/sys ioctl constants cover the operations with small Linux UAPI wire records. SECCOMP_GET_NOTIF_SIZES validates the supported prefix and supplies the kernel’s buffer sizes before the irreversible attachment. The libseccomp Go binding exposes notification operations through cgo and requires native libseccomp, so adopting it would change the package’s build contract. Linux 7.0 notification layout, libseccomp Go bindings.
An ioctl already waiting for a notification pins the listener. The Linux receive ioctl can block after readiness changes, so treating poll readiness as cancellation would make deadlines unreliable. The supervisor owns workload shutdown and coordinates in-flight receives. The listener owns its descriptor and provides explicit value, errno, and continue operations. A notification ID proves only that a request is pending at the time of validation, and continued syscalls leave any memory-dependent enforcement to independent kernel policy. seccomp_unotify(2).
Two named operations make the kernel’s reply boundary visible. AddFile supports a supervisor that needs to install a file before making a separate reply. AddFileAndRespond uses the kernel’s SECCOMP_ADDFD_FLAG_SEND because the target can leave the interception between separate installation and reply calls. A failed separate reply leaves the installed descriptor under target ownership. Exact placement uses Linux’s replacement semantics, so it requires the caller to select it explicitly. Close-on-exec is the default, with an explicit choice for exec inheritance. Linux 7.0 seccomp implementation, Linux 7.0 descriptor replacement.
The implementation uses the existing pure-Go listener and the maintained x/sys ioctl and flag constants. os.File.SyscallConn pins the borrowed source through the ioctl, avoiding a temporary duplicate that would consume another descriptor slot. The target gets its own descriptor and shares the underlying open file description. The resulting descriptor number is meaningful in the target’s table. Linux 7.0 seccomp UAPI.