Skip to content
Rivoryxa Technologies

Showing debug registers could be accessed outside debug mode

A closed bug report on a RISC-V core: accessing a debug register outside debug mode did not trap. We reproduced it and proved the maintainers' fix holds.

Open source RISC-V core, bug report 333Outcome: Bug reproduced, fix verified

1The issue

The core has four registers kept for the debugger, such as dcsr and dpc. Outside debug mode, an instruction that accesses them must be rejected as illegal, which causes a trap. The report said that in machine mode the access did not trap. The core flagged the instruction as illegal, but the flag never reached the end of the pipeline, so the instruction finished as if it were allowed.

The points on the issue

Before the fix: debug register access in machine modeFlagged illegal, but finishes with no trap. Found in 8 clock cycles.
After the fix: same checkAlways traps. Proven for every reachable state.
Same access inside debug modeStill allowed, as it should be.

2What we did

  1. 1Wrote a rule: outside debug mode, an instruction that accesses a debug register must raise an illegal instruction exception.
  2. 2It took five versions of the rule. Each was corrected from a trace, for example to rule out bus errors and to allow a debug trigger on the same instruction.
  3. 3Ran the final rule with formal verification, which checks every reachable state. It fails on the design before the fix and holds on the current design.
  4. 4Read the fix by the core's maintainers only after the proof. A condition that is always false when the extension interface is off had blocked the illegal flag; the fix inverts it.

3Result

The bug is reproduced on the design before the fix, and the rule holds on the current design. The failing case shows exactly the gap the fix closes: the flag was set, but the trap never came.

The core's maintainers wrote the fix, and we checked it only against our own checks, not the wider test suite.

Have a bug like this one?

Describe the problem in a few lines. An engineer replies, and we agree the scope together.

Discuss a verification problem