• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## TFSA-2021-068: Heap buffer overflow in `MaxPoolGrad`
2
3### CVE Number
4CVE-2021-29579
5
6### Impact
7The implementation of `tf.raw_ops.MaxPoolGrad` is vulnerable to a heap buffer
8overflow:
9
10```python
11import tensorflow as tf
12
13orig_input = tf.constant([0.0], shape=[1, 1, 1, 1], dtype=tf.float32)
14orig_output = tf.constant([0.0], shape=[1, 1, 1, 1], dtype=tf.float32)
15grad = tf.constant([], shape=[0, 0, 0, 0], dtype=tf.float32)
16ksize = [1, 1, 1, 1]
17strides = [1, 1, 1, 1]
18padding = "SAME"
19
20tf.raw_ops.MaxPoolGrad(
21  orig_input=orig_input, orig_output=orig_output, grad=grad, ksize=ksize,
22  strides=strides, padding=padding, explicit_paddings=[])
23```
24
25The
26[implementation](https://github.com/tensorflow/tensorflow/blob/ab1e644b48c82cb71493f4362b4dd38f4577a1cf/tensorflow/core/kernels/maxpooling_op.cc#L194-L203)
27fails to validate that indices used to access elements of input/output arrays
28are valid:
29
30```cc
31for (int index = out_start; index < out_end; ++index) {
32  int input_backprop_index = out_arg_max_flat(index);
33  FastBoundsCheck(input_backprop_index - in_start, in_end - in_start);
34  input_backprop_flat(input_backprop_index) += out_backprop_flat(index);
35}
36```
37
38Whereas accesses to `input_backprop_flat` are guarded by `FastBoundsCheck`, the
39indexing in `out_backprop_flat` can result in OOB access.
40
41### Patches
42We have patched the issue in GitHub commit
43[a74768f8e4efbda4def9f16ee7e13cf3922ac5f7](https://github.com/tensorflow/tensorflow/commit/a74768f8e4efbda4def9f16ee7e13cf3922ac5f7).
44
45The fix will be included in TensorFlow 2.5.0. We will also cherrypick this
46commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow
472.1.4, as these are also affected and still in supported range.
48
49### For more information
50Please consult [our security
51guide](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for
52more information regarding the security model and how to contact us with issues
53and questions.
54
55### Attribution
56This vulnerability has been reported by Ying Wang and Yakun Zhang of Baidu
57X-Team.
58