memory: bound segment growth to prevent makeslice panic on malformed program - #702
Open
ipezygj wants to merge 1 commit into
Open
memory: bound segment growth to prevent makeslice panic on malformed program#702ipezygj wants to merge 1 commit into
ipezygj wants to merge 1 commit into
Conversation
…program Segment.Read/Write grow the segment to fit an offset via IncreaseSegmentSize(offset+1), which calls make([]MemoryValue, newSize) with an unbounded, program-controlled size. A program that reads/writes a huge memory offset (e.g. offset 0x80000000000001) makes the runtime panic with 'makeslice: len out of range', crashing the process — there is no recover() in the VM. Reject offsets beyond a generous maxSegmentSize with a clean error instead. Adds a regression test.
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.
Problem
Segment.Read/Writegrow a segment to fit an offset viaIncreaseSegmentSize(offset + 1), which doesmake([]MemoryValue, newSize)with an unbounded, program-controlled size. A program that reads or writes a huge memory offset makes the Go runtime panic withmakeslice: len out of range, which crashes the process — there is norecover()in the VM/runner.Repro (a program whose bytecode reads offset
0x80000000000001):Fix
Reject an offset beyond a generous
maxSegmentSizewith a clean error inRead/Write, so a malformed program returns an error instead of crashing the host. The limit is intentionally generous (no legitimate execution approaches it) and commented as tunable to the intended memory model.make([]MemoryValue, huge)panic → gracefulerror.TestSegmentReadWriteHugeOffsetReturnsError.go test ./pkg/vm/memory/passes; the repro program now returnsmemory offset ... exceeds max segment sizeinstead of panicking.