Skip to content

Commit

Permalink
c18n: Push dummy frame during _rtld_tlsdesc_dynamic
Browse files Browse the repository at this point in the history
The dummy frame indicates that the current compartment is RTLD. Because
_rtld_tlsdesc_dynamic may cause domain transitions (e.g., locking), a
frame that correctly identifies the current compartment as RTLD is
necessary.
dpgao committed Jul 4, 2024
1 parent b3b8d81 commit 905deea
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 0 additions & 2 deletions libexec/rtld-elf/aarch64/rtld_start.S
Original file line number Diff line number Diff line change
@@ -380,13 +380,11 @@ ENTRY(C18N_SYM(_rtld_tlsdesc_dynamic))
* get the caller's old stack top.
*/
update_stk_table c11, c10, w12
#ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
/*
* Switch to RTLD's stack.
*/
get_rtld_stk c10
set_untrusted_stk c10
#endif
/*
* Save caller's old stack top.
*/
15 changes: 14 additions & 1 deletion libexec/rtld-elf/rtld.c
Original file line number Diff line number Diff line change
@@ -5750,13 +5750,26 @@ void *
tls_get_addr_common(uintptr_t **dtvp, int index, size_t offset)
{
uintptr_t *dtv;
void *ret;

dtv = *dtvp;
/* Check dtv generation in case new modules have arrived */
if (__predict_true(dtv[0] == tls_dtv_generation &&
dtv[index + 1] != 0))
return ((void *)(dtv[index + 1] + offset));
return (tls_get_addr_slow(dtvp, index, offset, false));

#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
struct trusted_frame *tf;

if (C18N_ENABLED)
tf = push_dummy_rtld_trusted_frame(get_trusted_stk());
#endif
ret = tls_get_addr_slow(dtvp, index, offset, false);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
if (C18N_ENABLED)
tf = pop_dummy_rtld_trusted_frame(tf);
#endif
return (ret);
}

#ifdef TLS_VARIANT_I

0 comments on commit 905deea

Please sign in to comment.