Skip to content

Commit 8d62bd8

Browse files
authored
Fix: Update handling of shared mem integer values (#8170)
Added an additional check to prevent the value of byte_size and offset used in a request from exceeding the bounds of shared memory.
1 parent 02706fd commit 8d62bd8

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

qa/L0_shared_memory/shared_memory_test.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# Copyright 2019-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
44
#
55
# Redistribution and use in source and binary forms, with or without
66
# modification, are permitted provided that the following conditions
@@ -385,6 +385,59 @@ def test_infer_byte_size_out_of_bound(self):
385385
)
386386
self._cleanup_shm_handles()
387387

388+
def test_infer_integer_overflow(self):
389+
# Test for integer overflow vulnerability in offset + byte_size calculation
390+
error_msg = []
391+
self._configure_server()
392+
393+
offset = 32
394+
byte_size = 2**64 - 32
395+
396+
if self.protocol == "http":
397+
iu.shm_basic_infer(
398+
self,
399+
self.triton_client,
400+
self._shm_handles[0],
401+
self._shm_handles[1],
402+
self._shm_handles[2],
403+
self._shm_handles[3],
404+
error_msg,
405+
shm_output_offset=offset,
406+
shm_output_byte_size=byte_size,
407+
protocol=self.protocol,
408+
use_system_shared_memory=True,
409+
)
410+
411+
self.assertEqual(len(error_msg), 1)
412+
self.assertTrue(
413+
"Integer overflow detected: byte_size " in error_msg[0],
414+
f"Unexpected error message: {error_msg[0]}",
415+
)
416+
self._cleanup_shm_handles()
417+
else:
418+
# The gRPC client utilizes the int64_param and will throw a separate error for values larger than 2**63-1
419+
try:
420+
iu.shm_basic_infer(
421+
self,
422+
self.triton_client,
423+
self._shm_handles[0],
424+
self._shm_handles[1],
425+
self._shm_handles[2],
426+
self._shm_handles[3],
427+
error_msg,
428+
shm_output_offset=offset,
429+
shm_output_byte_size=byte_size,
430+
protocol=self.protocol,
431+
use_system_shared_memory=True,
432+
)
433+
self.assertTrue(
434+
False,
435+
"Expected gRPC client to fail on value larger than int64_param maximum",
436+
)
437+
except ValueError as ex:
438+
self.assertIn("Value out of range:", str(ex))
439+
self._cleanup_shm_handles()
440+
388441
def test_register_out_of_bound(self):
389442
create_byte_size = self.DEFAULT_SHM_BYTE_SIZE
390443

qa/L0_shared_memory/test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# Copyright 2019-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -53,6 +53,7 @@ for i in \
5353
test_unregisterall \
5454
test_infer_offset_out_of_bound \
5555
test_infer_byte_size_out_of_bound \
56+
test_infer_integer_overflow \
5657
test_register_out_of_bound \
5758
test_python_client_leak; do
5859
for client_type in http grpc; do

src/shared_memory_manager.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
// Copyright 2019-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
@@ -485,6 +485,19 @@ SharedMemoryManager::GetMemoryInfo(
485485
std::string("Invalid offset for shared memory region: '" + name + "'")
486486
.c_str());
487487
}
488+
489+
// Check for potential integer overflow before validating bounds
490+
if (byte_size > (SIZE_MAX - offset)) {
491+
return TRITONSERVER_ErrorNew(
492+
TRITONSERVER_ERROR_INVALID_ARG,
493+
std::string(
494+
"Integer overflow detected: byte_size (" +
495+
std::to_string(byte_size) + ") + offset (" +
496+
std::to_string(offset) + ") exceeds maximum value (" +
497+
std::to_string(SIZE_MAX) + ") for region '" + name + "'")
498+
.c_str());
499+
}
500+
488501
// validate byte_size + offset is within memory bounds
489502
size_t total_req_shm = offset + byte_size - 1;
490503
if (total_req_shm > shm_region_end) {

0 commit comments

Comments
 (0)