Skip to content

Commit b3bf557

Browse files
authored
Use after free in Neon externally allocated JavaScript buffers (#1256)
1 parent ef71758 commit b3bf557

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

crates/neon/RUSTSEC-0000-0000.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```toml
2+
[advisory]
3+
id = "RUSTSEC-0000-0000"
4+
package = "neon"
5+
date = "2022-05-22"
6+
url = "https://github.com/neon-bindings/neon/issues/896"
7+
categories = ["memory-corruption", "memory-exposure"]
8+
keywords = ["use-after-free", "incorrect-lifetime"]
9+
10+
[affected.functions]
11+
"neon::types::JsArrayBuffer::external" = ["< 0.10.1, >= 0.8.0"]
12+
"neon::types::JsBuffer::external" = ["< 0.10.1, >= 0.8.0"]
13+
14+
[versions]
15+
patched = [">= 0.10.1"]
16+
unaffected = ["< 0.8.0"]
17+
```
18+
19+
# Use after free in Neon external buffers
20+
21+
Neon provides functionality for creating JavaScript `ArrayBuffer` (and the `Buffer` subtype) instances backed by bytes allocated outside of V8/Node. The [`JsArrayBuffer::external`](https://docs.rs/neon/0.10.0/neon/types/struct.JsArrayBuffer.html#method.external) and [`JsBuffer::external`](https://docs.rs/neon/0.10.0/neon/types/struct.JsBuffer.html#method.external) did not require `T: '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`.
22+
23+
The following example demonstrates use after free. It compiles on versions `<0.10.1` and fails to compile afterward.
24+
25+
```rust
26+
pub fn soundness_hole(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {
27+
let mut data = vec![0u8, 1, 2, 3];
28+
29+
// Creating an external from `&mut [u8]` instead of `Vec<u8>` since there is a blanket impl
30+
// of `AsMut<T> for &mut T`
31+
let buf = JsArrayBuffer::external(&mut cx, data.as_mut_slice());
32+
33+
// `buf` is still holding a reference to `data`!
34+
drop(data);
35+
36+
Ok(buf)
37+
}
38+
```

0 commit comments

Comments
 (0)