For Linux kernel v4.14+, you can use SECCOMP_RET_LOG to log syscalls via the audit subsystem. This allows generate_seccomp_policy.py to inspect syscall arguments for finer-grained filtering. This method requires Python 3 bindings for auparse (e.g., python3-audit or python-audit packages).
1. Setup Audit Rules
Set up audit rules and an empty policy. Use a specific $UID to avoid logspam. The following rules enable SYSCALL auditing for specific syscalls to allow argument inspection:
for arch in b32 b64; do
auditctl -a exit,always -F uid=$UID -F arch=$arch -S ioctl -S socket \
-S prctl -S mmap -S mprotect \
$([ "$arch" = "b32" ] && echo "-S mmap2") -c
done
touch /tmp/empty.policy
2. Run Program with Empty Policy
Run your program under minijail0 using the empty policy to stimulate all corner cases and error conditions:
minijail0 -u $UID -g $GID -L -S /tmp/empty.policy -- <program>
3. Generate Policy
Generate the policy from the resulting audit.log:
./tools/generate_seccomp_policy.py --audit-comm $PROGRAM_NAME audit.log > $PROGRAM_NAME.policy
Note: The tool can consume multiple audit logs and/or strace traces to produce a single unified policy.
# Setup audit rules
for arch in b32 b64; do
auditctl -a exit,always -F uid=$UID -F arch=$arch -S ioctl -S socket \
-S prctl -S mmap -S mprotect \
$([ "$arch" = "b32" ] && echo "-S mmap2") -c
done
touch /tmp/empty.policy
# Run with empty policy
minijail0 -u $UID -g $GID -L -S /tmp/empty.policy -- <program>
# Generate policy
./tools/generate_seccomp_policy.py --audit-comm $PROGRAM_NAME audit.log > $PROGRAM_NAME.policy