bytecodealliance / bytecodealliance/wasmtime
Wasmtime is not using the recommended approach to set the RA state register on Linux AArch64 with PAC enabled
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 126
Description
## Description
[DWARF for the Arm® 64-bit Architecture (AArch64)](https://github.com/ARM-software/abi-aa/blob/a82eef0433556b30539c0d4463768d9feb8cfd0b/aadwarf64/aadwarf64.rst#note-8) specifies that the RA state should be set with `DW_CFA_AARCH64_negate_ra_state `.
The same result can be obtained using `DW_CFA_val_expression`.
```c
// RA_SIGN_STATE corresponds to the DWARF register number 34.
DW_CFA_val_expression 34, 1, DW_OP_lit1
```
This behavior was added to libgcc to support unwinding when the RA state is set with `DW_CFA_val_expression` ([Bug 104689](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104689)).
Current implementation in Wasmtime:
https://github.com/bytecodealliance/wasmtime/blob/37ed724c9da2ee5a516923cf221ade19b78f63eb/cranelift/codegen/src/isa/unwind/systemv.rs#L115-L128
## Issue
Armv9.5-A introduced a new extension to PAC for return address signing: *PAuth_LR*. It adds a new diversifier PC, aside to SP. The value of PC used by PAC2 algorithm corresponds to its value at the time of signing, i.e. the address of the `pacisppc` instruction, or `pacisp` if NOP-space instructions are used.
A new DWARF directive `DW_CFA_AARCH64_negate_ra_state_with_pc` was introduced to record the position of signing and authentication, and to express that PACv2 algorithm was used (vs PACv1 relying on `DW_CFA_AARCH64_negate_ra_state`). During unwinding, this directive saves the PC diversifier into the frame state, to later use it to authenticate the return address.
In my understanding, the approach based on `DW_CFA_val_expression` is not working anymore in this context, as the libgcc unwinder cannot know the difference between a `DW_CFA_val_expression` used for PAC, and another one used for something else, and so cannot save PC at the time of signing.
1. Is it an issue for your use case ? Do you plan to add support for PAuth_LR ?
2. Would it be possible to change the CFI directive to the recommended one ?
## Links
- [DWARF for the Arm® 64-bit Architecture (AArch64) - DWARF register names, RA_SIGN_STATE](https://github.com/ARM-software/abi-aa/blob/a82eef0433556b30539c0d4463768d9feb8cfd0b/aadwarf64/aadwarf64.rst#id20)](https://github.com/ARM-software/abi-aa/blob/a82eef0433556b30539c0d4463768d9feb8cfd0b/aadwarf64/aadwarf64.rst#note-8)
- [DWARF for the Arm® 64-bit Architecture (AArch64) - 4.4 Call frame instructions](https://github.com/ARM-software/abi-aa/blob/a82eef0433556b30539c0d4463768d9feb8cfd0b/aadwarf64/aadwarf64.rst#id1)
- Related discussion: #9264
Contributor guide
Assessment
This issue has not been assessed yet.