3 ms·
When killing an entire cgroup, you might avoid the PID reuse race by getting a list of PIDs in a cgroup, then for each PID, first opening a PIDFD to that PID, c
by teddyh 4y ago
When killing an entire cgroup, you might avoid the PID reuse race by getting a list of PIDs in a cgroup, then for each PID, first opening a PIDFD to that PID, check via that PIDFD whether it’s a member of the correct cgroup, and then killing the PIDFD using pidfd_send_signal(). This way, no process can be killed inadvertently by PID reuse.
There may be a better way to do this, but one way might be to open() /proc/<PID> and use the resulting FD to both to check /proc/<PID>/cgroup (using openat(FD, "cgroup", O_RDONLY|O_NOCTTY)) and then use the same FD as a PIDFD when calling pidfd_send_signal().
ISTM that systemd should use this method if its current method is just looping over PIDs.
- Arnavion 4y agoMight be easier to freeze the cgroup, send the signals, then unfreeze. Only danger there is that it needs to not be reentrant. Edit: Indeed both your and my methods were proposed to systemd: https://github.com/systemd/systemd/issues/13101 https://github.com/systemd/systemd/issues/13101 It's just waiting for someone to implement it.