Skip to content

Commit caf3bd5

Browse files
nwf-msrronortonrmn30
authored
Require store local when storing return sentries (#64)
* Belatedly fix StoreCapImmediate docs We no longer throw exceptions for !SL authorities storing !G capabilities, just clear the tag. * Require store local when storing return sentries Backwards control-flow arcs should ideally be confined to the stack and register save areas. Conveniently, we have mechanism in the RTOS to identify exactly those areas of memory, with capabilities bearing `SL` (store local) permission. And, after #54, the ISA has mechanism for identifying backwards control-flow arcs, with the two return sentry types. We should have capability store impose the requirement for `SL` in the authorizing cap if the cap being stored is a return sentry. Credit where it's due: this is Robert's idea, originally suggested in the obviously-wrong-in-retrospect #63 ("Have CJALR create !G sentries?"). Co-authored-by: Robert Norton <[email protected]> * Review feedback Co-authored-by: Robert Norton <[email protected]> --------- Co-authored-by: Robert Norton <[email protected]> Co-authored-by: Robert Norton <[email protected]>
1 parent 114e78a commit caf3bd5

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

archdoc/chap-changes.tex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ \chapter{Version history}
66
\begin{description}
77
\item[0.5] The version released as technical report MSR-TR-2023-6: \emph{CHERIoT: Rethinking security for low-cost embedded systems}, February 2023\footnote{\url{https://aka.ms/cheriot-tech-report}}.
88
\item[0.6] The current, under-development version of the ISA. The following changes have been made since the previous released version:
9-
\begin{description}
9+
\begin{description}
1010
\item[\ghissue{20}, \ghpr{26}] Capability stores now clear the tag of the stored value instead of raising an exception in case of a store-local violation
1111
(i.e. an attempt to store a non-global capability via a capability without the store-local permission).
1212
Tag clearing is preferable for software because it removes the possibility of a trap when copying untrusted inputs.
@@ -37,9 +37,11 @@ \chapter{Version history}
3737
Software accepting sealed capabilities must be prepared to receive local (that is, \cappermG-lacking) variants,
3838
even if none were ever explicitly constructed.
3939
\end{description}
40-
\end{description}
4140
\item[\ghissue{15}, \ghpr{49}] Document stack high water mark.
4241
Make it explicitly 16-byte aligned and point out the unaligned write spanning \mshwmb{} corner case, which we do not require hardware to handle.
4342
\item[\ghpr{54}] Create backward sentries for function returns and add more checks in \rvcheriasminsnref{CJAL}
4443
Because CHERIoT allows manipulating the status of the interrupt through a function call (and function return) by encoding the interrupt type in the otype, the following attack can occur: A caller calling an interrupt-disabling callee can set the return sentry of the callee to the same callee. This means, the callee will call itself on return all the while operating with interrupts disabled. This will lead to infinite repeated calls to the callee with interrupts disabled, violating availability. This attack can be prevented in CHERIoT by adding two new ``backwards-edge'' sentries and adding more checks on \rvcheriasminsnref{CJALR}.
44+
\item[\ghpr{64}] Attempting to store a ``backwards-edge'' sentry through an authorizing cap lacking \cappermSLC will clear the tag of the stored value.
45+
This enables the RTOS to confine ``backwards-edge'' sentries to the stack and register spill area.
46+
\end{description}
4547
\end{description}

archdoc/chap-cheri-riscv.tex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ \subsection{Capability permissions}
327327
It is intended to be used as a software defined permission.
328328
\item[GL] If \cappermG is set then this capability is global and can be stored anywhere, otherwise it is local and may be stored only via capabilities with the \cappermSLC permission.
329329
\item[SL] If \cappermSLC is set (along with \cappermS and \cappermMC) then any capability may be stored via this capability.
330-
Otherwise, attempting to store a local capability (with GL unset) will store the capability with the tag cleared.
330+
Otherwise, attempting to store a local capability (with GL unset) or a backwards sentry (see \cref{sec:sealing}) will store the capability with the tag cleared.
331331
\item[LM] If \cappermLM is not set then any tagged capabilities loaded via this capability will have SD and LM cleared.
332332
Thus, if SD and LM are cleared on a capability then it, and any capability loaded via it (including via indirection), will be read-only.
333333
This is useful for delegating a read-only pointer to a data structure, for example to enforce a language level transitive \asm{const}.
@@ -487,6 +487,9 @@ \subsection{Sealed capabilities}
487487
\end{tabular}
488488
\end{center}
489489

490+
As an additional special case, \insnriscvref{CSC} will require an authority with \cappermSLC to store a backwards sentry (that is, a capability sealed with type 4 or 5).
491+
This allows the RTOS to confine backward sentries to stacks and register store areas.
492+
490493
\subsection{Capability bounds}
491494
\label{sec:bounds}
492495

src/cheri_insts.sail

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,10 @@ union clause ast = StoreCapImm : (regidx, regidx, bits(12))
860860
* The capability located in memory at *cs1*.**address** $+$ *imm* is
861861
* replaced with capability register *cs2*.
862862
*
863+
* The stored capability will have its tag forcibly cleared if *cs1*.**perms**
864+
* does not grant **Permit_Store_Local_Capability** and either *cs2*.**perms** does not
865+
* grant **Global** or *cs2* is a backwards sentry.
866+
*
863867
* ## Exceptions
864868
*
865869
* An exception is raised if:
@@ -868,8 +872,6 @@ union clause ast = StoreCapImm : (regidx, regidx, bits(12))
868872
* - *cs1*.**perms** does not grant **Permit_Store**.
869873
* - *cs1*.**perms** does not grant **Permit_Store_Capability** and
870874
* *cs2*.**tag** is set.
871-
* - *cs1*.**perms** does not grant **Permit_Store_Local_Capability**,
872-
* *cs2*.**tag** is set and *cs2*.**perms** does not grant **Global**.
873875
* - *cs1*.**address** $+$ *imm* $\lt$ *cs1*.**base**.
874876
* - *cs1*.**address** $+$ *imm* $+$ **CLEN** $/$ 8 $\gt$ *cs1*.**top**.
875877
*/
@@ -903,7 +905,10 @@ function clause execute StoreCapImm(cs2, cs1, imm) = {
903905
match (eares) {
904906
MemException(e) => { handle_mem_exception(vaddrBits, e); RETIRE_FAIL },
905907
MemValue(_) => {
906-
let stored_val = clearTagIf(cs2_val, not (auth_val.permit_store_local_cap) & not(cs2_val.global));
908+
let stored_val =
909+
clearTagIf(cs2_val, not (auth_val.permit_store_local_cap) &
910+
( not(cs2_val.global)
911+
| isCapBackwardSentry(cs2_val) ));
907912
let res : MemoryOpResult(bool) = mem_write_cap(addr, stored_val, false, false, false);
908913
match (res) {
909914
MemValue(true) => RETIRE_SUCCESS,

0 commit comments

Comments
 (0)