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 #899

Merged
merged 2 commits into from
May 23, 2022

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 kjvalencik changed the base branch from main to 0.10 May 23, 2022 14:23
Copy link
Collaborator

@dherman dherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@kjvalencik kjvalencik merged commit c17014e into 0.10 May 23, 2022
@kjvalencik kjvalencik deleted the kv/fix-external-soundness branch May 23, 2022 17:16
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
2 participants