fix(vm): harden WASM host-ABI boundary and read into guest memory in place - #518
Merged
Conversation
…place
Three tenant-isolation / DoS fixes on the vm-low-orbit host functions, plus a
read-path change that also removes the unbounded-allocation vector:
- Storage content files were created at a fixed relative path
("tempFile"+counter) in the shared process CWD, with the counter reset per
instance, so concurrent functions (even within one project) aliased the same
file — a cross-tenant read/corrupt, and the files were never removed. Use
os.CreateTemp, namespaced by project, and remove on close and factory close.
- memoryViewRead clamped its count with `size < offset+count`, which overflows
uint32 for a large guest-supplied count and slips into an out-of-range
data[offset:offset+count] slice. Clamp against the remaining bytes instead.
- The guest-read host functions (contentReadFile, storageReadFile,
readHttpResponseBody, readHttpEventBody, cryptoRead) did make([]byte,
guestLen) before any bound — a multi-GiB host allocation per call, outside
the wasm page limit. Read directly into the guest's linear memory instead:
Memory().Read returns an aliasing slice, so the reader fills guest memory in
place. That range-checks the request (rejecting an oversized length without
allocating) and drops both the allocation and the extra copy on every read.
Regression tests cover each fix: the cross-instance temp-file collision, the
count-overflow clamp, and the oversized-read rejection (asserting bytes
allocated, since the pre-fix code returned the same errno after allocating).
taubyte0
approved these changes
Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Hardening pass on the
pkg/vm-low-orbithost functions (the ABI a tenant's WASM function calls), plus a read-path change that removes an unbounded allocation while dropping a copy.Fixes
Storage content files collided across tenants.
storageNewContent/storageOpenCidcreated scratch files at a fixed relative path ("tempFile"+counter) in the shared substrate process CWD, and the counter resets to 0 per instance. Two functions running concurrently — even within one project — opened the sametempFile0, so one guest's staged content could be read or truncated by another; the files were also never removed. Now usesos.CreateTemp(namespaced by project) and removes the file on close and on factory teardown.memoryViewReadinteger overflow. The length clampif size < offset+countoverflowsuint32for a large guest-suppliedcount, skipping the clamp and indexingdata[offset:offset+count]out of range. Clamped against the remaining bytes (count > mv.size-offset) instead.Unbounded host allocation on guest reads.
contentReadFile,storageReadFile,readHttpResponseBody,readHttpEventBodyandcryptoReaddidmake([]byte, guestLen)before any bound — a multi-GiB host allocation per call, outside the wasm page limit (cryptoReadadditionallyrand.Reads it, forcing real RSS).The read-path change
Rather than cap the allocation, the read functions now read directly into the guest's linear memory: wazy's
Memory().Readreturns a slice aliasing guest memory, so the reader (os.File,http.Body,crypto/rand) fills it in place. This range-checks the request — an oversized length is rejected without allocating — and removes both the allocation and the subsequent copy on every read.Tests
Regression tests for each fix, each verified to fail on the pre-fix code:
TestContentTempFilesDoNotCollideAcrossInstances/TestContentCloseRemovesTempFileTestMemoryViewReadCountOverflowIsClampedTestContentReadRejectsOversizedLength/TestCryptoReadRejectsOversizedLength(assert bytes allocated, since the pre-fix code returned the same errno after allocating gigabytes)The existing end-to-end
pkg/vm-low-orbit/testsharness (real wazy runtime) passes, confirming the in-place reads land correct data and the caps reject nothing legitimate.