-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
CFI: Fix many vtable-related problems #121962
Commits on Mar 6, 2024
-
This query computes the trait object, complete with associated type projections for its supertraits, from a trait ref. This is intended for use by CFI shimming.
Configuration menu - View commit details
-
Copy full SHA for de2edc3 - Browse repository at this point
Copy the full SHA de2edc3View commit details -
Refactor visiting instance_def
In preparation to add recursive instance_defs, move this logic to its own convenience method.
Configuration menu - View commit details
-
Copy full SHA for 754c789 - Browse repository at this point
Copy the full SHA 754c789View commit details -
Factored out to minimize the amount of noise in the main CfiShim defining patch.
Configuration menu - View commit details
-
Copy full SHA for 28bdb59 - Browse repository at this point
Copy the full SHA 28bdb59View commit details -
Configuration menu - View commit details
-
Copy full SHA for ff7fb59 - Browse repository at this point
Copy the full SHA ff7fb59View commit details -
Indirect calls through vtables (trait objects or drop_in_place) expect to have a type based on `dyn Trait` at the call-site. The actual implementations have types based on `MyImplType`. These shims allow the insertion of an explicit cast at the beginning of any instance, allowing a different type to be assigned. These shims function for both CFI and KCFI, as they have a single principal type.
Configuration menu - View commit details
-
Copy full SHA for 2102551 - Browse repository at this point
Copy the full SHA 2102551View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5cca174 - Browse repository at this point
Copy the full SHA 5cca174View commit details -
Configuration menu - View commit details
-
Copy full SHA for 646befe - Browse repository at this point
Copy the full SHA 646befeView commit details -
Revert "CFI: Fix SIGILL reached via trait objects"
We no longer need the special instance resolution this added, and it can be broken in edge cases (specifically with a FnPtr shim, which will cause the calculation of fn_abi to fail). * We keep the Clone impls it added, because they have since become used by other portions of the compiler. * Add a test for the address-taken calls that this previously broke. This reverts commit 7c7b22e.
Configuration menu - View commit details
-
Copy full SHA for ada412a - Browse repository at this point
Copy the full SHA ada412aView commit details -
CFI: Skip non-passed arguments
Rust will occasionally rely on fn((), X) -> Y being compatible with fn(X) -> Y, since () is a non-passed argument. Relax CFI by choosing not to encode non-passed arguments.
Configuration menu - View commit details
-
Copy full SHA for 252fcd1 - Browse repository at this point
Copy the full SHA 252fcd1View commit details -
CFI: Handle dyn with no principal
In user-facing Rust, `dyn` always has at least one predicate following it. Unfortunately, because we filter out marker traits and `dyn Sync` is, for example, legal, this results in us having `dyn` types with no predicates on occasion. This patch handles cases where there are no predicates in a `dyn` type.
Configuration menu - View commit details
-
Copy full SHA for b30fedb - Browse repository at this point
Copy the full SHA b30fedbView commit details -
CFI: Support self_cell-like recursion
Current `transform_ty` attempts to avoid cycles when normalizing `#[repr(transparent)]` types to their interior, but runs afoul of this pattern used in `self_cell`: ``` struct X<T> { x: u8, p: PhantomData<T>, } #[repr(transparent)] struct Y(X<Y>); ``` When attempting to normalize Y, it will still cycle indefinitely. By using a types-visited list, this will instead get expanded exactly one layer deep to X<Y>, and then stop, not attempting to normalize `Y` any further.
Configuration menu - View commit details
-
Copy full SHA for 09d1d3e - Browse repository at this point
Copy the full SHA 09d1d3eView commit details -
CFI: Generate super vtables explicitly
CFI shimming means they're not gauranteed to be pre-generated. Traditionally, the base vtable has all the elements of the supertrait vtable, and so visiting the base vtable implies you don't need to visit the supertrait vtable. However, with CFI the base vtable entries will have invocation type `dyn Child`, and the parent vtable will have invocation type `dyn Parent`, so they aren't actually the same instance, and both must be visited.
Configuration menu - View commit details
-
Copy full SHA for 4912a32 - Browse repository at this point
Copy the full SHA 4912a32View commit details -
CFI: Strip auto traits from Virtual receivers
As the instance being called is behind a vtable, it cannot depend on auto traits on the receiver (unless the principal trait requires them, in which case the additional constraint is not needed). Removing this causes the type signature of the `Virtual` instance to match the type signature of the `CfiShim`-wrapped entry in the vtable.
Configuration menu - View commit details
-
Copy full SHA for 50a0a86 - Browse repository at this point
Copy the full SHA 50a0a86View commit details