Repository navigation
Add check for vtable metadata of a different trait - #5001
Open
miguelcorderopamphile wants to merge 1 commit into
Open
miguelcorderopamphile wants to merge 1 commit into
miguelcorderopamphile wants to merge 1 commit into
Conversation
Record each generated vtable global together with its principal trait and fail verification when a virtual call uses a vtable generated for a different principal trait. This detects invalid wide pointer metadata, e.g. built via `ptr::from_raw_parts`, which was previously accepted.
This branch has not been deployed
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.
Refs #3738 (this does not close the issue: cross-crate metadata is not covered yet).
What this changes
Kani now fails verification when the vtable pointer used by a virtual call is equal to a vtable that it generated for a different principal trait. This detects invalid wide pointer metadata like the reproducer in #3738:
Context
ptr::from_raw_partsgoes through normal MIR, and nothing validated the metadata. Vtables are already generated asKani::CommonVTableglobals with a size sanity check (check_vtable_size), so this check reuses that machinery:VtableCtxrecords each generated vtable with its principal trait, andcodegen_virtual_funcalladds oneSafetyCheckassertion per call site (a single conjunction over the mismatching vtables).The principal comparison matches what codegen already uses to reuse vtables for dyn-to-dyn casts, so auto trait differences (e.g.
dyn T + Sendtodyn T) do not trigger the check.Known limitations
--restrict-vtableaggregates after linking (left as the design question in Check vtable validity when explicitly creating wide pointer #3738).Testing
tests/expected/dyn-vtable-wrong-trait/wrong_trait_vtable.rs, plus the reproducer above.tests/kani: 618 passed (3 pre-existing, unrelated failures inQuantifierson this machine because z3 is unavailable),tests/ui: 153 passed,tests/expected: 499 passed (remaining failures are pre-existing on this CBMC build),DynTraitsuite: 30/30, covering upcasting,dyn Fnand cross-crate trait objects.AI assistance was used to develop this change.