Git Product home page Git Product logo

riscv / riscv-smmtt Goto Github PK

View Code? Open in Web Editor NEW
24.0 9.0 11.0 2.06 MB

This specification will define the RISC-V privilege ISA extensions required to support Supervisor Domain isolation for multi-tenant security use cases e.g. confidential-computing, trusted platform services, fault isolation and so on.

Home Page: https://jira.riscv.org/browse/RVG-65

License: Creative Commons Attribution 4.0 International

Makefile 68.04% TeX 31.96%
access-control confidential-computing smmtt supervisor-domains trusted-computing trusted-execution-environment ap-tee

riscv-smmtt's Introduction

RISC-V Specification

This document describes Supervisor Domain Access Protection - RISC-V privileged architecture extension to support physical address space (memory and devices) isolation for more than one supervisor domain use cases for RISC-V platforms. Use cases may use supervisor domains to reduce the supervisor Trusted Computing Base (TCB), with differential access to memory and other platform resources e.g. Confidential Computing (CoVE), Security Services, Secure Devices etc.

License

This work is licensed under a Creative Commons Attribution 4.0 International License (CC-BY-4.0). See the LICENSE file for details.

Contributors

Contributors to this specification are contained in the contributors file.

For instructions on how to contribute please see the CONTRIBUTING file.

Dependencies

To build the document, you’ll need the following tools installed on your system:

  Make
  asciiDoctor-pdf, asciidoctor-bibtex, asciidoctor-diagram and asciidoctor-mathematical
  Docker

Cloning and Building the Document

This project uses submodules to include the RISC-V documentation toolchain.

  git clone --recurse-submodules https://github.com/riscv/riscv-smmtt.git
  cd ./riscv-smmtt.git
  make VERSION=v1.0.0 REVMARK=Draft

VERSION: Represents the version of the specification being built. By default, this is set to 'v0.0.0'. You can change this to a different value, like 'v1.0.0', 'v1.1.0', etc., based on the current version of your specification.

REVMARK: This represents a revision marker for the project. Its default value is 'Draft'. You may want to change this to something like 'Release', 'Stable' or 'Ratified'.

riscv-smmtt's People

Contributors

a4lg avatar riscv-tech-admin avatar rpsene avatar rsahita avatar sameo avatar ved-rivos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

riscv-smmtt's Issues

How many MTT structures are necessary?

Does RDSM need to maintain one MTT structure per domain? Or the domains share one global MTT structure?

I can imagine that if supervisor domains share all the physical memory, there would be one MTT structure per supervisor domain. Although there would be additional overhead for RDSM to save/restore memory contents during domain switching to avoid data leakage.

So it seems that more common policy is allocating mutually exclusive memory regions to supervisor domains.
(e.g., 2GB memory, first 1GB is allocated to SD0 and remaining 1GB is allocated to SD1.)
Obviously, one MTT structure per domain is feasible.
But I am wondering if one global MTT structure is enough in this policy.
However it needs MTT entries to have SDID field to tag which domain owns that memory region, am I correct?

Trigger breakpoint exception action in debug mode

The trigger action 0 (Raise a breakpoint exception) is legal in debug mode. This will be a problem if we:

  1. enable debug for partition A
  2. set trigger to raise exception in address of partition B

The adversary could take advantage of breakpoint exception action to tamper partition B, since the exception behavior is not subject to current debug control knob.

Proposal to mitigate:
Disallow the trigger being set to action 0, in debug mode.

Screenshot 2024-02-07 at 11 38 41

Other actions seem fine. Even if the adversary leaves footprint in trigger, the action will not take effect.

TOCTOU mitigation of debug control check

Previously we did not mandate the implementation details of debug control logic. The logic might be far away from the hart (e.g. inside Debug Module) depending on implementation.  This choice of design will lead to TOCTOU issue. For example, an incoming haltreq passes the check logic, but the hart changes to a undebuggable privilege mode when haltreq arrives hart.

privilege security control-Page-2 drawio

Mitigation: the spec shall explicitly mandate implementations to guarantee no privilege change between debug request check and serving the debug request by hart.

Similar, the same rule should be mandated for trigger that privilege must not change during debug control check and trigger firing/matching when trigger action is configured to enter Debug Mode.

Protections on external trigger

External trigger missing M/S/VS/VU enable bits in tmexttrigger CSR. The debugger with S-mode privilege might affect M-mode by enabling an external trigger and letting it fire in M-mode code to achieve attack (e.g. DoS, side channel).
Mitigation: Add per privilege enable bit in tmexttrigger like other triggers.

External trigger inputs might have resource belongs to M-mode (e.g. interrupts or performance counter etc.). A S-mode debugger might snoop the behavior the M-mode by enable those external trigger.
Mitigation: Since M-Mode is enabled by RoT, external triggers should be enabled by RoT as well .

