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

Bug fix #34

Merged
merged 1 commit into from
Jul 22, 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
1 change: 1 addition & 0 deletions include/compartment.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct LibDependencySymbol
void *sym_offset;
unsigned short sym_type;
unsigned short sym_bind;
uint16_t sym_shndx;
};

/* Struct representing the result of searching for a library symbol in a
Expand Down
10 changes: 4 additions & 6 deletions src/compartment.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ parse_lib_symtb(Elf64_Shdr *symtb_shdr, Elf64_Ehdr *lib_ehdr, int lib_fd,
strcpy(ld_syms[actual_syms].sym_name, sym_name);
ld_syms[actual_syms].sym_type = ELF64_ST_TYPE(curr_sym.st_info);
ld_syms[actual_syms].sym_bind = ELF64_ST_BIND(curr_sym.st_info);
ld_syms[actual_syms].sym_shndx = curr_sym.st_shndx;
actual_syms += 1;
}
ld_syms
Expand Down Expand Up @@ -1080,18 +1081,15 @@ find_lib_dep_sym_in_lib(const char *to_find, struct Compartment *comp_to_search,
// Ignore `LOCAL` bind symbols - they cannot be relocated against
bool cond = curr_sym.sym_bind != STB_LOCAL;

// Check symbol is indeed local, not another external reference
cond = cond && curr_sym.sym_shndx != 0;

// Check symbol name matches
cond = cond && !strcmp(to_find, curr_sym.sym_name);

// Check symbol type matches
cond = cond && curr_sym.sym_type == sym_type;

// Symbols cannot have 0-offset values (except if they are a TLS symbol)
if (sym_type != STT_TLS)
{
cond = cond && curr_sym.sym_offset != 0;
}

// If all conditions pass, we found a valid symbol to relocate against
if (cond)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ set(tests
"simple_syscall_write"
"simple_thrloc_var"
"simple_time"
#"simple_toupper"
"simple_toupper"
"simple_va_args"
"tls_check"

Expand Down