$ seccomp-tools dump ./pwn line CODE JT JF K ================================= 0000: 0x20 0x00 0x00 0x00000004 A = arch 0001: 0x15 0x00 0x07 0xc000003e if (A != ARCH_X86_64) goto 0009 0002: 0x20 0x00 0x00 0x00000000 A = sys_number 0003: 0x35 0x05 0x00 0x40000000 if (A >= 0x40000000) goto 0009 0004: 0x15 0x04 0x00 0x00000002 if (A == open) goto 0009 0005: 0x15 0x03 0x00 0x00000101 if (A == openat) goto 0009 0006: 0x15 0x02 0x00 0x0000003b if (A == execve) goto 0009 0007: 0x15 0x01 0x00 0x00000142 if (A == execveat) goto 0009 0008: 0x06 0x00 0x00 0x7fff0000 return ALLOW 0009: 0x06 0x00 0x00 0x7ff00000 return TRACE
查阅资料发现return TRACE行为是由SECCOMP_RET_TRACE来控制,同时查阅第二节seccomp的手册对应的介绍。注意到两点(1)沙箱规则中的系统调用发生时会去通知该进程的tracer,tracer可以skip或者 change to a valid system call来处理本次系统调用。(2)4.8版本内核之前,在tracer被通知之后,沙箱就会不再检测,从而失效。第二点存在逃逸的可能,同时括号内说了安全的seccomp-based的沙箱应该禁止ptrace系统调用。
$ man 2 seccomp ... SECCOMP_RET_TRACE When returned, this value will cause the kernel to attempt to notify a ptrace(2)-based tracer prior to executing the system call. If there is no tracer present, the system call is not executed and returns a failure status with errno set to ENOSYS.
A tracer will be notified if it requests PTRACE_O_TRACESECCOMP using ptrace(PTRACE_SETOPTIONS). The tracer will be notified of a PTRACE_EVENT_SECCOMP and the SECCOMP_RET_DATA portion of the filter's re‐ turn value will be available to the tracer via PTRACE_GETEVENTMSG.
The tracer can skip the system call by changing the system call number to -1. Alternatively, the tracer can change the system call requested by changing the system call to a valid system call number. If the tracer asks to skip the system call, then the system call will appear to return the value that the tracer puts in the return value register.
Before kernel 4.8, the seccomp check will not be run again after the tracer is notified. (This means that, on older kernels, seccomp-based sandboxes must not allow use of ptrace(2)—even of other sandboxed processes—without extreme care; ptracers can use this mechanism to escape from the seccomp sandbox.)
Note that a tracer process will not be notified if another filter returns an action value with a prece‐ dence greater than SECCOMP_RET_TRACE.