|
1 |
| -// Copyright 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 1 | +// Copyright 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
2 | 2 | //
|
3 | 3 | // Redistribution and use in source and binary forms, with or without
|
4 | 4 | // modification, are permitted provided that the following conditions
|
|
26 | 26 |
|
27 | 27 | #include "pb_memory.h"
|
28 | 28 |
|
| 29 | +#include <sstream> |
| 30 | + |
29 | 31 | namespace triton { namespace backend { namespace python {
|
30 | 32 |
|
31 | 33 | std::unique_ptr<PbMemory>
|
@@ -225,7 +227,6 @@ PbMemory::LoadFromSharedMemory(
|
225 | 227 | {
|
226 | 228 | MemoryShm* memory_shm_ptr = reinterpret_cast<MemoryShm*>(data_shm);
|
227 | 229 | char* memory_data_shm = data_shm + sizeof(MemoryShm);
|
228 |
| - |
229 | 230 | char* data_ptr = nullptr;
|
230 | 231 | bool opened_cuda_ipc_handle = false;
|
231 | 232 | if (memory_shm_ptr->memory_type == TRITONSERVER_MEMORY_GPU &&
|
@@ -260,6 +261,19 @@ PbMemory::LoadFromSharedMemory(
|
260 | 261 | } else {
|
261 | 262 | data_ptr = memory_data_shm;
|
262 | 263 | }
|
| 264 | + |
| 265 | + // This check only validates CPU shared memory access. |
| 266 | + if (memory_shm_ptr->memory_type != TRITONSERVER_MEMORY_GPU && |
| 267 | + (data_ptr + memory_shm_ptr->byte_size > |
| 268 | + (char*)shm_pool->GetBaseAddress() + shm_pool->GetCurrentCapacity())) { |
| 269 | + std::ostringstream oss; |
| 270 | + oss << "0x" << std::hex |
| 271 | + << (reinterpret_cast<uintptr_t>(data_ptr) + memory_shm_ptr->byte_size); |
| 272 | + throw PythonBackendException( |
| 273 | + std::string("Attempted to access out of bounds memory address ") + |
| 274 | + oss.str()); |
| 275 | + } |
| 276 | + |
263 | 277 | return std::unique_ptr<PbMemory>(new PbMemory(
|
264 | 278 | data_shm, data_ptr, handle,
|
265 | 279 | opened_cuda_ipc_handle /* opened_cuda_ipc_handle */));
|
@@ -309,6 +323,19 @@ PbMemory::LoadFromSharedMemory(
|
309 | 323 | } else {
|
310 | 324 | data_ptr = memory_data_shm;
|
311 | 325 | }
|
| 326 | + |
| 327 | + // This check only validates CPU shared memory access. |
| 328 | + if (memory_shm_ptr->memory_type != TRITONSERVER_MEMORY_GPU && |
| 329 | + (data_ptr + memory_shm_ptr->byte_size > |
| 330 | + (char*)shm_pool->GetBaseAddress() + shm_pool->GetCurrentCapacity())) { |
| 331 | + std::ostringstream oss; |
| 332 | + oss << "0x" << std::hex |
| 333 | + << (reinterpret_cast<uintptr_t>(data_ptr) + memory_shm_ptr->byte_size); |
| 334 | + throw PythonBackendException( |
| 335 | + std::string("Attempted to access out of bounds memory address ") + |
| 336 | + oss.str()); |
| 337 | + } |
| 338 | + |
312 | 339 | return std::unique_ptr<PbMemory>(new PbMemory(
|
313 | 340 | memory_shm, data_ptr,
|
314 | 341 | opened_cuda_ipc_handle /* opened_cuda_ipc_handle */));
|
|
0 commit comments