Categorygithub.com/elastic/go-seccomp-bpf
modulepackage
1.5.0
Repository: https://github.com/elastic/go-seccomp-bpf.git
Documentation: pkg.go.dev

# README

go-seccomp-bpf

Go Report
Card Contributors GitHub release Go Documentation

go-seccomp-bpf is a library for Go (golang) for loading a system call filter on Linux 3.17 and later by taking advantage of secure computing mode, also known as seccomp. Seccomp restricts the system calls that a process can invoke.

The kernel exposes a large number of system calls that are not used by most processes. By installing a seccomp filter, you can limit the total kernel surface exposed to a process (principle of least privilege). This minimizes the impact of unknown vulnerabilities that might be found in the process.

The filter is expressed as a Berkeley Packet Filter (BPF) program. The BPF program is generated based on a filter policy created by you.

Requirements
  • Requires Linux 3.17 because it uses the seccomp syscall in order to take advantage of the SECCOMP_FILTER_FLAG_TSYNC flag to sync the filter to all threads.
Features
  • Pure Go and does not have a libseccomp dependency.
  • Filters are customizable and can be written as an allowlist or blocklist.
  • Supports system call argument filtering.
  • Uses SECCOMP_FILTER_FLAG_TSYNC to sync the filter to all threads created by the Go runtime.
  • Invokes prctl(PR_SET_NO_NEW_PRIVS, 1) to set the threads no_new_privs bit which is generally required before loading a seccomp filter.
  • seccomp-profiler tool for automatically generating a allowlist policy based on the system calls that a binary uses.
Limitations
  • System call tables are only implemented for 386, amd64, arm and arm64. (More system call table generation code should be added to arch/mk_syscalls_linux.go.)
Examples
Updating syscalls for new Linux releases

This package contains a list of syscall numbers that are generated from the Linux sources. Update the git tag here and then run this command to generate the code.

docker run -it --rm -v `pwd`:/go-seccomp-bpf -w /go-seccomp-bpf/arch golang:1.18 go generate
Projects Using elastic/go-seccomp-bpf

Please open a PR to submit your project.

# Packages

Package arch provides architecture specific Linux constants like the audit arch constant and syscall tables.
No description provided by the author

# Functions

LoadFilter will install seccomp using native methods.
NewProgram returns an initialized empty program.
SetNoNewPrivs will use prctl to set the calling thread's no_new_privs bit to 1 (true).
Supported returns true if the seccomp syscall is supported.

# Constants

Allow.
Disallow and return an errno.
Kill the process (since kernel 4.14).
Kill the calling thread.
Allow after logging.
Pass to a tracer or disallow.
Disallow and force a SIGSYS signal.
Forward to user-space supervisor.
No description provided by the author
No description provided by the author
No description provided by the author
All filter return actions except SECCOMP_RET_ALLOW should be logged.
When adding a new filter, synchronize all other threads of the calling process to the same seccomp filter tree.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

No description provided by the author
Filter contains all the parameters necessary to install a Linux seccomp filter for the process.
JumpIf jumps conditionally to the true or the false label.
No description provided by the author
Policy defines the BPF seccomp filter.
The Program consists of a list of bpf.Instructions.
SyscallGroup is a logical block within a Policy that contains a set of syscalls to match against and an action to take.
SyscallWithConditions consists of a syscall number and optional conditions.

# Type aliases

Action specifies what to do when a syscall matches during filter evaluation.
ArgumentConditions consist of a list of up to six conditions for the six arguments.
FilterFlag is a flag that is passed to the seccomp.
Index is the concrete index of an instruction in the instruction list.
Label marks a jump destination in the instruction list of the Program.
No description provided by the author