def seccomp_example

bend-osdev-bpf@0.1.0.0 · LAWS.bend:252

import bend-osdev-bpf@0.1.0.0/LAWS.bend as LAWS
import Base
import bend-osdev-bpf@0.1.0.0/insn.bend as I
import bend-osdev-bpf@0.1.0.0/seccomp.bend as S

252# seccomp(2), EXAMPLES, install_filter(syscall_nr, t_arch, f_errno) with
253# t_arch = AUDIT_ARCH_X86_64, so upper_nr_limit = X32_SYSCALL_BIT - 1: the
254# call syscall_nr fails with f_errno, other calls are allowed, and another
255# architecture or an x32 call (nr above the limit) kills the process
256def seccomp_example(nr: U32, e: U32) -> List<&2, I.BpfOp>:
257  [I.BpfLdAbs{I.BpfW{}, 4}, I.BpfJmp{I.BpfJeq{}, I.BpfK{S.seccomp_arch_x86_64()}, 0, 5}, I.BpfLdAbs{I.BpfW{}, 0}, I.BpfJmp{I.BpfJgt{}, I.BpfK{U32.sub(S.seccomp_x32_syscall_bit(), 1)}, 3, 0}, I.BpfJmp{I.BpfJeq{}, I.BpfK{nr}, 0, 1}, I.BpfRet{I.BpfRetK{S.SeccompAction.to_u32(S.SeccompErrno{e})}}, I.BpfRet{I.BpfRetK{S.SeccompAction.to_u32(S.SeccompAllow{})}}, I.BpfRet{I.BpfRetK{S.SeccompAction.to_u32(S.SeccompKillProcess{})}}]

Uses (12)

Used by (7)