[SJF Logo]
Best Practices for UNIX chroot() Operations

Systems exposed to the internet are heavily challenged to keep the bad guys out, and keeping up with the latest security patches is not always easy. So, the wise admin will attempt to institute systemic steps to limit the damage should a compromise occur, and one excellent method is the use of a chroot() jail.

This document touches on how chroot works and discusses some best practices that developers and administators can use to make their installations more secure.

* Background on chroot

The chroot system call changes the root directory of the current and all child processes to the given path, and this is nearly always some restricted subdirectory below the real root of the filesystem. This new path is seen entirely as "/" by the process, and we refer to this restricted enviroment as the "jail". It's not possible to escape this jail except in very limited circumstances.

The hierarchy that forms the top of the jailed tree The chroot system call is found in all versions of UNIX that we know of, and it serves to create a temporary root directory for a running process, and it's a way of taking a limited hierarchy of a filesystem (say, /chroot/named) and making this /fill in here/

* How to break out of jail

There are well-known techniques used to escape from jail, but the most common one requires root privileges inside the jail. The idea is for the program to do a chroot to a subdirectory, leaving the current directory outside the jail.

We'll add more notes on ways to break out of a jail - which is meant more to show what must be protected against than it is as a how-to for jailbreakers -- but we've found a good article on chroot in general here.

Almost all jail breaking requires root privileges.

* General chroot principles

We have presented these in no particular order, and no one site will use them all. In particular, some tips apply to developers at the source code level, while others apply to administrators trying to jail an existing system.

Many of these points may end up being overly petty in practice, in that there are only so many layers of defense that a workable system can use, but we'll present all we can think of and let you pick and choose. An overriding principle is "What if the bad guy somehow does X? How can we limit our exposure".

Our general concern is mostly about remote buffer overflows, and this can give the bad guy complete control over our CPU: all our steps are designed to limit the damage should this unfortunate circumstance arise.

* EXAMPLES

(to be added)

Navigate: More Tech Tips