Skip to content

Conversation

@kjvalencik
Copy link
Member

@kjvalencik kjvalencik commented May 23, 2022

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 force-pushed the kv/cherry-pick-soundness-fix branch from c6f705e to 28f79ec Compare May 23, 2022 14:17
@kjvalencik kjvalencik force-pushed the kv/cherry-pick-soundness-fix branch from 28f79ec to 9fa8768 Compare May 23, 2022 14:20
@kjvalencik kjvalencik changed the title Cherry-pick soundness fix for JsArrayBuffer::external and JsBuffer::external soundness(neon): Require T: 'static on JsArrayBuffer::external and JsBuffer::external May 23, 2022
@kjvalencik kjvalencik closed this May 23, 2022
@kjvalencik kjvalencik deleted the kv/cherry-pick-soundness-fix branch May 23, 2022 14:22
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.

2 participants