VYPR
Low severityNVD Advisory· Published May 14, 2021· Updated Aug 3, 2024

CHECK-fail in SparseConcat

CVE-2021-29534

Description

TensorFlow is an end-to-end open source platform for machine learning. An attacker can trigger a denial of service via a CHECK-fail in tf.raw_ops.SparseConcat. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/b432a38fe0e1b4b904a6c222cbce794c39703e87/tensorflow/core/kernels/sparse_concat_op.cc#L76) takes the values specified in shapes[0] as dimensions for the output shape. The TensorShape constructor(https://github.com/tensorflow/tensorflow/blob/6f9896890c4c703ae0a0845394086e2e1e523299/tensorflow/core/framework/tensor_shape.cc#L183-L188) uses a CHECK operation which triggers when InitDims(https://github.com/tensorflow/tensorflow/blob/6f9896890c4c703ae0a0845394086e2e1e523299/tensorflow/core/framework/tensor_shape.cc#L212-L296) returns a non-OK status. This is a legacy implementation of the constructor and operations should use BuildTensorShapeBase or AddDimWithStatus to prevent CHECK-failures in the presence of overflows. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, as these are also affected and still in supported range.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
tensorflowPyPI
< 2.1.42.1.4
tensorflowPyPI
>= 2.2.0, < 2.2.32.2.3
tensorflowPyPI
>= 2.3.0, < 2.3.32.3.3
tensorflowPyPI
>= 2.4.0, < 2.4.22.4.2
tensorflow-cpuPyPI
< 2.1.42.1.4
tensorflow-cpuPyPI
>= 2.2.0, < 2.2.32.2.3
tensorflow-cpuPyPI
>= 2.3.0, < 2.3.32.3.3
tensorflow-cpuPyPI
>= 2.4.0, < 2.4.22.4.2
tensorflow-gpuPyPI
< 2.1.42.1.4
tensorflow-gpuPyPI
>= 2.2.0, < 2.2.32.2.3
tensorflow-gpuPyPI
>= 2.3.0, < 2.3.32.3.3
tensorflow-gpuPyPI
>= 2.4.0, < 2.4.22.4.2

Affected products

1

Patches

1
69c68ecbb24d

Fix overflow CHECK issue with `tf.raw_ops.AddManySparseToTensorsMap`.

https://github.com/tensorflow/tensorflowAmit PatankarApr 20, 2021via ghsa
1 file changed · +19 7
  • tensorflow/core/kernels/sparse_tensors_map_ops.cc+19 7 modified
    @@ -21,16 +21,14 @@ limitations under the License.
     #include <utility>
     #include <vector>
     
    -#include "tensorflow/core/framework/op_kernel.h"
    -#include "tensorflow/core/framework/register_types.h"
    -
     #include "tensorflow/core/framework/op_kernel.h"
     #include "tensorflow/core/framework/register_types.h"
     #include "tensorflow/core/framework/resource_mgr.h"
     #include "tensorflow/core/framework/tensor.h"
     #include "tensorflow/core/framework/tensor_util.h"
     #include "tensorflow/core/framework/types.h"
     #include "tensorflow/core/lib/gtl/inlined_vector.h"
    +#include "tensorflow/core/util/overflow.h"
     #include "tensorflow/core/util/sparse/sparse_tensor.h"
     
     namespace tensorflow {
    @@ -254,16 +252,30 @@ class AddManySparseToTensorsMapOp : public SparseTensorAccessingOp {
             errors::InvalidArgument(
                 "Rank of input SparseTensor should be > 1, but saw rank: ", rank));
     
    -    TensorShape tensor_input_shape(input_shape->vec<int64>());
    +    auto input_shape_vec = input_shape->vec<int64>();
    +    int new_num_elements = 1;
    +    bool overflow_ocurred = false;
    +    for (int i = 0; i < input_shape_vec.size(); i++) {
    +      new_num_elements =
    +          MultiplyWithoutOverflow(new_num_elements, input_shape_vec(i));
    +      if (new_num_elements < 0) {
    +        overflow_ocurred = true;
    +      }
    +    }
    +
    +    OP_REQUIRES(
    +        context, !overflow_ocurred,
    +        errors::Internal("Encountered overflow from large input shape."));
    +
    +    TensorShape tensor_input_shape(input_shape_vec);
         gtl::InlinedVector<int64, 8> std_order(rank);
         std::iota(std_order.begin(), std_order.end(), 0);
         SparseTensor input_st;
         OP_REQUIRES_OK(context, SparseTensor::Create(*input_indices, *input_values,
                                                      tensor_input_shape, std_order,
                                                      &input_st));
     
    -    auto input_shape_t = input_shape->vec<int64>();
    -    const int64 N = input_shape_t(0);
    +    const int64 N = input_shape_vec(0);
     
         Tensor sparse_handles(DT_INT64, TensorShape({N}));
         auto sparse_handles_t = sparse_handles.vec<int64>();
    @@ -274,7 +286,7 @@ class AddManySparseToTensorsMapOp : public SparseTensorAccessingOp {
         // minibatch entries.
         TensorShape output_shape;
         OP_REQUIRES_OK(context, TensorShapeUtils::MakeShape(
    -                                input_shape_t.data() + 1,
    +                                input_shape_vec.data() + 1,
                                     input_shape->NumElements() - 1, &output_shape));
     
         // Get groups by minibatch dimension
    

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

7

News mentions

0

No linked articles in our index yet.