Advisory

RUSTSEC-2022-0028

Also known as: GHSA-8mj7-wxmc-f424

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)
}

Severity

Not rated by the source.

Dates

Published
2022-05-22 12:00 UTC
Modified
2023-11-08 04:17 UTC

Affected packages and fixes

neon

crates.io · All systems

Affected

  • introduced 0.8.0, fixed 0.10.1 (semver)

Fixed versions

0.10.1

Fix

  • Fixed version 0.10.1
    cargo update -p neon --precise 0.10.1

Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.

Check your own computer: guard packages check

View this record on OSV.dev

Source

Source: RustSec Advisory Database · CC0-1.0

Sources & licences