Skip to content

Commit c0cef6c

Browse files
psiddhGithub Executorch
andauthored
Title: Fix OOB heap read in bundled program tensor deserialization (pytorch#17163)
Summary: This diff addresses a security vulnerability (TOB-EXECUTORCH-9) in the bundled program tensor parsing code. Problem: tensor_like() in bundled_program.cpp copies tensor data using ret_tensor.nbytes() derived from the sizes[] field No validation that data[] buffer actually contains that many bytes A malicious .bpte file could claim large dimensions with minimal data, causing heap over-read Fix: Added null check for bundled_tensor->data() Added size validation: data()->size() >= ret_tensor.nbytes() Memcpy only proceeds if source buffer is sufficiently sized Co-authored-by: Github Executorch <github_executorch@arm.com>
1 parent eee5d96 commit c0cef6c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

devtools/bundled_program/bundled_program.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ at::Tensor tensor_like(bundled_program_flatbuffer::Tensor* bundled_tensor) {
5454
at::Tensor ret_tensor = at::zeros(
5555
{ret_t_sizes, bundled_tensor->sizes()->size()},
5656
at::dtype(static_cast<ScalarType>(bundled_tensor->scalar_type())));
57+
58+
// Validate data buffer exists and has sufficient size
59+
ET_CHECK(bundled_tensor->data() != nullptr);
60+
ET_CHECK_MSG(
61+
bundled_tensor->data()->size() >= ret_tensor.nbytes(),
62+
"Tensor data buffer too small: got %zu bytes, need %zu bytes",
63+
static_cast<size_t>(bundled_tensor->data()->size()),
64+
static_cast<size_t>(ret_tensor.nbytes()));
65+
5766
memcpy(
5867
ret_tensor.mutable_data_ptr(),
5968
static_cast<const void*>(bundled_tensor->data()->Data()),

0 commit comments

Comments
 (0)