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

Work around a segfault caused by x86_64 emulation on arm64. #1081

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ main(int argc, char **argv, char **env)

sys_exec(ebuf, inferior_command, argc-optind, &argv[optind], env);

return 0;
// We should not return from sys_exec unless there was an error loading the static exec.
// In this case, just start the exec without being scoped.
execve(argv[optind], &argv[optind], environ);

err:
if (ebuf) scope_free(ebuf);
exit(EXIT_FAILURE);
Expand Down
20 changes: 11 additions & 9 deletions src/sysexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,21 @@ map_segment(char *buf, Elf64_Phdr *phead)
lsize = phead->p_memsz + ((char*)phead->p_vaddr - laddr);


sysprint("%s:%d vaddr 0x%lx size 0x%lx\n",
__FUNCTION__, __LINE__, phead->p_vaddr, (size_t)phead->p_memsz);
sysprint("%s:%d vaddr 0x%lx size 0x%lx laddr %p\n",
__FUNCTION__, __LINE__, phead->p_vaddr, (size_t)phead->p_memsz, laddr);

if ((addr = scope_mmap(laddr, ROUND_UP((size_t)lsize, phead->p_align),
prot | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
-1, (off_t)NULL)) == MAP_FAILED) {
prot | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1, (off_t)NULL)) == MAP_FAILED) {
scopeLogError("ERROR: load_segment:scope_mmap");
return -1;
}

if (laddr != addr) {
scopeLogError("ERROR: load_segment:scope_mmap:laddr mismatch");
return -1;
scope_munmap(addr, ROUND_UP((size_t)lsize, phead->p_align));
michalbiesek marked this conversation as resolved.
Show resolved Hide resolved
scopeLogError("ERROR: map_segment:scope_mmap:laddr mismatch. The kernel could not map to an address that the executable requires. This executable is not 'scoped'.");
return -1;
}

load_sections(buf, (char *)phead->p_vaddr, (size_t)lsize);
Expand Down Expand Up @@ -195,7 +196,7 @@ load_elf(char *buf)

for (i = 0; i < pnum; i++) {
if (phead[i].p_type == PT_LOAD) {
map_segment(buf, &phead[i]);
if (map_segment(buf, &phead[i]) == -1) return (Elf64_Addr)NULL;
iapaddler marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -385,11 +386,12 @@ sys_exec(elf_buf_t *ebuf, const char *path, int argc, const char **argv, const c
scopeLog(CFG_LOG_DEBUG, "fd:%d sys_exec type:", ehdr->e_type);

phaddr = load_elf((char *)ebuf->buf);
if (!phaddr) return -1;

// TODO: are we loading a Go app or a glibc app?
initGoHook(ebuf);

set_go((char *)ebuf->buf, argc, argv, env, phaddr);

return 0;
return -1;
}