Reject .so files using ELF TLS.

Bug: http://b/74361956
Test: ran tests

(cherry picked from commit 9724e93c19)

Change-Id: I287c926951c337aacd2246940a1e6474e4c661e1
This commit is contained in:
Elliott Hughes 2018-03-23 18:46:07 -07:00
parent 1142f7e70d
commit 45a93c13bf
5 changed files with 48 additions and 0 deletions

View file

@ -260,6 +260,8 @@ typedef Elf64_Xword Elf64_Relr;
#define DT_ANDROID_RELASZ (DT_LOOS + 5)
#define DT_GNU_HASH 0x6ffffef5
#define DT_TLSDESC_PLT 0x6ffffef6
#define DT_TLSDESC_GOT 0x6ffffef7
/* http://www.sco.com/developers/gabi/latest/ch4.eheader.html */
#define EI_ABIVERSION 8

View file

@ -2784,6 +2784,11 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
}
}
#endif
if (ELF_ST_TYPE(s->st_info) == STT_TLS) {
DL_ERR("unsupported ELF TLS symbol \"%s\" referenced by \"%s\"",
sym_name, get_realpath());
return false;
}
sym_addr = lsi->resolve_symbol_address(s);
#if !defined(__LP64__)
if (protect_segments) {
@ -3437,6 +3442,11 @@ bool soinfo::prelink_image() {
default:
if (!relocating_linker) {
if (d->d_tag == DT_TLSDESC_GOT || d->d_tag == DT_TLSDESC_PLT) {
DL_ERR("unsupported ELF TLS DT entry in \"%s\"", get_realpath());
return false;
}
const char* tag_name;
if (d->d_tag == DT_RPATH) {
tag_name = "DT_RPATH";

View file

@ -1080,6 +1080,13 @@ TEST(dlfcn, dlopen_library_with_only_sysv_hash) {
ASSERT_SUBSTR("libsysv-hash-table-library.so", dlinfo.dli_fname);
}
TEST(dlfcn, dlopen_library_with_ELF_TLS) {
dlerror(); // Clear any pending errors.
void* handle = dlopen("libelf-tls-library.so", RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
ASSERT_SUBSTR("unsupported ELF TLS", dlerror());
}
TEST(dlfcn, dlopen_bad_flags) {
dlerror(); // Clear any pending errors.
void* handle;

View file

@ -39,6 +39,16 @@ cc_defaults {
},
}
// -----------------------------------------------------------------------------
// Library to test ELF TLS
// -----------------------------------------------------------------------------
cc_test_library {
name: "libelf-tls-library",
defaults: ["bionic_testlib_defaults"],
srcs: ["elf_tls_test_library.cpp"],
cflags: ["-fno-emulated-tls"],
}
// -----------------------------------------------------------------------------
// Library to test gnu-styled hash
// -----------------------------------------------------------------------------

View file

@ -0,0 +1,19 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
thread_local int elf_tls_variable;
extern "C" int* get() { return &elf_tls_variable; }