CVE-2022-36018: Reachable Assertion (CWE-617)
value: TensorFlow is an open source platform for machine learning. If `RaggedTensorToVariant` is given a `rt_nested_splits` list that contains tensors of ranks other than one, it results in a `CHECK` fail that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 88f93dfe691563baa4ae1e80ccde2d5c7a143821. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
CWE description: The product contains an assert() or similar statement that can be triggered by an attacker, which leads to an application exit or other behavior that is more severe than necessary.
CVSS v3 base score: 7.5
Published: 2022-09-16T22:15Z
Repository: https://github.com/tensorflow/tensorflow
Language: Python
Files changed: tensorflow/core/kernels/ragged_tensor_to_variant_op.cc, tensorflow/python/ops/ragged/ragged_tensor_test.py
Commit date: 2022-07-19 10:25:42 -0700
Commit message: [security] Fix failed shape check in RaggedTensorToVariant.

`row_splits` must have rank 1.

PiperOrigin-RevId: 461915027

Diff: diff --git a/tensorflow/core/kernels/ragged_tensor_to_variant_op.cc b/tensorflow/core/kernels/ragged_tensor_to_variant_op.cc
index fe6c3ca30db4e..45fab4531b6e5 100644
--- a/tensorflow/core/kernels/ragged_tensor_to_variant_op.cc
+++ b/tensorflow/core/kernels/ragged_tensor_to_variant_op.cc
@@ -186,10 +186,14 @@ class RaggedTensorToVariantOp : public OpKernel {
     // Read ragged_values input.
     batched_ragged_input.set_values(context->input(ragged_nested_splits_len));
     batched_ragged_input.mutable_nested_splits()->reserve(
         ragged_nested_splits_len);
     for (int i = 0; i < ragged_nested_splits_len; i++) {
+      OP_REQUIRES(context, ragged_nested_splits_in[i].dims() == 1,
+                  errors::InvalidArgument("Requires nested_row_splits[", i, "]",
+                                          " to be rank 1 but is rank ",
+                                          ragged_nested_splits_in[i].dims()));
       batched_ragged_input.append_splits(ragged_nested_splits_in[i]);
     }
 
     if (!batched_input_) {
       // Encode as a Scalar Variant Tensor.
diff --git a/tensorflow/python/ops/ragged/ragged_tensor_test.py b/tensorflow/python/ops/ragged/ragged_tensor_test.py
index 29a421d396401..9ac19f620db89 100644
--- a/tensorflow/python/ops/ragged/ragged_tensor_test.py
+++ b/tensorflow/python/ops/ragged/ragged_tensor_test.py
@@ -1466,10 +1466,25 @@ class RaggedTensorTest(test_util.TensorFlowTestCase, parameterized.TestCase):
       out = it.get_next()
       with self.cached_session() as sess:
         for i in range(3):
           self.assertAllEqual(sess.run(rt[i]), out)
 
+  def testToVariantInvalidParams(self):
+    self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
+                           r'be rank 1 but is rank 0',
+                           gen_ragged_conversion_ops.ragged_tensor_to_variant,
+                           rt_nested_splits=[0, 1, 2],
+                           rt_dense_values=[0, 1, 2],
+                           batched_input=True)
+
+    self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
+                           r'be rank 1 but is rank 2',
+                           gen_ragged_conversion_ops.ragged_tensor_to_variant,
+                           rt_nested_splits=[[[0]], [[1]], [[2]]],
+                           rt_dense_values=[0, 1, 2],
+                           batched_input=True)
+
   def testFromVariantInvalidParams(self):
     rt = ragged_factory_ops.constant([[0], [1], [2], [3]])
     batched_variant = rt._to_variant(batched_input=True)
     nested_batched_variant = array_ops.reshape(batched_variant, [2, 2])
     with self.assertRaisesRegex(ValueError,

Fixed code:       OP_REQUIRES(context, ragged_nested_splits_in[i].dims() == 1,
                  errors::InvalidArgument("Requires nested_row_splits[", i, "]",
                                          " to be rank 1 but is rank ",
                                          ragged_nested_splits_in[i].dims()));
  def testToVariantInvalidParams(self):
    self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                           r'be rank 1 but is rank 0',
                           gen_ragged_conversion_ops.ragged_tensor_to_variant,
                           rt_nested_splits=[0, 1, 2],
                           rt_dense_values=[0, 1, 2],
                           batched_input=True)

    self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                           r'be rank 1 but is rank 2',
                           gen_ragged_conversion_ops.ragged_tensor_to_variant,
                           rt_nested_splits=[[[0]], [[1]], [[2]]],
                           rt_dense_values=[0, 1, 2],
                           batched_input=True)