Missing validation causes denial of service in TensorFlow via `SparseTensorToCSRSparseMatrix`
Description
TensorFlow is an open source platform for machine learning. Prior to versions 2.9.0, 2.8.1, 2.7.2, and 2.6.4, the implementation of tf.raw_ops.SparseTensorToCSRSparseMatrix does not fully validate the input arguments. This results in a CHECK-failure which can be used to trigger a denial of service attack. The code assumes dense_shape is a vector and indices is a matrix (as part of requirements for sparse tensors) but there is no validation for this. Versions 2.9.0, 2.8.1, 2.7.2, and 2.6.4 contain a patch for this issue.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
tensorflowPyPI | < 2.6.4 | 2.6.4 |
tensorflowPyPI | >= 2.7.0, < 2.7.2 | 2.7.2 |
tensorflowPyPI | >= 2.8.0, < 2.8.1 | 2.8.1 |
tensorflow-cpuPyPI | < 2.6.4 | 2.6.4 |
tensorflow-cpuPyPI | >= 2.7.0, < 2.7.2 | 2.7.2 |
tensorflow-cpuPyPI | >= 2.8.0, < 2.8.1 | 2.8.1 |
tensorflow-gpuPyPI | < 2.6.4 | 2.6.4 |
tensorflow-gpuPyPI | >= 2.7.0, < 2.7.2 | 2.7.2 |
tensorflow-gpuPyPI | >= 2.8.0, < 2.8.1 | 2.8.1 |
Affected products
1- Range: < 2.6.4
Patches
1ea50a40e84f6Fix failed check in SparseTensorToCSRSparseMatrix
2 files changed · +26 −0
tensorflow/core/kernels/sparse/sparse_tensor_to_csr_sparse_matrix_op.cc+7 −0 modified@@ -67,6 +67,13 @@ class SparseTensorToCSRSparseMatrixCPUOp : public OpKernel { const Tensor& values = ctx->input(1); const Tensor& dense_shape = ctx->input(2); const int rank = dense_shape.NumElements(); + OP_REQUIRES( + ctx, TensorShapeUtils::IsVector(dense_shape.shape()), + errors::InvalidArgument("dense_shape must be rank 1 but got rank", + dense_shape.shape().dims())); + OP_REQUIRES(ctx, TensorShapeUtils::IsMatrix(indices.shape()), + errors::InvalidArgument("indices must be rank 2 but got rank", + indices.shape().dims())); OP_REQUIRES(ctx, rank == 2 || rank == 3, errors::InvalidArgument("SparseTensor must have rank 2 or 3; ", "but indices has rank: ", rank));
tensorflow/python/kernel_tests/linalg/sparse/csr_sparse_matrix_ops_test.py+19 −0 modified@@ -168,6 +168,25 @@ def testSparseTensorConversion(self): self.assertAllClose(a_values, a_st_rt_value.values) self.assertAllEqual(a_dense_shape, a_st_rt_value.dense_shape) + def testSparseTensorConversionInvalidInputShapes(self): + values = constant_op.constant( + 0.554979503, shape=[5], dtype=dtypes.float32) + with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError), + "must be rank 1"): + indices = constant_op.constant(0, shape=[5, 2], dtype=dtypes.int64) + dense_shape = constant_op.constant(53, shape=[], dtype=dtypes.int64) + csr = sparse_csr_matrix_ops.sparse_tensor_to_csr_sparse_matrix( + indices=indices, values=values, dense_shape=dense_shape) + self.evaluate(csr) + + with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError), + "must be rank 2"): + indices = constant_op.constant(0, shape=[5], dtype=dtypes.int64) + dense_shape = constant_op.constant(53, shape=[1], dtype=dtypes.int64) + csr = sparse_csr_matrix_ops.sparse_tensor_to_csr_sparse_matrix( + indices=indices, values=values, dense_shape=dense_shape) + self.evaluate(csr) + # TODO(b/139491352): Add handle_data propagation to array_ops.identity. @test_util.run_deprecated_v1 def testCSRSparseMatrixResourceVariable(self):
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
9- github.com/advisories/GHSA-mg66-qvc5-rm93ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2022-29198ghsaADVISORY
- github.com/tensorflow/tensorflow/blob/f3b9bf4c3c0597563b289c0512e98d4ce81f886e/tensorflow/core/kernels/sparse/sparse_tensor_to_csr_sparse_matrix_op.ccghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/commit/ea50a40e84f6bff15a0912728e35b657548cef11ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/releases/tag/v2.6.4ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/releases/tag/v2.7.2ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/releases/tag/v2.8.1ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/releases/tag/v2.9.0ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/security/advisories/GHSA-mg66-qvc5-rm93ghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.