Skip to content

Commit

Permalink
Map dynamic library globals to root set on CHERI
Browse files Browse the repository at this point in the history
(a cherry-pick of commit 61c5a8a partly from capablevms/bdwgc)

Issue #627 (bdwgc).

Without `DYNAMIC_LOADING` being defined, libgc only marks global
variables in the compiled executable.  Variables in the `.data` and
`.bss` sections of dynamically linked libraries are ignored in this
scenario.

The current commit adds a valid capability with required bounds to
scan global global variables in additional dynamically linked libraries.

* dyn_load.c [DYNAMIC_LOADING && !ANY_MSWIN && (DGUX || HURD || NACL
|| SCO_ELF || (ANY_BSD || LINUX) && __ELF__) && !USE_PROC_FOR_LIBRARIES
&& HAVE_DL_ITERATE_PHDR && CHERI_PURECAP]
(GC_register_dynlib_callback): Align `my_start` up; align `my_end`
down; call `SPANNING_CAPABILITY()` and `cheri_bounds_set()`.
  • Loading branch information
Dejice Jacob authored and ivmai committed Nov 11, 2024
1 parent 973f27c commit 3b1ac88
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dyn_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,18 @@ GC_register_dynlib_callback(struct dl_phdr_info *info, size_t size, void *ptr)

my_start = MAKE_CPTR(p->p_vaddr) + info->dlpi_addr;
my_end = my_start + p->p_memsz;
# ifdef CHERI_PURECAP
my_start = PTR_ALIGN_UP(my_start, sizeof(ptr_t));
my_end = PTR_ALIGN_DOWN(my_end, sizeof(ptr_t));
if (!SPANNING_CAPABILITY(info->dlpi_addr, ADDR(my_start), ADDR(my_end)))
continue;
my_start = cheri_bounds_set(my_start, (word)(my_end - my_start));
# endif

if (callback != 0 && !callback(info->dlpi_name, my_start, p->p_memsz))
continue;
# ifdef PT_GNU_RELRO
# if CPP_PTRSZ >= 64
# if CPP_PTRSZ >= 64 && !defined(CHERI_PURECAP)
/* TODO: GC_push_all eventually does the correct */
/* rounding to the next multiple of ALIGNMENT, so, most */
/* probably, we should remove the corresponding assertion */
Expand Down

0 comments on commit 3b1ac88

Please sign in to comment.