97 points · by zdw · 3y ago · 15 comments
[1] https://davidlattimore.github.io/making-supply-chain-attacks...
But yes technically such a setup is possible (not with any mainstream OS though). It would have to be very restrictive w.r.t mounts and virtual file systems.
Is it just "it just takes effect at the time of call and it's up to you to synchronize whatever you need to synchronize"? Anything racing with a pledge call in an observable way is clearly tempting fate anyhow.
If the flag were used, then each thread's filter tree would be atomically swapped out from its old version, then the thread would be set to be in SECCOMP_MODE_FILTER if it isn't already. Setting the mode causes the SYSCALL_WORK_SECCOMP bit to be set in the thread's syscall_work field, which the thread checks every time it enters a syscall from user mode. Therefore, any currently-running syscall in the thread may or may not go through, but all future syscalls will be subject to the new filter.
If current long-running syscalls are a concern, then I think (but haven't tested) it would be sufficient to define a signal handler without SA_RESTART, then send the corresponding signal to every other thread to interrupt all their syscalls. The handler could even have a counter that gets incremented so that the caller knows when all threads have been interrupted; this is basically how libcs implement a process-wide setuid/setgid on top of Linux's per-thread syscalls.
Also, the OpenBSD man page (https://man.openbsd.org/pledge.2) states “The pledge() system call forces the current process into a restricted-service operating mode”, indicating it’s process-wide.
Reading https://news.ycombinator.com/item?id=38032251, that seems different from its Linux port.
Of course! I think the chance of that happening must be about 100%. When else would it start such threads?
It would be an interesting bug if somebody managed to get a garbage collector thread to read files or to make network requests fo them…