Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
9a65a375
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9a65a375
编写于
7月 04, 2022
作者:
W
wangjiahui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test case about rm011
Signed-off-by:
N
wangjiahui
<
wangjiahui27@huawei.com
>
上级
e6587537
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
96 addition
and
35 deletion
+96
-35
libc-test/src/functionalext/ldso_randomization/ldso_randomization_test.c
...unctionalext/ldso_randomization/ldso_randomization_test.c
+51
-0
libc-test/src/functionalext/relro/dlopen_ext_relro_test.c
libc-test/src/functionalext/relro/dlopen_ext_relro_test.c
+27
-27
porting/linux/user/include/dlfcn_ext.h
porting/linux/user/include/dlfcn_ext.h
+5
-5
porting/linux/user/ldso/dynlink.c
porting/linux/user/ldso/dynlink.c
+2
-2
porting/linux/user/ldso/dynlink_rand.c
porting/linux/user/ldso/dynlink_rand.c
+11
-1
未找到文件。
libc-test/src/functionalext/ldso_randomization/ldso_randomization_test.c
浏览文件 @
9a65a375
...
...
@@ -24,6 +24,7 @@
#include "functionalext.h"
#define PIPE_FD 2
#define NUM_OF_BYTE 8
#define BASE_NUM 11
#define TEST_COUNTS 32
...
...
@@ -312,6 +313,55 @@ static void dlopen_ext_randomization_0800(void)
dlclose
(
handle
);
}
/**
* @tc.name : dlopen_ext_randomization_0900
* @tc.desc : Different processes call the dlopen_ext interface to load a dynamic library,
* the flag of dl_extinfo is set to DL_EXT_RESERVED_ADDRESS_RECURSIVE,
* and then call the dlsym interface to get symbol address
* @tc.level : Level1
*/
static
void
dlopen_ext_randomization_0900
(
void
)
{
void
*
parent_handle
=
0
;
void
*
child_handle
=
0
;
void
*
parent_sym
=
0
;
void
*
child_sym
=
0
;
void
*
get_child_sym
=
0
;
int
fd
[
PIPE_FD
];
if
(
pipe
(
fd
)
<
0
)
{
EXPECT_FALSE
(
__FUNCTION__
,
true
);
return
;
}
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
};
pid_t
pid
=
fork
();
if
(
pid
==
0
)
{
child_handle
=
dlopen_ext
(
LIB_NAME_A
,
RTLD_NOW
,
&
extinfo
);
EXPECT_PTRNE
(
__FUNCTION__
,
child_handle
,
0
);
if
(
!
child_handle
)
{
exit
(
-
1
);
}
child_sym
=
dlsym
(
child_handle
,
"test"
);
write
(
fd
[
1
],
&
child_sym
,
sizeof
(
void
*
));
dlclose
(
child_handle
);
exit
(
0
);
}
parent_handle
=
dlopen_ext
(
LIB_NAME_A
,
RTLD_NOW
,
&
extinfo
);
EXPECT_PTRNE
(
__FUNCTION__
,
parent_handle
,
0
);
if
(
!
parent_handle
)
{
return
;
};
parent_sym
=
dlsym
(
parent_handle
,
"test"
);
dlclose
(
parent_handle
);
int
status
;
waitpid
(
pid
,
&
status
,
0
);
read
(
fd
[
0
],
&
get_child_sym
,
sizeof
(
void
*
));
EXPECT_PTREQ
(
__FUNCTION__
,
parent_sym
,
get_child_sym
);
close
(
fd
[
0
]);
close
(
fd
[
1
]);
}
/**
* @tc.name : dlopen_ns_randomization_0100
* @tc.desc : Call the dlopen_ns interface to load a valid dynamic library
...
...
@@ -479,6 +529,7 @@ TEST_FUNC test_cases[] = {
dlopen_ext_randomization_0400
,
dlopen_ext_randomization_0600
,
dlopen_ext_randomization_0800
,
dlopen_ext_randomization_0900
,
dlopen_ns_randomization_0100
,
dlopen_ns_randomization_0200
,
dlopen_ns_randomization_0300
,
...
...
libc-test/src/functionalext/relro/dlopen_ext_relro_test.c
浏览文件 @
9a65a375
...
...
@@ -63,12 +63,12 @@ static void clear_handle(void *handle)
}
}
static
void
test_w
ir
te_relro_file
(
const
char
*
lib
,
const
int
relro_fd
)
static
void
test_w
ri
te_relro_file
(
const
char
*
lib
,
const
int
relro_fd
)
{
pid_t
pid
=
fork
();
if
(
pid
==
0
)
{
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_W
IRTE_INF
O
,
.
flag
=
DL_EXT_W
RITE_RELR
O
,
.
relro_fd
=
relro_fd
,
};
void
*
handle
=
dlopen_ext
(
lib
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -126,7 +126,7 @@ static void dlopen_ext_relro_0300(void)
/**
* @tc.name : dlopen_ext_relro_0400
* @tc.desc : extinfo flag is DL_EXT_W
IRTE_INF
O, relro_fd is valid, call dlopen_ext, return handle is not NULL.
* @tc.desc : extinfo flag is DL_EXT_W
RITE_RELR
O, relro_fd is valid, call dlopen_ext, return handle is not NULL.
* @tc.level : Level 1
*/
static
void
dlopen_ext_relro_0400
(
void
)
...
...
@@ -141,7 +141,7 @@ static void dlopen_ext_relro_0400(void)
return
;
}
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_W
IRTE_INF
O
,
.
flag
=
DL_EXT_W
RITE_RELR
O
,
.
relro_fd
=
relro_fd
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -152,13 +152,13 @@ static void dlopen_ext_relro_0400(void)
/**
* @tc.name : dlopen_ext_relro_0500
* @tc.desc : extinfo flag is DL_EXT_W
IRTE_INF
O, relro_fd is not valid, call dlopen_ext, return handle is NULL.
* @tc.desc : extinfo flag is DL_EXT_W
RITE_RELR
O, relro_fd is not valid, call dlopen_ext, return handle is NULL.
* @tc.level : Level 2
*/
static
void
dlopen_ext_relro_0500
(
void
)
{
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_W
IRTE_INF
O
,
.
flag
=
DL_EXT_W
RITE_RELR
O
,
.
relro_fd
=
-
1
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -168,7 +168,7 @@ static void dlopen_ext_relro_0500(void)
/**
* @tc.name : dlopen_ext_relro_0600
* @tc.desc : extinfo flag is DL_EXT_USE_
INF
O, relro_fd is valid, call dlopen_ext, return handle is not NULL.
* @tc.desc : extinfo flag is DL_EXT_USE_
RELR
O, relro_fd is valid, call dlopen_ext, return handle is not NULL.
* @tc.level : Level 1
*/
static
void
dlopen_ext_relro_0600
(
void
)
...
...
@@ -182,9 +182,9 @@ static void dlopen_ext_relro_0600(void)
t_error
(
"%s relro file %s open failed error is : %s
\n
"
,
__FUNCTION__
,
relro_file
,
dlerror
());
return
;
}
test_w
ir
te_relro_file
(
LIB_NAME
,
relro_fd
);
test_w
ri
te_relro_file
(
LIB_NAME
,
relro_fd
);
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_USE_
INF
O
,
.
flag
=
DL_EXT_USE_
RELR
O
,
.
relro_fd
=
relro_fd
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -195,7 +195,7 @@ static void dlopen_ext_relro_0600(void)
/**
* @tc.name : dlopen_ext_relro_0700
* @tc.desc : extinfo flag is DL_EXT_USE_
INF
O, relro_fd is not valid, call dlopen_ext, return handle is NULL.
* @tc.desc : extinfo flag is DL_EXT_USE_
RELR
O, relro_fd is not valid, call dlopen_ext, return handle is NULL.
* @tc.level : Level 2
*/
static
void
dlopen_ext_relro_0700
(
void
)
...
...
@@ -209,9 +209,9 @@ static void dlopen_ext_relro_0700(void)
t_error
(
"%s relro file %s open failed error is : %s
\n
"
,
__FUNCTION__
,
relro_file
,
dlerror
());
return
;
}
test_w
ir
te_relro_file
(
LIB_NAME
,
relro_fd
);
test_w
ri
te_relro_file
(
LIB_NAME
,
relro_fd
);
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_USE_
INF
O
,
.
flag
=
DL_EXT_USE_
RELR
O
,
.
relro_fd
=
-
1
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -222,7 +222,7 @@ static void dlopen_ext_relro_0700(void)
/**
* @tc.name : dlopen_ext_relro_0800
* @tc.desc : extinfo flag is DL_EXT_W
IRTE_INF
O | DL_EXT_RESERVED_ADDRESS_RECURSIVE, relro_fd is valid,
* @tc.desc : extinfo flag is DL_EXT_W
RITE_RELR
O | DL_EXT_RESERVED_ADDRESS_RECURSIVE, relro_fd is valid,
* call dlopen_ext, return handle is not NULL.
* @tc.level : Level 1
*/
...
...
@@ -238,7 +238,7 @@ static void dlopen_ext_relro_0800(void)
return
;
}
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_W
IRTE_INF
O
|
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
.
flag
=
DL_EXT_W
RITE_RELR
O
|
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
.
relro_fd
=
relro_fd
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -249,13 +249,13 @@ static void dlopen_ext_relro_0800(void)
/**
* @tc.name : dlopen_ext_relro_0900
* @tc.desc : extinfo flag is DL_EXT_W
IRTE_INF
O, relro_fd is not valid, call dlopen_ext, return handle is NULL.
* @tc.desc : extinfo flag is DL_EXT_W
RITE_RELR
O, relro_fd is not valid, call dlopen_ext, return handle is NULL.
* @tc.level : Level 2
*/
static
void
dlopen_ext_relro_0900
(
void
)
{
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_W
IRTE_INF
O
|
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
.
flag
=
DL_EXT_W
RITE_RELR
O
|
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
.
relro_fd
=
-
1
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -266,7 +266,7 @@ static void dlopen_ext_relro_0900(void)
/**
* @tc.name : dlopen_ext_relro_1000
* @tc.desc : extinfo flag is DL_EXT_USE_
INF
O | DL_EXT_RESERVED_ADDRESS_RECURSIVE, relro_fd is valid,
* @tc.desc : extinfo flag is DL_EXT_USE_
RELR
O | DL_EXT_RESERVED_ADDRESS_RECURSIVE, relro_fd is valid,
* call dlopen_ext, return handle is not NULL.
* @tc.level : Level 1
*/
...
...
@@ -281,9 +281,9 @@ static void dlopen_ext_relro_1000(void)
t_error
(
"%s relro file %s open failed error is : %s
\n
"
,
__FUNCTION__
,
relro_file
,
dlerror
());
return
;
}
test_w
ir
te_relro_file
(
LIB_NAME
,
relro_fd
);
test_w
ri
te_relro_file
(
LIB_NAME
,
relro_fd
);
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_USE_
INF
O
|
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
.
flag
=
DL_EXT_USE_
RELR
O
|
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
.
relro_fd
=
relro_fd
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -294,7 +294,7 @@ static void dlopen_ext_relro_1000(void)
/**
* @tc.name : dlopen_ext_relro_1100
* @tc.desc : extinfo flag is DL_EXT_USE_
INF
O | DL_EXT_RESERVED_ADDRESS_RECURSIVE, relro_fd is not valid,
* @tc.desc : extinfo flag is DL_EXT_USE_
RELR
O | DL_EXT_RESERVED_ADDRESS_RECURSIVE, relro_fd is not valid,
* call dlopen_ext, return handle is NULL.
* @tc.level : Level 2
*/
...
...
@@ -309,9 +309,9 @@ static void dlopen_ext_relro_1100(void)
t_error
(
"%s relro file %s open failed error is : %s
\n
"
,
__FUNCTION__
,
relro_file
,
dlerror
());
return
;
}
test_w
ir
te_relro_file
(
LIB_NAME
,
relro_fd
);
test_w
ri
te_relro_file
(
LIB_NAME
,
relro_fd
);
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_USE_
INF
O
|
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
.
flag
=
DL_EXT_USE_
RELR
O
|
DL_EXT_RESERVED_ADDRESS_RECURSIVE
,
.
relro_fd
=
-
1
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -322,7 +322,7 @@ static void dlopen_ext_relro_1100(void)
/**
* @tc.name : dlopen_ext_relro_1200
* @tc.desc : extinfo flag is DL_EXT_USE_
INFO when relro file do not wir
te,
* @tc.desc : extinfo flag is DL_EXT_USE_
RELRO when relro file do not wri
te,
* when call dlopen_ext, return handle is NULL.
* @tc.level : Level 2
*/
...
...
@@ -338,7 +338,7 @@ static void dlopen_ext_relro_1200(void)
return
;
}
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_USE_
INF
O
,
.
flag
=
DL_EXT_USE_
RELR
O
,
.
relro_fd
=
relro_fd
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
@@ -349,7 +349,7 @@ static void dlopen_ext_relro_1200(void)
/**
* @tc.name : dlopen_ext_relro_1500
* @tc.desc : extinfo flag is DL_EXT_USE_
INFO | DL_EXT_WIRTE_INF
O, relro_fd is valid,
* @tc.desc : extinfo flag is DL_EXT_USE_
RELRO | DL_EXT_WRITE_RELR
O, relro_fd is valid,
* call dlopen_ext, return handle is not NULL.
* @tc.level : Level 1
*/
...
...
@@ -364,9 +364,9 @@ static void dlopen_ext_relro_1500(void)
t_error
(
"%s relro file %s open failed error is : %s
\n
"
,
__FUNCTION__
,
relro_file
,
dlerror
());
return
;
}
test_w
ir
te_relro_file
(
LIB_NAME
,
relro_fd
);
test_w
ri
te_relro_file
(
LIB_NAME
,
relro_fd
);
dl_extinfo
extinfo
=
{
.
flag
=
DL_EXT_W
IRTE_INFO
|
DL_EXT_USE_INF
O
,
.
flag
=
DL_EXT_W
RITE_RELRO
|
DL_EXT_USE_RELR
O
,
.
relro_fd
=
relro_fd
,
};
void
*
handle
=
dlopen_ext
(
LIB_NAME
,
RTLD_NOW
,
&
extinfo
);
...
...
porting/linux/user/include/dlfcn_ext.h
浏览文件 @
9a65a375
...
...
@@ -23,12 +23,12 @@ extern "C" {
#endif
/* for dl_extinfo flag */
#define DL_EXT_W
IRTE_INF
O 0x1
#define DL_EXT_USE_
INF
O 0x2
#define DL_EXT_W
RITE_RELR
O 0x1
#define DL_EXT_USE_
RELR
O 0x2
#define DL_EXT_RESERVED_ADDRESS_RECURSIVE 0x4
/** Mask of valid bits. */
#define DL_EXT_VALID_FLAG_BITS (DL_EXT_W
IRTE_INFO | DL_EXT_USE_INF
O | DL_EXT_RESERVED_ADDRESS_RECURSIVE)
#define DL_EXT_VALID_FLAG_BITS (DL_EXT_W
RITE_RELRO | DL_EXT_USE_RELR
O | DL_EXT_RESERVED_ADDRESS_RECURSIVE)
typedef
struct
{
int
flag
;
...
...
@@ -38,9 +38,9 @@ typedef struct {
/**
* @brief Loads the dynamic shared object (shared library) file with the extended feature.
* If extinfo is NULL, it is equivalent to dlopen.
* If DL_EXT_W
IRTE_INF
O is set in extinfo, the GNU RELRO section will be written to relro_fd and allowed to
* If DL_EXT_W
RITE_RELR
O is set in extinfo, the GNU RELRO section will be written to relro_fd and allowed to
* reused by other process loading the same library at the same address.
* IF DL_EXT_USE_
INF
O is set in extinfo, the GNU RELRO section written in relro_fd will be reused.
* IF DL_EXT_USE_
RELR
O is set in extinfo, the GNU RELRO section written in relro_fd will be reused.
* @param file Equivalent to the argument of dlopen.
* @param mode Equivalent to the argument of dlopen.
* @param extinfo Indicates the dl_extinfo struct.
...
...
porting/linux/user/ldso/dynlink.c
浏览文件 @
9a65a375
...
...
@@ -3940,14 +3940,14 @@ static void handle_relro_sharing(struct dso *p, const dl_extinfo *extinfo, ssize
if
(
extinfo
==
NULL
)
{
return
;
}
if
(
extinfo
->
flag
&
DL_EXT_W
IRTE_INF
O
)
{
if
(
extinfo
->
flag
&
DL_EXT_W
RITE_RELR
O
)
{
LD_LOGD
(
"Serializing GNU_RELRO %s"
,
p
->
name
);
if
(
serialize_gnu_relro
(
extinfo
->
relro_fd
,
p
,
relro_fd_offset
)
<
0
)
{
LD_LOGE
(
"Error serializing GNU_RELRO %s"
,
p
->
name
);
error
(
"Error serializing GNU_RELRO"
);
if
(
runtime
)
longjmp
(
*
rtld_fail
,
1
);
}
}
else
if
(
extinfo
->
flag
&
DL_EXT_USE_
INF
O
)
{
}
else
if
(
extinfo
->
flag
&
DL_EXT_USE_
RELR
O
)
{
LD_LOGD
(
"Mapping GNU_RELRO %s"
,
p
->
name
);
if
(
map_gnu_relro
(
extinfo
->
relro_fd
,
p
,
relro_fd_offset
)
<
0
)
{
LD_LOGE
(
"Error mapping GNU_RELRO %s"
,
p
->
name
);
...
...
porting/linux/user/ldso/dynlink_rand.c
浏览文件 @
9a65a375
...
...
@@ -162,6 +162,10 @@ void free_task(struct loadtask *task)
if
(
task
==
NULL
)
{
return
;
}
if
(
task
->
name
)
{
free
(
task
->
name
);
task
->
name
=
NULL
;
}
if
(
task
->
allocated_buf
)
{
free
(
task
->
allocated_buf
);
task
->
allocated_buf
=
NULL
;
...
...
@@ -228,11 +232,17 @@ void shuffle_loadtasks(struct loadtasks *tasks)
struct
loadtask
*
create_loadtask
(
const
char
*
name
,
struct
dso
*
needed_by
,
ns_t
*
ns
,
bool
check_inherited
)
{
size_t
name_len
=
strlen
(
name
);
char
*
name_buf
=
(
char
*
)
malloc
(
name_len
+
1
);
if
(
!
name_buf
)
{
return
NULL
;
}
struct
loadtask
*
task
=
calloc
(
1
,
sizeof
(
struct
loadtask
));
if
(
!
task
)
{
return
NULL
;
}
task
->
name
=
name
;
strcpy
(
name_buf
,
name
);
task
->
name
=
name_buf
;
task
->
needed_by
=
needed_by
;
task
->
namespace
=
ns
;
task
->
check_inherited
=
check_inherited
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录