CVE-2022-35963 (Python, published 2022-09-16T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The implementation of `FractionalAvgPoolGrad` does not fully validate the input `orig_input_tensor_shape`. This results in an overflow that results in a `CHECK` failure which can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 03a659d7be9a1154fdf5eeac221e5950fec07dad. 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.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-617 \u2014 Reachable Assertion
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.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/fractional_avg_pool_op.cc
tensorflow/python/kernel_tests/nn_ops/fractional_avg_pool_op_test.py
Commit message: Fix security vulnerability with FractionalAvgPoolGrad

PiperOrigin-RevId: 462292194


Vulnerable code:
#include "tensorflow/core/kernels/fractional_pool_common.h"


Fixed code:

#include "tensorflow/core/kernels/fractional_pool_common.h"
#include "tensorflow/core/util/overflow.h"
    int64_t num_elements = 1;
    for (int i = 0; i < orig_input_tensor_shape.dims(); i++) {
      OP_REQUIRES(context, orig_input_tensor_shape.dim_size(i) > 0,
                  errors::InvalidArgument(
                      "orig_input_tensor_shape must be positive, got: ",
                      orig_input_tensor_shape.dim_size(i)));
      num_elements = MultiplyWithoutOverflow(
          num_elements, orig_input_tensor_shape.dim_size(i));
      OP_REQUIRES(
          context, num_elements > 0,
          errors::InvalidArgument(
              "The total elements specified by orig_input_tensor_shape",
              " is too large. Encountered overflow after multiplying ",
              orig_input_tensor_shape.dim_size(i), ", result: ", num_elements));
    }

    OP_REQUIRES(context, out_backprop.dims() == 4,
                errors::InvalidArgument("out_backprop must be 4-dimensional"));
    for (int i = 0; i < out_backprop.dims(); i++) {
      OP_REQUIRES(context, out_backprop.dim_size(i) > 0,
                  errors::InvalidArgument(
                      "out_backprop must be positive for all dimension, got:",
                      out_backprop.dim_size(i)));
    }

  def testInvalidSeqRaiseErrorForFractionalAvgPoolGrad(self):
    with self.assertRaises((errors.InvalidArgumentError, ValueError)):
      with self.cached_session() as _:
        overlapping = True
        orig_input_tensor_shape = constant_op.constant(
            -1879048192, shape=[4], dtype=dtypes.int64)
        out_backprop = constant_op.constant([],
                                            shape=[0, 0, 0, 0],
                                            dtype=dtypes.float64)
        row_pooling_sequence = constant_op.constant(
            1, shape=[4], dtype=dtypes.int64)
        col_pooling_sequence = constant_op.constant(
            1, shape=[4], dtype=dtypes.int64)
        t = gen_nn_ops.fractional_avg_pool_grad(
            orig_input_tensor_shape=orig_input_tensor_shape,
            out_backprop=out_backprop,
            row_pooling_sequence=row_pooling_sequence,
            col_pooling_sequence=col_pooling_sequence,
            overlapping=overlapping)
        self.evaluate(t)