diff --git a/include/compartment.h b/include/compartment.h index 7af4dcc..bf4976d 100644 --- a/include/compartment.h +++ b/include/compartment.h @@ -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 diff --git a/src/compartment.c b/src/compartment.c index 5672a28..ef6e27d 100644 --- a/src/compartment.c +++ b/src/compartment.c @@ -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 @@ -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) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8fd7611..6489588 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -177,7 +177,7 @@ set(tests "simple_syscall_write" "simple_thrloc_var" "simple_time" - #"simple_toupper" + "simple_toupper" "simple_va_args" "tls_check"