CVE-2022-35995: Reachable Assertion (CWE-617)
value: TensorFlow is an open source platform for machine learning. When `AudioSummaryV2` receives an input `sample_rate` with more than one element, it gives a `CHECK` fails that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit bf6b45244992e2ee543c258e519489659c99fb7f. 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-16T23:15Z
Repository: https://github.com/tensorflow/tensorflow
Language: Python
Files changed: tensorflow/core/kernels/summary_audio_op.cc, tensorflow/python/summary/summary_test.py
Commit date: 2022-07-13 15:44:37 -0700
Commit message: Fix tf.raw_ops.AudioSummaryV2 vulnerability with invalid `sample_rate`.

Check that `sample_rate` has the required shape.

PiperOrigin-RevId: 460819553

Diff: diff --git a/tensorflow/core/kernels/summary_audio_op.cc b/tensorflow/core/kernels/summary_audio_op.cc
index 09aab681f560a..6015fe2ab5ebe 100644
--- a/tensorflow/core/kernels/summary_audio_op.cc
+++ b/tensorflow/core/kernels/summary_audio_op.cc
@@ -47,10 +47,15 @@ class SummaryAudioOp : public OpKernel {
     const string& base_tag = tag.scalar<tstring>()();
 
     float sample_rate = sample_rate_attr_;
     if (!has_sample_rate_attr_) {
       const Tensor& sample_rate_tensor = c->input(2);
+      OP_REQUIRES(c,
+                  sample_rate_tensor.IsAligned() &&
+                      sample_rate_tensor.NumElements() == 1,
+                  errors::InvalidArgument(
+                      "sample_rate must be rank-0 or contain a single value"));
       sample_rate = sample_rate_tensor.scalar<float>()();
     }
     OP_REQUIRES(c, sample_rate > 0.0f,
                 errors::InvalidArgument("sample_rate must be > 0"));
 
diff --git a/tensorflow/python/summary/summary_test.py b/tensorflow/python/summary/summary_test.py
index dd37a1e7a4da5..0329ba1c784f4 100644
--- a/tensorflow/python/summary/summary_test.py
+++ b/tensorflow/python/summary/summary_test.py
@@ -21,10 +21,11 @@ tensorflow/python/kernel_tests/summary_v1_*.py.
 
 
 from tensorflow.core.framework import summary_pb2
 from tensorflow.python.framework import constant_op
 from tensorflow.python.framework import dtypes
+from tensorflow.python.framework import errors
 from tensorflow.python.framework import meta_graph
 from tensorflow.python.framework import ops
 from tensorflow.python.framework import test_util
 from tensorflow.python.ops import array_ops
 from tensorflow.python.ops import variables
@@ -181,10 +182,15 @@ class SummaryTest(test.TestCase):
     tags = sorted(v.tag for v in values)
     expected = sorted(
         'family/outer/family/inner/audio/{}'.format(i) for i in range(3))
     self.assertEqual(tags, expected)
 
+  def testAudioSummaryWithInvalidSampleRate(self):
+    with self.assertRaises(errors.InvalidArgumentError):
+      invalid_sample_rate = [22000.0, 22000.0]
+      self.evaluate(summary_lib.audio('', [[1.0]], invalid_sample_rate))
+
   @test_util.run_deprecated_v1
   def testTextSummary(self):
     with self.cached_session():
       with self.assertRaises(ValueError):
         num = array_ops.constant(1)

Fixed code:       OP_REQUIRES(c,
                  sample_rate_tensor.IsAligned() &&
                      sample_rate_tensor.NumElements() == 1,
                  errors::InvalidArgument(
                      "sample_rate must be rank-0 or contain a single value"));
from tensorflow.python.framework import errors
  def testAudioSummaryWithInvalidSampleRate(self):
    with self.assertRaises(errors.InvalidArgumentError):
      invalid_sample_rate = [22000.0, 22000.0]
      self.evaluate(summary_lib.audio('', [[1.0]], invalid_sample_rate))