CVE-2022-35981 (Python, published 2022-09-16T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. `FractionalMaxPoolGrad` validates its inputs with `CHECK` failures instead of with returning errors. If it gets incorrectly sized inputs, the `CHECK` failure can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 8741e57d163a079db05a7107a7609af70931def4. 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_max_pool_op.cc
tensorflow/python/kernel_tests/nn_ops/fractional_max_pool_op_test.py
Commit message: Fix security vulnerability with FractionalMaxPoolGrad

PiperOrigin-RevId: 461722693


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

        DCHECK_EQ(tensor_out_dup_mat(j, i), tensor_out_mat(j, i));
      // According to maxpooling_op.cc, the performance impact below is small.
      CHECK(input_backprop_index >= 0 &&
            input_backprop_index < num_total_inputs)
          << "Invalid input backprop index: " << input_backprop_index << ", "
          << num_total_inputs;
    with self.cached_session() as sess:
      with self.cached_session() as sess:

Fixed code:
#include "tensorflow/core/framework/op_requires.h"
#include "tensorflow/core/kernels/fractional_pool_common.h"
#include "tensorflow/core/platform/errors.h"
        OP_REQUIRES(context, tensor_out_dup_mat(j, i) == tensor_out_mat(j, i),
                    errors::InvalidArgument(
                        "tensor_out_dup is not the same as tensor_out"));
      OP_REQUIRES(
          context,
          input_backprop_index >= 0 && input_backprop_index < num_total_inputs,
          errors::InvalidArgument(
              "Invalid input backprop index: ", input_backprop_index, ", ",
              num_total_inputs));
    with self.cached_session():
      with self.cached_session():
  def testInvalidSeqRaiseErrorForFractionalMaxPoolGrad(self):
    with self.assertRaises(errors.InvalidArgumentError):
      with self.cached_session() as _:
        overlapping = True
        orig_input = constant_op.constant(
            .453409232, shape=[1, 7, 13, 1], dtype=dtypes.float32)
        orig_output = constant_op.constant(
            .453409232, shape=[1, 7, 13, 1], dtype=dtypes.float32)
        out_backprop = constant_op.constant(
            .453409232, shape=[1, 7, 13, 1], dtype=dtypes.float32)
        row_pooling_sequence = constant_op.constant(
            0, shape=[5], dtype=dtypes.int64)
        col_pooling_sequence = constant_op.constant(
            0, shape=[5], dtype=dtypes.int64)
        t = gen_nn_ops.FractionalMaxPoolGrad(
            orig_input=orig_input,
            orig_output=orig_output,
            out_backprop=out_backprop,
            row_pooling_sequence=row_pooling_sequence,
            col_pooling_sequence=col_pooling_sequence,
            overlapping=overlapping)
        self.evaluate(t)