Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix switch_compartment PCC bounds #56

Merged
merged 1 commit into from
Jan 17, 2022
Merged

Conversation

0152la
Copy link
Contributor

@0152la 0152la commented Jan 14, 2022

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.

Also some comment inconsistency fixes.

@0152la
Copy link
Contributor Author

0152la commented Jan 14, 2022

I'm also working on updating the negative example, as of course it's not as easy as copy pasting, and needs to be debugged...

@ltratt
Copy link
Collaborator

ltratt commented Jan 14, 2022

This looks good to me. @jacobbramley are you able to quickly take a peek?

@0152la
Copy link
Contributor Author

0152la commented Jan 14, 2022

Also a way of maybe splitting the assembly code in multiple files, so there is less duplication, and less stuff I have to change when I modify core parts. I'll have to play with #includes and makefiles and see.

@0152la 0152la marked this pull request as draft January 14, 2022 11:57
@@ -63,6 +63,7 @@ extern void comp_f_fn();
extern void comp_g_fn();
extern void *comp_f_fn_end;
extern void *comp_g_fn_end;
extern void *switch_compartment_end;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types of these _end variables aren't really correct. These are the types that they point to, which here is just a zero-sized part of the code (.text section). There isn't a good, correct choice, but perhaps representing them as a function pointer is best for this example. Just don't call them; that won't end well. (It shouldn't be possible if the compartment is set up correctly.)

I think this caused your earlier question about taking the address. It's surprising to take the address of a global void* but not so much to take the address of a function, especially given the arithmetic where this is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking address values are usually represented as void*, but if you think functions are better, I have nothing against that. Amended in 1b46b9c.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't addresses, though. If anything, they're voids. The label points to the value (which has zero size) and you take the address (&switch_compartment_end) to do some pointer arithmetic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll maybe have to read more on this, but I believe the current incarnation should be sufficient at the time, until we find a "proper" way (if one such way exists). Or maybe improve how we calculate function sizes in #54 .

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobbramley Are you suggesting using something other than void * e.g. char * or u8*?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @jacobbramley is suggesting s/void */void/.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see; I was confused by the small detail. I think what we want is in 420bddc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also need to s/extern void *comp_f_fn_end();/extern void comp_f_fn_end();/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I must have been looking at the wrong thing -- sorry!

@@ -53,14 +58,11 @@ switch_compartment:
ldr x11, [x29, x11]
mov sp, x11

// Derive a new clr to restore PCC, and store it.
cvtp c11, lr

// Install compartment DDC
msr DDC, c1

// Save old DDC (c2), old SP (x12), old LR (c11) on stack
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment (c11) is now out of date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ca60bd.

@0152la 0152la marked this pull request as ready for review January 14, 2022 14:00
@0152la
Copy link
Contributor Author

0152la commented Jan 14, 2022

Updated negative example, split files to make things clearer (now the delta between negative and positive example should be clearer in a tree view), and implemented comments.

@ltratt
Copy link
Collaborator

ltratt commented Jan 17, 2022

Please squash.

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.
@0152la
Copy link
Contributor Author

0152la commented Jan 17, 2022

Squashed.

@ltratt
Copy link
Collaborator

ltratt commented Jan 17, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 17, 2022

Build succeeded:

@bors bors bot merged commit 58247cc into capablevms:master Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants