cybersecurity · advanced · ~15 min
seccomp's allow-list semantics + binary search.
Decide whether a syscall is permitted by checking it against a sorted allowlist — the set-membership test at the heart of a seccomp filter.
Implement int syscall_allowed(int sys, const int *allow, int n_allow) that returns 1 if sys appears in the allowlist and 0 otherwise. The allowlist is sorted ascending, so use binary search.
sys: the candidate syscall number.allow: a sorted (ascending) array of allowed syscall numbers the grader provides; may be NULL.n_allow: the number of entries in allow.Returns 1 if sys is in the allowlist, 0 otherwise.
allow = {0, 1, 2, 3, 11, 60, 231}
syscall_allowed(0, allow, 7) -> 1 (read)
syscall_allowed(11, allow, 7) -> 1 (mmap)
syscall_allowed(59, allow, 7) -> 0 (execve — not listed)
syscall_allowed(-1, allow, 7) -> 0
syscall_allowed(0, NULL, 0) -> 0 (empty list denies all)
n_allow <= 0 or allow == NULL): deny everything, return 0.seccomp filters are how Chrome, OpenSSH and Docker shrink attack surface. The core operation is a simple set-membership test.
A syscall number sys, a sorted ascending array allow (may be NULL), and its length n_allow.
1 if sys is in the allowlist; otherwise 0.
Use binary search (O(log n)); empty list denies all.
int syscall_allowed(int sys, const int *allow, int n_allow) { /* TODO */ (void)sys; (void)allow; (void)n_allow; return 0; }
Linear search — works but doesn't demonstrate the right pattern.
Empty allow-list (deny all). Negative syscall.
O(log n).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.