rustsec-2023-0035
Vulnerability from osv_rustsec
Published
2023-04-17 12:00
Modified
2023-06-13 13:10
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
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
}
{
"affected": [
{
"database_specific": {
"categories": [],
"cvss": null,
"informational": "unsound"
},
"ecosystem_specific": {
"affected_functions": null,
"affects": {
"arch": [],
"functions": [],
"os": []
}
},
"package": {
"ecosystem": "crates.io",
"name": "enumflags2",
"purl": "pkg:cargo/enumflags2"
},
"ranges": [
{
"events": [
{
"introduced": "0.7.0"
},
{
"fixed": "0.7.7"
}
],
"type": "SEMVER"
}
],
"versions": []
}
],
"aliases": [
"GHSA-qvc4-78gw-pv8p"
],
"database_specific": {
"license": "CC0-1.0"
},
"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\u0027s 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\u003cTest\u003e`, 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```",
"id": "RUSTSEC-2023-0035",
"modified": "2023-06-13T13:10:24Z",
"published": "2023-04-17T12:00:00Z",
"references": [
{
"type": "PACKAGE",
"url": "https://crates.io/crates/enumflags2"
},
{
"type": "ADVISORY",
"url": "https://rustsec.org/advisories/RUSTSEC-2023-0035.html"
},
{
"type": "WEB",
"url": "https://github.com/meithecatte/enumflags2/releases/tag/v0.7.7"
}
],
"related": [],
"severity": [],
"summary": "Adverserial use of `make_bitflags!` macro can cause undefined behavior"
}
Loading…
Loading…
Sightings
| Author | Source | Type | Date |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Loading…
Loading…