August 26, 2009, 6:22 am
While virtualization seems to be next big thing, providing great opportunities in resource allocation, system management, savings on power and cooling, and the ability to grow and shrink resources depending on demand.
But what about the security?
What happens when a cracker breaks into a virtual machine and takes it over?Â¬â What happens if there is a bug in the hypervisor?
Before virtualization, we had isolated servers.Â¬â A cracker taking over one server meant that he controlled just that server. The cracker would then have to launch network attacks against other servers in the environment.Â¬â System administrators had lots of tools to defend against network attacks on machines: firewalls, network traffic analysis tools, intrusion detection tools, etc.
After virtualization, we have multiple services running on the same host.Â¬â If a virtual machine is broken into, the cracker just needs to break though the hypervisor.Â¬â If a hypervisor vulnerability exists, the cracker can take over all of the virtual machines on the host.Â¬â He can even write into any virtual host images that are accessible from the host machine.
This is very scary stuff. The question is not âÃÃºifâÃÃ¹, but âÃÃºwhenâÃÃ¹.Â¬â Hacker/cracker conventions are already examining hypervisor vulnerabilities.Â¬â Crackers have already broken though the xen hypervisor, as I documented in one of my previous blogs.
Now letâÃÃ´s examine libvirtd/qemu/kvm in Fedora 11.
libvirtd starts all virtual machines.Â¬â All virtual machines run as separate processes.Â¬â Virtual images are stored as files or devices like logical volumes and iscsi targets.
What is SELinux really good at?
It is great at labeling processes, files, and devices.Â¬â It is great at defining rules on how labeled processes interact with labeled processes, files, and devices.
Seems like a nice match.Â¬â SELinux can be used to mitigate the problems of a vulnerability in the hypervisor.
But, you ask, âÃÃºDidnâÃÃ´t we do this in Red Hat Enterprise Linux 5?âÃÃ¹Â¬â Yes, but we were still vulnerable to the Xen breakout.
If you read the Xen vulnerability document, it explains the mechanism used to thwart SELinux protection in RHEL5.Â¬â The cracker realized that the xen process, labeled xend_t, was allowed to read/write all fixed disks labeled fixed_disk_device_t.Â¬â This allowed the cracker to break out ofÂ¬â the SELinux confinement by writing to the physical disk.Â¬â When I was writing policy for Xen in RHEL5, I had initially required the administrator to label volume xen image devices as xen_image_t.Â¬â The xen developers thought this was too difficult for the administrators to have to manage, and would cause too many failures.Â¬â We ran out of time to make the management tool do this automatically.Â¬â It was decided that usability was more important then security in this instance, and I had to allow this access.Â¬â I wonâÃÃ´t make that mistake again.
In Fedora 11, James Morris, Daniel Berrange, myself and othersÂ¬â have added SELinux support to libvirt, in the form of sVirt.Â¬â We added a security plug-in architecture to libvirt that defaults to SELinux protection.Â¬â Theoretically you can use other security architectures.Â¬â libvirt dynamically labels the image files and starts the virtual machines with the correct labels.Â¬â This allows us to avoid the problem of the administrator having to remember to set the correct label on the image files and devices.Â¬â By default all virtual machines in F11 get labeled with the svirt_t type and all image files get the svirt_image_t type.
SELinux policy has rules that allow the svirt_t processes to read/write svirt_image_t files and devices.
This protection allows us to protect the host machine from any of its virtual machines.Â¬â A virtual machine will only be able to interact with the files and devices with the correct labels.Â¬â A compromised virtual machine would not be allowed to read my home directory, for example, even if the virtual machine is running as root.
However, this âÃÃºtypeâÃÃ¹ protection does not prevent one virtual machine from attacking another virtual machine.Â¬â We needed a way to label the domains and the image files with the same TYPES, but at the same time, stop virtual machine 1, running as svirt_t, attacking virtual machine 2,Â¬â which would also be running as svirt_t.
Multi Category Security (MCS) to the rescue!
When we developed RHEL5 we added Multi Level Security (MLS) support.Â¬â Â¬â This involved adding a fourth field to the SELinux context.
Originally in RHEL4 the SELinux context consisted of three fields (âÃÃ¹USER:ROLE:TYPEâÃÃ¹).Â¬â In RHEL5 the SELinux context consists of four fields (âÃÃ¹USER:ROLE:TYPE:MLSâÃÃ¹).Â¬â For example, files in the home directory could be labeled âÃÃºsystem_u:system_r:user_home_t:TopSecretRecipeâÃÃ¹.Â¬â The MLS labels define a sensitivity level (s0-s15) and category of the data (c0.c1023), TopSecretRecipe in the example above is a human-readable translation of a field like s15:c0.c36.Â¬â The MLS label allows MLS machines to not only label the file based on its use, user_home_t in this example, but also by the sensitivity and nature of its content, âÃÃºTopSecretRecipeâÃÃ¹.
This field was only used in MLS policy.Â¬â We attempted to make use of it in our default policy (âÃÃ¹targetedâÃÃ¹), by only defining a single sensitivity level (âÃÃ¹s0âÃâ¥) and allowing administrators to define categories.Â¬â We called this Multi Category Security (MCS).Â¬â The goal was to allow administrators and users to label their files based on the nature of their contents.Â¬â For example, system_u:object_r:database_t:PatientRecord could be a database which contained patient records.Â¬â For multiple reasons, MCS has not beenÂ¬â widely used.Â¬â I believe you are still better off defining a new SELinux type patient_record_database_t âÃÃ® MCS does not afford the richness of access control that you can express with standard SELinux types.
When we were developing sVirt, though, we realized that we could use MCS to provide us separation between two virtual machines running with the same SELinux type, svirt_t.Â¬â We designed libvirt to assign a different randomly-selected MCS label to each virtual machine and its associated virtual image.Â¬â libvirt guarantees that the MCS fields it selects are unique.Â¬â SELinux prevents different virtual machinesÂ¬â running with different MCS fields from interacting with each other or any of their content.
For example, libvirt creates two virtual machines with these labels:
|Name||Virtual Machine Process label||Virtual Machine Image Label|
|Virtual Machine 1||system_u:system_r:svirt_t:s0:c0,c10||system_u:object_r:svirt_image_t:s0:c0,c10|
|Virtual Machine 2||system_u:system_r:svirt_t:s0:c101,c230||system_u:object_r:svirt_image_t:s0:c101,c230|
SELinux prevents virtual machine 1 (system_u:system_r:svirt_t:s0:c0,c10) from accessing virtual machine 2âÃÃ´s image file (system_u:object_r:svirt_image_t:s0:c101,c230) âÃÃ® the virtual machines can not attack each other.
These are the labels libvirt assigns.
|Virtual Machine Processes||system_u:system_r:svirt_t:MCS1||MCS1 is a randomly selected MCS field.Â¬â Currently we support ~500,000 labels.|
|Virtual Machine Image||system_u:object_r:svirt_image_t:MCS1||Only svirt_t processes with the same MCS fields are able to read/write these image files and devices.|
|Virtual Machine Shared Read/Write content||system_u:object_r:svirt_image_t:s0||All svirt_t processes are allowed to write to the svirt_image_t:s0 files and devices.|
|Virtual Machine Shared Shared Read Only content||system_u:object_r:svirt_content_t:s0||All svirt_t processes are able to read files/devices with this label.|
|Virtual Machine images||system_u:object_r:virt_content_t:s0||When a virtual machine exits, its image file is relabeled to the system default, which usually is virt_content_t:s0,Â¬â No svirt_t virtual processes are allowed to read files/devices with this label.|
We also added the ability to do static labeling to sVirt.Â¬â Static labels allow the administrator to select a particular label, including the MCS/MLS field,Â¬â for a virtual machine.Â¬â The virtual machine will always be started with that label.Â¬â Administrator who run static virtual machines are responsible for setting the correct label on the image files.Â¬â libvirt will never modify the label of a statically-labelled virtual machineâÃÃ´s content. This allows the sVirt component to run in an MLSÂ¬â environment.Â¬â You can run multiple virtual machines on a libvirt system at different sensitivity levels.