foundations
foundations copied to clipboard
OXY-1404: Avoid crashes resulting from double seccomp initialization
If a service using foundations accidentally initializes seccomp in a thread that already seccomp initialized, the seccomp violation (depending on configuration) may be violated and crash the process.
An easy way to enter into this scenario is by having a hook in tokio::runtime::Builder::on_thread_start that initializes seccomp for threads that are initialized before the main thread. In this scenario, any threads created from tokio threads (say, inside a tokio task) may lead to a seccomp violation.
This PR uses the syscall prctl(PR_GET_SECCOMP)
(PR_GET_SECCOMP) to find out definitively whether seccomp is already enabled for the current thread. If it is, then the default behavior is to not initialize seccomp again, thus avoiding what may have been a crash otherwise.