spender wrote:There's a utility called 'slay' that can be used to do this.
Thanks, I know this utility...
I want to write it on my own, as a part of a bigger program. I need such functionality as "kill all processes owned by x", "stop (SIGSTOP) all processes owned by y" etc.
Slay does exactly what I thought was the cleanest way - fork+setuid+kill(-1). This is a snippet from "slay" source code:
- Code: Select all
su -m $slayee -c "kill $SIGNAL -1"
I might be wrong, but I believe
what slay does is unreliable: the user whose processes I'm going to kill can kill or ptrace the killing process after it's uid has been changed and before it did kill().
I also believe it would become much more reliable with grsec's random pids! (Then, the attacker would probably use inotify/dnotify on /proc, and it would be considerably harder for him to win the race).
Another way to do this would be to iterate though /proc and send the signal to each process ("skill" utility does that)... But I don't think it's that good either, because I wouldn't SIGSTOP/SIGCONT all processes at once.
(Also, I don't think one iteration over /proc is enough to be sure I stopped/killed all processes of that user... I'm worried about that user forking() in a clever way while I'm iterating)
What do you think about it?