Skip to content

fix: Verify MemoryShm::byte_size inside shared memory boundary #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/pb_memory.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -226,6 +226,11 @@ PbMemory::LoadFromSharedMemory(
MemoryShm* memory_shm_ptr = reinterpret_cast<MemoryShm*>(data_shm);
char* memory_data_shm = data_shm + sizeof(MemoryShm);

if (memory_data_shm + memory_shm_ptr->byte_size >
(char*)shm_pool->GetBaseAddress() + shm_pool->GetCurrentCapacity()) {
throw PythonBackendException("Attempted to access out of bounds memory.");
}

char* data_ptr = nullptr;
bool opened_cuda_ipc_handle = false;
if (memory_shm_ptr->memory_type == TRITONSERVER_MEMORY_GPU &&
Expand Down Expand Up @@ -275,6 +280,11 @@ PbMemory::LoadFromSharedMemory(
reinterpret_cast<MemoryShm*>(memory_shm.data_.get());
char* memory_data_shm = memory_shm.data_.get() + sizeof(MemoryShm);

if (memory_data_shm + memory_shm_ptr->byte_size >
(char*)shm_pool->GetBaseAddress() + shm_pool->GetCurrentCapacity()) {
throw PythonBackendException("Attempted to access out of bounds memory.");
}

char* data_ptr = nullptr;
bool opened_cuda_ipc_handle = false;
if (memory_shm_ptr->memory_type == TRITONSERVER_MEMORY_GPU) {
Expand Down
5 changes: 4 additions & 1 deletion src/shm_manager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright 2021-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -188,6 +188,9 @@ class SharedMemoryManager {
return cuda_memory_pool_manager_;
}

uint64_t GetCurrentCapacity() { return current_capacity_; }
void* GetBaseAddress() { return managed_buffer_->get_address(); }

~SharedMemoryManager() noexcept(false);

private:
Expand Down
Loading