提交 c2bfac38 编写于 作者: W wangjiahui

fix dlopen ld-musl-aarch64.so.1 error

Signed-off-by: Nwangjiahui <wangjiahui27@huawei.com>
上级 bfeda6a1
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "functionalext.h" #include "functionalext.h"
#define PIPE_FD 2 #define PIPE_FD 2
#define NUM_OF_BYTE 8 #define LEN_OF_POINTER 8
#define BASE_NUM 11 #define BASE_NUM 11
#define TEST_COUNTS 32 #define TEST_COUNTS 32
...@@ -561,6 +561,42 @@ static void dlclose_randomization_0100(void) ...@@ -561,6 +561,42 @@ static void dlclose_randomization_0100(void)
EXPECT_EQ(__FUNCTION__, -1, ret); EXPECT_EQ(__FUNCTION__, -1, ret);
} }
/**
* @tc.name : dlopen_randomization_0800
* @tc.desc : Call the dlopen interface to load libc.so
* @tc.level : Level1
*/
static void dlopen_randomization_0800(void)
{
if (sizeof(void *) == LEN_OF_POINTER) {
system("cp /system/lib64/libc.so .");
} else {
system("cp /system/lib/libc.so .");
}
void *handle = dlopen("./libc.so", RTLD_NOW);
EXPECT_PTRNE(__FUNCTION__, handle, 0);
system("rm ./libc.so");
}
/**
* @tc.name : dlopen_randomization_0900
* @tc.desc : Call the dlopen interface to load ld.so
* @tc.level : Level1
*/
static void dlopen_randomization_0900(void)
{
void *handle = NULL;
if (sizeof(void *) == LEN_OF_POINTER) {
system("cp /system/lib/ld-musl-aarch64.so.1 .");
handle = dlopen("./ld-musl-aarch64.so.1", RTLD_NOW);
system("rm ld-musl-aarch64.so.1");
} else {
system("cp /system/lib/ld-musl-arm.so.1 .");
handle = dlopen("./ld-musl-arm.so.1", RTLD_NOW);
system("rm ./ld-musl-arm.so.1");
}
EXPECT_PTRNE(__FUNCTION__, handle, 0);
}
TEST_FUNC test_cases[] = { TEST_FUNC test_cases[] = {
dlopen_randomization_0100, dlopen_randomization_0100,
...@@ -586,6 +622,8 @@ TEST_FUNC test_cases[] = { ...@@ -586,6 +622,8 @@ TEST_FUNC test_cases[] = {
dlsym_randomization_0600, dlsym_randomization_0600,
dlsym_randomization_0700, dlsym_randomization_0700,
dlclose_randomization_0100, dlclose_randomization_0100,
dlopen_randomization_0800,
dlopen_randomization_0900,
}; };
int main(int argc, char *argv[]) int main(int argc, char *argv[])
......
...@@ -2397,6 +2397,7 @@ static void *dlopen_impl( ...@@ -2397,6 +2397,7 @@ static void *dlopen_impl(
#ifdef LOAD_ORDER_RANDOMIZATION #ifdef LOAD_ORDER_RANDOMIZATION
struct loadtasks *tasks = NULL; struct loadtasks *tasks = NULL;
struct loadtask *task = NULL; struct loadtask *task = NULL;
bool is_task_appended = false;
#endif #endif
if (!file) { if (!file) {
...@@ -2498,42 +2499,47 @@ static void *dlopen_impl( ...@@ -2498,42 +2499,47 @@ static void *dlopen_impl(
file); file);
goto end; goto end;
} }
p = task->p;
if (reserved_address) { if (reserved_address) {
reserved_params.target = p; reserved_params.target = task->p;
} }
#else
p = load_library(file, head, ns, true, reserved_address ? &reserved_params : NULL);
#endif
} }
if (!task->p) {
if (!p) {
error(noload ? error(noload ?
"Library %s is not already loaded" : "Library %s is not already loaded" :
"Error loading shared library %s: %m", "Error loading shared library %s: %m",
file); file);
goto end; goto end;
} }
#ifdef LOAD_ORDER_RANDOMIZATION
if (!task->isloaded) { if (!task->isloaded) {
append_loadtasks(tasks, task); is_task_appended = append_loadtasks(tasks, task);
} }
preload_deps(p, ns, tasks); preload_deps(task->p, ns, tasks);
unmap_preloaded_sections(tasks); unmap_preloaded_sections(tasks);
if (!reserved_address_recursive) { if (!reserved_address_recursive) {
shuffle_loadtasks(tasks); shuffle_loadtasks(tasks);
} }
run_loadtasks(tasks, reserved_address ? &reserved_params : NULL); run_loadtasks(tasks, reserved_address ? &reserved_params : NULL);
p = task->p;
if (!task->isloaded) { if (!task->isloaded) {
assign_tls(p); assign_tls(p);
} else { }
if (!is_task_appended) {
free_task(task); free_task(task);
task = NULL; task = NULL;
} }
free_loadtasks(tasks); free_loadtasks(tasks);
tasks = NULL; tasks = NULL;
#else #else
p = load_library(file, head, ns, true, reserved_address ? &reserved_params : NULL);
}
if (!p) {
error(noload ?
"Library %s is not already loaded" :
"Error loading shared library %s: %m",
file);
goto end;
}
/* First load handling */ /* First load handling */
load_deps(p, ns, reserved_address && reserved_address_recursive ? &reserved_params : NULL); load_deps(p, ns, reserved_address && reserved_address_recursive ? &reserved_params : NULL);
#endif #endif
...@@ -2588,8 +2594,10 @@ static void *dlopen_impl( ...@@ -2588,8 +2594,10 @@ static void *dlopen_impl(
#endif #endif
end: end:
#ifdef LOAD_ORDER_RANDOMIZATION #ifdef LOAD_ORDER_RANDOMIZATION
if (!is_task_appended) {
free_task(task);
}
free_loadtasks(tasks); free_loadtasks(tasks);
tasks = NULL;
#endif #endif
__release_ptc(); __release_ptc();
if (p) gencnt++; if (p) gencnt++;
...@@ -3704,11 +3712,17 @@ static void task_load_library(struct loadtask *task, struct reserved_address_par ...@@ -3704,11 +3712,17 @@ static void task_load_library(struct loadtask *task, struct reserved_address_par
decode_dyn(task->p); decode_dyn(task->p);
if (find_sym(task->p, "__libc_start_main", 1).sym && if (find_sym(task->p, "__libc_start_main", 1).sym &&
find_sym(task->p, "stdin", 1).sym) { find_sym(task->p, "stdin", 1).sym) {
unmap_library(task->p); do_dlclose(task->p);
task->p = NULL;
free((void*)task->name); free((void*)task->name);
task->name = strdup("libc.so"); task->name = strdup("libc.so");
task->check_inherited = true; task->check_inherited = true;
load_library_header(task); if (!load_library_header(task)) {
error("Error loading library %s: failed to load libc.so", task->name);
if (runtime) {
longjmp(*rtld_fail, 1);
}
}
return; return;
} }
/* Past this point, if we haven't reached runtime yet, ldso has /* Past this point, if we haven't reached runtime yet, ldso has
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册