Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpf_loader: fix non-portable cross-VM transmutation of Instruction
The `sol_invoke_signed_rust` syscall handler initializes takes a reference to the `Instruction` type backed by VM memory in the `translate_instruction` function. The `Instruction` type contains an std `Vec<AccountMeta>`. Because the host and VM have different memory maps the resulting `&Vec` object is corrupted in a way that breaks Rust's safety semantics. For example, trying to access any Vec element (a safe operation) will result in a segfault, as the host would try to resolve a VM pointer without translating it. The transmutation of the `Vec<_>` type in an SBFv2 Rust environment to the host (x86_64 or arm64) Rust environment is also UB. Rust has no ABI stability guarantees, neither across different compiler versions, nor across different architectures. For this reason, the solana-bpf-loader-program would not be able to execute any Rust programs that use CPIs on 32-bit hosts. This code does not cause a security vulnerability but this construct should be improved to bring it more in line with the [Rust Unsafe Code Guidelines Reference](https://rust-lang.github.io/unsafe-code-guidelines/). - Introduces a new stable `RustVMVec<T>` type that describes `Vec<T>` on SBFv2. - Introduces a new stable `RustVMInstruction` type that describes `Instruction` on SBFv2. - Replaces non-portable `translate_instruction` code with a cross-arch/cross-rustc portable variant.
- Loading branch information