diff --git a/core/frame/standard/init/include/if_softbus_server.h b/core/frame/standard/init/include/if_softbus_server.h index 7279d85065aded9f3e35b373156b979e60cbd5b7..1b9a3f382daf4f37ba8008d0152caa3a3be40aaa 100644 --- a/core/frame/standard/init/include/if_softbus_server.h +++ b/core/frame/standard/init/include/if_softbus_server.h @@ -40,6 +40,7 @@ public: virtual int32_t OpenSession(const SessionParam *param, TransInfo *info) = 0; virtual int32_t OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo) = 0; virtual int32_t NotifyAuthSuccess(int32_t channelId, int32_t channelType) = 0; + virtual int32_t GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) = 0; virtual int32_t CloseChannel(int32_t channelId, int32_t channelType) = 0; virtual int32_t SendMessage(int32_t channelId, int32_t channelType, const void *data, uint32_t len, int32_t msgType) = 0; diff --git a/core/frame/standard/init/include/softbus_server.h b/core/frame/standard/init/include/softbus_server.h index 76e433c40cbf6dcf4bb99c054a31a2069dd751df..9bde8ffc77b3b6e0ef55ae4a5198b7ba5335f636 100644 --- a/core/frame/standard/init/include/softbus_server.h +++ b/core/frame/standard/init/include/softbus_server.h @@ -39,6 +39,7 @@ public: int32_t OpenSession(const SessionParam *param, TransInfo *info) override; int32_t OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo) override; int32_t NotifyAuthSuccess(int32_t channelId, int32_t channelType) override; + int32_t GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) override; int32_t CloseChannel(int32_t channelId, int32_t channelType) override; int32_t SendMessage(int32_t channelId, int32_t channelType, const void *data, uint32_t len, int32_t msgType) override; diff --git a/core/frame/standard/init/src/softbus_server.cpp b/core/frame/standard/init/src/softbus_server.cpp index 46236855c19e4802827ee8ea562b4f54d1f7e75c..3b4c17559296b88b1320a3fa0b2350f180228a87 100644 --- a/core/frame/standard/init/src/softbus_server.cpp +++ b/core/frame/standard/init/src/softbus_server.cpp @@ -177,6 +177,11 @@ int32_t SoftBusServer::NotifyAuthSuccess(int32_t channelId, int32_t channelType) return TransNotifyAuthSuccess(channelId, channelType); } +int32_t SoftBusServer::GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) +{ + return TransGetAndComparePid(pid, channelId, channelType); +} + int32_t SoftBusServer::CloseChannel(int32_t channelId, int32_t channelType) { return TransCloseChannel(channelId, channelType); diff --git a/core/frame/standard/init/src/softbus_server_stub.cpp b/core/frame/standard/init/src/softbus_server_stub.cpp index 503454e6abeec83b28f073bc65896397ee3874cd..d40afb624ee3fbad0c900977c1a63f296125f2bc 100644 --- a/core/frame/standard/init/src/softbus_server_stub.cpp +++ b/core/frame/standard/init/src/softbus_server_stub.cpp @@ -706,6 +706,18 @@ int32_t SoftBusServerStub::CloseChannelInner(MessageParcel &data, MessageParcel return SOFTBUS_ERR; } + int32_t callingPid; + if (!data.ReadInt32(callingPid)) { + COMM_LOGE(COMM_SVC, "CloseChannelInner read channel callingPid failed!"); + return SOFTBUS_ERR; + } + + int32_t checkResult = GetAndComparePid(callingPid, channelId, channelType); + if (checkResult != SOFTBUS_OK) { + COMM_LOGE(COMM_SVC, "This pid:%d, can not close channel:%d", callingPid, channelId); + return SOFTBUS_ERR; + } + int32_t retReply = CloseChannel(channelId, channelType); if (!reply.WriteInt32(retReply)) { COMM_LOGE(COMM_SVC, "CloseChannelInner write reply failed!"); diff --git a/core/transmission/trans_channel/manager/include/trans_channel_manager.h b/core/transmission/trans_channel/manager/include/trans_channel_manager.h index e6e3e2963e4b7014d95d0258e066f47ffff7e9b5..10f6ed9d6e6e7a0edb01696ed2329c9d7286ce6c 100644 --- a/core/transmission/trans_channel/manager/include/trans_channel_manager.h +++ b/core/transmission/trans_channel/manager/include/trans_channel_manager.h @@ -53,6 +53,8 @@ void TransChannelDeathCallback(const char *pkgName, int32_t pid); int32_t TransGetNameByChanId(const TransInfo *info, char *pkgName, char *sessionName, uint16_t pkgLen, uint16_t sessionNameLen); +int32_t TransGetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType); + int32_t TransGetAppInfoByChanId(int32_t channelId, int32_t channelType, AppInfo* appInfo); int32_t TransGetConnByChanId(int32_t channelId, int32_t channelType, int32_t* connId); diff --git a/core/transmission/trans_channel/manager/src/trans_channel_manager.c b/core/transmission/trans_channel/manager/src/trans_channel_manager.c index 24e34acdc0520d08fc57f2da420516923b6f2c70..8abcedc7c210c45603ef4843be89d65e84fc4e34 100644 --- a/core/transmission/trans_channel/manager/src/trans_channel_manager.c +++ b/core/transmission/trans_channel/manager/src/trans_channel_manager.c @@ -837,6 +837,22 @@ int32_t TransGetNameByChanId(const TransInfo *info, char *pkgName, char *session } } +int32_t TransGetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) +{ + AppInfo appInfo; + int32_t ret = TransGetAppInfoByChanId(channelId, channelType, &appInfo); + if (ret != SOFTBUS_OK) { + TRANS_LOGE(TRANS_CTRL, "get appInfo by channelId failed!"); + return ret; + } + int32_t curChannelPid = appInfo.myData.pid; + if (pid != curChannelPid) { + TRANS_LOGE(TRANS_CTRL, "callingPid not equal curChannelPid !"); + return SOFTBUS_ERR; + } + return SOFTBUS_OK; +} + int32_t TransGetAppInfoByChanId(int32_t channelId, int32_t channelType, AppInfo* appInfo) { if (appInfo == NULL) { diff --git a/sdk/bus_center/ipc/standard/include/bus_center_server_proxy_standard.h b/sdk/bus_center/ipc/standard/include/bus_center_server_proxy_standard.h index d1d3cca64bd9d29e7a96119a96deac4ae076b2c8..0733aacf95a79176c3a9a823a873ff4ffc535b32 100644 --- a/sdk/bus_center/ipc/standard/include/bus_center_server_proxy_standard.h +++ b/sdk/bus_center/ipc/standard/include/bus_center_server_proxy_standard.h @@ -37,6 +37,7 @@ public: int32_t OpenSession(const SessionParam *param, TransInfo *info) override; int32_t NotifyAuthSuccess(int32_t channelId, int32_t channelType) override; int32_t OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo) override; + int32_t GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) override; int32_t CloseChannel(int32_t channelId, int32_t channelType) override; int32_t SendMessage(int32_t channelId, int32_t channelType, const void *data, uint32_t len, int32_t msgType) override; diff --git a/sdk/bus_center/ipc/standard/src/bus_center_server_proxy_standard.cpp b/sdk/bus_center/ipc/standard/src/bus_center_server_proxy_standard.cpp index f58180a15953e0ab118c9a7aa65c1326e605cfe1..d00812ac2628398a384a8919a4f97aa5deb578af 100644 --- a/sdk/bus_center/ipc/standard/src/bus_center_server_proxy_standard.cpp +++ b/sdk/bus_center/ipc/standard/src/bus_center_server_proxy_standard.cpp @@ -132,6 +132,14 @@ int32_t BusCenterServerProxy::NotifyAuthSuccess(int32_t channelId, int32_t chann return SOFTBUS_OK; } +int32_t BusCenterServerProxy::GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) +{ + (void)pid; + (void)channelId; + (void)channelType; + return SOFTBUS_OK; +} + int32_t BusCenterServerProxy::CloseChannel(int32_t channelId, int32_t channelType) { (void)channelId; diff --git a/sdk/discovery/ipc/standard/include/disc_server_proxy_standard.h b/sdk/discovery/ipc/standard/include/disc_server_proxy_standard.h index 5a086b260b633cd4034974dcbe41483f347a1650..5491146412950e679a8ac209a288d87e3bbe612c 100644 --- a/sdk/discovery/ipc/standard/include/disc_server_proxy_standard.h +++ b/sdk/discovery/ipc/standard/include/disc_server_proxy_standard.h @@ -38,6 +38,7 @@ public: int32_t OpenSession(const SessionParam *param, TransInfo *info) override; int32_t NotifyAuthSuccess(int32_t channelId, int32_t channelType) override; int32_t OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo) override; + int32_t GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) override; int32_t CloseChannel(int32_t channelId, int32_t channelType) override; int32_t SendMessage(int32_t channelId, int32_t channelType, const void *data, uint32_t len, int32_t msgType) override; diff --git a/sdk/discovery/ipc/standard/src/disc_server_proxy_standard.cpp b/sdk/discovery/ipc/standard/src/disc_server_proxy_standard.cpp index dad4858ae14018f60bdf55322384ee076e8e4fc4..8109db152516a6558a4ecff6fd01a2b620485ed8 100644 --- a/sdk/discovery/ipc/standard/src/disc_server_proxy_standard.cpp +++ b/sdk/discovery/ipc/standard/src/disc_server_proxy_standard.cpp @@ -301,6 +301,14 @@ int32_t DiscServerProxy::NotifyAuthSuccess(int32_t channelId, int32_t channelTyp return SOFTBUS_OK; } +int32_t DiscServerProxy::GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) +{ + (void)pid; + (void)channelId; + (void)channelType; + return SOFTBUS_OK; +} + int32_t DiscServerProxy::CloseChannel(int32_t channelId, int32_t channelType) { (void)channelId; diff --git a/sdk/frame/standard/include/softbus_server_proxy_standard.h b/sdk/frame/standard/include/softbus_server_proxy_standard.h index 0e0ed9be81349e5a858daae29f1ca1e62a4ab8db..47b26d2baa81fe7f02326bc12a5d0f1a39606904 100644 --- a/sdk/frame/standard/include/softbus_server_proxy_standard.h +++ b/sdk/frame/standard/include/softbus_server_proxy_standard.h @@ -40,6 +40,7 @@ public: int32_t OpenSession(const SessionParam *param, TransInfo *info) override; int32_t OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo) override; int32_t NotifyAuthSuccess(int32_t channelId, int32_t channelType) override; + int32_t GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) override; int32_t CloseChannel(int32_t channelId, int32_t channelType) override; int32_t SendMessage(int32_t channelId, int32_t channelType, const void *data, uint32_t len, int32_t msgType) override; diff --git a/sdk/frame/standard/src/softbus_server_proxy_standard.cpp b/sdk/frame/standard/src/softbus_server_proxy_standard.cpp index 6bdc23656975a2929ed27117310dbd2012ce4a8b..0476946d6e82fe972b74164df6aeed27513ba9c8 100644 --- a/sdk/frame/standard/src/softbus_server_proxy_standard.cpp +++ b/sdk/frame/standard/src/softbus_server_proxy_standard.cpp @@ -141,6 +141,14 @@ int32_t SoftBusServerProxyFrame::NotifyAuthSuccess(int32_t channelId, int32_t ch return SOFTBUS_OK; } +int32_t SoftBusServerProxyFrame::GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) +{ + (void)pid; + (void)channelId; + (void)channelType; + return SOFTBUS_OK; +} + int32_t SoftBusServerProxyFrame::CloseChannel(int32_t channelId, int32_t channelType) { (void)channelId; diff --git a/sdk/transmission/ipc/standard/include/trans_server_proxy_standard.h b/sdk/transmission/ipc/standard/include/trans_server_proxy_standard.h index 94e704ae210c1f626b888b34d915474ff317a694..ea7cae80af46a7737df3cb132efedcbedf089994 100644 --- a/sdk/transmission/ipc/standard/include/trans_server_proxy_standard.h +++ b/sdk/transmission/ipc/standard/include/trans_server_proxy_standard.h @@ -37,6 +37,7 @@ public: int32_t OpenSession(const SessionParam *param, TransInfo *info) override; int32_t OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo) override; int32_t NotifyAuthSuccess(int32_t channelId, int32_t channelType) override; + int32_t GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) override; int32_t CloseChannel(int32_t channelId, int32_t channelType) override; int32_t SendMessage(int32_t channelId, int32_t channelType, const void *dataInfo, uint32_t len, int32_t msgType) override; diff --git a/sdk/transmission/ipc/standard/src/trans_server_proxy_standard.cpp b/sdk/transmission/ipc/standard/src/trans_server_proxy_standard.cpp index 1fbca87b6997b4e80e9358424059f67776f28eb9..d1e2de0d3209918e824f93ed8a728fb04fa98baa 100644 --- a/sdk/transmission/ipc/standard/src/trans_server_proxy_standard.cpp +++ b/sdk/transmission/ipc/standard/src/trans_server_proxy_standard.cpp @@ -15,6 +15,7 @@ #include "trans_server_proxy_standard.h" +#include #include "ipc_skeleton.h" #include "ipc_types.h" @@ -382,6 +383,14 @@ int32_t TransServerProxy::NotifyAuthSuccess(int32_t channelId, int32_t channelTy return serverRet; } +int32_t TransServerProxy::GetAndComparePid(int32_t pid, int32_t channelId, int32_t channelType) +{ + (void)pid; + (void)channelId; + (void)channelType; + return SOFTBUS_OK; +} + int32_t TransServerProxy::CloseChannel(int32_t channelId, int32_t channelType) { sptr remote = GetSystemAbility(); @@ -390,6 +399,7 @@ int32_t TransServerProxy::CloseChannel(int32_t channelId, int32_t channelType) return SOFTBUS_ERR; } MessageParcel data; + int32_t callingPid = (int32_t)getpid(); if (!data.WriteInterfaceToken(GetDescriptor())) { TRANS_LOGE(TRANS_SDK, "CloseChannel write InterfaceToken failed!"); return SOFTBUS_ERR; @@ -402,6 +412,10 @@ int32_t TransServerProxy::CloseChannel(int32_t channelId, int32_t channelType) TRANS_LOGE(TRANS_SDK, "CloseChannel write channel type failed!"); return SOFTBUS_ERR; } + if (!data.WriteInt32(callingPid)) { + TRANS_LOGE(TRANS_SDK, "CloseChannel write channel callingPid failed!"); + return SOFTBUS_ERR; + } MessageParcel reply; MessageOption option;