Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
* Fix a bug with relocating against other external symbols
* Enable 1.33 tests (one `lua` test from the suite passing)
  • Loading branch information
0152la committed Jul 22, 2024
1 parent 12e7ab2 commit cecb762
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
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

0 comments on commit cecb762

Please sign in to comment.