DEV Community

Ju
Ju

Posted on

Why Pivot Root is Safer Than Chroot

Root

The root is the top-most node in the hierarchy of a file system.

What is Pivot Root

Pivot root (pivot_root) changes the root mount of the process.

Changing the root directory means the root directory maps to another inode in the file system.

What is Chroot

Chroot changes the root directory of the process.

Changing the root mount means the root directory is attached to another new file system.

Jailbreak

A jailbreak trick allows accessing files outside the changed root.

Say, if there is a link in newdir that links to a directory or file outside newdir, you may read the linked file content, despite the linked file is not under newdir. This is like a jailbreak.

Prevent Jailbreak

Use pivot root, never use chroot.

After running pivot_root newdir newdir/olddir, following a second umount /olddir; rmdir /olddir. There will be no way you can still access any files within the olddir.

Top comments (0)