-
Notifications
You must be signed in to change notification settings - Fork 61
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
Userspace runtime loader support for sub-library c18n #2267
Open
bsdjhb
wants to merge
13
commits into
CTSRD-CHERI:dev
Choose a base branch
from
bsdjhb:sublib_c18n
base: dev
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.
+939
−450
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a0b392e
rtld: Remove code to track start and end offsets of text and rodata
bsdjhb e91535e
rtld: Support multiple PT_GNU_RELRO program headers
bsdjhb 7d6a2fd
rtld: Support multiple PLTs
bsdjhb 716960b
elf: Add definition of PT_CHERI_BOUNDS program header type
bsdjhb 1a3a972
elftoolchain: Add support for PT_CHERI_BOUNDS
bsdjhb 706b550
rtld: Support narrower PCC bounds via PT_CHERI_BOUNDS
bsdjhb a10092d
fixup! rtld: Support narrower PCC bounds via PT_CHERI_BOUNDS
bsdjhb a0e96d5
rtld: Require PT_CHERI_BOUNDS to be exact
bsdjhb f6c3abd
elf: Add definitions for PT_COMPARTMENT and DT_C18NSTRTAB*
bsdjhb d607049
elftoolchain: Add support for PT_COMPARTMENT and DT_C18NSTRTAB*
bsdjhb c6bda98
rtld: Add compartments for sub-object compartments described by PT_CO…
bsdjhb 51db786
rtld_c18n: Fix copy/paste typo in _rtld_safebox_code error messages
bsdjhb f179912
rtld: Use compartment IDs from sub-object compartments for policy enf…
bsdjhb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
|
@@ -546,8 +546,10 @@ evaluate_rules(compart_id_t caller, compart_id_t callee, const char *sym) | |
} | ||
|
||
static bool | ||
tramp_should_include(const Obj_Entry *reqobj, const struct tramp_data *data) | ||
tramp_should_include(const Obj_Entry *reqobj, compart_id_t caller, | ||
const struct tramp_data *data) | ||
{ | ||
compart_id_t callee; | ||
const char *sym; | ||
|
||
if (data->def == NULL) | ||
|
@@ -561,23 +563,28 @@ tramp_should_include(const Obj_Entry *reqobj, const struct tramp_data *data) | |
if (string_base_search(&uni_compart.trusts, sym) != -1) | ||
return (false); | ||
|
||
if (reqobj == NULL) | ||
if (reqobj == NULL) { | ||
assert(caller == RTLD_COMPART_ID); | ||
return (true); | ||
} | ||
|
||
if (reqobj->compart_id == data->defobj->compart_id) | ||
callee = compart_id_for_address(data->defobj, | ||
(ptraddr_t)data->defobj->relocbase + data->def->st_value); | ||
|
||
if (caller == callee) | ||
return (false); | ||
|
||
if (string_base_search(&comparts.data[reqobj->compart_id].trusts, sym) | ||
if (string_base_search(&comparts.data[caller].trusts, sym) | ||
!= -1) | ||
return (false); | ||
|
||
if (evaluate_rules(reqobj->compart_id, data->defobj->compart_id, sym)) | ||
if (evaluate_rules(caller, callee, sym)) | ||
return (true); | ||
|
||
rtld_fatal("c18n: Policy violation: %s is not allowed to access symbol " | ||
"%s defined by %s", | ||
comparts.data[reqobj->compart_id].name, sym, | ||
comparts.data[data->defobj->compart_id].name); | ||
comparts.data[caller].name, sym, | ||
comparts.data[callee].name); | ||
} | ||
|
||
/* | ||
|
@@ -1375,7 +1382,8 @@ tramp_make_entry(const struct tramp_header *header) | |
} | ||
|
||
void * | ||
tramp_intern(const Obj_Entry *reqobj, const struct tramp_data *data) | ||
tramp_intern(const Obj_Entry *reqobj, compart_id_t caller, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just pass the Plt_Entry instead of the Obj_Entry and use reqplt->compart_id everywhere? |
||
const struct tramp_data *data) | ||
{ | ||
RtldLockState lockstate; | ||
const struct tramp_header *header; | ||
|
@@ -1411,7 +1419,7 @@ tramp_intern(const Obj_Entry *reqobj, const struct tramp_data *data) | |
data->defobj->dynsymcount); | ||
assert(func_sig_legal(data->sig)); | ||
|
||
if (!tramp_should_include(reqobj, data)) | ||
if (!tramp_should_include(reqobj, caller, data)) | ||
return (data->target); | ||
|
||
start: | ||
|
@@ -1720,7 +1728,8 @@ c18n_init2(Obj_Entry *obj_rtld) | |
* XXX: Manually wrap _rtld_unw_setcontext_impl in a trampoline for now | ||
* because it is called via a function pointer. | ||
*/ | ||
_rtld_unw_setcontext_ptr = tramp_intern(NULL, &(struct tramp_data) { | ||
_rtld_unw_setcontext_ptr = tramp_intern(NULL, RTLD_COMPART_ID, | ||
&(struct tramp_data) { | ||
.target = &_rtld_unw_setcontext_impl, | ||
.defobj = obj_rtld, | ||
.sig = (struct func_sig) { | ||
|
@@ -1744,7 +1753,8 @@ _rtld_thread_start_init(void (*p)(struct pthread *)) | |
{ | ||
assert((cheri_getperm(p) & CHERI_PERM_EXECUTIVE) == 0); | ||
assert(thr_thread_start == NULL); | ||
thr_thread_start = tramp_intern(NULL, &(struct tramp_data) { | ||
thr_thread_start = tramp_intern(NULL, RTLD_COMPART_ID, | ||
&(struct tramp_data) { | ||
.target = p, | ||
.defobj = obj_from_addr(p), | ||
.sig = (struct func_sig) { | ||
|
@@ -1888,7 +1898,8 @@ _rtld_sighandler_init(__siginfohandler_t *handler) | |
{ | ||
assert((cheri_getperm(handler) & CHERI_PERM_EXECUTIVE) == 0); | ||
assert(signal_dispatcher == sigdispatch); | ||
signal_dispatcher = tramp_intern(NULL, &(struct tramp_data) { | ||
signal_dispatcher = tramp_intern(NULL, RTLD_COMPART_ID, | ||
&(struct tramp_data) { | ||
.target = handler, | ||
.defobj = obj_from_addr(handler), | ||
.sig = (struct func_sig) { | ||
|
@@ -2126,7 +2137,8 @@ _rtld_siginvoke(int sig, siginfo_t *info, ucontext_t *ucp, | |
header = tramp_reflect(sigfunc); | ||
if (header == NULL) { | ||
defobj = obj_from_addr(sigfunc); | ||
sigfunc = tramp_intern(NULL, &(struct tramp_data) { | ||
sigfunc = tramp_intern(NULL, RTLD_COMPART_ID, | ||
&(struct tramp_data) { | ||
.target = sigfunc, | ||
.defobj = defobj | ||
}); | ||
|
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a TODO that in future this should be simplified to cheri_setbounds_exact + cheri_gettag, once we can assume tag clearing on RISC-V (which is almost there...)?