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

soundness(neon): Require T: 'static on JsArrayBuffer::external and JsBuffer::external #897

Closed
wants to merge 1 commit into from

Conversation

kjvalencik
Copy link
Member

Currently, types used as the backing storage of external ArrayBuffer do not need to be 'static! This makes it trivial to create a soundness hole (use after free), with only safe Rust.

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

Fixes #896

@kjvalencik
Copy link
Member Author

Closing this PR. I'm going to reverse the cherry pick order so that main gets the CHANGELOG.

@kjvalencik kjvalencik closed this May 23, 2022
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.

JsArrayBuffer::external soundness hole
1 participant