]> git.proxmox.com Git - mirror_lxc.git/commit - src/lxc/conf.c
use pivot_root instead of chroot
authorMichael Holtz <lxc@my.fqdn.org>
Fri, 8 Jan 2010 13:34:13 +0000 (14:34 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Fri, 8 Jan 2010 13:34:13 +0000 (14:34 +0100)
commitbf601689a9e0cea1ceaf17e4f7f853f5392c2827
tree0ed2d1e218feedfbf5a8671d9db54003b2b4cfff
parent7b379ab3a54e12c89c664acce557f759258c629a
use pivot_root instead of chroot

lxc currently does a chroot into the target rootfs. chroot is insecure and
can easily be broken, as demonstrated here:

| root@synergy:~# touch /this_is_the_realrootfs_ouch
| # touch /container/webhost/this_is_the_container
| # lxc-start -n webhost /bin/sh
| # ls this*
| this_is_the_container
| # ./breakchroot
| # ls this*
| this_is_the_realrootfs_ouch

code to break chroot taken from
http://www.bpfh.net/simes/computing/chroot-break.html

Now this can be fixed. As our container has his own mount namespace, we can
easily pivot_root into the rootfs and then unmount all old mounts. The patch
attached add a new config keyword which contains the path to a temporary
mount for the old rootfs (inside the container). This stops the chroot break
method shown before.

Example:

| root@synergy:~# grep pivotdir /var/lib/lxc/webhost/config
| lxc.pivotdir = /oldrootfs
| root@synergy:~# ls -lad /container/webhost/oldrootfs
| drwxr-xr-x 2 root root 4096 2010-01-02 03:59 /container/webhost/oldrootfs
| root@synergy:~# lxc-start -n webhost /bin/sh
| # mount -t proc proc /proc
| # cat /proc/mounts
| rootfs / rootfs rw 0 0
| /dev/root / ext3 rw,relatime,errors=remount-ro,data=writeback 0 0
| devpts /dev/console devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
| proc /proc proc rw,relatime 0 0
| # ls this*
| this_is_the_container
| # ./breakchroot
| # ls this*
| this_is_the_container

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Michael Holtz <lxc@my.fqdn.org>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c