capablevms / CHERI-ELF-comp

Other
4 stars 1 forks source link

First draft #1

Closed 0152la closed 2 years ago

0152la commented 2 years ago

Includes work in progress of minimal required ELF loader, with basic memory management, and compartmentalization manager.

The main components are as follows:

In addition, a number of tests are provided to assess functionality. The most current ones are lua_simple.c, which performs some basic lua operations, and hello_world_comps.c, which creates a compartment from a compiled variant of the aforementioned executable and attempts to execute it.

As this is a work-in-progress, things are broken, and very in flux.

0152la commented 2 years ago

I'll leave this as a draft PR, as buildbot/bors stuff still needs to be done. Otherwise, questions/comments on the code very welcome.

ltratt commented 2 years ago

As I'm sure you expected, I don't pretend to have fully understood this yet! But I get many of the major ideas, and overall it looks like a really promising start!

A question that immediately sprung to mind: what would it mean to create a compartment "mid stream" i.e. after the program has started running? In other words, imagine the process has been running for a while, and you want to create a new DDC compartment: would that be the rough equivalent of fork or would you definitely need to go through the full ELF initialisation stuff and so on? [I'm not expecting a solution for this in this PR: but it's a question that might be worth chewing over.]

0152la commented 2 years ago

A question that immediately sprung to mind: what would it mean to create a compartment "mid stream" i.e. after the program has started running? In other words, imagine the process has been running for a while, and you want to create a new DDC compartment: would that be the rough equivalent of fork or would you definitely need to go through the full ELF initialisation stuff and so on? [I'm not expecting a solution for this in this PR: but it's a question that might be worth chewing over.]

Just to clarify some things, when you say "the process", I will understand it as being the combination of the loader and its underlying compartments (as they are all within a single process on the OS side, at least at the moment). Creating a new compartment should be a call to comp_from_elf from within the manager context. I believe "the full ELF initialisation stuff" means what's happening in this function. This needs to be done for every single new compartment (i.e., every new static binary we want to load) in the current design. It might be possible to have separate processes for each compartment, if that's what you suggest by fork, but I don't think we need that for parallelization.

ltratt commented 2 years ago

I didn't phrase my question very well -- sorry! I'm partly thinking "what happens if, after running for a while, you want to run another computation in a compartment?" I'm wondering if you can "setup" a new compartment without having to go through main every time.

0152la commented 2 years ago

You need to load the compartment once in memory, which is done via comp_from_elf. Once it's in memory, it should be possible to execute it as many times as desired, via comp_exec. I haven't gotten to the point yet where we call specific functions with specific arguments passed to them, but I see no technical reason why this wouldn't be possible. But the compartment needs to be loaded into memory a single time, and then should be able to be reused as many times as desired, until it is explicitly unloaded (which is not fully implemented yet).

ltratt commented 2 years ago

Ah, that's an interesting point -- that does sound plausible.

0152la commented 2 years ago

@jacobbramley Do you want to spare some time looking at this PR in its current state (it's draft for now as I haven't done the bors stuff required to be able to merge it), or do you prefer to wait until the code becomes more stable?

0152la commented 2 years ago

Ok, seems the comments I wrote end of last week weren't actually submitted, and were marked pending. They should be visible now. Sorry for the confusion.

ltratt commented 2 years ago

I've resolved a few of my comments: a few are still open. I'll leave you and @jacobbramley to discuss your various comments :)

0152la commented 2 years ago

bors ping

bors[bot] commented 2 years ago

pong

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build succeeded:

0152la commented 2 years ago

Alright, bors is set up. Had a temporary issue that got fixed over the weekend.

ltratt commented 2 years ago

Are you asking for rereview or .. ?

0152la commented 2 years ago

I haven't changed any of the stuff that has already been reviewed, I guess I'm asking if there any any unresolved comments that need further attention, or if either you or @jacobbramley want to take more time with this PR.

jacobbramley commented 2 years ago

I don't have anything new. There are quite a few things that are for future use or investigation, but we can wait for #2, I'm sure :-)

0152la commented 2 years ago

Ready for review @ltratt .

ltratt commented 2 years ago

I've just noticed that this PR is 49KLoC, but I remember it being ~2KLoC at some point. Is my memory faulty?

0152la commented 2 years ago

No, I needed to add lua to it for the future. Although now that I think of it, I might be able to simplify it, and just include a patch and a submodule.

ltratt commented 2 years ago

Yes, I'd really much prefer we didn't slurp in the whole Lua code if at all possible!

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build failed:

0152la commented 2 years ago

bors try

bors[bot] commented 2 years ago

try

Build succeeded:

0152la commented 2 years ago

Ready for review. Lua has been replaced with a submodule and the build system adjusted appropriately.

ltratt commented 2 years ago

Please squash.

0152la commented 2 years ago

Squashed.