Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS1yZmoyLXEzaDMtaG01as4AAu1O
Cargo extracting malicious crates can corrupt arbitrary files
The Rust Security Response WG was notified that Cargo did not prevent extracting some malformed packages downloaded from alternate registries. An attacker able to upload packages to an alternate registry could corrupt arbitary files when Cargo downloaded the package.
The severity of this vulnerability is "low" for users of alternate registries. Users relying on crates.io are not affected.
Note that by design Cargo allows code execution at build time, due to build scripts and procedural macros. The vulnerabilities in this advisory allow performing a subset of the possible damage in a harder to track down way. Your dependencies must still be trusted if you want to be protected from attacks, as it's possible to perform the same attacks with build scripts and procedural macros.
Arbitrary file corruption
After a package is downloaded, Cargo extracts its source code in the ~/.cargo
folder on disk, making it available to the Rust projects it builds. To record when an extraction is successfull, Cargo writes "ok" to the .cargo-ok
file at the root of the extracted source code once it extracted all the files.
It was discovered that Cargo allowed packages to contain a .cargo-ok
symbolic link, which Cargo would extract. Then, when Cargo attempted to write "ok" into .cargo-ok
, it would actually replace the first two bytes of the file the symlink pointed to with ok
. This would allow an attacker to corrupt one file on the machine using Cargo to extract the package.
Affected versions
The vulnerability is present in all versions of Cargo. Rust 1.64, to be released on September 22nd, will include a fix for it.
Since the vulnerability is just a more limited way to accomplish what a malicious build scripts or procedural macros can do, we decided not to publish Rust point releases backporting the security fix. Patch files are available for Rust 1.63.0 are available in the wg-security-response repository for people building their own toolchain.
Mitigations
We recommend users of alternate registries to excercise care in which package they download, by only including trusted dependencies in their projects. Please note that even with these vulnerabilities fixed, by design Cargo allows arbitrary code execution at build time thanks to build scripts and procedural macros: a malicious dependency will be able to cause damage regardless of these vulnerabilities.
crates.io implemented server-side checks to reject these kinds of packages years ago, and there are no packages on crates.io exploiting these vulnerabilities. crates.io users still need to excercise care in choosing their dependencies though, as remote code execution is allowed by design there as well.
Acknowledgements
We want to thank Ori Hollander from JFrog Security Research for responsibly disclosing this to us according to the Rust security policy.
We also want to thank Josh Triplett for developing the fixes, Weihang Lo for developing the tests, and Pietro Albini for writing this advisory. The disclosure was coordinated by Pietro Albini and Josh Stone.
Permalink: https://github.com/advisories/GHSA-rfj2-q3h3-hm5jJSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1yZmoyLXEzaDMtaG01as4AAu1O
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Low
Classification: General
Published: about 2 years ago
Updated: over 1 year ago
CVSS Score: 3.9
CVSS vector: CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:U/C:L/I:L/A:L
EPSS Percentage: 0.00272
EPSS Percentile: 0.68506
Identifiers: GHSA-rfj2-q3h3-hm5j, CVE-2022-36113
References:
- https://github.com/rust-lang/cargo/security/advisories/GHSA-rfj2-q3h3-hm5j
- https://nvd.nist.gov/vuln/detail/CVE-2022-36113
- https://github.com/rust-lang/cargo/commit/97b80919e404b0768ea31ae329c3b4da54bed05a
- https://github.com/rust-lang/cargo/commit/dafe4a7ea016739680ec7998aebe1bc6de131a5b
- https://security.gentoo.org/glsa/202210-09
- https://github.com/rust-lang/cargo/commit/15f1e4b0bf4b4fc20369e0a85d9b77957c4dd52a
- https://github.com/advisories/GHSA-rfj2-q3h3-hm5j
Blast Radius: 9.5
Affected Packages
cargo:cargo
Dependent packages: 169Dependent repositories: 280
Downloads: 4,179,474 total
Affected Version Ranges: = 0.66.0, < 0.65.0
Fixed in: 0.67.0, 0.65.0
All affected versions: 0.0.1, 0.4.0, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.8.0, 0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0, 0.14.0, 0.15.0, 0.16.0, 0.17.0, 0.18.0, 0.19.0, 0.20.0, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 0.33.0, 0.34.0, 0.35.0, 0.36.0, 0.37.0, 0.38.0, 0.39.0, 0.40.0, 0.41.0, 0.42.0, 0.43.0, 0.43.1, 0.44.0, 0.44.1, 0.45.0, 0.45.1, 0.46.0, 0.46.1, 0.47.0, 0.48.0, 0.49.0, 0.50.0, 0.50.1, 0.51.0, 0.52.0, 0.53.0, 0.54.0, 0.55.0, 0.56.0, 0.57.0, 0.58.0, 0.59.0, 0.60.0, 0.61.0, 0.61.1, 0.62.0, 0.63.0, 0.63.1, 0.64.0, 0.66.0
All unaffected versions: 0.65.0, 0.67.0, 0.67.1, 0.68.0, 0.69.0, 0.69.1, 0.70.0, 0.70.1, 0.71.0, 0.72.0, 0.72.1, 0.72.2, 0.73.0, 0.73.1, 0.74.0, 0.75.0, 0.75.1, 0.76.0, 0.77.0, 0.78.0, 0.78.1, 0.79.0, 0.80.0, 0.81.0, 0.82.0, 0.83.0, 0.84.0