GHSA-qvc4-78gw-pv8p: Enumflags2 Adverserial Use Of `make_bitflags!` Macro Vulnerability

MODERATE
Published
Advisory Summary

GHSA-qvc4-78gw-pv8p is a MODERATE adverserial use of `make_bitflags!` macro vulnerability (General Security Weakness) affecting Enumflags2 libraries in the crates.io ecosystem. The issue involves adverserial use of `make_bitflags!` macro can cause undefined behavior. Remediation is available by upgrading affected packages to version 0.7.7.

GHSA-qvc4-78gw-pv8p at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-qvc4-78gw-pv8p
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification General Security Weakness
Affected Product Enumflags2
Package Ecosystem crates.io
Published Date
Last Updated

How to Fix GHSA-qvc4-78gw-pv8p

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

enumflags2 fixed: 0.7.7
Upgrade enumflags2 to 0.7.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 enumflags2

How to Check if You Are Affected

To determine whether your application is affected by GHSA-qvc4-78gw-pv8p, inspect your project dependencies for Enumflags2:

inspect dependencies for enumflags2

Analyze the terminal output to locate any version of Enumflags2 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.7.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 General Security Weakness. In Enumflags2, 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

The macro relied on an expression of the form `Enum::Variant` always being a variant of the enum. However, it may also be an associated integer constant, in which case there's no guarantee that the value of said constant consists only of bits valid for this bitflag type. Thus, code like this could create an invalid `BitFlags<Test>`, which would cause iterating over it to trigger undefined behavior. As the debug formatter internally iterates over the value, it is also affected. ```rust use enumflags2::{bitflags, make_bitflags}; #[bitflags] #[repr(u8)] #[derive(Copy, Clone, Debug)] enum Test { A = 1, B = 2, } impl Test { const C: u8 = 69; } fn main() { let x = make_bitflags!(Test::{C}); // printing or iterating over x is UB } ```

GHSA-qvc4-78gw-pv8p Affected Enumflags2 Versions

1 component(s)
Fixed Versions:
0.7.7
Product / Package Ecosystem Affected Versions Fixed Version
enumflags2
crates.io
≥ 0.7.0
< 0.7.7
0.7.7

References

Frequently Asked Questions

What is GHSA-qvc4-78gw-pv8p?
GHSA-qvc4-78gw-pv8p is a security vulnerability in Enumflags2 involving Adverserial use of `make_bitflags!` macro can cause undefined behavior under General Security Weakness.
Which Enumflags2 versions are affected?
Affected versions include releases prior to 0.7.7 across affected packages: enumflags2.
What version fixes GHSA-qvc4-78gw-pv8p?
Upgrading to 0.7.7 (or the latest patched release for your respective branch) resolves the vulnerability.
Is enumflags2 affected?
Yes, enumflags2 is affected in releases prior to 0.7.7. Upgrade your dependency to 0.7.7 or later.
What CWE is associated with GHSA-qvc4-78gw-pv8p?
GHSA-qvc4-78gw-pv8p is classified under General Security Weakness.
How can I check crates.io dependencies for GHSA-qvc4-78gw-pv8p?
Run the dependency tree command: 'inspect dependencies for enumflags2'. 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-qvc4-78gw-pv8p",
  "modified" : "2023-04-24T16:47:24Z",
  "published" : "2023-04-24T16:47:24Z",
  "aliases" : [ ],
  "summary" : "Adverserial use of `make_bitflags!` macro can cause undefined behavior",
  "details" : "The macro relied on an expression of the form `Enum::Variant` always being a\nvariant of the enum. However, it may also be an associated integer constant, in\nwhich case there's no guarantee that the value of said constant consists only of\nbits valid for this bitflag type.\n\nThus, code like this could create an invalid `BitFlags<Test>`, which would cause\niterating over it to trigger undefined behavior. As the debug formatter\ninternally iterates over the value, it is also affected.\n\n```rust\nuse enumflags2::{bitflags, make_bitflags};\n\n#[bitflags]\n#[repr(u8)]\n#[derive(Copy, Clone, Debug)]\nenum Test {\n    A = 1,\n    B = 2,\n}\n\nimpl Test {\n    const C: u8 = 69;\n}\n\nfn main() {\n    let x = make_bitflags!(Test::{C});\n    // printing or iterating over x is UB\n}\n```\n",
  "severity" : [ ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "enumflags2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.7.0"
      }, {
        "fixed" : "0.7.7"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "PACKAGE",
    "url" : "https://github.com/meithecatte/enumflags2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/meithecatte/enumflags2/releases/tag/v0.7.7"
  }, {
    "type" : "WEB",
    "url" : "https://rustsec.org/advisories/RUSTSEC-2023-0035.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-04-24T16:47:24Z",
    "nvd_published_at" : null
  }
}