/

CVE-2026-29648

Severity:

HIGH RISK

(8.8)

Improper Privilege Management in OpenXiangShan NEMU

CVE-2026-29648

Deferred

Vulnerability type

Category:

Improper Privilege Management

CWE:

CWE-269

Impact:

Privilege Bypass / Isolation Break

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

OpenXiangShan NEMU contains an improper privilege management issue where, with Smstateen enabled, clearing the mstateen0.ENVCFG bit does not correctly restrict access to the henvcfg and senvcfg control and status registers (CSRs).

This allows less-privileged code to read or write these CSRs without raising the expected exceptions, potentially bypassing state-enable based isolation controls in virtualized or multi-privilege RISC‑V environments.

Affected context

The vulnerability occurs in RISC‑V environments that use OpenXiangShan NEMU for emulation or verification and have the Smstateen extension enabled.

It specifically affects scenarios where mstateen0.ENVCFG is used to gate access to environment configuration CSRs (henvcfg and senvcfg) across privilege levels, such as in:

  • Virtualized setups with hypervisor and guest privilege modes
  • Systems relying on state-enable bits to enforce isolation between supervisor, hypervisor, and machine mode

In these contexts, code running at a lower privilege level may still interact with configuration state that was expected to be disabled.

Exploit preconditions

  • Attack surface: Guest or lower-privileged software executing on a NEMU-based RISC‑V platform (e.g., OS kernel, hypervisor guest, or user-space with CSR access paths).
  • Required access: Ability to execute instructions at a less-privileged level (e.g., S-mode or VS-mode) that can attempt CSR reads/writes to henvcfg or senvcfg.
  • Configuration requirements:
  • Smstateen extension enabled in NEMU.
  • mstateen0.ENVCFG cleared (intended to restrict access) but still ineffective due to the bug.
  • Trigger point: The lower-privileged code issues CSR read or write instructions to henvcfg or senvcfg that should be blocked or trap, but instead succeed.
  • Why exploitation is possible: The implementation fails to correctly tie CSR access checks to the mstateen0.ENVCFG state, so the hardware-model does not enforce the expected privilege and state-enable restrictions.

Why this happens

This issue stems from incorrect enforcement of privilege and state-enable checks when accessing environment configuration CSRs under the Smstateen extension.

The mstateen0.ENVCFG bit is intended to act as a gate for henvcfg and senvcfg, ensuring that once cleared, less-privileged software cannot access these CSRs without triggering an exception.

In the affected NEMU implementation, the logic that validates CSR accesses does not properly consult or apply the ENVCFG state, allowing CSR reads and writes to succeed regardless of the intended restriction.

Conceptually, this maps to CWE-269: Improper Privilege Management, where privilege boundaries and configuration gates are defined but not correctly enforced, leading to unintended access to sensitive control state.

Potential impact

  • Less-privileged code may read configuration from henvcfg and senvcfg, gaining insight into hypervisor or supervisor environment settings.
  • Less-privileged code could modify henvcfg or senvcfg, altering execution behavior or isolation assumptions of higher-privilege software.
  • Virtualization boundaries relying on Smstateen-based gating may be weakened, enabling guest environments to influence host or other guests' behavior.
  • Security policies that depend on trapping or blocking CSR access when mstateen0.ENVCFG is cleared may be silently bypassed.

General mitigation guidance

Mitigation focuses on enforcing privilege boundaries for CSRs and avoiding security decisions that rely solely on misimplemented gating bits:

  • Review and correct CSR access control logic so that all accesses to henvcfg and senvcfg are conditioned on both privilege level and the current mstateen0.ENVCFG state.
  • Introduce centralized, table-driven CSR permission checks that uniformly apply privilege and state-enable constraints rather than scattered, ad-hoc checks.
  • Where possible, design software to assume that state-enable controls may be imperfect and include additional validation (e.g., sanity checks on guest-controlled configuration) before applying sensitive configuration changes.
  • Use least-privilege defaults in higher-level software: avoid exposing CSR manipulation interfaces to code that does not strictly require them, and gate such operations through well-defined, audited pathways.
  • In testing and verification setups, treat environment configuration CSRs as sensitive and ensure that test code simulates stricter access control to catch similar issues early.

How teams detect issues like this

Detection can combine code inspection, formal reasoning about privilege checks, and runtime tests:

  • Static analysis and code review:
  • Identify all handlers for CSR accesses, especially for henvcfg and senvcfg.
  • Verify that each path includes explicit privilege checks and consults Smstateen bits (e.g., mstateen0.ENVCFG) as specified by the architecture.
  • Look for duplicated or inconsistent access control logic that might omit state-enable checks.
  • Specification-driven review:
  • Compare the implementation of Smstateen-related CSR logic against the RISC‑V privileged specification and internal design docs.
  • Use checklists or policy rules (e.g., "every CSR access must reference a shared access-control helper") during review.
  • Runtime and regression testing:
  • Add tests that attempt CSR reads/writes to henvcfg and senvcfg from lower privilege levels with different mstateen0.ENVCFG states and assert correct trapping behavior.
  • Integrate these tests into continuous integration so regressions in privilege checks are quickly caught.
  • Automated tooling:
  • Employ verification or model-checking tools, where feasible, to prove that CSR access control properties hold under all privilege and state-enable combinations.

Sources

SourceLink
docs.riscv.orgdocs.riscv.org/reference/isa/priv/smstateen.html
github.comgithub.com/OpenXiangShan/NEMU/issues/690
github.comgithub.com/OpenXiangShan/XiangShan/pull/3978

Frequently asked

questions

It is not directly network-exploitable by itself. Exploitation requires the ability to run code on a system using the affected NEMU environment, such as guest or kernel code within an emulator or verification setup. However, any remote vector that allows code execution in a guest or lower-privilege context could leverage this weakness to escalate its impact.

The attacker needs the ability to execute instructions at a lower privilege level (e.g., supervisor, virtual supervisor, or similar) in a RISC‑V environment where Smstateen is enabled and mstateen0.ENVCFG is expected to restrict CSR access. From there, they can attempt CSR operations on henvcfg and senvcfg that should normally be blocked.

The general fix is to centralize and enforce privilege and state-based access control for all CSRs, ensuring that each access is validated against both the current privilege level and any relevant state-enable bits. Implementations should rely on shared helpers or tables that encode CSR permissions, rather than duplicating access logic in multiple places.

Prevention involves combining strong design and verification practices:

  • Define a clear, architecture-aligned model for CSR permissions and state-enable behavior.
  • Implement access control through a single, well-tested mechanism used consistently across all CSRs.
  • Use specification-based tests and, where possible, formal verification to assert that forbidden accesses always trap or fail.
  • Include privilege and CSR access control checks in code review guidelines and automated testing pipelines to catch regressions early.
Find out what's already
exploitable in your codebase.