Skip to content

Commit 3cdfa11

Browse files
committed
Revert "fix: Proper handling of system shm register offset (#8330) (#8334)"
This reverts commit b0ee457.
1 parent 903fbd0 commit 3cdfa11

4 files changed

Lines changed: 19 additions & 142 deletions

File tree

qa/L0_shared_memory/shared_memory_test.py

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def _configure_server(
114114
shm_op1_handle,
115115
]
116116
# Implicit assumption that input and output byte_sizes are 64 bytes for now
117+
input0_data = np.arange(start=0, stop=16, dtype=np.int32)
118+
input1_data = np.ones(shape=16, dtype=np.int32)
119+
shm.set_shared_memory_region(shm_ip0_handle, [input0_data])
120+
shm.set_shared_memory_region(shm_ip1_handle, [input1_data])
117121
self.triton_client.register_system_shared_memory(
118122
"input0_data", "/input0_data", register_byte_size, offset=register_offset
119123
)
@@ -126,16 +130,6 @@ def _configure_server(
126130
self.triton_client.register_system_shared_memory(
127131
"output1_data", "/output1_data", register_byte_size, offset=register_offset
128132
)
129-
130-
# Write data to shared memory regions
131-
input0_data = np.arange(start=0, stop=16, dtype=np.int32)
132-
input1_data = np.ones(shape=16, dtype=np.int32)
133-
shm.set_shared_memory_region(
134-
shm_ip0_handle, [input0_data], offset=register_offset
135-
)
136-
shm.set_shared_memory_region(
137-
shm_ip1_handle, [input1_data], offset=register_offset
138-
)
139133
self.shm_names = ["input0_data", "input1_data", "output0_data", "output1_data"]
140134

141135
def _cleanup_shm_handles(self):
@@ -299,39 +293,6 @@ def test_too_big_shm(self):
299293
self._shm_handles.append(shm_ip2_handle)
300294
self._cleanup_shm_handles()
301295

302-
def test_large_shm_register_offset(self):
303-
# Test for out of bounds read vulnerability when registering system shared memory with large offset
304-
for platform in ["python", "onnx", "libtorch", "plan", "openvino"]:
305-
model_name = f"{platform}_int32_int32_int32"
306-
307-
# Test for large offset
308-
error_msg = []
309-
# Create a large shm size (page_size * 1024 is large enough to reproduce a segfault).
310-
# Register offset at 1 page before the end of the shm region to give enough space for the input/output data.
311-
create_byte_size = self.SYS_PAGE_SIZE * 1024
312-
register_offset = self.SYS_PAGE_SIZE * 1023
313-
self._configure_server(
314-
create_byte_size=create_byte_size,
315-
register_offset=register_offset,
316-
)
317-
318-
iu.shm_basic_infer(
319-
self,
320-
self.triton_client,
321-
self._shm_handles[0],
322-
self._shm_handles[1],
323-
self._shm_handles[2],
324-
self._shm_handles[3],
325-
error_msg,
326-
register_offset=register_offset,
327-
protocol=self.protocol,
328-
use_system_shared_memory=True,
329-
override_model_name=model_name,
330-
)
331-
self.triton_client.unregister_system_shared_memory()
332-
if len(error_msg) > 0:
333-
raise Exception(str(error_msg))
334-
335296
def test_mixed_raw_shm(self):
336297
# Mix of shared memory and RAW inputs
337298
error_msg = []

qa/L0_shared_memory/test.sh

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,12 @@
2525
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

28-
REPO_VERSION=${NVIDIA_TRITON_SERVER_VERSION}
29-
if [ "$#" -ge 1 ]; then
30-
REPO_VERSION=$1
31-
fi
32-
if [ -z "$REPO_VERSION" ]; then
33-
echo -e "Repository version must be specified"
34-
echo -e "\n***\n*** Test Failed\n***"
35-
exit 1
36-
fi
37-
if [ ! -z "$TEST_REPO_ARCH" ]; then
38-
REPO_VERSION=${REPO_VERSION}_${TEST_REPO_ARCH}
39-
fi
40-
4128
CLIENT_LOG="./client.log"
4229
SHM_TEST=shared_memory_test.py
4330
TEST_RESULT_FILE='test_results.txt'
4431

4532
# Configure to support test on jetson as well
4633
TRITON_DIR=${TRITON_DIR:="/opt/tritonserver"}
47-
DATADIR=/data/inferenceserver/${REPO_VERSION}
4834
SERVER=${TRITON_DIR}/bin/tritonserver
4935
BACKEND_DIR=${TRITON_DIR}/backends
5036
SERVER_ARGS_EXTRA="--backend-directory=${BACKEND_DIR}"
@@ -157,60 +143,6 @@ for test_case in \
157143
done
158144
done
159145

160-
# Test large system shared memory offset
161-
rm -rf models/*
162-
# prepare add_sub model of various backends
163-
BACKENDS="python onnx libtorch plan openvino"
164-
for backend in ${BACKENDS} ; do
165-
model="${backend}_int32_int32_int32"
166-
model_dir="models/${model}"
167-
if [[ $backend == "python" ]]; then
168-
mkdir -p ${model_dir}/1
169-
cp ../python_models/add_sub/model.py ${model_dir}/1/
170-
cp ../python_models/add_sub/config.pbtxt ${model_dir}/
171-
sed -i 's/TYPE_FP32/TYPE_INT32/g' ${model_dir}/config.pbtxt
172-
echo "max_batch_size: 8" >> ${model_dir}/config.pbtxt
173-
else
174-
mkdir -p ${model_dir}
175-
cp -r $DATADIR/qa_model_repository/${model}/1 ${model_dir}/1
176-
cp $DATADIR/qa_model_repository/${model}/config.pbtxt ${model_dir}/
177-
cp $DATADIR/qa_model_repository/${model}/output0_labels.txt ${model_dir}/
178-
if [ $backend == "openvino" ]; then
179-
echo 'parameters { key: "ENABLE_BATCH_PADDING" value { string_value: "YES" } }' >> models/${model}/config.pbtxt
180-
fi
181-
fi
182-
done
183-
184-
test_case="test_large_shm_register_offset"
185-
for client_type in http grpc; do
186-
SERVER_ARGS="--model-repository=`pwd`/models --log-verbose=1 ${SERVER_ARGS_EXTRA}"
187-
SERVER_LOG="./${test_case}.${client_type}.server.log"
188-
run_server
189-
if [ "$SERVER_PID" == "0" ]; then
190-
echo -e "\n***\n*** Failed to start $SERVER\n***"
191-
cat $SERVER_LOG
192-
exit 1
193-
fi
194-
195-
export CLIENT_TYPE=$client_type
196-
CLIENT_LOG="./${test_case}.${client_type}.client.log"
197-
set +e
198-
python3 $SHM_TEST SharedMemoryTest.${test_case} >>"$CLIENT_LOG" 2>&1
199-
if [ $? -ne 0 ]; then
200-
cat $CLIENT_LOG
201-
echo -e "\n***\n*** Test Failed - ${client_type}\n***"
202-
RET=1
203-
fi
204-
205-
kill $SERVER_PID
206-
wait $SERVER_PID
207-
if [ $? -ne 0 ]; then
208-
echo -e "\n***\n*** Test Server shut down non-gracefully\n***"
209-
RET=1
210-
fi
211-
set -e
212-
done
213-
214146
if [ $RET -eq 0 ]; then
215147
echo -e "\n***\n*** Test Passed\n***"
216148
else

qa/common/infer_util.py

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

3-
# Copyright 2018-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# Copyright 2018-2024, 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
@@ -1367,13 +1367,11 @@ def shm_basic_infer(
13671367
big_shm_name="",
13681368
big_shm_size=64,
13691369
default_shm_byte_size=64,
1370-
register_offset=0,
13711370
shm_output_offset=0,
13721371
shm_output_byte_size=64,
13731372
protocol="http",
13741373
use_system_shared_memory=False,
13751374
use_cuda_shared_memory=False,
1376-
override_model_name=None,
13771375
):
13781376
# Lazy shm imports...
13791377
if use_system_shared_memory:
@@ -1383,34 +1381,20 @@ def shm_basic_infer(
13831381
else:
13841382
raise Exception("No shared memory type specified")
13851383

1386-
if override_model_name is None:
1387-
model_name = "simple"
1388-
else:
1389-
model_name = override_model_name
1390-
1391-
if model_name.startswith("libtorch"):
1392-
output_names = ["OUTPUT__0", "OUTPUT__1"]
1393-
else:
1394-
output_names = ["OUTPUT0", "OUTPUT1"]
1395-
13961384
input0_data = np.arange(start=0, stop=16, dtype=np.int32)
13971385
input1_data = np.ones(shape=16, dtype=np.int32)
13981386
inputs = []
13991387
outputs = []
14001388
if protocol == "http":
14011389
inputs.append(httpclient.InferInput("INPUT0", [1, 16], "INT32"))
14021390
inputs.append(httpclient.InferInput("INPUT1", [1, 16], "INT32"))
1403-
outputs.append(
1404-
httpclient.InferRequestedOutput(output_names[0], binary_data=True)
1405-
)
1406-
outputs.append(
1407-
httpclient.InferRequestedOutput(output_names[1], binary_data=False)
1408-
)
1391+
outputs.append(httpclient.InferRequestedOutput("OUTPUT0", binary_data=True))
1392+
outputs.append(httpclient.InferRequestedOutput("OUTPUT1", binary_data=False))
14091393
else:
14101394
inputs.append(grpcclient.InferInput("INPUT0", [1, 16], "INT32"))
14111395
inputs.append(grpcclient.InferInput("INPUT1", [1, 16], "INT32"))
1412-
outputs.append(grpcclient.InferRequestedOutput(output_names[0]))
1413-
outputs.append(grpcclient.InferRequestedOutput(output_names[1]))
1396+
outputs.append(grpcclient.InferRequestedOutput("OUTPUT0"))
1397+
outputs.append(grpcclient.InferRequestedOutput("OUTPUT1"))
14141398

14151399
inputs[0].set_shared_memory("input0_data", default_shm_byte_size)
14161400

@@ -1430,9 +1414,9 @@ def shm_basic_infer(
14301414

14311415
try:
14321416
results = triton_client.infer(
1433-
model_name, inputs, model_version="", outputs=outputs
1417+
"simple", inputs, model_version="", outputs=outputs
14341418
)
1435-
output = results.get_output(output_names[0])
1419+
output = results.get_output("OUTPUT0")
14361420
if protocol == "http":
14371421
output_datatype = output["datatype"]
14381422
output_shape = output["shape"]
@@ -1443,16 +1427,11 @@ def shm_basic_infer(
14431427

14441428
if use_system_shared_memory:
14451429
output_data = shm.get_contents_as_numpy(
1446-
shm_op0_handle,
1447-
output_dtype,
1448-
output_shape,
1449-
offset=register_offset + shm_output_offset,
1430+
shm_op0_handle, output_dtype, output_shape
14501431
)
14511432
elif use_cuda_shared_memory:
14521433
output_data = cudashm.get_contents_as_numpy(
1453-
shm_op0_handle,
1454-
output_dtype,
1455-
output_shape,
1434+
shm_op0_handle, output_dtype, output_shape
14561435
)
14571436

14581437
tester.assertTrue(

src/shared_memory_manager.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,12 @@ SharedMemoryManager::GetMemoryInfo(
513513
*shm_info = std::static_pointer_cast<const SharedMemoryInfo>(it->second);
514514
}
515515

516-
*shm_mapped_addr = (void*)((uint8_t*)it->second->mapped_addr_ + offset);
516+
if (it->second->kind_ == TRITONSERVER_MEMORY_CPU) {
517+
*shm_mapped_addr = (void*)((uint8_t*)it->second->mapped_addr_ +
518+
it->second->offset_ + offset);
519+
} else {
520+
*shm_mapped_addr = (void*)((uint8_t*)it->second->mapped_addr_ + offset);
521+
}
517522

518523
*memory_type = it->second->kind_;
519524
*device_id = it->second->device_id_;

0 commit comments

Comments
 (0)