Skip to content
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

PCC: fully support dynamic and static memories in Wasmtime on x86-64 and aarch64. #7468

Merged
merged 9 commits into from
Nov 4, 2023

Conversation

cfallin
Copy link
Member

@cfallin cfallin commented Nov 3, 2023

This PR completes the work to add proof-carrying-code validation to Wasm heap accesses in Wasmtime, for all bounds-check cases (dynamic and static, covering the 4 and 3 cases of the former and latter respectively), on x86-64 and aarch64.

The PR includes an integration test at the top level (tests/pcc_memory.rs) that compiles a Wasm module with PCC enabled under a range of memory configurations. Ideally we'd use the existing Wasm filetest infrastructure for this; but it has its own Wasm environment definitions and PCC hasn't been plumbed through those (this would also mean we'd be testing a slightly different path of at least the memory-type setup than production Wasmtime).

The test expectations change slightly because this PR had to change iadd_imm(x, -k) to isub(x, iconst(k)) in the generated bounds-checking code. Some of the backends (riscv64, s390x) seem to match iadd-of-negative better than isub-of-positive; but that's an orthogonal isel issue and can be fixed up.

I hope to add fuzzing to exercise this further, but we at least have (theoretical) functional completeness with this PR. Hence, I think this fixes #6090.

Followup work on PCC could include use of PCC annotations to verify table accesses as well, and a strong-enforcing mode that disallows all non-checked memory accesses (so we have to audit and allowlist constant pools and ABI code and the like, and ensure all lowered Wasm ops are covered). However I don't think this additional assurance level is necessary to turn on and benefit from Wasm-memory-bounds-checking PCC.

The first half of this PR was

Co-authored-by: Nick Fitzgerald fitzgen@gmail.com

cfallin and others added 5 commits November 1, 2023 22:01
…cts.

Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
…as needed.

This commit also adds an integration test to Wasmtime that checks all
dynamic and static memory cases on x86-64 and aarch64.

Test expected-output changes are due to a change from `iadd_imm(x, -k)`
to `isub(x, iconst(k))` in bounds-check code to facilitate facts on the
computation.
@cfallin cfallin requested a review from fitzgen November 3, 2023 05:27
@cfallin cfallin requested review from a team as code owners November 3, 2023 05:27
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen isle Related to the ISLE domain-specific language labels Nov 3, 2023
Copy link

github-actions bot commented Nov 3, 2023

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64", "cranelift:area:machinst", "cranelift:area:x64", "isle"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

r=me with comments addressed

cranelift/codegen/src/ir/pcc.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/ir/pcc.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/ir/pcc.rs Outdated Show resolved Hide resolved
cranelift/reader/src/parser.rs Show resolved Hide resolved
cranelift/wasm/src/code_translator/bounds_checks.rs Outdated Show resolved Hide resolved
cranelift/wasm/src/code_translator/bounds_checks.rs Outdated Show resolved Hide resolved
cranelift/wasm/src/code_translator/bounds_checks.rs Outdated Show resolved Hide resolved
tests/pcc_memory.rs Outdated Show resolved Hide resolved
@cfallin cfallin enabled auto-merge November 4, 2023 00:10
@cfallin cfallin added this pull request to the merge queue Nov 4, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 4, 2023
@cfallin cfallin added this pull request to the merge queue Nov 4, 2023
@cfallin cfallin removed this pull request from the merge queue due to a manual request Nov 4, 2023
@cfallin cfallin enabled auto-merge November 4, 2023 04:40
@cfallin cfallin added this pull request to the merge queue Nov 4, 2023
Merged via the queue into bytecodealliance:main with commit 4513d9c Nov 4, 2023
20 checks passed
@cfallin cfallin deleted the pcc-dynamic-wasm branch November 4, 2023 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verification of addressing / memory accesses with VeriWasm or similar
2 participants