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

Label /proc/pid/maps entries in permissive mode logs #421

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
25 changes: 23 additions & 2 deletions runtime/libia2/include/permissive_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void permissive_mode_handler(int sig, siginfo_t *info, void *ctxt) {
static bool exiting IA2_SHARED_DATA = false;

// Process-specific name for log file
static char log_name[256] IA2_SHARED_DATA = {0};
char log_name[256] IA2_SHARED_DATA = {0};

int elfaddr(const void *addr, Dl_info *info) {
static struct f {
Expand Down Expand Up @@ -458,6 +458,7 @@ __attribute__((constructor)) void permissive_mode_init(void) {
install_permissive_mode_handler();
}

extern char *ia2_stacks[16];
/*
* Constructor to wait for the logging thread to finish and log the memory map.
* If a process forks and execve's this function will not be called.
Expand All @@ -471,7 +472,27 @@ __attribute((destructor)) void wait_logging_thread(void) {
assert(maps);
char tmp[256] = {0};
while (fgets(tmp, sizeof(tmp), maps)) {
fprintf(log, "%s", tmp);
bool identified = false;
uintptr_t start, end, offset;
int name_pos;
char prot[5] = {0};
sscanf(tmp, "%lx-%lx %4c %lx %*lx:%*lx %*lu %n", &start, &end, prot, &offset, &name_pos);
fprintf(log, "%08lx-%08lx %s %08lx ", start, end, prot, offset);
if (name_pos != strlen(tmp)) {
fprintf(log, "%s", tmp + name_pos);
identified = true;
} else {
for (int i = 0; i < 16; i++) {
if (start == ia2_stacks[i]) {
fprintf(log, "[stack:tid ?:compartment %d]\n", i);
identified = true;
break;
}
}
}
if (!identified) {
fprintf(log, "TODO: identify this segment\n");
}
memset(tmp, 0, sizeof(tmp));
}
fclose(log);
Expand Down
2 changes: 2 additions & 0 deletions runtime/libia2/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
extern __thread void *ia2_stackptr_0[PAGE_SIZE / sizeof(void *)]
__attribute__((aligned(4096)));

char *ia2_stacks[16] = {0};
/* Allocate a fixed-size stack and protect it with the ith pkey. */
/* Returns the top of the stack, not the base address of the allocation. */
char *allocate_stack(int i) {
Expand All @@ -26,6 +27,7 @@ char *allocate_stack(int i) {
exit(-1);
}
}
ia2_stacks[i] = stack;
/* Each stack frame start + 8 is initially 16-byte aligned. */
return stack + STACK_SIZE - 8;
}
Expand Down
Loading