chroot policy
I've implemented my chroot policy as described in two previous messages today. I have updated the copy of my policy tree stored on
http://www.coker.com.au/selinux/policy.tgz to have the chroot policy, and I have attached a short document describing it.
I've installed the policy in question on my SE play machine and I'll create a chroot for anyone who asks.
Signature · 3 lines
I do not get viruses because I do not use MS software. If you use Outlook then please do not put my email address in your address-book so that WHEN you get a virus it won't use my address in the
Quoted 1 line
From field.
To create a chroot environment you use the chroot() macro in the following fashion:chroot(user_XXX, XXX, user_XXX_r, user_XXX_devpts_t)
This creates a chroot environment to be started from domain user_XXX_t (patameter 1), the chroot environment has a base name of "XXX" which is used for naming the domains XXX_t, XXX_super_t, and XXX_chroot_t, and the types XXX_ro_t, XXX_rw_t, XXX_dropdown_t, and XXX_super_entry_t.
The domain XXX_t is used for programs running in the chroot environment.
The type XXX_rw_t is for files/directories in the chroot that can be read and written by the domain XXX_t.
The type XXX_ro_t is for files/directories in the chroot that can be read but not written by the domain XXX_t.
The domain XXX_super_t is a domain for running in the chroot that can see and kill processes in the XXX_t domain (but not be seen or killed by them).
Also it can write to XXX_ro_t, it is to be used for administration of the chroot environment. When XXX_super_t executes a program of type XXX_rw_t then it transitions to domain XXX_t. However this does not entirely prevent you from accidentally running code written by a XXX_t domain while running as XXX_super_t - watch out for scripts and configuration files containing names of programs to execute. As long as /etc is of type XXX_ro_t and XXX_dropdown_t and /lib and /usr are of XXX_ro_t then it should be fine.
The type XXX_super_entry_t is used as an entry point into the XXX_super_t domain. I suggest having a copy of the shell with this type for entering into administration mode (but a package administration program such as dselect could have it too).
The type XXX_dropdown_t is used for the contents of /etc/init.d or other files that should trigger a domain change from XXX_super_t to XXX_t. The idea is that when a package administration program such as dpkg runs a script to start a daemon then the daemon should automatically transition to XXX_t. This requires that /etc/init.d also have the type XXX_dropdown_t so that new scripts also have that type.
The domain XXX_chroot_t is used for the chroot program, it has the chroot capability and has access to read directories and execute files under the chroot.
When the domain user_XXX executes the chroot program (type chroot_exec_t) then it transitions to XXX_chroot_t. When XXX_chroot_t executes XXX_ro_t, XXX_rw_t, or XXX_dropdown_t then it transitions to XXX_t. When it executes XXX_super_entry_t it transitions to XXX_super_t.
Also there is a domain XXX_mount_t used for mounting devices under the chroot environment. A script for bind mounting /dev entries and mounting /proc is below. NB the domain XXX_mount_t can not be entered from processes in XXX_t or XXX_super_t domains - this has to be setup from outside the chroot!
The general idea is that when installing a chroot you have the default type be XXX_ro_t, then you have /dev, /dev/pts, /var, /home, /tmp with type XXX_rw_t, and /var/lib/dpkg, /var/cache/apt/archives, and /var/{lib,state}/apt with type XXX_ro_t so processes in domain XXX_t can't mess with the installation of new packages.
The end result is that as root in the chroot environment you can create new users, delete users, manage users' processes, etc. But you can't change system files or do anything outside the chroot.
#!/bin/bash -e
# script to mount device nodes and /proc or umount them.
DEVFILES="pts random urandom"
if [ "$1" == "mount" ]; then
cd $2
mount -n none -t proc proc
for n in $DEVFILES ; do
mount -n /dev/$n dev/$n --bind
done
fi
if [ "$1" == "umount" ]; then
cd $2
umount -n pwd/proc/
for n in $DEVFILES ; do
umount -n `pwd`/dev/$n
done
fi