Add test for libraries with textrels

Make sure android fails to load them.

Bug: http://b/30795430
Test: bionic-unit-tests --gtest_filter=dlfcn.dlopen_invalid*
Test: cts-tradefed run singleCommand cts --skip-preconditions -m CtsBionicTestCases
Change-Id: Id0ebdf336b2f297007479ceb1bbccf778a7ca3f2
This commit is contained in:
Dimitry Ivanov 2016-10-19 11:00:28 -07:00
parent d824421475
commit 816676e70d
15 changed files with 34 additions and 7 deletions

View file

@ -2880,7 +2880,7 @@ bool soinfo::prelink_image() {
case DT_TEXTREL:
#if defined(__LP64__)
DL_ERR("text relocations (DT_TEXTREL) found in 64-bit ELF file \"%s\"", get_realpath());
DL_ERR("\"%s\" has text relocations", get_realpath());
return false;
#else
has_text_relocations = true;
@ -2898,7 +2898,7 @@ bool soinfo::prelink_image() {
case DT_FLAGS:
if (d->d_un.d_val & DF_TEXTREL) {
#if defined(__LP64__)
DL_ERR("text relocations (DF_TEXTREL) found in 64-bit ELF file \"%s\"", get_realpath());
DL_ERR("\"%s\" has text relocations", get_realpath());
return false;
#else
has_text_relocations = true;
@ -2913,7 +2913,7 @@ bool soinfo::prelink_image() {
set_dt_flags_1(d->d_un.d_val);
if ((d->d_un.d_val & ~SUPPORTED_DT_FLAGS_1) != 0) {
DL_WARN("%s: unsupported flags DT_FLAGS_1=%p", get_realpath(), reinterpret_cast<void*>(d->d_un.d_val));
DL_WARN("\"%s\" has unsupported flags DT_FLAGS_1=%p", get_realpath(), reinterpret_cast<void*>(d->d_un.d_val));
}
break;
#if defined(__mips__)
@ -2980,7 +2980,7 @@ bool soinfo::prelink_image() {
default:
if (!relocating_linker) {
DL_WARN("%s: unused DT entry: type %p arg %p", get_realpath(),
DL_WARN("\"%s\" unused DT entry: type %p arg %p", get_realpath(),
reinterpret_cast<void*>(d->d_tag), reinterpret_cast<void*>(d->d_un.d_val));
}
break;
@ -3067,13 +3067,12 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
if (has_text_relocations) {
// Fail if app is targeting sdk version > 22
if (get_application_target_sdk_version() > 22) {
PRINT("%s: has text relocations", get_realpath());
DL_ERR("%s: has text relocations", get_realpath());
DL_ERR_AND_LOG("\"%s\" has text relocations", get_realpath());
return false;
}
// Make segments writable to allow text relocations to work properly. We will later call
// phdr_table_protect_segments() after all of them are applied.
DL_WARN("%s has text relocations. This is wasting memory and prevents "
DL_WARN("\"%s\" has text relocations. This is wasting memory and prevents "
"security hardening. Please fix.", get_realpath());
add_dlwarning(get_realpath(), "text relocations");
if (phdr_table_unprotect_segments(phdr, phnum, load_bias) < 0) {

View file

@ -41,6 +41,12 @@ include $(LOCAL_PATH)/Android.build.prebuilt.mk
bionic_tests_module := libtest_invalid-zero_shdr_table_content.so
include $(LOCAL_PATH)/Android.build.prebuilt.mk
bionic_tests_module := libtest_invalid-textrels.so
include $(LOCAL_PATH)/Android.build.prebuilt.mk
bionic_tests_module := libtest_invalid-textrels2.so
include $(LOCAL_PATH)/Android.build.prebuilt.mk
ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
build_host := true
else

View file

@ -1227,4 +1227,26 @@ TEST(dlfcn, dlopen_invalid_zero_shdr_table_content) {
ASSERT_SUBSTR(expected_dlerror.c_str(), dlerror());
}
TEST(dlfcn, dlopen_invalid_textrels) {
const std::string libpath = g_testlib_root +
"/" + kPrebuiltElfDir +
"/libtest_invalid-textrels.so";
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has text relocations";
ASSERT_SUBSTR(expected_dlerror.c_str(), dlerror());
}
TEST(dlfcn, dlopen_invalid_textrels2) {
const std::string libpath = g_testlib_root +
"/" + kPrebuiltElfDir +
"/libtest_invalid-textrels2.so";
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has text relocations";
ASSERT_SUBSTR(expected_dlerror.c_str(), dlerror());
}
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.