# GHSA-wcv5-vrvr-3rx2: Integer Overflow or Wraparound in TensorFlow

> An attacker can cause a denial of service in TensorFlow via integer overflow in Grappler constant folding by providing crafted tensor shapes.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 9 Feb 2022

## What is GHSA-wcv5-vrvr-3rx2?

GHSA-wcv5-vrvr-3rx2 is a vulnerability in tensorflow, published on 9 Feb 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Impact
The Grappler component of TensorFlow is vulnerable to a denial of service via `CHECK`-failure (assertion failure) in [constant folding](https://github.com/tensorflow/tensorflow/blob/a1320ec1eac186da1d03f033109191f715b2b130/tensorflow/core/grappler/optimizers/constant_folding.cc#L963-L1035):

```cc
  for (const auto& output_prop : output_props) {
    const PartialTensorShape output_shape(output_prop.shape());
    // ...
  }
```
  
The `output_prop` tensor has a shape that is controlled by user input and this can result in triggering one of the `CHECK`s in the `PartialTensorShape` constructor. This is an instance of [TFSA-2021-198](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/security/advisory/tfsa-2021-198.md) (CVE-2021-41197).

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

The fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, 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.

## Which versions are affected by GHSA-wcv5-vrvr-3rx2?

18 open source packages ship an affected version, including tensorflow, tensorflow-cpu and tensorflow-gpu.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `tensorflow` | PyPI | All versions | 2.5.3 |
| `tensorflow` | PyPI | All versions | 2.5.3 |
| `tensorflow` | PyPI | From 2.6.0 | 2.6.3 |
| `tensorflow` | PyPI | From 2.6.0 | 2.6.3 |
| `tensorflow` | PyPI | From 2.7.0 | 2.7.1 |
| `tensorflow` | PyPI | From 2.7.0 | 2.7.1 |
| `tensorflow-cpu` | PyPI | All versions | 2.5.3 |
| `tensorflow-cpu` | PyPI | All versions | 2.5.3 |
| `tensorflow-cpu` | PyPI | From 2.6.0 | 2.6.3 |
| `tensorflow-cpu` | PyPI | From 2.6.0 | 2.6.3 |
| `tensorflow-cpu` | PyPI | From 2.7.0 | 2.7.1 |
| `tensorflow-cpu` | PyPI | From 2.7.0 | 2.7.1 |
| `tensorflow-gpu` | PyPI | All versions | 2.5.3 |
| `tensorflow-gpu` | PyPI | All versions | 2.5.3 |
| `tensorflow-gpu` | PyPI | From 2.6.0 | 2.6.3 |
| `tensorflow-gpu` | PyPI | From 2.6.0 | 2.6.3 |
| `tensorflow-gpu` | PyPI | From 2.7.0 | 2.7.1 |
| `tensorflow-gpu` | PyPI | From 2.7.0 | 2.7.1 |

## How do I fix GHSA-wcv5-vrvr-3rx2?

Upgrade tensorflow to a fixed version for your release line: 2.5.3, 2.6.3 or 2.7.1.

## Is GHSA-wcv5-vrvr-3rx2 being exploited?

There is no known exploitation of GHSA-wcv5-vrvr-3rx2 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-wcv5-vrvr-3rx2 and fix it if it is affected.

What it is: GHSA-wcv5-vrvr-3rx2 is a vulnerability in tensorflow, published on 9 Feb 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-wcv5-vrvr-3rx2 in the wild and no public exploit code.

Affected packages and fixed versions:
- tensorflow (PyPI): affected all versions; fixed in 2.5.3
- tensorflow (PyPI): affected all versions; fixed in 2.5.3
- tensorflow (PyPI): affected from 2.6.0; fixed in 2.6.3
- tensorflow (PyPI): affected from 2.6.0; fixed in 2.6.3
- tensorflow (PyPI): affected from 2.7.0; fixed in 2.7.1
- tensorflow (PyPI): affected from 2.7.0; fixed in 2.7.1
- tensorflow-cpu (PyPI): affected all versions; fixed in 2.5.3
- tensorflow-cpu (PyPI): affected all versions; fixed in 2.5.3
- tensorflow-cpu (PyPI): affected from 2.6.0; fixed in 2.6.3
- tensorflow-cpu (PyPI): affected from 2.6.0; fixed in 2.6.3
- tensorflow-cpu (PyPI): affected from 2.7.0; fixed in 2.7.1
- tensorflow-cpu (PyPI): affected from 2.7.0; fixed in 2.7.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-wcv5-vrvr-3rx2/ (Markdown: https://insights.sbomify.com/GHSA-wcv5-vrvr-3rx2/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-wcv5-vrvr-3rx2

---
From sbomify Insights: https://insights.sbomify.com/GHSA-wcv5-vrvr-3rx2/
Summaries are generated and may contain mistakes; the official description above is the record.
