mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-02 01:40:02 +00:00
cmse: clear padding when crossing the secure boundary
tracking issue: https://github.com/rust-lang/rust/issues/81391
tracking issue: https://github.com/rust-lang/rust/issues/75835
RFC: https://github.com/rust-lang/rfcs/pull/3884
related: https://github.com/rust-lang/rust/pull/147697
quick context: cmse creates a distinction between code running in secure mode and non-secure mode (think kernel space versus user space). Secure mode has access to data (e.g. encryption keys) that must not leak to non-secure mode. They use a special calling convention that clears unused registers, but padding in arguments/return values can contain stale secure data.
This PR clears the padding bytes (and similar, e.g. space not used in any variant of a union/enum) when values are passed over the secure boundary.
Separately we'll have a lint to warn on enums and unions being passed across the boundary: for them we can't statically know whether the variant that is passed contains padding.
This is conceptually modeled after a similar feature in `clang` ([implementation](065a39b9f7/clang/lib/CodeGen/CGCall.cpp (L4041-L4087))).
cc @Jules-Bertholet
r? @davidtwco