-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A hardcoded value of the bounds over `switch_compartment` meant that the bounds were much wider than expected. This meant two things: - the `clean` function called within `switch_compartment` was reachable and executable; - when deriving the `clr` within `switch_compartment`, we would derive with the larger bound, and return to a compartment with much more executable permissions than intended. We now tightly bind the PCC to `switch_compartment`. This means moving `clean` within these bounds (a better way would be to create capabilities allowing this function to be called, and provide local copies to each compartment, but that is beyond the scope of this example, and an exercise in engineering), and not deriving `clr` within `switch_compartment`, but just retaining the provided `clr`. Additional small cleanups, such as code-base splitting, and comment-fixing.
- Loading branch information
Showing
9 changed files
with
245 additions
and
249 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
hybrid/compartment_examples/inter_comp_call/secure-try_deref/Makefile.morello-hybrid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
hybrid/compartment_examples/inter_comp_call/secure-try_deref/compartments-try_deref.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Compartment from which we call the switcher to perform inter-compartment | ||
* transition. The call is via a capability, to update the PCC bounds | ||
* appropriately to cover `switch_compartment`. | ||
*/ | ||
comp_f_fn: | ||
// Retrieve local capability containing switcher information | ||
mrs c1, DDC | ||
gclim x1, c1 | ||
sub x1, x1, #16 | ||
ldr c1, [x1] | ||
|
||
// Try to dereference it to retrieve switcher DDC; this is expected to fail | ||
// due to the local capability being sealed (`main.c:143`). | ||
ldr c1, [c1] | ||
|
||
ldr clr, [sp], #16 | ||
|
||
ret clr | ||
comp_f_fn_end: | ||
|
||
/* The function in this compartment just writes to some memory within its | ||
* bounds, to ensure it is properly called. | ||
*/ | ||
.type comp_g_fn, "function" | ||
comp_g_fn: | ||
mrs c10, DDC | ||
mov x11, 42 | ||
str x11, [x10, #4000] | ||
|
||
ret clr | ||
comp_g_fn_end: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
hybrid/compartment_examples/inter_comp_call/secure-try_deref/shared.S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2021 The CapableVMs "CHERI Examples" Contributors. | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
#include "main.h" | ||
|
||
// Compartment functions | ||
.global comp_f_fn | ||
.global comp_g_fn | ||
|
||
// Labels for size computations | ||
.global comp_f_fn_end | ||
.global comp_g_fn_end | ||
.global switch_compartment_end | ||
|
||
.text | ||
.balign 4 | ||
|
||
.global executive_switch | ||
.type executive_switch, "function" | ||
executive_switch: | ||
mov c29, c0 | ||
mov x0, #0 | ||
cvtp clr, lr | ||
b switch_compartment | ||
ret clr | ||
|
||
#include "switch_compartment.s" | ||
|
||
#include "compartments-try_deref.s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
hybrid/compartment_examples/inter_comp_call/secure/compartments.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Compartment from which we call the switcher to perform inter-compartment | ||
* transition. The call is via a capability, to update the PCC bounds | ||
* appropriately to cover `switch_compartment`. | ||
*/ | ||
.type comp_f_fn, "function" | ||
comp_f_fn: | ||
// Set compartment ID we want to switch to | ||
mov x0, #1 | ||
|
||
// Store the `clr` for exitting `comp_f_fn`; this is overwritten by | ||
// `switch_compartment`. | ||
str clr, [sp, #-16]! | ||
|
||
// Retrieve local capability containing switcher information for `pdlblr` | ||
// instruction (DDC is used as it contains the address where the capability | ||
// is stored in this particular example) | ||
mrs c1, DDC | ||
gclim x1, c1 | ||
sub x1, x1, #16 | ||
ldr c1, [x1] | ||
ldpblr c29, [c1] | ||
|
||
ldr clr, [sp], #16 | ||
|
||
ret clr | ||
comp_f_fn_end: | ||
|
||
/* The function in this compartment just writes to some memory within its | ||
* bounds, to ensure it is properly called. | ||
*/ | ||
.type comp_g_fn, "function" | ||
comp_g_fn: | ||
mrs c10, DDC | ||
mov x11, 42 | ||
str x11, [x10, #4000] | ||
|
||
ret clr | ||
comp_g_fn_end: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.