Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use after free in Neon externally allocated JavaScript buffers #1256

Merged
merged 1 commit into from
May 23, 2022

Conversation

kjvalencik
Copy link
Contributor

In versions prior to Neon 0.10.1, users could create a JavaScript buffer backed by bytes owned by Rust without the 'static lifetime. The following example demonstrates how this could trivially result in a use-after-free bug.

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

@alex alex merged commit b3bf557 into rustsec:main May 23, 2022
@Shnatsel
Copy link
Member

Thanks for the detailed advisory!

@kjvalencik
Copy link
Contributor Author

👍 For any Neon users who happen to come across this issue. If your code continues to compile after updating the Neon version, it means your code was not impacted by the soundness issue.

Thanks @Shnatsel!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants