Skip to content

Commit 2f2c207

Browse files
committed
Initial impl
1 parent 87f6f2a commit 2f2c207

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/pb_memory.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
// Copyright 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
//
33
// Redistribution and use in source and binary forms, with or without
44
// modification, are permitted provided that the following conditions
@@ -226,6 +226,11 @@ PbMemory::LoadFromSharedMemory(
226226
MemoryShm* memory_shm_ptr = reinterpret_cast<MemoryShm*>(data_shm);
227227
char* memory_data_shm = data_shm + sizeof(MemoryShm);
228228

229+
if (memory_data_shm + memory_shm_ptr->byte_size >
230+
(char*)shm_pool->GetBaseAddress() + shm_pool->GetCurrentCapacity()) {
231+
throw PythonBackendException("Attempted to access out of bounds memory.");
232+
}
233+
229234
char* data_ptr = nullptr;
230235
bool opened_cuda_ipc_handle = false;
231236
if (memory_shm_ptr->memory_type == TRITONSERVER_MEMORY_GPU &&
@@ -275,6 +280,11 @@ PbMemory::LoadFromSharedMemory(
275280
reinterpret_cast<MemoryShm*>(memory_shm.data_.get());
276281
char* memory_data_shm = memory_shm.data_.get() + sizeof(MemoryShm);
277282

283+
if (memory_data_shm + memory_shm_ptr->byte_size >
284+
(char*)shm_pool->GetBaseAddress() + shm_pool->GetCurrentCapacity()) {
285+
throw PythonBackendException("Attempted to access out of bounds memory.");
286+
}
287+
278288
char* data_ptr = nullptr;
279289
bool opened_cuda_ipc_handle = false;
280290
if (memory_shm_ptr->memory_type == TRITONSERVER_MEMORY_GPU) {

src/shm_manager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
// Copyright 2021-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
//
33
// Redistribution and use in source and binary forms, with or without
44
// modification, are permitted provided that the following conditions
@@ -188,6 +188,9 @@ class SharedMemoryManager {
188188
return cuda_memory_pool_manager_;
189189
}
190190

191+
uint64_t GetCurrentCapacity() { return current_capacity_; }
192+
void* GetBaseAddress() { return managed_buffer_->get_address(); }
193+
191194
~SharedMemoryManager() noexcept(false);
192195

193196
private:

0 commit comments

Comments
 (0)