Skip to content

Validate heap types #5279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 22, 2022
Merged

Validate heap types #5279

merged 3 commits into from
Nov 22, 2022

Conversation

tlively
Copy link
Member

@tlively tlively commented Nov 18, 2022

Validate that GC is enabled if struct and array types are used by the module and
validate that both GC and isorecursive types are enabled when nontrivial rec
groups are used.

This fixes a fuzz bug in #5239 where initial contents included a rec group but
the fuzzer disabled GC. Since the resulting module passed validation, the rec
groups made it into the binary output, making the type section malformed.

Validate that GC is enabled if struct and array types are used by the module and
validate that both GC and isorecursive types are enabled when nontrivial rec
groups are used.

This fixes a fuzz bug in #5239 where initial contents included a rec group but
the fuzzer disabled GC. Since the resulting module passed validation, the rec
groups made it into the binary output, making the type section malformed.
@tlively tlively requested a review from kripken November 18, 2022 18:05
@tlively
Copy link
Member Author

tlively commented Nov 18, 2022

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@@ -3461,6 +3461,25 @@ static void validateTags(Module& module, ValidationInfo& info) {
}
}

static void validateTypes(Module& module, ValidationInfo& info) {
for (auto type : ModuleUtils::collectHeapTypes(module)) {
Copy link
Member

Choose a reason for hiding this comment

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

I am somewhat worried about scanning the entire module for this validation - it will basically double validation times, I think.

We already validate GC instructions, which are most of the places GC types can appear. Perhaps we can add validation in the other places, like function params and locals?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe. I'd be worried about missing places and duplicating the logic from ModuleUtils::collectHeapTypes (which we've had trouble remembering to update in just a single place), but for better or worse maybe the fuzzer will help find cases where we miss adding validation.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, definitely a tradeoff. Not sure what's best.

Can we at least not do the extra pass when GC is not enabled? That is, if GC is not enabled then I'd expect to get lots of other validation errors if the code contains GC types. And the new check added here seems to mostly be important to differentiate things in the context of GC being enabled anyhow (nominal/isorecursive differences).

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that seems reasonable for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I pushed a better solution just now. PTAL.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Looks great aside from that question!

@@ -2903,6 +2903,9 @@ void FunctionValidator::visitFunction(Function* curr) {
"Multivalue function results (multivalue is not enabled)");
}
FeatureSet features;
// Check for things like having a rec group with GC enabled.
features |=
Copy link
Member

Choose a reason for hiding this comment

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

Why are reference types ignored here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because a function reference type always requires ReferenceTypes as a baseline, but it's kind of a false positive in this situation. MVP functions will have some MVP signature type here, but getFeatures() will still return ReferenceTypes.

In practice the only thing this line checks for is rec groups.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, right, the type itself is a reference type. A comment perhaps could help?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh oops, I saw this comment just after merging. Will add a comment in a follow-up.

@tlively tlively merged commit 310a4e9 into main Nov 22, 2022
@tlively tlively deleted the validate-types branch November 22, 2022 16:16
tlively added a commit that referenced this pull request Nov 22, 2022
tlively added a commit that referenced this pull request Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants