add uid verify for ProcPutFeature

This commit is contained in:
zjucx 2021-07-02 17:05:01 +08:00
parent fbbe80282f
commit e41b760ebd
3 changed files with 26 additions and 1 deletions

View File

@ -162,6 +162,29 @@ int SASTORA_FindHandleByPid(SAStore *saStore, pid_t callingPid, PidHandle *handl
return INVALID_INDEX;
}
int SASTORA_FindHandleByUidPid(SAStore *saStore, uid_t callingUid, pid_t callingPid, PidHandle *handle)
{
if (saStore == NULL || saStore->maps == NULL || handle == NULL) {
return INVALID_INDEX;
}
int16 high = saStore->mapTop - 1;
int16 low = 0;
while (low <= high) {
// binary search need div 2
int16 mid = (high + low) / 2;
if (saStore->maps[mid].pid == callingPid && saStore->maps[mid].uid == callingUid) {
*handle = saStore->maps[mid];
return mid;
}
if (saStore->maps[mid].pid < callingPid) {
low = mid + 1;
continue;
}
high = mid - 1;
}
return INVALID_INDEX;
}
PidHandle SASTORA_FindPidHandleByIpcHandle(const SAStore *saStore, uint32 handle)
{
PidHandle pidHandle = {INVALID_INDEX, INVALID_INDEX, INVALID_INDEX, INVALID_INDEX};

View File

@ -75,6 +75,7 @@ static inline void SASTORA_Init(SAStore *saStore)
int SASTORA_Save(SAStore *saStore, const char *service, const char *feature, const SvcIdentity *identity);
int SASTORA_SaveHandleByPid(SAStore *saStore, PidHandle handle);
int SASTORA_FindHandleByPid(SAStore *saStore, pid_t callingPid, PidHandle *handle);
int SASTORA_FindHandleByUidPid(SAStore *saStore, uid_t callingUid, pid_t callingPid, PidHandle *handle);
SvcIdentity SASTORA_Find(SAStore *saStore, const char *service, const char *feature);
int SASTORA_ClearByPid(SAStore *saStore, pid_t pid);
PidHandle SASTORA_FindPidHandleByIpcHandle(const SAStore *saStore, uint32 handle);

View File

@ -194,10 +194,11 @@ static int32 ProcPutFeature(SamgrServer *server, const void *origin, IpcIo *req,
return EC_INVALID;
}
pid_t pid = GetCallingPid(origin);
uid_t uid = GetCallingUid(origin);
char *feature = IpcIoPopBool(req) ? NULL : (char *)IpcIoPopString(req, &len);
MUTEX_Lock(server->mtx);
PidHandle handle;
int index = SASTORA_FindHandleByPid(&server->store, pid, &handle);
int index = SASTORA_FindHandleByUidPid(&server->store, uid, pid, &handle);
if (index == INVALID_INDEX) {
MUTEX_Unlock(server->mtx);
HILOG_ERROR(HILOG_MODULE_SAMGR, "Endpoint[%d] is not register", pid);