Syscall Filtering and Attack Surface Reduction
A comprehensive collection of seccomp-bpf (Berkeley Packet Filter) profiles and tooling for reducing attack surface by filtering system calls. Provides pre-built profiles for common security scenarios and a framework for creating custom syscall filters.
seccomp-profiles enables fine-grained control over which system calls a process can execute, dramatically reducing the attack surface of applications. By whitelisting only necessary syscalls, you can prevent entire classes of exploits.
- strict: Minimal syscall set for computation-only workloads
- web-server: Profile optimized for HTTP/HTTPS servers
- database: Profile for database engines
- build-tools: Profile for compilers and build systems
- container-runtime: Profile for container execution environments
- nodejs: Profile for Node.js applications
- python: Profile for Python interpreters
- general: Balanced profile for general-purpose applications
- Profile Generator: Create custom profiles from syscall traces
- Profile Validator: Verify profile correctness and security
- Profile Analyzer: Analyze attack surface reduction metrics
- Profile Merger: Combine multiple profiles intelligently
- Runtime Tracer: Capture syscalls from running processes
- Architecture Support: x86_64, ARM64, ARM, x86
- Kernel Version Detection: Automatic feature detection
- Error Handling: Configurable actions (KILL, TRAP, ERRNO, LOG)
- Argument Filtering: Filter based on syscall arguments
- Conditional Filters: Dynamic filters based on process state
┌─────────────────────────────────────────────┐
│ Application Layer │
│ (Your code using seccomp-profiles) │
└─────────────────┬───────────────────────────┘
│
┌─────────────────▼───────────────────────────┐
│ Profile Management API │
│ - Profile Loader │
│ - Profile Compiler │
│ - Profile Applicator │
└─────────────────┬───────────────────────────┘
│
┌─────────────────▼───────────────────────────┐
│ BPF Program Generator │
│ - Syscall Filter Rules │
│ - Argument Matchers │
│ - Action Handlers │
└─────────────────┬───────────────────────────┘
│
┌─────────────────▼───────────────────────────┐
│ Linux Seccomp Interface │
│ - prctl(PR_SET_SECCOMP) │
│ - seccomp(2) syscall │
└─────────────────────────────────────────────┘
git submodule add https://github.com/navinBRuas/_SecureExecutionEnvironment.git vendor/secure-execution
cd vendor/secure-execution/seccomp-profiles
makemake install PREFIX=/usr/local#include <seccomp-profiles/profile.h>
int main() {
// Load a pre-built profile
seccomp_profile_t *profile = seccomp_profile_load("strict.json");
if (!profile) {
fprintf(stderr, "Failed to load profile\n");
return 1;
}
// Apply the profile to current process
if (seccomp_profile_apply(profile, SECCOMP_ACTION_KILL) != 0) {
fprintf(stderr, "Failed to apply profile\n");
return 1;
}
// From this point, only allowed syscalls work
printf("Seccomp profile applied successfully\n");
// Clean up
seccomp_profile_free(profile);
return 0;
}{
"name": "my-application",
"version": "1.0",
"arch": ["x86_64", "aarch64"],
"default_action": "SCMP_ACT_ERRNO",
"syscalls": {
"allow": [
"read",
"write",
"open",
"close",
"stat",
"fstat",
"lstat",
"mmap",
"munmap",
"brk",
"exit",
"exit_group"
],
"conditional": [
{
"name": "ioctl",
"args": [
{"index": 1, "op": "==", "value": "FIONREAD"}
]
}
]
}
}from seccomp_profiles import Profile, Action
# Load profile
profile = Profile.load('strict.json')
# Apply to current process
profile.apply(default_action=Action.KILL)
# Or apply to a subprocess
import subprocess
profile.apply_to_subprocess(['/bin/ls', '-la'])Minimal syscall set for pure computation. No filesystem, network, or IPC access.
Allowed syscalls: read, write, brk, mmap, munmap, mprotect, exit, exit_group
Use cases:
- Mathematical computations
- Data transformations
- Cryptographic operations
- Sandboxed code execution
Optimized for HTTP/HTTPS server processes.
Key features:
- Socket operations (bind, listen, accept, send, recv)
- File serving (open, read, stat)
- No process creation
- No ptrace/debugging capabilities
Use cases:
- Nginx workers
- Apache workers
- Node.js HTTP servers
- Python WSGI applications
Profile for database engine processes.
Key features:
- File I/O operations
- Memory management
- Shared memory (IPC)
- No network operations (assumes local socket)
Use cases:
- PostgreSQL
- MySQL/MariaDB
- SQLite
- Redis
Load a profile from a JSON file.
Parse a profile from a JSON string.
Load a pre-built profile by name.
Apply profile to the current process.
Actions:
SECCOMP_ACTION_KILL- Kill process on violationSECCOMP_ACTION_TRAP- Send SIGSYS on violationSECCOMP_ACTION_ERRNO- Return errno on violationSECCOMP_ACTION_TRACE- Notify tracer on violationSECCOMP_ACTION_LOG- Log violation and allow
Apply profile to a child process (requires ptrace).
Create a new empty profile.
Add a syscall to the allow list.
Add a syscall with argument filtering.
Save profile to a JSON file.
Analyze a syscall trace and suggest a profile.
Compare two profiles and show differences.
Validate profile for correctness and security.
Capture syscalls from a running process:
# Trace a command
seccomp-trace /path/to/program args
# Generate profile from trace
seccomp-trace --generate-profile output.json /path/to/program argsAnalyze attack surface reduction:
seccomp-analyze profiles/strict.json
# Output:
# Profile: strict
# Syscalls allowed: 12 / 334 (3.6%)
# Attack surface reduction: 96.4%
# Risk categories blocked:
# - Process creation: ✓
# - Network operations: ✓
# - File system modification: ✓
# - Privilege escalation: ✓seccomp-validate profiles/my-app.json
# Checks:
# - JSON syntax
# - Syscall name validity
# - Argument filter correctness
# - Architecture compatibility
# - Security best practices#include <process-sandbox/sandbox.h>
#include <seccomp-profiles/profile.h>
sandbox_config_t config = sandbox_config_new();
seccomp_profile_t *profile = seccomp_profile_load("web-server.json");
// Apply seccomp filter after sandbox creation
int apply_seccomp(void *arg) {
seccomp_profile_t *profile = (seccomp_profile_t *)arg;
return seccomp_profile_apply(profile, SECCOMP_ACTION_KILL);
}
sandbox_config_set_pre_exec_callback(&config, apply_seccomp, profile);
sandbox_exec(&config, "/usr/sbin/nginx", argv, NULL);# Use as Docker seccomp profile
docker run --security-opt seccomp=profiles/web-server.json nginx[Service]
ExecStart=/usr/bin/myapp
SystemCallFilter=@/path/to/seccomp-profiles/strict.json
SystemCallErrorNumber=EPERM- Linux kernel 3.5+ (seccomp-bpf support)
- libseccomp-dev
- GCC 9+ or Clang 10+
- Python 3.7+ (for tooling)
# Build library
make
# Build tools
make tools
# Run tests
make test
# Install
sudo make installseccomp-trace --output trace.log ./myapp --my-argsseccomp-generate --input trace.log --output myapp.jsonseccomp-validate myapp.json
seccomp-analyze myapp.jsonseccomp-test myapp.json ./myapp --my-argssudo cp myapp.json /etc/seccomp-profiles/- Start Strict: Begin with the strictest profile that works
- Iterate: Add syscalls only as needed
- Use Argument Filters: Restrict syscall arguments when possible
- Default Deny: Always use deny-by-default with allowlists
- Test Thoroughly: Test all application paths
- Monitor Violations: Log and monitor seccomp violations in production
- Version Profiles: Keep profiles in version control
- Regular Audits: Review and update profiles regularly
- Overhead: <1% CPU overhead for most workloads
- Memory: ~4KB per profile loaded
- Filter Complexity: Linear search through rules (keep profiles concise)
- Argument Filters: Add minimal overhead (~10 ns per check)
The application is attempting a blocked syscall. Use the tracer to identify:
seccomp-trace --identify-violation ./myappValidate profile syntax:
seccomp-validate myapp.jsonCheck filter complexity:
seccomp-analyze --performance myapp.jsonSee CONTRIBUTING.md
MIT License - See LICENSE
git submodule add https://github.com/navinBRuas/_SecureExecutionEnvironment.git vendor/secure-executionUse vendor/secure-execution/seccomp-profiles for local builds and integration.
Follow the C and Python examples above and module tooling for profile generation.
Profiles are configured via JSON files and applied through the seccomp profile API.
Current version: 0.1.0 (see VERSION.md).
See CHANGELOG.md for release history.