88#include <assert.h>
99#include <stdbool.h>
1010#include <stddef.h>
11+ #include <stdint.h>
1112#include <string.h>
1213
1314#include <umf.h>
@@ -754,8 +755,20 @@ static umf_result_t ze_memory_provider_allocation_split(void *provider,
754755typedef struct ze_ipc_data_t {
755756 int pid ;
756757 ze_ipc_mem_handle_t ze_handle ;
758+ uint64_t checksum ;
757759} ze_ipc_data_t ;
758760
761+ // Compute a simple checksum of the ze_handle field in ze_ipc_data_t
762+ static uint64_t ze_ipc_handle_checksum (const ze_ipc_data_t * ipc_data ) {
763+ // Interpret the ze_handle as a byte array
764+ const uint8_t * bytes = (const uint8_t * )& ipc_data -> ze_handle ;
765+ uint64_t checksum = 0 ;
766+ for (size_t i = 0 ; i < sizeof (ipc_data -> ze_handle ); ++ i ) {
767+ checksum += bytes [i ];
768+ }
769+ return checksum ;
770+ }
771+
759772static umf_result_t ze_memory_provider_get_ipc_handle_size (void * provider ,
760773 size_t * size ) {
761774 (void )provider ;
@@ -783,6 +796,7 @@ static umf_result_t ze_memory_provider_get_ipc_handle(void *provider,
783796 }
784797
785798 ze_ipc_data -> pid = utils_getpid ();
799+ ze_ipc_data -> checksum = ze_ipc_handle_checksum (ze_ipc_data );
786800
787801 return UMF_RESULT_SUCCESS ;
788802}
@@ -794,6 +808,11 @@ static umf_result_t ze_memory_provider_put_ipc_handle(void *provider,
794808 (struct ze_memory_provider_t * )provider ;
795809 ze_ipc_data_t * ze_ipc_data = (ze_ipc_data_t * )providerIpcData ;
796810
811+ if (ze_ipc_data -> checksum != ze_ipc_handle_checksum (ze_ipc_data )) {
812+ LOG_FATAL ("Checksum mismatch for IPC handle data." );
813+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
814+ }
815+
797816 if (g_ze_ops .zeMemPutIpcHandle == NULL ) {
798817 // g_ze_ops.zeMemPutIpcHandle can be NULL because it was introduced
799818 // starting from Level Zero 1.6. Before Level Zero 1.6 IPC handle
0 commit comments