Skip to content

Commit 0d66dff

Browse files
authored
Add missing missing stack map declaration for array.new_data (#12935)
`translate_array_new_data` created a GC reference (array ref) via a libcall but did not call `builder.declare_value_needs_stack_map()` on the result. This meant that the reference was not included in stack maps at subsequent safepoints, so if a GC occurred, the reference became stale (leading to use-after-free bugs inside the GC heap sandbox).
1 parent 763622c commit 0d66dff

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

crates/cranelift/src/func_environ.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2742,7 +2742,9 @@ impl FuncEnvironment<'_> {
27422742
libcall,
27432743
&[vmctx, interned_type_index, data_index, data_offset, len],
27442744
);
2745-
Ok(builder.func.dfg.first_result(call_inst))
2745+
let array_ref = builder.func.dfg.first_result(call_inst);
2746+
builder.declare_value_needs_stack_map(array_ref);
2747+
Ok(array_ref)
27462748
}
27472749

27482750
pub fn translate_array_new_elem(
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
;;! gc = true
2+
;;! bulk_memory = true
3+
4+
(module
5+
(type $arr (array i8))
6+
(data $d "hello world")
7+
8+
(import "wasmtime" "gc" (func $gc))
9+
10+
(func (export "test") (result i32)
11+
(array.new_data $arr $d (i32.const 0) (i32.const 5))
12+
13+
(call $gc)
14+
(drop (array.new $arr (i32.const 0) (i32.const 5)))
15+
16+
(array.get_u $arr (i32.const 0))
17+
)
18+
)
19+
20+
(assert_return (invoke "test") (i32.const 104)) ;; 'h'

0 commit comments

Comments
 (0)