posted 2017-09-01
MIMEDefang 2.80 and earlier creates a PID file after dropping privileges to a non-root account. This is exploitable by that non-root account to kill root processes, because the init script supplied by MIMEDefang (and many distributions) will send a SIGTERM to the contents of the PID file upon stopping the service.
The purpose of the PID file is to hold the PID of the running daemon, so that later it can be stopped, restarted, or otherwise signalled (many daemons reload their configurations in response to a SIGHUP). To fulfil that purpose, the contents of the PID file need to be trustworthy. If the PID file is writable by a non-root user, then he can replace its contents with the PID of a root process. Afterwards, any attempt to signal the PID contained in the PID file will instead signal a root process chosen by the non-root user (a vulnerability).
This is commonly exploitable through init scripts that are run as root and which blindly trust the contents of their PID files. Examples of said init scripts can be found in the MIMEDefang source tree:
An example of a problematic scenario involving an init script would be,
/etc/init.d/mimedefang start
to start the daemon.
/etc/init.d/mimedefang stop
to stop the daemon
while I investigate the weird behavior resulting from the hack.
The problem is resolved in MIMEDefang 2.81 by creating the PID files
as root before dropping privileges. The role of the lock
files—previously played by the PID files—is now played
by a separate set of files (specified on the command-line with
-o
).
Init script authors should relocate their PID files to /run or a similar root-owned directory.