I'm working on a password manager application, and for security reasons I want to launch an unkillable process.
And besides I don't want this program to be a daemon since I need to read from standard input and write to it.
Is there a way to do this?
I'm working on a password manager application, and for security reasons I want to launch an unkillable process.
And besides I don't want this program to be a daemon since I need to read from standard input and write to it.
Is there a way to do this?
Make the password manager run under a separate user and handle/ignore/block terminal-generated signals (SIGINT, SIGQUIT, SIGHUP, SIGTSTP, SIGTTIN, and SIGTTOU).
You can't send signals to (=kill) processes run under a different user (user whose both real uid and saved-set uid is different from your effective uid) unless your effective id is 0 (root).
All processes will still be killable by root.
For closer details, see kill(2).
The only way to make a process unkillable is to implement it as a kernel thread, which is not something trivial.
You can still kill it but that would be an OS shutdown collateral damage.
You might also develop a custom kernel module that would set the SIGNAL_UNKILLABLE flag to your process. This flag is designed to be only set for init (or systemd, whatever initial process the kernel launch) which are the only userland processes protected against an unconditional kill but nothing seems to forbid that flag to be present for a regular process.
Technically, there is no way for a user to make a process unkillable.
Of course, for non-root users they can only kill processes that have the same user ID that they do, so if you can make different accounts you can use a "unique" user ID for the process and then only root could kill it.
A simple, but less robust, solution is to have your process catch as many signals as possible (perhaps ignoring them). This is only suitable for toy examples or non-adversarial environments since there is no way to catch the KILL signal (signal 9), but otherwise you can avoid being killed by them.
Finally, you can arrange to have your process respawn if killed. This is also fragile, but will make it a bit harder to expunge. This can be accomplished using a monitor process of your own, or using inittab. For an adversary who knows what they are doing, this can be circumvented by killing multiple processes at once.
inittab) it's possible the monitor process could also be killed, no?