If LD_PRELOAD
is preserved by sudo, then it’s possible to use a malicious dynamic library to gain root access — just run sudo LD_PRELOAD=/path/to/malicious.so program-runnable-with-nopasswd
. Preserved environment variables are listed by “sudo -l”.
A simple malicious library (perhaps the simplest) that can exploit the LD_PRELOAD
trick is:
Compile with: