Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
74b193a5
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
大约 1 年 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
74b193a5
编写于
5月 24, 2022
作者:
Y
yangguangzhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check samgr by access token
Signed-off-by:
N
yangguangzhao
<
yangguangzhao1@huawei.com
>
上级
f2e814a3
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
25 addition
and
9 deletion
+25
-9
BUILD.gn
BUILD.gn
+0
-5
interfaces/innerkits/ipc_core/BUILD.gn
interfaces/innerkits/ipc_core/BUILD.gn
+1
-0
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
+1
-0
ipc/native/src/core/source/ipc_object_stub.cpp
ipc/native/src/core/source/ipc_object_stub.cpp
+23
-4
未找到文件。
BUILD.gn
浏览文件 @
74b193a5
...
...
@@ -37,9 +37,4 @@ config("ipc_util_config") {
if (defined(build_public_version) && build_public_version) {
cflags += [ "-DBUILD_PUBLIC_VERSION" ]
}
if (use_musl) {
cflags += [ "-DSAMGR_PROCESS_UID=1005" ]
} else {
cflags += [ "-DSAMGR_PROCESS_UID=1000" ]
}
}
interfaces/innerkits/ipc_core/BUILD.gn
浏览文件 @
74b193a5
...
...
@@ -69,6 +69,7 @@ ohos_shared_library("ipc_core") {
deps = [ "//utils/native/base:utils" ]
external_deps = [
"access_token:libaccesstoken_sdk",
"dsoftbus_standard:softbus_client",
"hitrace_native:libhitrace",
"hiviewdfx_hilog_native:libhilog",
...
...
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
浏览文件 @
74b193a5
...
...
@@ -85,6 +85,7 @@ private:
int32_t
TransDataBusName
(
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
);
std
::
string
CreateDatabusName
(
int
uid
,
int
pid
);
std
::
string
GetDataBusName
();
bool
IsSamgrCall
(
uint32_t
accessToken
);
#endif
private:
bool
IsDeviceIdIllegal
(
const
std
::
string
&
deviceID
);
...
...
ipc/native/src/core/source/ipc_object_stub.cpp
浏览文件 @
74b193a5
...
...
@@ -23,6 +23,8 @@
#include "ipc_skeleton.h"
#ifndef CONFIG_IPC_SINGLE
#include "accesstoken_kit.h"
#include "access_token_adapter.h"
#include "dbinder_databus_invoker.h"
#include "dbinder_error_code.h"
#include "rpc_feature_set.h"
...
...
@@ -37,10 +39,11 @@ using namespace IPC_SINGLE;
using
namespace
OHOS
::
HiviewDFX
;
static
constexpr
HiLogLabel
LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"IPCObjectStub"
};
#ifndef CONFIG_IPC_SINGLE
using
namespace
OHOS
::
Security
;
// Authentication information can be added only for processes with system permission.
static
constexpr
pid_t
ALLOWED_UID
=
10000
;
// Only the samgr can obtain the UID and PID.
static
const
expr
pid_t
SYSTEM_SERVER_UID
=
SAMGR_PROCESS_UID
;
static
const
std
::
string
SAMGR_PROCESS_NAME
=
"samgr"
;
#endif
static
constexpr
pid_t
SHELL_UID
=
2000
;
...
...
@@ -91,7 +94,7 @@ int IPCObjectStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa
switch
(
code
)
{
#ifndef CONFIG_IPC_SINGLE
case
DBINDER_OBITUARY_TRANSACTION
:
{
if
(
IPCSkeleton
::
GetCallingUid
()
!=
SYSTEM_SERVER_UID
)
{
if
(
!
IsSamgrCall
(
IPCSkeleton
::
GetCallingTokenID
())
)
{
ZLOGE
(
LABEL
,
"%s: DBINDER_OBITUARY_TRANSACTION unauthenticated user "
,
__func__
);
result
=
IPC_STUB_INVALID_DATA_ERR
;
break
;
...
...
@@ -227,7 +230,7 @@ int IPCObjectStub::SendRequest(uint32_t code, MessageParcel &data, MessageParcel
break
;
}
case
GRANT_DATABUS_NAME
:
{
if
(
!
IPCSkeleton
::
IsLocalCalling
()
||
getuid
()
!=
SYSTEM_SERVER_UID
)
{
if
(
!
IPCSkeleton
::
IsLocalCalling
()
||
!
IsSamgrCall
((
uint32_t
)
RpcGetSelfTokenID
())
)
{
ZLOGE
(
LABEL
,
"GRANT_DATABUS_NAME message is excluded in sa manager"
);
result
=
IPC_STUB_INVALID_DATA_ERR
;
break
;
...
...
@@ -236,7 +239,7 @@ int IPCObjectStub::SendRequest(uint32_t code, MessageParcel &data, MessageParcel
break
;
}
case
TRANS_DATABUS_NAME
:
{
if
(
!
IPCSkeleton
::
IsLocalCalling
()
||
getuid
()
!=
SYSTEM_SERVER_UID
)
{
if
(
!
IPCSkeleton
::
IsLocalCalling
()
||
!
IsSamgrCall
((
uint32_t
)
RpcGetSelfTokenID
())
)
{
ZLOGE
(
LABEL
,
"TRANS_DATABUS_NAME message is excluded in sa manager"
);
result
=
IPC_STUB_INVALID_DATA_ERR
;
break
;
...
...
@@ -574,5 +577,21 @@ std::string IPCObjectStub::CreateDatabusName(int uid, int pid)
return
sessionName
;
}
bool
IPCObjectStub
::
IsSamgrCall
(
uint32_t
accessToken
)
{
auto
tokenType
=
AccessToken
::
AccessTokenKit
::
GetTokenTypeFlag
(
accessToken
);
if
(
tokenType
!=
AccessToken
::
ATokenTypeEnum
::
TOKEN_NATIVE
)
{
ZLOGE
(
LABEL
,
"not native call"
);
return
false
;
}
AccessToken
::
NativeTokenInfo
nativeTokenInfo
;
int32_t
result
=
AccessToken
::
AccessTokenKit
::
GetNativeTokenInfo
(
accessToken
,
nativeTokenInfo
);
if
(
result
==
ERR_NONE
&&
nativeTokenInfo
.
processName
==
SAMGR_PROCESS_NAME
)
{
return
true
;
}
ZLOGE
(
LABEL
,
"not samgr called, processName:%{private}s"
,
nativeTokenInfo
.
processName
.
c_str
());
return
false
;
}
#endif
}
// namespace OHOS
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录