A flaw in runc (CVE-2019-5736), announced last week, allows container processes to "escape" their containment and execute programs on the host operating system. The good news is that well-configured SELinux can stop it.
Do you enable SELinux (setenforce 1)?
A hypothetical attack using this security hole would start with an attacker packaging a container image with exploit code. If an admin makes the mistake of deploying this container image using tools like podman run
or docker run
or through an orchestrator like Kubernetes, then the executable could overwrite the runc command on the host, giving the attacker full access to the host.
Similar attacks are available when users exec
into a running exploited container image. This exploit effects any container engines (CRI-O, Podman, Docker, Containerd, Buildah) that use the runc container runtime.
Potentially, if an application running in an individual container gets hacked over the network, the attacker could then download the exploit code and break out of the container. Either way, it's bad news. So how can SELinux prevent this?
The vulnerability allows processes within the container to overwrite the /proc/self/exe file, which is meant to point to the currently running executable. For example, the next command shows you /proc/self/exe pointing to "ls", since you used ls to call it:
$ ls -l /proc/self/exe lrwxrwxrwx. 1 dwalsh dwalsh 0 Feb 10 05:45 /proc/self/exe -> /usr/bin/ls
In this exploit, security researchers discovered that it is possible to write to /proc/self/exe when it is pointing to runc, in order to modify that executable. Updated versions of runc now fix this issue.
First, this exploit should not be possible if you run your containers as non-root, which is the Red Hat OpenShift default. This is why almost all containers should be run as non-root.
But for the cases where your containers have to run as root
, you are vulnerable if your system is running setenforce 0
(with SELinux disabled).
SELinux to the rescue
SELinux can block this exploit, as long as you are running in enforcing mode.
Note: The post to the openwall list is incorrect when it states that containers run as container_runtime_t
by default. The tester ran tests on moby-engine, which was not running with the --selinux-enabled flag
. By enabling this flag moby-engine would have been protected also. The container engines packages Podman, Docker, Buildah, and CRI-O should have SELinux enabled by default, and were protected. A bug has been opened with the moby-engine package to change its default to --selinux-enabled
. Docker-ce was vulnerable also since it does not run with --selinux-enabled
by default.
On an SELinux system, container processes are launched as the SELinux type container_t
. SELinux policy defines that the only ordinary files container_t
types can write to are labeled container_file_t
. The default file label of runc is container_runtime_exec_t
, which container_t
would be denied when attempt is made to write to it.
When a attacker tricks a user into running the exploit, SELinux will block the exploit and generate an AVC that looks like:
feb 10 16:08:43 localhost.localdomain audit[1727]: AVC avc: denied { write } for pid=1727 comm="copy" name="runc" dev="sda3" ino=135490239 scontext=system_u:system_r:container_t:s0:c43,c93
tcontext=system_u:object_r:container_runtime_exec_t:s0 tclass=file permissive=0
In the example you'll see SELinux denying the container running as container_t attempting to write over runc which is labeled container_runtime_exec_t.
SELinux blocks the attempted write. Several of the known container exploits that have been found so far are file system exploits (exploits that happen when the process inside of the container gets access to the file system on the host system.) SELinux can be an effective tool to block these types of exploits.
Watch this video on SELinux and Containers from Devconf.CZ 2019.
User Namespace would also protect against this exploit
User namespace could also protect against this exploit, since the process inside of the container while running as root inside of the container, is actually running as non-root outside of the container. Since runc
is owned by root, the process would not be allowed to overwrite it.
Sadly, almost no one runs with user namespace enabled, because of limitations in Linux file systems support for User Namespace. User Namespace features have been added to podman
and the CRI-O
team plans to add features to allow easier running of containers with user namespace separation.
Note: Podman has the capability to run containers in rootless mode, meaning that root inside of the container is actually running as the UID of the user running Podman. In this case the exploit would not be able to work, since runc would be owned by real root on the system.
Conclusion
Please patch all versions of runc or docker-runc in your environment.
- Don't run random container images from the internet. Only run trusted content.
- Always run containers as non root if at all possible (OpenShift Default).
- Run your container engines in user namespace if at all possible.
- Always run with SELinux in enforcing mode and ensure the container engine is running with SELinux separation enabled in production.
Luckily, Red Hat Enterprise Linux, Fedora, and CentOS systems run with SELinux enabled by default. As I often recommend, do not run containers on systems with SELinux disabled or in Permissive mode.
Sull'autore
Daniel Walsh has worked in the computer security field for over 30 years. Dan is a Senior Distinguished Engineer at Red Hat. He joined Red Hat in August 2001. Dan leads the Red Hat Container Engineering team since August 2013, but has been working on container technology for several years.
Dan helped developed sVirt, Secure Virtualization as well as the SELinux Sandbox back in RHEL6 an early desktop container tool. Previously, Dan worked Netect/Bindview's on Vulnerability Assessment Products and at Digital Equipment Corporation working on the Athena Project, AltaVista Firewall/Tunnel (VPN) Products. Dan has a BA in Mathematics from the College of the Holy Cross and a MS in Computer Science from Worcester Polytechnic Institute.
Altri risultati simili a questo
Ricerca per canale
Automazione
Novità sull'automazione IT di tecnologie, team e ambienti
Intelligenza artificiale
Aggiornamenti sulle piattaforme che consentono alle aziende di eseguire carichi di lavoro IA ovunque
Hybrid cloud open source
Scopri come affrontare il futuro in modo più agile grazie al cloud ibrido
Sicurezza
Le ultime novità sulle nostre soluzioni per ridurre i rischi nelle tecnologie e negli ambienti
Edge computing
Aggiornamenti sulle piattaforme che semplificano l'operatività edge
Infrastruttura
Le ultime novità sulla piattaforma Linux aziendale leader a livello mondiale
Applicazioni
Approfondimenti sulle nostre soluzioni alle sfide applicative più difficili
Serie originali
Raccontiamo le interessanti storie di leader e creatori di tecnologie pensate per le aziende
Prodotti
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Servizi cloud
- Scopri tutti i prodotti
Strumenti
- Formazione e certificazioni
- Il mio account
- Supporto clienti
- Risorse per sviluppatori
- Trova un partner
- Red Hat Ecosystem Catalog
- Calcola il valore delle soluzioni Red Hat
- Documentazione
Prova, acquista, vendi
Comunica
- Contatta l'ufficio vendite
- Contatta l'assistenza clienti
- Contatta un esperto della formazione
- Social media
Informazioni su Red Hat
Red Hat è leader mondiale nella fornitura di soluzioni open source per le aziende, tra cui Linux, Kubernetes, container e soluzioni cloud. Le nostre soluzioni open source, rese sicure per un uso aziendale, consentono di operare su più piattaforme e ambienti, dal datacenter centrale all'edge della rete.
Seleziona la tua lingua
Red Hat legal and privacy links
- Informazioni su Red Hat
- Opportunità di lavoro
- Eventi
- Sedi
- Contattaci
- Blog di Red Hat
- Diversità, equità e inclusione
- Cool Stuff Store
- Red Hat Summit