diff --git a/interfaces/inner_api/src/standard/device_security_level_callback_helper.cpp b/interfaces/inner_api/src/standard/device_security_level_callback_helper.cpp index 6cc69b9861c38e7a82e0c393efaed5227b9b1735..6da2cdde432f89c0438ea1d5b4961fb50647c4ef 100644 --- a/interfaces/inner_api/src/standard/device_security_level_callback_helper.cpp +++ b/interfaces/inner_api/src/standard/device_security_level_callback_helper.cpp @@ -83,7 +83,7 @@ int32_t DeviceSecurityLevelCallbackHelper::OnRemoteRequest(uint32_t code, Messag auto cookie = data.ReadUint32(); auto result = data.ReadUint32(); auto level = data.ReadUint32(); - HiLog::Info(LABEL, "cookie %{public}u, result %{public}u, level %{public}u", cookie, result, level); + HiLog::Info(LABEL, "callback cookie %{public}u, result %{public}u, level %{public}u", cookie, result, level); holder_.PopCallback(cookie, result, level); } diff --git a/services/dslm/dslm_core_process.c b/services/dslm/dslm_core_process.c index 308e02f34aa7b3a9f8a5003beb5b50f7333a58c0..5dcb87f06a14c354b43d5b4d12e55cadd80ed328 100644 --- a/services/dslm/dslm_core_process.c +++ b/services/dslm/dslm_core_process.c @@ -124,8 +124,8 @@ int32_t OnMsgSendResultNotifier(const DeviceIdentify *deviceId, uint64_t transNo return SUCCESS; } -int32_t OnRequestDeviceSecLevelInfo(const DeviceIdentify *deviceId, const RequestOption *option, uint32_t cookie, - RequestCallback callback) +int32_t OnRequestDeviceSecLevelInfo(const DeviceIdentify *deviceId, const RequestOption *option, uint32_t owner, + uint32_t cookie, RequestCallback callback) { if (deviceId == NULL || option == NULL || callback == NULL) { SECURITY_LOG_ERROR("OnRequestDeviceSecLevelInfo invalid para"); @@ -156,6 +156,7 @@ int32_t OnRequestDeviceSecLevelInfo(const DeviceIdentify *deviceId, const Reques SECURITY_LOG_ERROR("OnRequestDeviceSecLevelInfo malloc error"); return ERR_NO_MEMORY; } + nofityNode->owner = owner; nofityNode->cookie = cookie; nofityNode->requestCallback = callback; nofityNode->start = GetMillisecondSinceBoot(); diff --git a/services/dslm/dslm_fsm_process.c b/services/dslm/dslm_fsm_process.c index 29d074c78096451e348a346242cbd568593d2f7d..44e24f71b39c335a23770dc8cff6c2be70299c57 100644 --- a/services/dslm/dslm_fsm_process.c +++ b/services/dslm/dslm_fsm_process.c @@ -135,7 +135,7 @@ static void ProcessSendDeviceInfoCallback(DslmDeviceInfo *info, DslmInfoChecker } SECURITY_LOG_DEBUG("ProcessSendDeviceInfoCallback result %{public}u for device %{public}x, level %{public}u.", result, info->machine.machineId, cbInfo.level); - notifyNode->requestCallback(notifyNode->cookie, result, &cbInfo); + notifyNode->requestCallback(notifyNode->owner, notifyNode->cookie, result, &cbInfo); RemoveListNode(node); FREE(notifyNode); } @@ -175,8 +175,9 @@ static bool ProcessSdkRequest(const StateMachine *machine, uint32_t event, const } AddListNode(¬ify->linkNode, &deviceInfo->notifyList); - SECURITY_LOG_DEBUG("ProcessSdkRequest, device is %{public}x, cookie is %{public}u, keep is %{public}u", - deviceInfo->machine.machineId, notify->cookie, notify->keep); + SECURITY_LOG_DEBUG( + "ProcessSdkRequest, device is %{public}x, owner is %{public}u, cookie is %{public}u, keep is %{public}u", + deviceInfo->machine.machineId, notify->owner, notify->cookie, notify->keep); uint32_t state = GetCurrentMachineState(deviceInfo); if (state == STATE_SUCCESS || state == STATE_FAILED || deviceInfo->credInfo.credLevel != 0) { ProcessSendDeviceInfoCallback(deviceInfo, RequestDoneCheker); @@ -252,8 +253,8 @@ static bool SdkTimeoutCheker(const DslmDeviceInfo *devInfo, const DslmNotifyList return false; } - SECURITY_LOG_INFO("SdkTimeoutCheker active, device is %{public}x, cookie is %{public}u, keep is %{public}u", - devInfo->machine.machineId, node->cookie, node->keep); + SECURITY_LOG_INFO("SdkTimeout, device is %{public}x, owner is %{public}u, cookie is %{public}u, keep is %{public}u", + devInfo->machine.machineId, node->owner, node->cookie, node->keep); *result = ERR_TIMEOUT; cbInfo->level = 0; @@ -269,6 +270,11 @@ static bool RequestDoneCheker(const DslmDeviceInfo *devInfo, const DslmNotifyLis cbInfo->level = devInfo->credInfo.credLevel; cbInfo->extraLen = 0; cbInfo->extraBuff = NULL; + + SECURITY_LOG_INFO( + "RequestDone, device is %{public}x, owner is %{public}u, cookie is %{public}u, keep is %{public}u", + devInfo->machine.machineId, node->owner, node->cookie, node->keep); + return true; } diff --git a/services/include/dslm_callback_info.h b/services/include/dslm_callback_info.h index 8e632edda0be252cc2d91f5fd315e8cff43aa18a..2c1bf921ee32ab653e8454d91ecc39fcefbdd9eb 100644 --- a/services/include/dslm_callback_info.h +++ b/services/include/dslm_callback_info.h @@ -28,7 +28,7 @@ typedef struct DslmCallbackInfo { uint32_t extraLen; } DslmCallbackInfo; -typedef void RequestCallback(uint32_t cookie, uint32_t result, const DslmCallbackInfo *info); +typedef void RequestCallback(uint32_t owner, uint32_t cookie, uint32_t result, const DslmCallbackInfo *info); #ifdef __cplusplus } diff --git a/services/include/dslm_core_process.h b/services/include/dslm_core_process.h index 333c61a8cb9345821b7012312c1101ad78f9eee9..dc8d16f294c2e67ee50e75fb836881e07771f5c3 100644 --- a/services/include/dslm_core_process.h +++ b/services/include/dslm_core_process.h @@ -31,8 +31,8 @@ int32_t OnPeerMsgRequestInfoReceived(const DeviceIdentify *deviceId, const uint8 int32_t OnPeerMsgResponseInfoReceived(const DeviceIdentify *deviceId, const uint8_t *msg, uint32_t len); -int32_t OnRequestDeviceSecLevelInfo(const DeviceIdentify *deviceId, const RequestOption *option, uint32_t cookie, - RequestCallback callback); +int32_t OnRequestDeviceSecLevelInfo(const DeviceIdentify *deviceId, const RequestOption *option, uint32_t owner, + uint32_t cookie, RequestCallback callback); int32_t OnMsgSendResultNotifier(const DeviceIdentify *deviceId, uint64_t transNo, uint32_t result); diff --git a/services/include/dslm_notify_node.h b/services/include/dslm_notify_node.h index 45ab0d254eeaf849e7a1ce75b393f794b7830f71..73f3c2a87d377fe1a5514a6564f0cce159b11417 100644 --- a/services/include/dslm_notify_node.h +++ b/services/include/dslm_notify_node.h @@ -30,6 +30,7 @@ typedef struct DslmNotifyListNode { ListNode linkNode; uint64_t start; uint32_t keep; + uint32_t owner; uint32_t cookie; uint32_t extra; RequestCallback *requestCallback; diff --git a/services/sa/standard/dslm_ipc_process.cpp b/services/sa/standard/dslm_ipc_process.cpp index 77fe479c9ac53e5a5716141451f66c59a5fc7a60..f3201a43ff5bbfc2da37f9c2c60c969facedc301 100644 --- a/services/sa/standard/dslm_ipc_process.cpp +++ b/services/sa/standard/dslm_ipc_process.cpp @@ -15,6 +15,7 @@ #include "dslm_ipc_process.h" +#include #include #include @@ -28,17 +29,22 @@ constexpr uint32_t DFT_TIMEOUT = 45; constexpr uint32_t MAX_TIMEOUT = 60; constexpr uint32_t MIN_TIMEOUT = 1; constexpr uint32_t WARAING_GATE = 64; +constexpr uint32_t COOKIE_SHIFT = 32; } // namespace namespace OHOS { namespace Security { namespace DeviceSecurityLevel { -static void ProcessCallback(uint32_t cookie, uint32_t result, const DslmCallbackInfo *info) +static void ProcessCallback(uint32_t owner, uint32_t cookie, uint32_t result, const DslmCallbackInfo *info) { if ((cookie == 0) || (info == nullptr)) { return; } - auto object = Singleton::GetInstance().Pop(cookie); + auto object = Singleton::GetInstance().Pop(owner, cookie); + if (object == nullptr) { + SECURITY_LOG_ERROR("ProcessCallback Pop error."); + return; + } auto proxy = iface_cast(object); if (object == nullptr) { @@ -123,18 +129,19 @@ int32_t DslmIpcProcess::DslmProcessGetDeviceSecurityLevel(MessageParcel &data, M return ret; } - Singleton::GetInstance().Push(cookie, callback); + auto owner = IPCSkeleton::GetCallingPid(); + Singleton::GetInstance().Push(owner, cookie, callback); - ret = OnRequestDeviceSecLevelInfo(&identity, &option, cookie, ProcessCallback); + ret = OnRequestDeviceSecLevelInfo(&identity, &option, owner, cookie, ProcessCallback); if (ret != SUCCESS) { - Singleton::GetInstance().Pop(cookie); + Singleton::GetInstance().Pop(owner, cookie); SECURITY_LOG_ERROR("ProcessGetDeviceSecurityLevel OnRequestDeviceSecLevelInfo failed, ret = %{public}d", ret); return ret; } ret = DslmSetResponseToParcel(reply, cookie); if (ret != SUCCESS) { - Singleton::GetInstance().Pop(cookie); + Singleton::GetInstance().Pop(owner, cookie); SECURITY_LOG_ERROR("ProcessGetDeviceSecurityLevel DslmSetResponseToParcel failed, ret = %{public}d", ret); return ret; } @@ -149,20 +156,22 @@ DslmIpcProcess::RemoteHolder::~RemoteHolder() { } -bool DslmIpcProcess::RemoteHolder::Push(uint32_t cookie, const sptr object) +bool DslmIpcProcess::RemoteHolder::Push(uint32_t owner, uint32_t cookie, const sptr object) { std::lock_guard lock(mutex_); - map_[cookie] = object; + uint64_t key = (static_cast(owner) << COOKIE_SHIFT) | cookie; + map_[key] = object; if (map_.size() > WARAING_GATE) { SECURITY_LOG_WARN("DslmIpcProcess remote objects max warning"); } return true; } -const sptr DslmIpcProcess::RemoteHolder::Pop(uint32_t cookie) +const sptr DslmIpcProcess::RemoteHolder::Pop(uint32_t owner, uint32_t cookie) { std::lock_guard lock(mutex_); - auto iter = map_.find(cookie); + uint64_t key = (static_cast(owner) << COOKIE_SHIFT) | cookie; + auto iter = map_.find(key); if (iter == map_.end()) { return nullptr; } diff --git a/services/sa/standard/dslm_ipc_process.h b/services/sa/standard/dslm_ipc_process.h index 293e1d976d2b5dc55499fcd9ae26f5dfb84f7268..d3ac2aa5539f488653f0575f43a0a75e8e7414f9 100644 --- a/services/sa/standard/dslm_ipc_process.h +++ b/services/sa/standard/dslm_ipc_process.h @@ -37,11 +37,11 @@ public: DECLARE_SINGLETON(RemoteHolder); public: - bool Push(uint32_t cookie, const sptr object); - const sptr Pop(uint32_t cookie); + bool Push(uint32_t owner, uint32_t cookie, const sptr object); + const sptr Pop(uint32_t owner, uint32_t cookie); private: - std::map> map_; + std::map> map_; std::mutex mutex_; }; diff --git a/test/dslm_request_callback_mock.cpp b/test/dslm_request_callback_mock.cpp index 57920280a0ac56f758b6de4c7ddad491a9f1dda9..beb015fc1fdf4b891fc92564f89e031b792cd7ef 100644 --- a/test/dslm_request_callback_mock.cpp +++ b/test/dslm_request_callback_mock.cpp @@ -39,7 +39,8 @@ DslmRequestCallbackMock::~DslmRequestCallbackMock() obj_ = nullptr; } -void DslmRequestCallbackMock::MockedCallback(uint32_t cookie, uint32_t result, const DslmCallbackInfo *info) +void DslmRequestCallbackMock::MockedCallback(uint32_t owner, uint32_t cookie, uint32_t result, + const DslmCallbackInfo *info) { std::lock_guard lock(mutex_); if (obj_ != nullptr) { diff --git a/test/dslm_request_callback_mock.h b/test/dslm_request_callback_mock.h index fc95d708d9d2b6b809ff5741bc4e6ef57b787f7f..f187266764eab2fdfb98df579b66f82e2867752a 100644 --- a/test/dslm_request_callback_mock.h +++ b/test/dslm_request_callback_mock.h @@ -39,7 +39,7 @@ public: ~DslmRequestCallbackMock() override; MOCK_METHOD3(RequestCallback, void(uint32_t cookie, uint32_t result, const DslmCallbackInfo *info)); - static void MockedCallback(uint32_t cookie, uint32_t result, const DslmCallbackInfo *info); + static void MockedCallback(uint32_t owner, uint32_t cookie, uint32_t result, const DslmCallbackInfo *info); private: static DslmRequestCallback *obj_; diff --git a/test/dslm_test.cpp b/test/dslm_test.cpp index 10c85bdfa31ed8f5c56f130d53ad554960623d23..bef1840f6c443c9c7f822776aca2afe5dc0d99cd 100644 --- a/test/dslm_test.cpp +++ b/test/dslm_test.cpp @@ -376,7 +376,7 @@ HWTEST_F(DslmTest, OnRequestDeviceSecLevelInfo_case1, TestSize.Level1) uint32_t cookie = 1234; DslmRequestCallbackMock mockCallback; EXPECT_CALL(mockCallback, RequestCallback(_, _, _)).Times(Exactly(0)); - int32_t ret = OnRequestDeviceSecLevelInfo(&device, &option, cookie, DslmRequestCallbackMock::MockedCallback); + int32_t ret = OnRequestDeviceSecLevelInfo(&device, &option, 0, cookie, DslmRequestCallbackMock::MockedCallback); EXPECT_EQ((int32_t)ret, ERR_MSG_NOT_INIT); } @@ -387,7 +387,7 @@ HWTEST_F(DslmTest, OnRequestDeviceSecLevelInfo_case1, TestSize.Level1) EXPECT_CALL(mockMsg, IsMessengerReady(_)).Times(AtLeast(1)); EXPECT_CALL(mockMsg, GetDeviceOnlineStatus(_, _, _)).Times(AtLeast(1)).WillRepeatedly(Return(false)); EXPECT_CALL(mockCallback, RequestCallback(_, _, _)).Times(Exactly(0)); - int32_t ret = OnRequestDeviceSecLevelInfo(&device, &option, cookie, DslmRequestCallbackMock::MockedCallback); + int32_t ret = OnRequestDeviceSecLevelInfo(&device, &option, 0, cookie, DslmRequestCallbackMock::MockedCallback); EXPECT_EQ((int32_t)ret, ERR_NOEXIST_DEVICE); EXPECT_CALL(mockMsg, SendMsgTo(_, _, _, _, _)).Times(AtLeast(2)); @@ -407,7 +407,7 @@ HWTEST_F(DslmTest, OnRequestDeviceSecLevelInfo_case1, TestSize.Level1) auto IsRightLevel = [](const DslmCallbackInfo *info) { return info->level >= 1; }; EXPECT_CALL(mockCallback, RequestCallback(cookie, 0, Truly(IsRightLevel))).Times(Exactly(1)); - int32_t ret = OnRequestDeviceSecLevelInfo(&device, &option, cookie, DslmRequestCallbackMock::MockedCallback); + int32_t ret = OnRequestDeviceSecLevelInfo(&device, &option, 0, cookie, DslmRequestCallbackMock::MockedCallback); EXPECT_EQ(ret, (int32_t)0); mockMsg.MakeDeviceOffline(&device); } @@ -434,7 +434,7 @@ HWTEST_F(DslmTest, OnRequestDeviceSecLevelInfo_case2, TestSize.Level1) uint32_t cookie = 0x4567; EXPECT_CALL(mockMsg, SendMsgTo(_, _, _, Truly(isSendRequestOut), _)).Times(AtLeast(1)).WillRepeatedly(Return(true)); - int32_t ret = OnRequestDeviceSecLevelInfo(&device, &option, cookie, DslmRequestCallbackMock::MockedCallback); + int32_t ret = OnRequestDeviceSecLevelInfo(&device, &option, 0, cookie, DslmRequestCallbackMock::MockedCallback); EXPECT_EQ((int32_t)ret, (int32_t)0); mockMsg.MakeDeviceOffline(&device); } @@ -475,7 +475,7 @@ HWTEST_F(DslmTest, OnRequestDeviceSecLevelInfo_case3, TestSize.Level1) for (int i = 1; i <= reqTimes; i++) { option.timeout = timeouts[i]; int32_t ret = - OnRequestDeviceSecLevelInfo(&device, &option, cookies[i], DslmRequestCallbackMock::MockedCallback); + OnRequestDeviceSecLevelInfo(&device, &option, i, cookies[i], DslmRequestCallbackMock::MockedCallback); EXPECT_EQ((int32_t)ret, (int32_t)0); }