Skip to content
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

c18n: Allow GDB to access compartment data #2087

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libexec/rtld-elf/Symbol-c18n.map
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FBSDprivate_1.0 {
r_debug_comparts_state;
_compart_size;
_rtld_thread_start_init;
_rtld_thread_start;
_rtld_thr_exit;
Expand Down
27 changes: 25 additions & 2 deletions libexec/rtld-elf/rtld_c18n.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,25 @@
bool restrict_imports;
};

extern int _compart_size;

Check failure on line 155 in libexec/rtld-elf/rtld_c18n.c

View workflow job for this annotation

GitHub Actions / Style Checker

externs should be avoided in .c files
int _compart_size = sizeof(struct compart);

extern struct r_debug r_debug;

Check failure on line 158 in libexec/rtld-elf/rtld_c18n.c

View workflow job for this annotation

GitHub Actions / Style Checker

externs should be avoided in .c files

void

Check failure on line 160 in libexec/rtld-elf/rtld_c18n.c

View workflow job for this annotation

GitHub Actions / Style Checker

externs should be avoided in .c files
r_debug_comparts_state(struct r_debug *, struct compart *);
void
r_debug_comparts_state(struct r_debug *rd __unused, struct compart *m __unused)
{
/*
* See r_debug_state().
*/
__compiler_membar();
}

#define GDB_COMPARTS_STATE(s,m) \

Check failure on line 171 in libexec/rtld-elf/rtld_c18n.c

View workflow job for this annotation

GitHub Actions / Style Checker

space required after that ',' (ctx:VxV)
r_debug.r_comparts_state = s; r_debug_comparts_state(&r_debug, m);

/*
* A pseudo-compartment that encompasses all compartments.
*/
Expand Down Expand Up @@ -183,7 +202,7 @@
data = realloc(comparts.data, sizeof(*data) * capacity);
if (data == NULL)
rtld_fatal("realloc failed");
comparts.data = data;
comparts.data = r_debug.r_comparts = data;
comparts.capacity = capacity;
}

Expand All @@ -198,10 +217,13 @@
if (comparts.size == comparts.capacity)
comparts_data_expand(comparts.capacity * 2);

GDB_COMPARTS_STATE(RCT_ADD, NULL);
com = &comparts.data[comparts.size++];
*com = (struct compart) {
.name = name
};
r_debug.r_comparts_size = comparts.size;
GDB_COMPARTS_STATE(RCT_CONSISTENT, com);

return (com);
}
Expand Down Expand Up @@ -1496,7 +1518,8 @@
*/
data = xmalloc(sizeof(*data) * comparts.capacity);
memcpy(data, comparts.data, sizeof(*comparts.data) * comparts.capacity);
comparts.data = data;
comparts.data = r_debug.r_comparts = data;
r_debug.r_comparts_size = comparts.size;

/*
* Load the default policy
Expand Down
8 changes: 8 additions & 0 deletions sys/sys/link_elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
RT_DELETE /* removing a shared library */
} r_state;
void *r_ldbase; /* Base address of rtld */
#if defined(IN_RTLD) && defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)

Check warning on line 77 in sys/sys/link_elf.h

View workflow job for this annotation

GitHub Actions / Style Checker

line over 80 characters
enum {
RCT_CONSISTENT, /* vector is stable */
RCT_ADD, /* adding a compartment */
} r_comparts_state;
int r_comparts_size;
void *r_comparts; /* struct compart [] */
#endif
};

#define R_DEBUG_VERSION 1
Expand Down
Loading