VYPR
Critical severityNVD Advisory· Published Sep 25, 2020· Updated Aug 4, 2024

Out of bounds write in tensorflow-lite

CVE-2020-15214

Description

In TensorFlow Lite before versions 2.2.1 and 2.3.1, models using segment sum can trigger a write out bounds / segmentation fault if the segment ids are not sorted. Code assumes that the segment ids are in increasing order, using the last element of the tensor holding them to determine the dimensionality of output tensor. This results in allocating insufficient memory for the output tensor and in a write outside the bounds of the output array. This usually results in a segmentation fault, but depending on runtime conditions it can provide for a write gadget to be used in future memory corruption-based exploits. The issue is patched in commit 204945b19e44b57906c9344c0d00120eeeae178a and is released in TensorFlow versions 2.2.1, or 2.3.1. A potential workaround would be to add a custom Verifier to the model loading code to ensure that the segment ids are sorted, although this only handles the case when the segment ids are stored statically in the model. A similar validation could be done if the segment ids are generated at runtime between inference steps. If the segment ids are generated as outputs of a tensor during inference steps, then there are no possible workaround and users are advised to upgrade to patched code.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
tensorflowPyPI
>= 2.2.0, < 2.2.12.2.1
tensorflowPyPI
>= 2.3.0, < 2.3.12.3.1
tensorflow-cpuPyPI
>= 2.2.0, < 2.2.12.2.1
tensorflow-cpuPyPI
>= 2.3.0, < 2.3.12.3.1
tensorflow-gpuPyPI
>= 2.2.0, < 2.2.12.2.1
tensorflow-gpuPyPI
>= 2.3.0, < 2.3.12.3.1

Affected products

1

Patches

3
a4030d8ba369

[tflite] Validate segment ids for segment_sum.

https://github.com/tensorflow/tensorflowMihai MaruseacSep 18, 2020via ghsa
2 files changed · +48 3
  • tensorflow/lite/kernels/segment_sum.cc+16 3 modified
    @@ -32,11 +32,24 @@ TfLiteStatus ResizeOutputTensor(TfLiteContext* context,
                                     const TfLiteTensor* data,
                                     const TfLiteTensor* segment_ids,
                                     TfLiteTensor* output) {
    -  int max_index = -1;
    +  // Segment ids should be of same cardinality as first input dimension and they
    +  // should be increasing by at most 1, from 0 (e.g., [0, 0, 1, 2, 3] is valid)
       const int segment_id_size = segment_ids->dims->data[0];
    -  if (segment_id_size > 0) {
    -    max_index = segment_ids->data.i32[segment_id_size - 1];
    +  TF_LITE_ENSURE_EQ(context, segment_id_size, data->dims->data[0]);
    +  int previous_segment_id = -1;
    +  for (int i = 0; i < segment_id_size; i++) {
    +    const int current_segment_id = GetTensorData<int32_t>(segment_ids)[i];
    +    if (i == 0) {
    +      TF_LITE_ENSURE_EQ(context, current_segment_id, 0);
    +    } else {
    +      int delta = current_segment_id - previous_segment_id;
    +      TF_LITE_ENSURE(context, delta == 0 || delta == 1);
    +    }
    +    previous_segment_id = current_segment_id;
       }
    +
    +  const int max_index = previous_segment_id;
    +
       const int data_rank = NumDimensions(data);
       TfLiteIntArray* output_shape = TfLiteIntArrayCreate(NumDimensions(data));
       output_shape->data[0] = max_index + 1;
    
  • tensorflow/lite/kernels/segment_sum_test.cc+32 0 modified
    @@ -108,5 +108,37 @@ TEST(SegmentSumOpModelTest, Float32Test_ThreeDimensions) {
       EXPECT_THAT(model.GetOutputShape(), ElementsAreArray({2, 2, 1}));
     }
     
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotSorted) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 3, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotConsecutive) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 3, 5});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNegative) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {-1, 0, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotTheRightCardinality) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {2}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
     }  // namespace
     }  // namespace tflite
    
204945b19e44

[tflite] Validate segment ids for segment_sum.

