CVE-2023-38497: Cargo not respecting umask when extracting crate archives

Published Aug 1, 2023
·
Updated

A flaw was found in the rust-cargo package. Cargo, as bundled with the Rust compiler, did not respect the umask when extracting dependency tarballs and caching the extraction for future builds. If a dependency contained files with 0777 permissions, another local user could edit the cache of the extracted source code, potentially executing arbitrary code with the privileges of the user running Cargo during the next build.

Other sources

Cargo downloads the Rust project’s dependencies and compiles the project. Cargo prior to version 0.72.2, bundled with Rust prior to version 1.71.1, did not respect the umask when extracting crate archives on UNIX-like systems. If the user downloaded a crate containing files writeable by any local user, another local user could exploit this to change the source code compiled and executed by the current user. To prevent existing cached extractions from being exploitable, the Cargo binary version 0.72.2 included in Rust 1.71.1 or later will purge caches generated by older Cargo versions automatically. As a workaround, configure one's system to prevent other local users from accessing the Cargo directory, usually located in ~/.cargo.

Ubuntu

The Rust Security Response WG was notified that Cargo did not respect the umask when extracting crate archives on UNIX-like systems. If the user downloaded a crate containing files writeable by any local user, another local user could exploit this to change the source code compiled and executed by the current user.

This vulnerability has been assigned CVE-2023-38497.

Overview

In UNIX-like systems, each file has three sets of permissions: for the user owning the file, for the group owning the file, and for all other local users. The "[umask][1]" is configured on most systems to limit those permissions during file creation, removing dangerous ones. For example, the default umask on macOS and most Linux distributions only allow the user owning a file to write to it, preventing the group owning it or other local users from doing the same.

When a dependency is downloaded by Cargo, its source code has to be extracted on disk to allow the Rust compiler to read as part of the build. To improve performance, this extraction only happens the first time a dependency is used, caching the pre-extracted files for future invocations.

Unfortunately, it was discovered that Cargo did not respect the umask during extraction, and propagated the permissions stored in the crate archive as-is. If an archive contained files writeable by any user on the system (and the system configuration didn't prevent writes through other security measures), another local user on the system could replace or tweak the source code of a dependency, potentially achieving code execution the next time the project is compiled.

Affected Versions

All Rust versions before 1.71.1 on UNIX-like systems (like macOS and Linux) are affected. Note that additional system-dependent security measures configured on the local system might prevent the vulnerability from being exploited.

Users on Windows and other non-UNIX-like systems are not affected.

Mitigations

We recommend all users to update to Rust 1.71.1, which will be released later today, as it fixes the vulnerability by respecting the umask when extracting crate archives. If you build your own toolchain, patches for 1.71.0 source tarballs are [available here][2].

To prevent existing cached extractions from being exploitable, the Cargo binary included in Rust 1.71.1 or later will purge the caches it tries to access if they were generated by older Cargo versions.

If you cannot update to Rust 1.71.1, we recommend configuring your system to prevent other local users from accessing the Cargo directory, usually located in ~/.cargo:

chmod go= ~/.cargo

Acknowledgments

We want to thank Addison Crump for responsibly disclosing this to us according to the [Rust security policy][3].

We also want to thank the members of the Rust project who helped us disclose the vulnerability: Weihang Lo for developing the fix; Eric Huss for reviewing the fix; Pietro Albini for writing this advisory; Pietro Albini, Manish Goregaokar and Josh Stone for coordinating this disclosure; Josh Triplett, Arlo Siemen, Scott Schafer, and Jacob Finkelman for advising during the disclosure.

[1]: https://en.wikipedia.org/wiki/Umask [2]: https://github.com/rust-lang/wg-security-response/tree/main/patches/CVE-2023-38497 [3]: https://www.rust-lang.org/policies/security

Affected Software

14 affected componentsFixes available
redhat/rust-toolset<1.66-rust-0:1.66.1-2.el7_9
1.66-rust-0:1.66.1-2.el7_9
redhat/rust<0:1.66.1-2.el9_2
0:1.66.1-2.el9_2
rust/cargo<=0.72.1
0.72.2
ubuntu/rust-cargo<0.57.0-1ubuntu0.1~
0.57.0-1ubuntu0.1~
ubuntu/cargo<0.72.2
0.72.2
ubuntu/cargo<0.66.0+
0.66.0+
ubuntu/cargo<0.67.1+
0.67.1+
ubuntu/cargo<0.67.1+
0.67.1+
ubuntu/cargo<0.47.0-1~
0.47.0-1~
debian/cargo<=0.43.1-3~deb10u1, <=0.47.0-3, <=0.66.0+ds1-1, <=0.70.1+ds1-2
debian/rust-cargo<=0.32.0-2, <=0.43.1-4, <=0.66.0-1, <=0.70.1-2
redhat/rust<1.71.1
1.71.1
rust-lang Cargo Rust<0.72.2
Fedoraproject Fedora=38

Remediation

Information

We recommend configuring your system to prevent other local users from accessing the Cargo directory, usually located in `~/.cargo`.

Event History

Aug 3, 2023
CVE Published
via Ubuntu·12:00 AM
Advisory Published
04:30 PM
Aug 4, 2023
CVE Published
via MITRE·03:51 PM
Data Sourced
via MITRE·03:51 PM
DescriptionSeverityWeakness
Data Sourced
04:15 PM
DescriptionWeakness
Jan 12, 2024
Data Sourced
via Launchpad·12:22 AM
Description

Parent advisories

This vulnerability appears in the following advisories.

Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the vulnerability ID for this issue?

The vulnerability ID for this issue is CVE-2023-38497.

2

What is the severity of CVE-2023-38497?

CVE-2023-38497 has a severity value of 7.9 (high).

3

What is the affected software for CVE-2023-38497?

The affected software for CVE-2023-38497 includes rust-cargo versions 0.57.0-1ubuntu0.1~ to 0.72.2, cargo versions 0.47.0-1~ to 0.67.1+ and 0.72.2, and Rust-lang Cargo versions up to 0.72.2.

4

How can I fix CVE-2023-38497?

To fix CVE-2023-38497, update the affected software to a version that includes the fix. Refer to the official sources, such as the Rust-lang website.

5

Where can I find more information about CVE-2023-38497?

You can find more information about CVE-2023-38497 on the official GitHub page for the Rust-lang Cargo project, Wikipedia page about umask, and the Rust-lang website's security policies.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203