Vulnerability: Heap buffer overflow in `FractionalAvgPoolGrad` ### Impact
The implementation for `tf.raw_ops.FractionalAvgPoolGrad` can be tricked into accessing data outside of bounds of heap allocated buffers:

```python
import tensorflow as tf

tf.raw_ops.FractionalAvgPoolGrad(
  orig_input_tensor_shape=[0,1,2,3],
  out_backprop = np.array([[[[541],[541]],[[541],[541]]]]),
  row_pooling_sequence=[0, 0, 0, 0, 0],
  col_pooling_sequence=[-2, 0, 0, 2, 0],
  overlapping=True)
```

The [implementation](https://github.com/tensorflow/tensorflow/blob/f24faa153ad31a4b51578f8181d3aaab77a1ddeb/tensorflow/core/kernels/fractional_avg_pool_op.cc#L205) does not validate that the input tensor is non-empty. Thus, code constructs an empty `EigenDoubleMatrixMap` and then accesses this buffer with indices that are outside of the empty area.

### Patches
We have patched the issue in GitHub commit [0f931751fb20f565c4e94aa6df58d54a003cdb30](https://github.com/tensorflow/tensorflow/commit/0f931751fb20f565c4e94aa6df58d54a003cdb30).

The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

### For more information
Please consult [our security guide](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for more information regarding the security model and how to contact us with issues and questions.

### Attribution
This vulnerability has been reported by members of the Aivul Team from Qihoo 360.
Vulnerability ID: GHSA-hpv4-7p9c-mvfr
CWE: CWE-125
Severity score: 7.1
Project: https://github.com/tensorflow/tensorflow
Published: 2021-08-25
File: tensorflow/core/kernels/fractional_avg_pool_op.cc
Commit message: Validate dimensions of input tensor in `FractionalAvgPoolGrad`

PiperOrigin-RevId: 388286227
Change-Id: Ieb7566155e92acc8993a2212c76deacadc0edc8a
Commit author: Mihai Maruseac

Vulnerable version (before fix):
 class FractionalAvgPoolGradOp : public OpKernel {     const int64_t in_rows = orig_input_tensor_shape_flat(1);     const int64_t in_cols = orig_input_tensor_shape_flat(2);     const int64_t in_depth = orig_input_tensor_shape_flat(3);      constexpr int tensor_in_and_out_dims = 4;     // Transform orig_input_tensor_shape into TensorShape

Fixed version (after fix):
 class FractionalAvgPoolGradOp : public OpKernel {     const int64_t in_rows = orig_input_tensor_shape_flat(1);     const int64_t in_cols = orig_input_tensor_shape_flat(2);     const int64_t in_depth = orig_input_tensor_shape_flat(3);     OP_REQUIRES(         context, in_batch != 0,         errors::InvalidArgument("Batch dimension of input must not be 0"));     OP_REQUIRES(         context, in_rows != 0,         errors::InvalidArgument("Rows dimension of input must not be 0"));     OP_REQUIRES(         context, in_cols != 0,         errors::InvalidArgument("Columns dimension of input must not be 0"));     OP_REQUIRES(         context, in_depth != 0,         errors::InvalidArgument("Depth dimension of input must not be 0"));      constexpr int tensor_in_and_out_dims = 4;     // Transform orig_input_tensor_shape into TensorShape

Patch:
patch: @@ -271,6 +271,18 @@ class FractionalAvgPoolGradOp : public OpKernel {
     const int64_t in_rows = orig_input_tensor_shape_flat(1);
     const int64_t in_cols = orig_input_tensor_shape_flat(2);
     const int64_t in_depth = orig_input_tensor_shape_flat(3);
+    OP_REQUIRES(
+        context, in_batch != 0,
+        errors::InvalidArgument("Batch dimension of input must not be 0"));
+    OP_REQUIRES(
+        context, in_rows != 0,
+        errors::InvalidArgument("Rows dimension of input must not be 0"));
+    OP_REQUIRES(
+        context, in_cols != 0,
+        errors::InvalidArgument("Columns dimension of input must not be 0"));
+    OP_REQUIRES(
+        context, in_depth != 0,
+        errors::InvalidArgument("Depth dimension of input must not be 0"));
 
     constexpr int tensor_in_and_out_dims = 4;
     // Transform orig_input_tensor_shape into TensorShape
path: tensorflow/core/kernels/fractional_avg_pool_op.cc