Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

In the spill slot allocator, set RangeFragAndRefness::is_ref to `tr… #86

Merged
merged 1 commit into from
Jul 16, 2020
Merged

In the spill slot allocator, set RangeFragAndRefness::is_ref to `tr… #86

merged 1 commit into from
Jul 16, 2020

Conversation

julian-seward1
Copy link
Contributor

…ue` only when we know that

a reftyped VirtualRange is going to be spilled. This fixes a conceptual error in stackmap
generation found by Chris via fuzzing. The error was that RangeFragAndRefness::is_ref was
previously set to true too early. Specifically, spill slots for all VirtualRanges of a
virtual range equivalence class are allocated at the point where the first VirtualRange in the
eclass was spilled. And the RangeFragAndRefness::is_ref of all RangeFrags owned by the
eclass was set to true if the VirtualRange was reftyped.

From the point of view of "does this spill slot fragment carry a reftyped thing, or not?",
that's exactly correct. However, it ignores the fact that other VirtualRanges in the same
eclass ultimately might not be spilled. Hence the effect is to potentially mark some of those
spill slot sections as reftyped even though they will never be used. Consequently the client
could end up passing such slot sections to its GC for scavenging etc even though they contain
undefined values. This could cause crashing or worse.

The fix is (conceptually) very simple: don't set RangeFragAndRefness::is_ref to true when
initially allocating spill slots. Instead, set it (them) later in the process, when spilling a
VirtualRange that is reftyped. A new method,
SpillSlotAllocator::notify_spillage_of_reftyped_vlr, has been added for that purpose.

This was found by Chris' regalloc-result checker and fuzzing. That is fortunate, since it would
have otherwise caused an obscure GC crash which would have been hard to track down.

@julian-seward1 julian-seward1 requested a review from cfallin July 16, 2020 06:06
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good aside from one comment request -- thanks for the quick fix!

lib/src/bt_spillslot_allocator.rs Show resolved Hide resolved
@cfallin cfallin mentioned this pull request Jul 16, 2020
…ue` only when we know that

a reftyped `VirtualRange` is going to be spilled.  This fixes a conceptual error in stackmap
generation found by Chris via fuzzing.  The error was that `RangeFragAndRefness::is_ref` was
previously set to `true` too early.  Specifically, spill slots for all `VirtualRanges` of a
virtual range equivalence class are allocated at the point where the first `VirtualRange` in the
eclass was spilled.  And the `RangeFragAndRefness::is_ref` of all `RangeFrag`s owned by the
eclass was set to `true` if the `VirtualRange` was reftyped.

From the point of view of "does this spill slot fragment carry a reftyped thing, or not?",
that's exactly correct.  However, it ignores the fact that other `VirtualRange`s in the same
eclass ultimately might not be spilled.  Hence the effect is to potentially mark some of those
spill slot sections as reftyped even though they will never be used.  Consequently the client
could end up passing such slot sections to its GC for scavenging etc even though they contain
undefined values.  This could cause crashing or worse.

The fix is (conceptually) very simple: don't set `RangeFragAndRefness::is_ref` to `true` when
initially allocating spill slots.  Instead, set it (them) later in the process, when spilling a
`VirtualRange` that is reftyped.  A new method,
`SpillSlotAllocator::notify_spillage_of_reftyped_vlr`, has been added for that purpose.

This was found by Chris' regalloc-result checker and fuzzing.  That is fortunate, since it would
have otherwise caused an obscure GC crash which would have been hard to track down.
@julian-seward1 julian-seward1 merged commit 217b9bf into bytecodealliance:main Jul 16, 2020
cfallin added a commit to cfallin/wasmtime that referenced this pull request Jul 16, 2020
This version of regalloc.rs includes several bugfixes for
reference-types support used by the new backend framework and the
aarch64 backend (bytecodealliance/regalloc.rs#85 and
bytecodealliance/regalloc.rs#86).
cfallin added a commit to cfallin/wasmtime that referenced this pull request Jul 16, 2020
This version of regalloc.rs includes several bugfixes for
reference-types support used by the new backend framework and the
aarch64 backend (bytecodealliance/regalloc.rs#85 and
bytecodealliance/regalloc.rs#86).
cfallin added a commit to cfallin/regalloc.rs that referenced this pull request Jul 16, 2020
…isters.

This exposed an interesting fuzzbug related to dead spillslots being
named in stackmaps, which was fixed in PR bytecodealliance#86; the test case is included
here rather than in bytecodealliance#86 (because it needs the test-framework
reftypes/safepoints parsing support added here).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants