CVE-2022-35935: Reachable Assertion (CWE-617)
value: TensorFlow is an open source platform for machine learning. The implementation of SobolSampleOp is vulnerable to a denial of service via CHECK-failure (assertion failure) caused by assuming `input(0)`, `input(1)`, and `input(2)` to be scalar. This issue has been patched in GitHub commit c65c67f88ad770662e8f191269a907bf2b94b1bf. 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-16T20:15Z
Repository: https://github.com/tensorflow/tensorflow
Language: C++
Files changed: tensorflow/core/kernels/sobol_op.cc
Commit date: 2022-07-13 13:47:58 -0700
Commit message: Fix `CHECK`-fail due to passing invalid tensors in `SobolOp`.

PiperOrigin-RevId: 460794378

Diff: diff --git a/tensorflow/core/kernels/sobol_op.cc b/tensorflow/core/kernels/sobol_op.cc
index 94fff6baea268..ea3de5056f9e7 100644
--- a/tensorflow/core/kernels/sobol_op.cc
+++ b/tensorflow/core/kernels/sobol_op.cc
@@ -22,10 +22,11 @@ limitations under the License.
 
 #include "third_party/eigen3/Eigen/Core"
 #include "sobol_data.h"  // from @sobol_data
 #include "tensorflow/core/framework/device_base.h"
 #include "tensorflow/core/framework/op_kernel.h"
+#include "tensorflow/core/framework/tensor_shape.h"
 #include "tensorflow/core/lib/core/threadpool.h"
 #include "tensorflow/core/platform/platform_strings.h"
 
 namespace tensorflow {
 
@@ -132,12 +133,18 @@ class SobolSampleOp : public OpKernel {
  public:
   explicit SobolSampleOp(OpKernelConstruction* context)
       : OpKernel(context) {}
 
   void Compute(OpKernelContext* context) override {
+    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
+                errors::InvalidArgument("dim must be a scalar"));
     int32_t dim = context->input(0).scalar<int32_t>()();
+    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
+                errors::InvalidArgument("num_results must be a scalar"));
     int32_t num_results = context->input(1).scalar<int32_t>()();
+    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
+                errors::InvalidArgument("skip must be a scalar"));
     int32_t skip = context->input(2).scalar<int32_t>()();
 
     OP_REQUIRES(context, dim >= 1,
                 errors::InvalidArgument("dim must be at least one"));
     OP_REQUIRES(context, dim <= sobol_data::kMaxSobolDim,

Fixed code: #include "tensorflow/core/framework/tensor_shape.h"
    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
                errors::InvalidArgument("dim must be a scalar"));
    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
                errors::InvalidArgument("num_results must be a scalar"));
    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
                errors::InvalidArgument("skip must be a scalar"));