CVE-2021-29935: Rocket Use After Free Vulnerability

HIGH
Advisory Identifier: GHSA-vcw4-8ph6-7vw8
CVSS 7.3
CWE-416
Published
Advisory Summary

CVE-2021-29935 is a HIGH (CVSS 7.3) use after free vulnerability (CWE-416: Use After Free) affecting Rocket libraries in the crates.io ecosystem. The issue involves use after free in rocket. Remediation is available by upgrading affected packages to version 0.4.7.

CVE-2021-29935 at a Glance

CVE Identifier CVE-2021-29935
GHSA Identifier GHSA-vcw4-8ph6-7vw8
Severity HIGH
CVSS v3.1 Base Score 7.3
CWE Classification CWE-416: Use After Free
Affected Product Rocket
Package Ecosystem crates.io
Published Date
Last Updated

Security Impact

CVSS: 7.3

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability Low (A:L)

How to Fix CVE-2021-29935

To remediate this vulnerability, upgrade all affected Rocket dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

rocket fixed: 0.4.7
Upgrade rocket to 0.4.7
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for rocket

How to Check if You Are Affected

To determine whether your application is affected by CVE-2021-29935, inspect your project dependencies for Rocket:

inspect dependencies for rocket

Analyze the terminal output to locate any version of Rocket in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.4.7), 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-416: Use After Free, where the product reuses or references memory after it has been freed. at some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer. In Rocket, 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

Affected versions of this crate transmuted a &str to a &'static str before pushing it into a StackVec, this value was then popped later in the same function. This was assumed to be safe because the reference would be valid while the method's stack was active. In between the push and the pop, however, a function f was called that could invoke a user provided function. If the user provided panicked, then the assumption used by the function was no longer true and the transmute to &'static would create an illegal static reference to the string. This could result in a freed string being used during (such as in a Drop implementation) or after (e.g through catch_unwind) the panic unwinding. This flaw was corrected in commit `e325e2f` by using a guard object to ensure that the &'static str was dropped inside the function.

CVE-2021-29935 Affected Rocket Versions

1 component(s)
Fixed Versions:
0.4.7
Product / Package Ecosystem Affected Versions Fixed Version
rocket
crates.io
< 0.4.7
0.4.7

References

Frequently Asked Questions

What is CVE-2021-29935?
CVE-2021-29935 is a security vulnerability in Rocket involving Use after free in Rocket under CWE-416: Use After Free.
Which Rocket versions are affected?
Affected versions include releases prior to 0.4.7 across affected packages: rocket.
What version fixes CVE-2021-29935?
Upgrading to 0.4.7 (or the latest patched release for your respective branch) resolves the vulnerability.
Is rocket affected?
Yes, rocket is affected in releases prior to 0.4.7. Upgrade your dependency to 0.4.7 or later.
What is the CVSS score of CVE-2021-29935?
CVE-2021-29935 has a CVSS v3.1 base score of 7.3 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L.
What CWE is associated with CVE-2021-29935?
CVE-2021-29935 is classified under CWE-416: Use After Free (The product reuses or references memory after it has been freed. At some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. Any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer.).
How can I check crates.io dependencies for CVE-2021-29935?
Run the dependency tree command: 'inspect dependencies for rocket'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-vcw4-8ph6-7vw8",
  "modified" : "2023-06-13T20:47:54Z",
  "published" : "2021-08-25T20:54:20Z",
  "aliases" : [ "CVE-2021-29935" ],
  "summary" : "Use after free in Rocket",
  "details" : "Affected versions of this crate transmuted a &str to a &'static str before pushing it into a StackVec, this value was then popped later in the same function.\n\nThis was assumed to be safe because the reference would be valid while the method's stack was active. In between the push and the pop, however, a function f was called that could invoke a user provided function.\n\nIf the user provided panicked, then the assumption used by the function was no longer true and the transmute to &'static would create an illegal static reference to the string. This could result in a freed string being used during (such as in a Drop implementation) or after (e.g through catch_unwind) the panic unwinding.\n\nThis flaw was corrected in commit `e325e2f` by using a guard object to ensure that the &'static str was dropped inside the function.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "rocket"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.7"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-29935"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SergioBenitez/Rocket/issues/1534"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SergioBenitez/Rocket/commit/b53a906a8e170fe9b151381c66a76a872c419f9e"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SergioBenitez/Rocket/commit/e325e2fce4d9f9f392761e9fb58b418a48cef8bb"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/SergioBenitez/Rocket"
  }, {
    "type" : "WEB",
    "url" : "https://rustsec.org/advisories/RUSTSEC-2021-0044.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-416" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-08-19T17:09:45Z",
    "nvd_published_at" : null
  }
}