SWDEV-369548 - Disallow opening an ipc mem handle in the originating process.

Change-Id: Icce5e41a220566141bd7d92b7199d477f60bed8e


[ROCm/clr commit: 30e740023b]
This commit is contained in:
Ioannis Assiouras
2022-11-29 10:16:54 +00:00
orang tua f1407eb433
melakukan f3c412b183
3 mengubah file dengan 9 tambahan dan 7 penghapusan
+2 -2
Melihat File
@@ -192,7 +192,7 @@ hipError_t IPCEvent::GetHandle(ihipIpcEventHandle_t* handle) {
return hipErrorInvalidValue;
}
ipc_evt_.ipc_shmem_->owners_device_id = deviceId();
ipc_evt_.ipc_shmem_->owners_process_id = getpid();
ipc_evt_.ipc_shmem_->owners_process_id = amd::Os::getProcessId();
memset(handle->shmem_name, 0, HIP_IPC_HANDLE_SIZE);
ipc_evt_.ipc_name_.copy(handle->shmem_name, std::string::npos);
return hipSuccess;
@@ -206,7 +206,7 @@ hipError_t IPCEvent::OpenHandle(ihipIpcEventHandle_t* handle) {
return hipErrorInvalidValue;
}
if (getpid() == ipc_evt_.ipc_shmem_->owners_process_id.load()) {
if (amd::Os::getProcessId() == ipc_evt_.ipc_shmem_->owners_process_id.load()) {
// If this is in the same process, return error.
return hipErrorInvalidContext;
}
+2 -5
Melihat File
@@ -50,12 +50,13 @@
/*! IHIP IPC MEMORY Structure */
#define IHIP_IPC_MEM_HANDLE_SIZE 32
#define IHIP_IPC_MEM_RESERVED_SIZE LP64_SWITCH(24,16)
#define IHIP_IPC_MEM_RESERVED_SIZE LP64_SWITCH(20,12)
typedef struct ihipIpcMemHandle_st {
char ipc_handle[IHIP_IPC_MEM_HANDLE_SIZE]; ///< ipc memory handle on ROCr
size_t psize;
size_t poffset;
int owners_process_id;
char reserved[IHIP_IPC_MEM_RESERVED_SIZE];
} ihipIpcMemHandle_t;
@@ -68,10 +69,6 @@ typedef struct ihipIpcEventHandle_st {
char shmem_name[IHIP_IPC_EVENT_HANDLE_SIZE];
}ihipIpcEventHandle_t;
#ifdef _WIN32
inline int getpid() { return _getpid(); }
#endif
const char* ihipGetErrorName(hipError_t hip_error);
static amd::Monitor g_hipInitlock{"hipInit lock"};
@@ -2943,6 +2943,7 @@ hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* dev_ptr) {
LogPrintfError("IPC memory creation failed for memory: 0x%x", dev_ptr);
HIP_RETURN(hipErrorInvalidValue);
}
ihandle->owners_process_id = amd::Os::getProcessId();
HIP_RETURN(hipSuccess);
}
@@ -2966,6 +2967,10 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne
HIP_RETURN(hipErrorInvalidValue);
}
if (ihandle->owners_process_id == amd::Os::getProcessId()) {
HIP_RETURN(hipErrorInvalidContext);
}
if(!device->IpcAttach(&(ihandle->ipc_handle), ihandle->psize,
ihandle->poffset, flags, dev_ptr)) {
LogPrintfError("Cannot attach ipc_handle: with ipc_size: %u"