Merge "linker: disallow W + E PT_LOAD segments"

am: e8087022c1

Change-Id: I1732f395e90b4589720b3be89084ea1bd287c18d
This commit is contained in:
Dimitry Ivanov 2016-08-12 17:59:38 +00:00 committed by android-build-merger
commit 3c2f0a2c39
7 changed files with 42 additions and 1 deletions

View file

@ -604,9 +604,16 @@ bool ElfReader::LoadSegments() {
}
if (file_length != 0) {
int prot = PFLAGS_TO_PROT(phdr->p_flags);
// W + E PT_LOAD segments are not allowed.
if ((prot & (PROT_EXEC | PROT_WRITE)) == (PROT_EXEC | PROT_WRITE)) {
DL_ERR_AND_LOG("\"%s\": W + E load segments are not allowed", name_.c_str());
return false;
}
void* seg_addr = mmap64(reinterpret_cast<void*>(seg_page_start),
file_length,
PFLAGS_TO_PROT(phdr->p_flags),
prot,
MAP_FIXED|MAP_PRIVATE,
fd_,
file_offset_ + file_page_start);

View file

@ -16,6 +16,20 @@
LOCAL_PATH := $(call my-dir)
# Move prebuilt test elf-files to $(TARGET_OUT_NATIVE_TESTS)
include $(CLEAR_VARS)
LOCAL_MULTILIB := both
LOCAL_MODULE := libtest_invalid-rw_load_segment.so
LOCAL_MODULE_PATH_32 := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_NATIVE_TESTS)/prebuilt-elf-files
LOCAL_MODULE_PATH_64 := $(TARGET_OUT_DATA_NATIVE_TESTS)/prebuilt-elf-files
LOCAL_MODULE_CLASS := SHARED_LIBRARY
LOCAL_SRC_FILES_arm := prebuilt-elf-files/arm/$(LOCAL_MODULE)
LOCAL_SRC_FILES_arm64 := prebuilt-elf-files/arm64/$(LOCAL_MODULE)
LOCAL_SRC_FILES_x86 := prebuilt-elf-files/x86/$(LOCAL_MODULE)
LOCAL_SRC_FILES_x86_64 := prebuilt-elf-files/x86_64/$(LOCAL_MODULE)
include $(BUILD_PREBUILT)
ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
build_host := true
else

View file

@ -1142,3 +1142,23 @@ TEST(dlfcn, dt_runpath_absolute_path) {
dlclose(handle);
}
// Bionic specific tests
#if defined(__BIONIC__)
#if defined(__LP64__)
#define NATIVE_TESTS_PATH "/nativetest64"
#else
#define NATIVE_TESTS_PATH "/nativetest"
#endif
#define PREBUILT_ELF_PATH NATIVE_TESTS_PATH "/prebuilt-elf-files"
TEST(dlfcn, dlopen_invalid_rw_load_segment) {
std::string libpath = std::string(getenv("ANDROID_DATA")) + PREBUILT_ELF_PATH + "/libtest_invalid-rw_load_segment.so";
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\": W + E load segments are not allowed";
ASSERT_STREQ(expected_dlerror.c_str(), dlerror());
}
#endif