RUSTSEC-2022-0028

Source
https://rustsec.org/advisories/RUSTSEC-2022-0028
Import Source
https://github.com/rustsec/advisory-db/blob/osv/crates/RUSTSEC-2022-0028.json
JSON Data
https://api.osv.dev/v1/vulns/RUSTSEC-2022-0028
Aliases
Published
2022-05-22T12:00:00Z
Modified
2023-11-08T04:17:25.410603Z
Summary
Use after free in Neon external buffers
Details

Neon provides functionality for creating JavaScript ArrayBuffer (and the Buffer subtype) instances backed by bytes allocated outside of V8/Node. The JsArrayBuffer::external and JsBuffer::external did not require T: 'static prior to Neon 0.10.1. This allowed creating an externally backed buffer from types that may be freed while they are still referenced by a JavaScript ArrayBuffer.

The following example demonstrates use after free. It compiles on versions <0.10.1 and fails to compile afterward.

pub fn soundness_hole(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {
    let mut data = vec![0u8, 1, 2, 3];

    // Creating an external from `&mut [u8]` instead of `Vec<u8>` since there is a blanket impl
    // of `AsMut<T> for &mut T`
    let buf = JsArrayBuffer::external(&mut cx, data.as_mut_slice());

    // `buf` is still holding a reference to `data`!
    drop(data);

    Ok(buf)
}
Database specific
{
    "license": "CC0-1.0"
}
References

Affected packages

crates.io / neon

Package

Affected ranges

Type
SEMVER
Events
Introduced
0.8.0
Fixed
0.10.1

Ecosystem specific

{
    "affected_functions": null,
    "affects": {
        "os": [],
        "functions": [
            "neon::types::JsArrayBuffer::external",
            "neon::types::JsBuffer::external"
        ],
        "arch": []
    }
}

Database specific

{
    "cvss": null,
    "informational": null,
    "categories": [
        "memory-corruption",
        "memory-exposure"
    ]
}