target/riscv: Zicbom cbo.flush, cbo.clean, cbo.inval bypass Zicfiss shadow stack protection after load warms TLB
Host environment
-
Operating system: macOS 26.3 (Darwin 25.3.0)
-
OS/kernel version: Darwin Kernel Version 25.3.0: root:xnu-12377.81.4~5/RELEASE_ARM64_T8142
-
Architecture: arm64 (Apple M4)
-
QEMU flavor: qemu-system-riscv64
-
QEMU version: 11.1.50 (v11.0.0-934-gd731492832, commit d7314928)
-
QEMU command line:
qemu-system-riscv64 -machine virt -accel tcg -cpu rv64,zimop=true,zcmop=true,zicfiss=true,zicbom=true,zicboz=true -m 128M -smp 1 -display none -monitor none -serial stdio -bios none -kernel repro.elf -no-reboot
Emulated/Virtualized environment
- Operating system: none (bare-metal RV64 test)
- OS/kernel version: N/A
- Architecture: riscv64
Description of problem
Disclosure: An LLM agent helped me investigate this bug and prepare the reproducer.
Zicbom cache-block management instructions (cbo.flush, cbo.clean, and cbo.inval) targeting a Zicfiss shadow stack page (Sv39 leaf PTE with R=0, W=1, X=0 and menvcfg.SSE=1) retire without faulting if a prior ordinary load has populated the SoftMMU TLB for that page. When the SoftMMU TLB is cold or flushed with sfence.vma, the same instruction on the same page raises a Store/AMO access fault (mcause = 7).
The RISC-V Zicfiss specification forbids cache-block operations on shadow stack pages and requires a Store/AMO access fault (mcause = 7). Running the same ELF on sail_riscv_sim 0.16 raises mcause = 7 even immediately after ld from the shadow stack page.
Steps to reproduce
-
Build repro.elf from the attached link.ld and repro.S:
clang --target=riscv64-unknown-elf -march=rv64ima_zicsr_zicbom_zicboz -mabi=lp64 -mcmodel=medany -nostdlib -static -fuse-ld=lld -Wl,-T,link.ld -Wl,--build-id=none -Wl,--no-relax -o repro.elf repro.S -
Run repro.elf under qemu-system-riscv64:
qemu-system-riscv64 -machine virt -accel tcg -cpu rv64,zimop=true,zcmop=true,zicfiss=true,zicbom=true,zicboz=true -m 128M -smp 1 -display none -monitor none -serial stdio -bios none -kernel repro.elf -no-reboot -
Observe the output:
CONTROL 1 PASS: cold-TLB cbo.flush on shadow stack page raised store/AMO access fault (mcause=7) BUG: cbo.flush, cbo.clean, and cbo.inval on shadow stack page retired without faulting after LD warmed the TLB CONTROL 2 PASS: after sfence.vma, cbo.flush on the same shadow stack page raised store/AMO access fault (mcause=7) again