SysCall chroot
1 Background
- Prerequisite: Libcalls v syscalls.
 - Read through 
man syscallsandman chroot+man 2 chroot 
2 Usage/ Semantics of chroot
- The word root here is about the root of a directory hierarchy, not the super-user.
 - Before entering the chroot a number of directories need to be mounted. Some basic configuration files will need to be copied from the host.
 
# mount -t proc /proc /mnt/mychroot/proc # mount --rbind /dev /mnt/mychroot/dev # mount --rbind /sys /mnt/mychroot/sys # mount --rbind /tmp /mnt/mychroot/tmp # cp /etc/resolv.conf /mnt/mychroot/etc
Then, invoke # chroot /mnt/mychroot /bin/bash
2.1 Full Path Names
- Full path names begin with the 
/(the slash). - Consider the file/dir hierarchy preferably with multiple mounts.
 chrootcan re-locate the root directory of a full path name to any directory on this hierarchy.- Consider a process with PID 12345.  Examine 
/proc/12345/rootThis will be a symbolic link to the "root" dir of this process. 
2.2 Goal: Chroot Jail
- Having chroot-ed, 
/../becomes illegal. This brought us the term "chroot jail". "First Gen Sandbox" 
2.3 Man Pages?!
- Man pages do their best, but are not always unambiguous or definitive.
 man chroothas the following at the top: "chroot - run command or interactive shell with special root directory".- This is way too ambiguous.
 
2.4 Root Only?
- The chroot system call is only available to the root user. A non-root user cannot execute a chroot() call.
 - Any process having done a 
chrootought to drop its privileges to run asnobodyor an otherwise unknown user. - Computer System Security, Lecture 4, https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-858-computer-systems-security-fall-2014/lecture-notes/MIT6_858F14_lec4.pdf 8pp
 - "On Safes, Sandboxes, and Spies", CS 161 : Computer Security, Lecture 5, https://inst.eecs.berkeley.edu/~cs161/fa16/slides/lec5.pdf 33 slides, 2016.
 
3 References
- https://en.wikipedia.org/wiki/Chroot Required Reading
 - https://lwn.net/Articles/252794/ 2007 What chroot() is really for. Required Reading
 - https://wiki.gentoo.org/wiki/Chroot Required Reading