Skip to content

RUSTSEC-2022-0028: Use after free in Neon external buffers #135

@github-actions

Description

@github-actions

Use after free in Neon external buffers

Details
Package neon
Version 0.9.1
URL neon-bindings/neon#896
Date 2022-05-22
Patched versions >=0.10.1
Unaffected versions <0.8.0

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: &#39;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 &lt;0.10.1 and fails to compile afterward.

pub fn soundness_hole(mut cx: FunctionContext) -&gt; JsResult&lt;JsArrayBuffer&gt; {
    let mut data = vec![0u8, 1, 2, 3];
    
    // Creating an external from `&amp;mut [u8]` instead of `Vec&lt;u8&gt;` since there is a blanket impl
    // of `AsMut&lt;T&gt; for &amp;mut T`
    let buf = JsArrayBuffer::external(&amp;mut cx, data.as_mut_slice());

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

    Ok(buf)
}

See advisory page for additional details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions