target/riscv: fault shadow-stack accesses on non-shadow-stack data pages
PATCH 1/2 target/riscv: fault shadow-stack accesses on non-shadow-stack data pages
Hello,
The leaf rwx switch in get_physical_address() handles the W-only (shadow-stack) and R-only encodings for Zicfiss but has no cases for RW, R|X, X-only or RWX leaves when the access is a shadow-stack access (is_sstack_idx). Those fall through to the normal permission path, so sspush/sspopchk/ssamoswap freely read and write ordinary data pages mapped V|R|W (user or supervisor), and sspopchk comparisons succeed against attacker-chosen RW or R|X memory: a ROP+1-style gadget that pivots ssp to any RW page can push forged frames and have sspopchk validate them (probe T11 exits 0x75 "full pass on RW page" on unpatched v11.1.3).
Per the Zicfiss spec, shadow-stack accesses are only permitted on shadow-stack pages (and, for unwind reads, read-only pages - already handled by the PTE_R case). Reject the remaining non-SS leaf types when is_sstack_idx. This also closes the MXR path: if (mxr) prot |= PAGE_READ must not grant a shadow-stack read of an execute-only page (probe T32: unpatched exit 0x59, patched faults).
All probes in the Zicfiss conformance battery behave spec-conformantly after this change (SS-page push/popchk semantics unchanged: T4/T5/T8 pass; pivots fault: T11/T13/T31/T32 flip 117/89 -> 15).
--- target/riscv/tcg/cpu_helper.c | 9 +++++++++ 1 file changed, 9 insertions(+)
target/riscv/tcg/cpu_helper.c +9 -0
@@ -1345,6 +1348,15 @@ static int get_physical_address(CPURISCVState *env,return TRANSLATE_FAIL ; }break ; +case PTE_R |PTE_W : +case PTE_R |PTE_X : +case PTE_X : +case PTE_R |PTE_W |PTE_X : +/* Zicfiss: SS instructions on non-SS non-RO pages must fault */ +if (is_sstack_idx) { +return TRANSLATE_FAIL ; + } +break ; }int prot =0 ;
--
2.43.0
Thank,
Looking forward to your reply!