7979 | CLONE_NEWNET | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWCGROUP
8080)
8181
82- # Dangerous ioctl commands — TIOCSTI allows injecting input into
83- # another terminal session (terminal escape attack).
82+ # Dangerous ioctl commands:
83+ # - TIOCSTI: inject input into another terminal session (terminal escape)
84+ # - TIOCLINUX: access kernel console (keystroke injection on VTs,
85+ # selection buffer read, keyboard reprogramming)
8486TIOCSTI = 0x5412
87+ TIOCLINUX = 0x541C
88+ _DANGEROUS_IOCTLS = (TIOCSTI , TIOCLINUX )
8589
8690# Dangerous prctl(2) options — these allow a sandboxed process to
8791# weaken its own confinement.
@@ -304,7 +308,7 @@ def _build_arg_filters() -> bytes:
304308 - clone(2): Block namespace flags (CLONE_NEW*) with ERRNO.
305309 Plain forks fall through to the main filter (USER_NOTIF if
306310 clone is in the notif list, or ALLOW if not).
307- - ioctl(2): Block TIOCSTI (terminal input injection ).
311+ - ioctl(2): Block TIOCSTI and TIOCLINUX (terminal attacks ).
308312 - prctl(2): Block dangerous options (PR_SET_DUMPABLE,
309313 PR_SET_SECCOMP, PR_SET_SECUREBITS, PR_SET_PTRACER).
310314 """
@@ -323,16 +327,17 @@ def _build_arg_filters() -> bytes:
323327 insns += _bpf_jump (BPF_JMP | BPF_JSET | BPF_K , _CLONE_NS_FLAGS , 0 , 1 )
324328 insns += _bpf_stmt (BPF_RET | BPF_K , SECCOMP_RET_ERRNO | ERRNO_EPERM )
325329
326- # --- ioctl: block TIOCSTI (terminal input injection) ---
327- # Load syscall number
330+ # --- ioctl: block dangerous commands (TIOCSTI, TIOCLINUX) ---
328331 insns += _bpf_stmt (BPF_LD | BPF_W | BPF_ABS , OFFSET_NR )
329- # if nr != ioctl, skip ahead
330- insns += _bpf_jump (BPF_JMP | BPF_JEQ | BPF_K , _SYSCALL_NR ["ioctl" ], 0 , 3 )
332+ n_ioctls = len (_DANGEROUS_IOCTLS )
333+ # if nr != ioctl, skip: 1 (load arg1) + n_ioctls*2 (check+deny each)
334+ skip_count = 1 + n_ioctls * 2
335+ insns += _bpf_jump (BPF_JMP | BPF_JEQ | BPF_K , _SYSCALL_NR ["ioctl" ], 0 , skip_count )
331336 # Load ioctl request (arg1, low 32 bits)
332337 insns += _bpf_stmt (BPF_LD | BPF_W | BPF_ABS , OFFSET_ARGS1_LO )
333- # if request == TIOCSTI → deny
334- insns += _bpf_jump (BPF_JMP | BPF_JEQ | BPF_K , TIOCSTI , 0 , 1 )
335- insns += _bpf_stmt (BPF_RET | BPF_K , SECCOMP_RET_ERRNO | ERRNO_EPERM )
338+ for cmd in _DANGEROUS_IOCTLS :
339+ insns += _bpf_jump (BPF_JMP | BPF_JEQ | BPF_K , cmd , 0 , 1 )
340+ insns += _bpf_stmt (BPF_RET | BPF_K , SECCOMP_RET_ERRNO | ERRNO_EPERM )
336341
337342 # --- prctl: block dangerous options that weaken the sandbox ---
338343 insns += _bpf_stmt (BPF_LD | BPF_W | BPF_ABS , OFFSET_NR )
0 commit comments