GHSA-qvc4-78gw-pv8p Adverserial use of `make_bitflags!` macro can cause undefined behavior

Not scored Published

Adversarial use of the make_bitflags! macro can cause undefined behavior, potentially leading to crashes or code execution in applications using the enumflags2 library.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Not stated
Victim action needed
Not needed
Fix
Available

What is GHSA-qvc4-78gw-pv8p?

GHSA-qvc4-78gw-pv8p is a memory corruption vulnerability in enumflags2, published on 17 Apr 2023.

Official description

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.

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
}

Which versions are affected by GHSA-qvc4-78gw-pv8p?

3 open source packages ship an affected version, including enumflags2.

PackageAffectedFixed in
enumflags2 crates.ioFrom 0.7.00.7.7
enumflags2 crates.ioFrom 0.7.00.7.7
enumflags2 crates.ioFrom 0.7.00.7.7

How do I fix GHSA-qvc4-78gw-pv8p?

Upgrade enumflags2 to 0.7.7 or later.

Upgrade to the fixed version. Memory-safe languages, compiler hardening and fuzzing prevent most new cases. More about Memory corruption.

Is GHSA-qvc4-78gw-pv8p being exploited?

There is no known exploitation of GHSA-qvc4-78gw-pv8p in the wild and no public exploit code.

Sources

Also known as RUSTSEC-2023-0035.

Is GHSA-qvc4-78gw-pv8p in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free