https://github.com/tensorflow/tensorflowMihai MaruseacSep 18, 2020via ghsa
2 files changed · +48 3
  • tensorflow/lite/kernels/segment_sum.cc+16 3 modified
    @@ -34,11 +34,24 @@ TfLiteStatus ResizeOutputTensor(TfLiteContext* context,
                                     const TfLiteTensor* data,
                                     const TfLiteTensor* segment_ids,
                                     TfLiteTensor* output) {
    -  int max_index = -1;
    +  // Segment ids should be of same cardinality as first input dimension and they
    +  // should be increasing by at most 1, from 0 (e.g., [0, 0, 1, 2, 3] is valid)
       const int segment_id_size = segment_ids->dims->data[0];
    -  if (segment_id_size > 0) {
    -    max_index = segment_ids->data.i32[segment_id_size - 1];
    +  TF_LITE_ENSURE_EQ(context, segment_id_size, data->dims->data[0]);
    +  int previous_segment_id = -1;
    +  for (int i = 0; i < segment_id_size; i++) {
    +    const int current_segment_id = GetTensorData<int32_t>(segment_ids)[i];
    +    if (i == 0) {
    +      TF_LITE_ENSURE_EQ(context, current_segment_id, 0);
    +    } else {
    +      int delta = current_segment_id - previous_segment_id;
    +      TF_LITE_ENSURE(context, delta == 0 || delta == 1);
    +    }
    +    previous_segment_id = current_segment_id;
       }
    +
    +  const int max_index = previous_segment_id;
    +
       const int data_rank = NumDimensions(data);
       TfLiteIntArray* output_shape = TfLiteIntArrayCreate(NumDimensions(data));
       output_shape->data[0] = max_index + 1;
    
  • tensorflow/lite/kernels/segment_sum_test.cc+32 0 modified
    @@ -110,5 +110,37 @@ TEST(SegmentSumOpModelTest, Float32Test_ThreeDimensions) {
       EXPECT_THAT(model.GetOutputShape(), ElementsAreArray({2, 2, 1}));
     }
     
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotSorted) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 3, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotConsecutive) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 3, 5});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNegative) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {-1, 0, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotTheRightCardinality) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {2}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
     }  // namespace
     }  // namespace tflite
    
00c7ed7ce81c

[tflite] Validate segment ids for segment_sum.

https://github.com/tensorflow/tensorflowMihai MaruseacSep 18, 2020via ghsa
2 files changed · +48 3
  • tensorflow/lite/kernels/segment_sum.cc+16 3 modified
    @@ -34,11 +34,24 @@ TfLiteStatus ResizeOutputTensor(TfLiteContext* context,
                                     const TfLiteTensor* data,
                                     const TfLiteTensor* segment_ids,
                                     TfLiteTensor* output) {
    -  int max_index = -1;
    +  // Segment ids should be of same cardinality as first input dimension and they
    +  // should be increasing by at most 1, from 0 (e.g., [0, 0, 1, 2, 3] is valid)
       const int segment_id_size = segment_ids->dims->data[0];
    -  if (segment_id_size > 0) {
    -    max_index = segment_ids->data.i32[segment_id_size - 1];
    +  TF_LITE_ENSURE_EQ(context, segment_id_size, data->dims->data[0]);
    +  int previous_segment_id = -1;
    +  for (int i = 0; i < segment_id_size; i++) {
    +    const int current_segment_id = GetTensorData<int32_t>(segment_ids)[i];
    +    if (i == 0) {
    +      TF_LITE_ENSURE_EQ(context, current_segment_id, 0);
    +    } else {
    +      int delta = current_segment_id - previous_segment_id;
    +      TF_LITE_ENSURE(context, delta == 0 || delta == 1);
    +    }
    +    previous_segment_id = current_segment_id;
       }
    +
    +  const int max_index = previous_segment_id;
    +
       const int data_rank = NumDimensions(data);
       TfLiteIntArray* output_shape = TfLiteIntArrayCreate(NumDimensions(data));
       output_shape->data[0] = max_index + 1;
    
  • tensorflow/lite/kernels/segment_sum_test.cc+32 0 modified
    @@ -110,5 +110,37 @@ TEST(SegmentSumOpModelTest, Float32Test_ThreeDimensions) {
       EXPECT_THAT(model.GetOutputShape(), ElementsAreArray({2, 2, 1}));
     }
     
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotSorted) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 3, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotConsecutive) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 3, 5});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNegative) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {3}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {-1, 0, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
    +TEST(SegmentSumOpModelTest, TestFailIfSegmentsAreNotTheRightCardinality) {
    +  SegmentSumOpModel<int32_t> model({TensorType_INT32, {3, 2}},
    +                                   {TensorType_INT32, {2}});
    +  model.PopulateTensor<int32_t>(model.data(), {1, 2, 3, 4, 5, 6});
    +  model.PopulateTensor<int32_t>(model.segment_ids(), {0, 1});
    +  ASSERT_EQ(model.InvokeUnchecked(), kTfLiteError);
    +}
    +
     }  // namespace
     }  // namespace tflite
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

12

News mentions

0

No linked articles in our index yet.