Skip to content

Commit

Permalink
c18n: Do not attempt to get trusted stack when c18n is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgao committed Apr 19, 2024
1 parent 093618a commit c0da4f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
9 changes: 9 additions & 0 deletions libexec/rtld-elf/aarch64/rtld_c18n_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#include "rtld_c18n_machdep.h"
#undef IN_ASM

ENTRY(_rtld_unw_getcontext_epilogue)
/*
* FIXME: llvm-libunwind specific ABI. This should be better specified.
*/
mov c2, csp
str c2, [c1]
RETURN
END(_rtld_unw_getcontext_epilogue)

ENTRY(_rtld_unw_setcontext_epilogue)
/*
* FIXME: llvm-libunwind specific ABI. This should be better specified.
Expand Down
22 changes: 15 additions & 7 deletions libexec/rtld-elf/rtld_c18n.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,13 @@ resolve_untrusted_stk_impl(stk_table_index index)
/*
* Stack unwinding
*/
/*
* Assembly functions that are tail-called when compartmentalisation is
* disabled.
*/
uintptr_t _rtld_unw_getcontext_epilogue(uintptr_t, void **);
struct jmp_args _rtld_unw_setcontext_epilogue(struct jmp_args, void *, void **);

static void *
unwind_cursor()
{
Expand Down Expand Up @@ -859,13 +866,21 @@ _rtld_setjmp(uintptr_t ret, void **buf)
uintptr_t
_rtld_unw_getcontext(uintptr_t ret, void **buf)
{
if (!C18N_ENABLED) {
__attribute__((musttail))
return (_rtld_unw_getcontext_epilogue(ret, buf));
}
*buf = cheri_seal(unwind_cursor(), sealer_unwbuf);
return (ret);
}

uintptr_t
_rtld_unw_getcontext_unsealed(uintptr_t ret, void **buf)
{
if (!C18N_ENABLED) {
__attribute__((musttail))
return (_rtld_unw_getcontext_epilogue(ret, buf));
}
*buf = unwind_cursor();
return (ret);
}
Expand Down Expand Up @@ -973,13 +988,6 @@ _rtld_longjmp(struct jmp_args ret, void *rcsp, void **buf)
return (unwind_stack(ret, rcsp, cheri_unseal(*buf, sealer_jmpbuf)));
}

/*
* An assembly function that is called to complete the unwind when
* compartmentalisation is disabled. The call must be a tail-call so that
* registers are not clobbered.
*/
struct jmp_args _rtld_unw_setcontext_epilogue(struct jmp_args, void *, void **);

struct jmp_args
_rtld_unw_setcontext(struct jmp_args ret, void *rcsp, void **buf)
{
Expand Down

0 comments on commit c0da4f1

Please sign in to comment.