Skip to content

Commit 0e9dd07

Browse files
authored
Merge pull request #1029 from rust-lang/pa-cargo-cves
Add blog post on cargo CVEs
2 parents b37b76a + 237d39b commit 0e9dd07

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

posts/2022-09-14-cargo-cves.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
layout: post
3+
title: "Security advisories for Cargo (CVE-2022-36113, CVE-2022-36114)"
4+
author: The Rust Security Response WG
5+
---
6+
7+
> This is a cross-post of [the official security advisory][advisory]. The
8+
> official advisory contains a signed version with our PGP key, as well.
9+
10+
[advisory]: https://groups.google.com/g/rustlang-security-announcements/c/ldvsemwk_VY
11+
12+
The Rust Security Response WG was notified that Cargo did not prevent
13+
extracting some malformed packages downloaded from alternate registries. An
14+
attacker able to upload packages to an alternate registry could fill the
15+
filesystem or corrupt arbitary files when Cargo downloaded the package.
16+
17+
These issues have been assigned CVE-2022-36113 and CVE-2022-36114. The severity
18+
of these vulnerabilities is "low" for users of alternate registries. Users
19+
relying on crates.io are not affected.
20+
21+
Note that **by design** Cargo allows code execution at build time, due to build
22+
scripts and procedural macros. The vulnerabilities in this advisory allow
23+
performing a subset of the possible damage in a harder to track down way. Your
24+
dependencies must still be trusted if you want to be protected from attacks, as
25+
it's possible to perform the same attacks with build scripts and procedural
26+
macros.
27+
28+
## Arbitrary file corruption (CVE-2022-36113)
29+
30+
After a package is downloaded, Cargo extracts its source code in the `~/.cargo`
31+
folder on disk, making it available to the Rust projects it builds. To record
32+
when an extraction is successfull, Cargo writes "ok" to the `.cargo-ok` file at
33+
the root of the extracted source code once it extracted all the files.
34+
35+
It was discovered that Cargo allowed packages to contain a `.cargo-ok`
36+
*symbolic link*, which Cargo would extract. Then, when Cargo attempted to write
37+
"ok" into `.cargo-ok`, it would actually replace the first two bytes of the
38+
file the symlink pointed to with `ok`. This would allow an attacker to corrupt
39+
one file on the machine using Cargo to extract the package.
40+
41+
## Disk space exaustion (CVE-2022-36114)
42+
43+
It was discovered that Cargo did not limit the amount of data extracted from
44+
compressed archives. An attacker could upload to an alternate registry a
45+
specially crafted package that extracts way more data than its size (also known
46+
as a "zip bomb"), exhausting the disk space on the machine using Cargo to
47+
download the package.
48+
49+
## Affected versions
50+
51+
Both vulnerabilities are present in all versions of Cargo. Rust 1.64, to be
52+
released on September 22nd, will include fixes for both of them.
53+
54+
Since these vulnerabilities are just a more limited way to accomplish what a
55+
malicious build scripts or procedural macros can do, we decided not to publish
56+
Rust point releases backporting the security fix. Patch files for Rust 1.63.0
57+
are available [in the wg-security-response repository][1] for people building
58+
their own toolchains.
59+
60+
## Mitigations
61+
62+
We recommend users of alternate registries to excercise care in which package
63+
they download, by only including trusted dependencies in their projects. Please
64+
note that even with these vulnerabilities fixed, by design Cargo allows
65+
arbitrary code execution at build time thanks to build scripts and procedural
66+
macros: a malicious dependency will be able to cause damage regardless of these
67+
vulnerabilities.
68+
69+
crates.io implemented server-side checks to reject these kinds of packages
70+
years ago, and there are no packages on crates.io exploiting these
71+
vulnerabilities. crates.io users still need to excercise care in choosing their
72+
dependencies though, as the same concerns about build scripts and procedural
73+
macros apply here.
74+
75+
## Acknowledgements
76+
77+
We want to thank Ori Hollander from JFrog Security Research for responsibly
78+
disclosing this to us according to the [Rust security policy][2].
79+
80+
We also want to thank Josh Triplett for developing the fixes, Weihang Lo for
81+
developing the tests, and Pietro Albini for writing this advisory. The
82+
disclosure was coordinated by Pietro Albini and Josh Stone.
83+
84+
[1]: https://github.com/rust-lang/wg-security-response/tree/master/patches
85+
[2]: https://www.rust-lang.org/policies/security

0 commit comments

Comments
 (0)