Skip to content

Commit 2e7895c

Browse files
authored
CABI: trap on misaligned waitable-set.{wait,poll} ptr (#741)
unpack_event stored the two i32 event payloads at the guest-supplied `ptr` through store, whose alignment and bounds checks are assertions rather than traps. A misaligned or out-of-bounds `ptr` thus raised an AssertionError in the reference interpreter instead of trapping, and the prose said nothing. Trap unless `ptr` is 4-byte-aligned and `ptr + 8` is within memory, matching the checks lower_flat_values applies to an out-param pointer and what Wasmtime already does. Document this in CanonicalABI.md and the Explainer, whose description of waitable-set.wait wrongly called `payload-addr` 8-byte-aligned: the payload is two contiguous i32s, so 4-byte alignment is all the ABI requires. Assisted-by: claude:claude-fable-5-1 Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent 06c3fa8 commit 2e7895c

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎design/mvp/CanonicalABI.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,10 +4043,15 @@ def canon_waitable_set_wait(mem, si, ptr):
40434043
def unpack_event(mem, inst, ptr, e: EventTuple):
40444044
event, p1, p2 = e
40454045
cx = LiftLowerContext(LiftLowerOptions(memory = mem), inst)
4046+
trap_if(ptr != align_to(ptr, 4))
4047+
trap_if(ptr + 8 > len(cx.opts.memory))
40464048
store(cx, p1, U32Type(), ptr)
40474049
store(cx, p2, U32Type(), ptr + 4)
40484050
return [event]
40494051
```
4052+
Note that `ptr` points to an 8-byte region of memory into which the two
4053+
`i32` payloads of the event are stored. `ptr` must be 4-byte-aligned and the
4054+
whole region must be in bounds, trapping otherwise.
40504055

40514056

40524057
### 🔀 `canon waitable-set.poll`

‎design/mvp/Explainer.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,8 @@ Lastly, the `task-cancelled` event is never returned by `waitable-set.wait` or
18411841

18421842
In the Canonical ABI, the `event-code` return value provides the `event`
18431843
discriminant and the case payloads are stored as two contiguous `i32`s at the
1844-
8-byte-aligned address `payload-addr`.
1844+
4-byte-aligned address `payload-addr`, trapping if `payload-addr` is misaligned
1845+
or out of bounds.
18451846

18461847
For details, see [Waitables and Waitable Sets] in the concurrency explainer and
18471848
[`canon_waitable_set_wait`] in the Canonical ABI explainer.

‎design/mvp/canonical-abi/definitions.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,8 @@ def canon_waitable_set_wait(mem, si, ptr):
23292329
def unpack_event(mem, inst, ptr, e: EventTuple):
23302330
event, p1, p2 = e
23312331
cx = LiftLowerContext(LiftLowerOptions(memory = mem), inst)
2332+
trap_if(ptr != align_to(ptr, 4))
2333+
trap_if(ptr + 8 > len(cx.opts.memory))
23322334
store(cx, p1, U32Type(), ptr)
23332335
store(cx, p2, U32Type(), ptr + 4)
23342336
return [event]

0 commit comments

Comments
 (0)