VYPR
Moderate severityNVD Advisory· Published Aug 12, 2021· Updated Aug 4, 2024

Reference binding to nullptr in `MatrixDiagV*` ops in TensorFlow

CVE-2021-37657

Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions an attacker can cause undefined behavior via binding a reference to null pointer in all operations of type tf.raw_ops.MatrixDiagV*. The implementation has incomplete validation that the value of k is a valid tensor. We have check that this value is either a scalar or a vector, but there is no check for the number of elements. If this is an empty tensor, then code that accesses the first element of the tensor is wrong. We have patched the issue in GitHub commit f2a673bd34f0d64b8e40a551ac78989d16daad09. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.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.3.42.3.4
tensorflowPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflowPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-cpuPyPI
< 2.3.42.3.4
tensorflow-cpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-cpuPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-gpuPyPI
< 2.3.42.3.4
tensorflow-gpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-gpuPyPI
>= 2.5.0, < 2.5.12.5.1

Affected products

1

Patches

1
f2a673bd34f0

Add missing validation to `matrix_diag_op.cc`

https://github.com/tensorflow/tensorflowMihai MaruseacJul 31, 2021via ghsa
1 file changed · +6 0
  • tensorflow/core/kernels/linalg/matrix_diag_op.cc+6 0 modified
    @@ -73,6 +73,9 @@ class MatrixDiagPartOp : public OpKernel {
                       errors::InvalidArgument(
                           "diag_index must be a scalar or vector, received shape: ",
                           diag_index.shape().DebugString()));
    +      OP_REQUIRES(context, diag_index.NumElements() > 0,
    +                  errors::InvalidArgument(
    +                      "Expected diag_index to have at least 1 element"));
           lower_diag_index = diag_index.flat<int32>()(0);
           upper_diag_index = lower_diag_index;
           if (TensorShapeUtils::IsVector(diag_index.shape())) {
    @@ -179,6 +182,9 @@ class MatrixDiagOp : public OpKernel {
                       errors::InvalidArgument(
                           "diag_index must be a scalar or vector, received shape: ",
                           diag_index.shape().DebugString()));
    +      OP_REQUIRES(context, diag_index.NumElements() > 0,
    +                  errors::InvalidArgument(
    +                      "Expected diag_index to have at least 1 element"));
           lower_diag_index = diag_index.flat<int32>()(0);
           upper_diag_index = lower_diag_index;
           if (TensorShapeUtils::IsVector(diag_index.shape())) {
    

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.