提交 c3cd425f 编写于 作者: F fanxiaoyu

Fix rpc session bug when there are more than one SA in open process.

Signed-off-by: Nfanxiaoyu <fanxiaoyu3@huawei.com>
上级 2bf73ced
......@@ -66,9 +66,8 @@ public:
int InvokeListenThread(MessageParcel &data, MessageParcel &reply);
int32_t NoticeServiceDie();
std::string GetPidAndUidInfo();
std::string GetDataBusName();
std::string GetPidAndUidInfo(int32_t systemAbilityId);
std::string GetDataBusName(int32_t systemAbilityId);
std::string TransDataBusName(uint32_t uid, uint32_t pid);
int GetProto() const;
void WaitForInit();
......
......@@ -83,8 +83,8 @@ public:
private:
int32_t GrantDataBusName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t TransDataBusName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
std::string CreateDatabusName(int uid, int pid);
std::string GetDataBusName();
std::string CreateDatabusName(int uid, int pid, int systemAbilityId);
std::string GetDataBusName(int32_t systemAbilityId);
bool IsSamgrCall(uint32_t accessToken);
bool HasDumpPermission(uint32_t accessToken) const;
#endif
......
......@@ -160,7 +160,7 @@ private:
bool OnRemoteInvokerDataBusMessage(IPCObjectProxy *proxy, struct DHandleEntryTxRx *replyMessage,
std::string &remoteDeviceId, int pid, int uid);
bool IsDeviceIdIllegal(const std::string &deviceID);
std::string GetDatabusNameByProxy(IPCObjectProxy *proxy);
std::string GetDatabusNameByProxy(IPCObjectProxy *proxy, int32_t systemAbilityId);
uint32_t GetSeqNumber();
bool RegisterRemoteProxyInner(std::u16string serviceName, binder_uintptr_t binder);
bool CheckSystemAbilityId(int32_t systemAbilityId);
......
......@@ -145,11 +145,12 @@ std::u16string IPCObjectProxy::GetInterfaceDescriptor()
return remoteDescriptor_;
}
std::string IPCObjectProxy::GetPidAndUidInfo()
std::string IPCObjectProxy::GetPidAndUidInfo(int32_t systemAbilityId)
{
MessageParcel data, reply;
MessageOption option;
data.WriteInt32(systemAbilityId);
int32_t err = SendRequestInner(false, GET_UIDPID_INFO, data, reply, option);
if (err != ERR_NONE) {
ZLOGE(LABEL, "GetPidAndUidInfo SendRequestInner return error = %{public}d", err);
......@@ -158,11 +159,12 @@ std::string IPCObjectProxy::GetPidAndUidInfo()
return reply.ReadString();
}
std::string IPCObjectProxy::GetDataBusName()
std::string IPCObjectProxy::GetDataBusName(int32_t systemAbilityId)
{
MessageParcel data, reply;
MessageOption option;
data.WriteInt32(systemAbilityId);
int32_t err = SendRequestInner(false, GRANT_DATABUS_NAME, data, reply, option);
if (err != ERR_NONE) {
ZLOGE(LABEL, "GetDataBusName transact return error = %{public}d", err);
......@@ -260,21 +262,16 @@ void IPCObjectProxy::OnLastStrongRef(const void *objectId)
ZLOGE(LABEL, "OnLastStrongRef current is null");
return;
}
if (current->DetachObject(this) == false) { // if detach successfully, this proxy will be destroyed
return;
}
#ifndef CONFIG_IPC_SINGLE
ReleaseProto();
std::shared_ptr<DBinderSessionObject> session = nullptr;
session = current->ProxyQueryDBinderSession(handle_);
(void)current->ProxyDetachDBinderSession(handle_);
(void)current->DetachHandleToIndex(handle_);
#endif
{
std::lock_guard<std::recursive_mutex> lock(current->mutex_);
if (current->DetachObjectInner(this) == false) { // if detach successfully, this proxy will be destroyed
return;
}
#ifndef CONFIG_IPC_SINGLE
ReleaseProto();
session = current->ProxyQueryDBinderSession(handle_);
(void)current->ProxyDetachDBinderSession(handle_);
(void)current->DetachHandleToIndex(handle_);
#endif
}
IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker();
if (invoker != nullptr) {
invoker->ReleaseHandle(handle_);
......
......@@ -241,7 +241,8 @@ int IPCObjectStub::SendRequest(uint32_t code, MessageParcel &data, MessageParcel
result = IPC_STUB_INVALID_DATA_ERR;
break;
}
std::string sessionName = GetDataBusName();
int32_t systemAbilityId = data.ReadInt32();
std::string sessionName = GetDataBusName(systemAbilityId);
if (sessionName.empty()) {
ZLOGE(LABEL, "sessionName is empty");
result = IPC_STUB_CREATE_BUS_SERVER_ERR;
......@@ -456,7 +457,6 @@ int32_t IPCObjectStub::IncStubRefs(MessageParcel &data, MessageParcel &reply)
ZLOGE(LABEL, "%s: current is null", __func__);
return IPC_STUB_CURRENT_NULL_ERR;
}
std::string deviceId = IPCSkeleton::GetCallingDeviceID();
if (deviceId.empty()) {
ZLOGE(LABEL, "%s: calling error", __func__);
......@@ -466,11 +466,9 @@ int32_t IPCObjectStub::IncStubRefs(MessageParcel &data, MessageParcel &reply)
ZLOGE(LABEL, "%s: attach stub ref info err, already in", __func__);
return ERR_NONE;
}
if (!current->DecStubRefTimes(this)) {
this->IncStrongRef(this);
}
return ERR_NONE;
}
......@@ -531,7 +529,7 @@ int32_t IPCObjectStub::AddAuthInfo(MessageParcel &data, MessageParcel &reply, ui
return ERR_NONE;
}
std::string IPCObjectStub::GetDataBusName()
std::string IPCObjectStub::GetDataBusName(int32_t systemAbilityId)
{
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
if (current == nullptr) {
......@@ -545,14 +543,15 @@ std::string IPCObjectStub::GetDataBusName()
}
IPCObjectProxy *samgr = reinterpret_cast<IPCObjectProxy *>(object.GetRefPtr());
return samgr->GetDataBusName();
return samgr->GetDataBusName(systemAbilityId);
}
int32_t IPCObjectStub::GrantDataBusName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
int pid = IPCSkeleton::GetCallingPid();
int uid = IPCSkeleton::GetCallingUid();
std::string sessionName = CreateDatabusName(uid, pid);
int systemAbilityId = data.ReadInt32();
std::string sessionName = CreateDatabusName(uid, pid, systemAbilityId);
if (sessionName.empty()) {
ZLOGE(LABEL, "pid/uid is invalid, pid = {public}%d, uid = {public}%d", pid, uid);
return IPC_STUB_INVALID_DATA_ERR;
......@@ -573,7 +572,7 @@ int32_t IPCObjectStub::TransDataBusName(uint32_t code, MessageParcel &data, Mess
ZLOGE(LABEL, "pid/uid is invalid, pid = {public}%d, uid = {public}%d", remotePid, remoteUid);
return IPC_STUB_INVALID_DATA_ERR;
}
std::string sessionName = CreateDatabusName(remoteUid, remotePid);
std::string sessionName = CreateDatabusName(remoteUid, remotePid, 0);
if (sessionName.empty()) {
ZLOGE(LABEL, "pid/uid is invalid, pid = {public}%d, uid = {public}%d", remotePid, remoteUid);
return IPC_STUB_INVALID_DATA_ERR;
......@@ -586,7 +585,7 @@ int32_t IPCObjectStub::TransDataBusName(uint32_t code, MessageParcel &data, Mess
return ERR_NONE;
}
std::string IPCObjectStub::CreateDatabusName(int uid, int pid)
std::string IPCObjectStub::CreateDatabusName(int uid, int pid, int systemAbilityId)
{
std::shared_ptr<ISessionService> softbusManager = ISessionService::GetInstance();
if (softbusManager == nullptr) {
......@@ -595,6 +594,9 @@ std::string IPCObjectStub::CreateDatabusName(int uid, int pid)
}
std::string sessionName = "DBinder" + std::to_string(uid) + std::string("_") + std::to_string(pid);
if (systemAbilityId > 0) {
sessionName += std::string("_") + std::to_string(systemAbilityId);
}
if (softbusManager->GrantPermission(uid, pid, sessionName) != ERR_NONE) {
ZLOGE(LABEL, "fail to Grant Permission softbus name");
return "";
......
......@@ -467,7 +467,6 @@ bool IPCProcessSkeleton::QueryProxyBySessionHandle(uint32_t handle, std::vector<
proxyHandle.push_back(it->first);
}
}
return true;
}
......@@ -1207,7 +1206,6 @@ bool IPCProcessSkeleton::AttachCommAuthInfo(IRemoteObject *stub, int pid, int ui
auto check = [&stub, &pid, &uid, &deviceId, this](const std::shared_ptr<CommAuthInfo> &auth) {
return IsSameRemoteObject(stub, pid, uid, deviceId, auth);
};
std::unique_lock<std::shared_mutex> lockGuard(commAuthMutex_);
auto it = std::find_if(commAuth_.begin(), commAuth_.end(), check);
if (it != commAuth_.end()) {
......@@ -1225,7 +1223,6 @@ void IPCProcessSkeleton::DetachCommAuthInfo(IRemoteObject *stub, int pid, int ui
auto check = [&stub, &pid, &uid, &deviceId, this](const std::shared_ptr<CommAuthInfo> &auth) {
return IsSameRemoteObject(stub, pid, uid, deviceId, auth);
};
std::unique_lock<std::shared_mutex> lockGuard(commAuthMutex_);
commAuth_.remove_if(check);
}
......@@ -1235,7 +1232,6 @@ std::shared_ptr<FeatureSetData> IPCProcessSkeleton::QueryIsAuth(int pid, int uid
auto check = [&pid, &uid, &deviceId, this](const std::shared_ptr<CommAuthInfo> &auth) {
return IsSameRemoteObject(pid, uid, deviceId, auth);
};
std::shared_lock<std::shared_mutex> lockGuard(commAuthMutex_);
auto it = std::find_if(commAuth_.begin(), commAuth_.end(), check);
if (it != commAuth_.end()) {
......
......@@ -570,7 +570,7 @@ int BinderInvoker::HandleReply(MessageParcel *reply)
int BinderInvoker::HandleCommandsInner(uint32_t cmd)
{
int error = ERR_NONE;
ZLOGD(LABEL, "HandleCommands:cmd:%{public}u\n", cmd);
ZLOGD(LABEL, "HandleCommands:cmd:%{public}u", cmd);
switch (cmd) {
case BR_ERROR:
error = input_.ReadInt32();
......@@ -679,7 +679,7 @@ int BinderInvoker::TransactWithDriver(bool doRead)
bwr.write_consumed = 0;
bwr.read_consumed = 0;
ZLOGD(LABEL, "TransactWithDriver write_size:%lld, read_size:%lld\n", bwr.write_size, bwr.read_size);
ZLOGD(LABEL, "TransactWithDriver write_size:%lld, read_size:%lld", bwr.write_size, bwr.read_size);
int error = binderConnector_->WriteBinder(BINDER_WRITE_READ, &bwr);
if (bwr.write_consumed > 0) {
if (bwr.write_consumed < output_.GetDataSize()) {
......@@ -693,7 +693,7 @@ int BinderInvoker::TransactWithDriver(bool doRead)
input_.RewindRead(0);
}
if (error != ERR_NONE) {
ZLOGE(LABEL, "TransactWithDriver result = %{public}d\n", error);
ZLOGE(LABEL, "TransactWithDriver result = %{public}d", error);
}
return error;
......@@ -908,6 +908,8 @@ bool BinderInvoker::FlattenObject(Parcel &parcel, const IRemoteObject *object) c
flat.hdr.type = BINDER_TYPE_BINDER;
flat.binder = reinterpret_cast<uintptr_t>(object);
flat.cookie = flat.binder;
ZLOGD(LABEL, "write stub object: %{public}s, ptr=%{public}p",
Str16ToStr8(object->GetObjectDescriptor()).c_str(), object);
}
flat.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
......
......@@ -79,7 +79,6 @@ std::shared_ptr<DBinderSessionObject> DBinderDatabusInvoker::NewSessionOfBinderP
DBINDER_LOGE("current ipc process skeleton is nullptr");
return nullptr;
}
sptr<IPCObjectProxy> ipcProxy = reinterpret_cast<IPCObjectProxy *>(current->FindOrNewObject(handle).GetRefPtr());
if (ipcProxy == nullptr) {
DBINDER_LOGE("attempt to send a invalid handle = %u", handle);
......@@ -91,7 +90,7 @@ std::shared_ptr<DBinderSessionObject> DBinderDatabusInvoker::NewSessionOfBinderP
return nullptr;
}
std::string sessionName = ipcProxy->GetPidAndUidInfo();
std::string sessionName = ipcProxy->GetPidAndUidInfo(0);
if (sessionName.empty()) {
DBINDER_LOGE("get bus name error");
return nullptr;
......@@ -324,6 +323,7 @@ void DBinderDatabusInvoker::OnMessageAvailable(std::shared_ptr<Session> session,
readSize += packageSize;
} else {
// If the current is abnormal, the subsequent is no longer processed.
DBINDER_LOGE("not complete message");
break;
}
} while (readSize + sizeof(dbinder_transaction_data) < static_cast<uint32_t>(len));
......
......@@ -490,7 +490,7 @@ bool DBinderService::OnRemoteInvokerMessage(const struct DHandleEntryTxRx *messa
return true;
}
std::string DBinderService::GetDatabusNameByProxy(IPCObjectProxy *proxy)
std::string DBinderService::GetDatabusNameByProxy(IPCObjectProxy *proxy, int32_t systemAbilityId)
{
if (proxy == nullptr) {
DBINDER_LOGE("proxy can not be null");
......@@ -501,7 +501,7 @@ std::string DBinderService::GetDatabusNameByProxy(IPCObjectProxy *proxy)
DBINDER_LOGI("sessionName has been granded");
return sessionName;
}
sessionName = proxy->GetPidAndUidInfo();
sessionName = proxy->GetPidAndUidInfo(systemAbilityId);
if (sessionName.empty()) {
DBINDER_LOGE("grand session name failed");
return "";
......@@ -556,7 +556,7 @@ bool DBinderService::OnRemoteInvokerDataBusMessage(IPCObjectProxy *proxy, struct
DBINDER_LOGE("remote device id is error");
return false;
}
std::string sessionName = GetDatabusNameByProxy(proxy);
std::string sessionName = GetDatabusNameByProxy(proxy, replyMessage->stubIndex);
if (sessionName.empty()) {
DBINDER_LOGE("get bus name fail");
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册