forked from AbsInt/CompCert
-
Notifications
You must be signed in to change notification settings - Fork 3
Changes to the compartment model #2
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
Open
jeremyThibault
wants to merge
87
commits into
ccs-blame
Choose a base branch
from
cross-external-call-removal
base: ccs-blame
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or 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
…rom external functions
…yntax, Events, and Memory
…d Allocation pass
…ck-translation after removal of compartments
Collaborator
Author
|
It would be great if someone was willing to look at it quickly and check that everything makes sense! |
Co-authored-by: Arthur Azevedo de Amorim <arthur.aa@gmail.com>
…-backtranslation' into cross-external-call-removal
…ls (do not free non freeable blocks)
…-backtranslation' into ccs-submission
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal of this PR is to restore the ability to compile programs all the way from C to RISC-V assembly, which had been broken since the removal of the default compartment. Additionally, this PR removes the notion of "cross-compartment external call" entirely. This means that after merging this, every call to an external function is treated as a call within the calling compartment.
The PR achieve these goals in the following manner:
The new compartment model
We adopt a new generic lattice-based compartment model, and we instantiate it appropriately. The
COMPTYPEmodule type incommon/AST.vgives the interface of our compartment model:and it is instantiated in the
COMPmodule incommon/AST.v. We use the following definitions for thecompartmenttype and theflowstoproperty:The intuition behind the lattice is the following: the higher in the lattice, the more privileged the compartment is. Given two compartments
cpandcp', ifcp ⊆ cp', thencp'has access to at least everythingcphas access to. This is done by replacing most of the checks of compartment equality (in memory operations or within-compartment calls, for instance) by checks of compartment flow.Compiler passes usually preserve compartments across languages. (i.e. they use compartment equality, not flow).
Changes to external calls
The changes to the semantics of all level w.r.t. external calls is best exemplified with Cminor.
First, callstates now record an additional element, the calling compartment:
This is because the calling compartment is not necessarily the one recorded in the continuation (for instance, in the case of tailcalls)
The relevant rules for steps of execution:
| step_call: forall f optid sig a bl k sp e m vf vargs fd t, eval_expr sp e m (comp_of f) a vf -> eval_exprlist sp e m (comp_of f) bl vargs -> Genv.find_funct ge vf = Some fd -> funsig fd = sig -> (* Check that the call to the function pointer is allowed *) forall (ALLOWED: Genv.allowed_call ge (comp_of f) vf), forall (NO_CROSS_PTR: Genv.type_of_call (comp_of f) (comp_of fd) = Genv.CrossCompartmentCall -> Forall not_ptr vargs), forall (EV: call_trace ge (comp_of f) (comp_of fd) vf vargs (sig_args sig) t), step (State f (Scall optid sig a bl) k sp e m) t (Callstate fd vargs (Kcall optid f sp e k) m (comp_of f)) | step_tailcall: forall f sig a bl k sp e m vf vargs fd m', eval_expr (Vptr sp Ptrofs.zero) e m (comp_of f) a vf -> eval_exprlist (Vptr sp Ptrofs.zero) e m (comp_of f) bl vargs -> Genv.find_funct ge vf = Some fd -> funsig fd = sig -> forall (COMP: comp_of fd = comp_of f), forall (SIG: sig_res (fn_sig f) = sig_res sig), Mem.free m sp 0 f.(fn_stackspace) (comp_of f) = Some m' -> step (State f (Stailcall sig a bl) k (Vptr sp Ptrofs.zero) e m) E0 (Callstate fd vargs (call_cont k) m' (comp_of f)) | step_builtin: forall f optid ef bl k sp e m vargs t vres m', eval_exprlist sp e m (comp_of f) bl vargs -> external_call ef ge (comp_of f) vargs m t vres m' -> step (State f (Sbuiltin optid ef bl) k sp e m) t (State f Sskip k sp (set_optvar optid vres e) m') … | step_internal_function: forall f vargs k m cp m' sp e, Mem.alloc m (comp_of f) 0 f.(fn_stackspace) = (m', sp) -> set_locals f.(fn_vars) (set_params vargs f.(fn_params)) = e -> step (Callstate (Internal f) vargs k m cp) E0 (State f f.(fn_body) k (Vptr sp Ptrofs.zero) e m') | step_external_function: forall ef vargs k m cp t vres m', external_call ef ge cp vargs m t vres m' -> step (Callstate (External ef) vargs k m cp) t (Returnstate vres k m' (sig_res (ef_sig ef)) bottom)External functions have compartment
bottom, so they are always allowed. When actually executing step, they are temporarily granted the calling compartment's privilege (this is useful to state the properties of external functions).