Search code examples
securitychroot

Prevent my program from accessing the filesystem


I have a program that may be compromised, but needs root rights initially. Currently, the program chroots into a preconfigured directory and then drops the privileges.

However, I would like to prevent my program from accessing the filesystem at all after it has dropped the root privileges, and if possible not require any configuration. Is there a better way than creating a temporary directory in /tmp and chrooting into it?


Solution

  • I ended up chrooting into a temporary directory (in my case, /var/run/programname) and dropping privileges thereafter. This offers adequate protection, and does not require any complicated installation. On the downside, it requires my program to be running as superuser in the first place.