Debug access control for U-mode only domain

The current proposal has only a knob in CSR to enable debuggability for supervisor mode. It will result in privilege escalation if a domain has only U-mode application (e.g. PENGLAI TEE architecture). This choice of U-mode only domain might reduce overhead of context switch (without save/restore S-mode context).

privilege security control-Page-1 drawio

There are tow direction to mitigate:

  1. In addition to S mode knob, add another U mode knob.
  2. Mandate that the SW has to add a thin layer of S mode runtime to enable self-hosted debug

Originally posted by @AoteJin in #11 (comment)

Shareable data and SDID domains

I think the intent of Smmtt is that data that passes PMP / MTT checks should be shared between supervisor domains based on:

To support IO/memory sharing, a hart/device may perform accesses to memory exclusively accessible to its supervisor domain, and to memory shared globally with all supervisor domains or other specific supervisor domains. Memory sharing between supervisor domains is achieved by simply making the physical memory region accessible to the supervisor domains via the MTT structure.

Later in the document it states that:

Data and instructions cached for one supervisor domain shall not be accessible to another supervisor domain, so the SDID (along with the other execution context identifiers such as ASID, VMID, shall factor into the data and instruction caches tags to enforce isolation.

I read this as memory shared globally with all supervisor domains but cached under one supervisor domain cannot be accessed by another supervisor domain (even though PMP and MTT checks passed). Is this understanding correct and what's the rationale?

PMP as an option for supervisor domain isolation

Add PMP as an option for supervisor domain isolation:

  • Add PMP as a mode in table 3.1
  • When PMP mode is used, then MTT is not required and PMP is used instead for physical memory isolation between domains
  • When PMP mode is used, the SDID CSR can still be used to identify the currently active supervisor domain

This allows systems based on PMP or MTT as the underlying physical memory isolation mechanism to implement and support supervisor domains in a consistent way across the RVI architecture.

Debug control for supervisor domains

Root supervisor domain manager should be able to control which supervisor domains are allowed to be debugged.

Initial debug configuration for a supervisor domain is expected to be derived from some configuration/manifest (and optionally reported as part of attestation) -- and then enforced by the root domain manager via this debug control.

Debug state of the Root supervisor domain manager itself is expected to be gated by the platform RoT (and also optionally reported as part of attestation).

Is `Svpams` an extension name?

As a person interested in this specification (as a developer once involved TEE), I'd like to prepare for it and found something not obvious from the documentation.

Considering from the CSR existence (16 CSRs allocated tentatively) and being dependent from Smmtt, Svpams looks like an extension. However, the documentation does not refer Svpams as an extension.

If you have any free time, clarifying whether Svpams is an extension would be helpful.

Does Smsdia have dependency on AIA for RV32 ?

Hi,

When I read section 6.4 Machine Interrupt registers (mip and mie), it says:

The Smsdia extension introduces the machine supervisor domain external interrupt-pending (MSDEIP
- bit 32) field in mip and the machine supervisor domain external interrupt-enable (MSDEIE - bit 32)
field in mie.

The mip and mie in Priv. Spec. is MXLEN, which is MXLEN=32 on RV32, which only has bit 0 ~ bit 31.
AIA extends them to have high-half miph and mieh.

Does it mean that Smsdia has dependency on AIA ?

Should mideleg[32] be hard-wired to 0 in Smsdia ?

According to Priv. Spec.: Machine Trap Delegation Registers (medeleg and mideleg):

mideleg holds trap delegation bits for individual interrupts, with the layout of bits matching those
in the mip register (i.e., STIP interrupt delegation control is located in bit 5).

Per discussion in #34.
We may not want to delegate MSDEI to less privilege mode.
If this is true, it's helpful to explicitly mention that mideleg[32] should be hard-wired to 0 if CPU supports Smsdia.

Selectively delegating some supervisor domain external interrupts

Some TEE OSes may have a requirement to toggle the interrupt enable bit from the REE. For instance, OPTEE calls spin_lock_xsave() to disable both FIQ and IRQ during some critical sections. It seems like the riscv porting effort has to upgrade this operation to a sbi-call even with smsdia in SMMTT. This is because msdeie is an m-mode register, and SDEIE is only available in mie, which means delegation of this type of interrupt to s-mode is impossible. This is a good security choice as s-mode domain should not interfere with interrupts belonging to others. Every thing related to inter-domain managements should be done by the RDSM. However, this may increase the latency or complexity to do interrupt management when the relationship between some domains are not symmetric (Linux + OPTEE).

To achieve the improved latency without sacrificing security. Should we consider adding following 2 changes?

  1. Make SDEIE visible in sie so delegation works.
  2. Add an m-mode MAXLEN CSR msdeideleg E.g. to selectively determine if any of a supervisor domain external interrupts are able to be delegated.

Interrupts for an inactive s-mode domain only get delegated into the hart if mie.SDEIE is set, and the bit representing the s-mode domain in msdeie and msdeideleg is set. Interrupts for an inactive domain where msdeie is true but msdeideleg is not set still trigger a m-mode interrupt.

This type of delegation does not mean the running s-mode domain should process interrupts from an inactive s-file domain. Instead, this delegation works as a mask-able notification for the running s-mode domain.

Should mttp.SDID be WARL? Can non-zero writes be ignored when mttp.MODE == Bare?

  1. An implementation may not implement all SDID domains, especially for larger SDIDLEN. Therefore, should we allow SDID to be WARL?

  2. When mttp.MODE == 0, the spec currently states:

In this case, the remaining fields (SDID, MTTPPN) in mttp must be set to zeros, else generate a fault.

Can hardware force the other values to 0 when mttp.MODE== Bare such that a fault doesn't need to be generated?

About MTTPPN[1:0]

I would like to know why MTTPPN[1:0] should always read as 0.
Please explain it to me, thanks.

M-mode interrupt registers for systems supporting multiple supervisor domains

For systems supporting multiple supervisor domains, add AIA extension along the lines of:

  • mseip and mseie CSR
  • mip.msdeip = |(mseip[] & mseie[])

allowing M-mode to arbitrate interrupts across multiple supervisor domains, analogous to corresponding registers allowing a hypervisor/OS to arbitrate interrupts across multiple guests.

Supporting an interrupt model along the following lines:

  • (Logically) separate APLIC and IMSIC for each supervisor domain
  • Each follow current AIA specification (no change to AIA spec; no change to programming model for S-mode software)
  • M-mode manages access control to each (logical) instance of APLIC/IMSIC - for example PMP/IOPMP
  • M-mode can arbitrate across S-mode interrupts and domains (context switch, mute, whatever)
  • M-mode can delegate interrupts for the currently active supervisor domain

Refer also to discussion with Ved.

In a virtualised system the same mechanism can be used for multiple domains at HV level.

Smsdia clarifications

Hi,

A couple of questions relating to Chapter 7 (Smsdia) please.

1
With respect to the Supervisor Domain External Interrupt (SDEI); The current text does not contain where in the priority order this is expected to be seen - am I right in thinking that since this is a machine-mode only interrupt which cannot be delegated, it comes before SEI?

Multiple simultaneous interrupts destined for different privilege modes are handled in decreasing order of
destined privilege mode. Multiple simultaneous interrupts destined for the same privilege mode are handled in the
following decreasing priority order: MEI, MSI, MTI, SDEI, SEI, SSI, STI, LCOFI.

2

riscv-smmtt/chapter7.adoc

Lines 201 to 203 in 3b03fb0

The `msdeie` is a MXLEN-bit read-write register, formatted for MXLEN=64 as shown
in <<MSDEIE>>. When MXLEN=32, `msdeieh` is a 32-bit read-only register which
aliases bits 63:32 of `msdeie`. When MXLEN=64, `msdeieh` does not exist.

msdeie is a read-write register, but msdeieh is mentioned to be read-only; am I correct in thinking this is a copy paste error?

3
https://github.com/riscv/riscv-smmtt/blob/3b03fb0a0ee88fc077006cb8e77d3ae3ffe67093/chapter7.adoc?plain=1#L40C1-L55C5
The "Supervisor Domain Interrupt Assignment" diagram references an SD-0 APLIC/IMSIC, but msdcfg does not allow 0 to be used as a selection for an IMSIC/APLIC. Is this intentional?

4

riscv-smmtt/chapter7.adoc

Lines 138 to 139 in 3b03fb0

* When `Ssaia` extension is implemented, then the implementation behaves as if
`mstateen0` bits 60, 59, and 58 were all 0.

SDICN being 0 refers to acting as mstateen0 bits 60/59/58 being 0; the AIA spec specifically states that this does not affect M-mode accesses.

As always, the state-enable CSRs do not affect the accessibility of any state when in M-mode, only in less privileged modes.

Am I right in thinking that the intended behaviour in all modes including M is actually to be the same as if there is no IMSIC connected (e.g. sireg access while siselect is in the IMSIC range raises an illegal instruction exception)?

When siselect is a number in a reserved range (currently 0x00–0x2F, 0x40–0x6F, or a number above 0xFF not designated for custom use), or in the range 0x70–0xFF when there is no IMSIC, attempts to access sireg should preferably raise an illegal instruction exception (unless executing in a virtual machine, covered in the next section).

Thanks! :)

Selina

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.