CVE-2021-29609: TensorFlow: SparseAdd heap OOB write and null deref

HIGH PoC AVAILABLE
Published May 14, 2021
CISO Take

If your ML environment runs TensorFlow < 2.5.0 and accepts user-influenced sparse tensor inputs, patch immediately to 2.5.0 or the backported fixes (2.4.2, 2.3.3, 2.2.3, 2.1.4). Low attack complexity means any caller with tensor access to the runtime can trigger this. Shared GPU clusters and multi-tenant inference services are highest risk.

What is the risk?

CVSS 7.8 High with local attack vector and low complexity/privileges. In ML contexts 'local' frequently maps to inference server processes or training jobs where user-submitted data reaches TF ops directly — effectively elevating the practical attack surface beyond what the CVSS vector implies. Risk is highest in multi-tenant GPU clusters or inference APIs that accept raw tensor inputs without pre-validation at the application boundary.

What systems are affected?

Package Ecosystem Vulnerable Range Patched
TensorFlow pip No patch
195.8K OpenSSF 7.1 3.7K dependents Pushed 2d ago 4% patched ~1372d to patch Full package profile →

Do you use TensorFlow? You're affected.

How severe is it?

CVSS 3.1
7.8 / 10
EPSS
0.2%
chance of exploitation in 30 days
Higher than 14% of all CVEs
Exploitation Status
Exploit Available
Exploitation: MEDIUM
Sophistication
Moderate
Exploitation Confidence
medium
Public PoC indexed (trickest/cve)
Composite signal derived from CISA KEV, VulnCheck KEV, CISA SSVC, EPSS, Metasploit, Exploit-DB, trickest/cve, Nuclei templates, and inthewild.io exploitation reports.

What is the attack surface?

AV AC PR UI S C I A
AV Local
AC Low
PR Low
UI None
S Unchanged
C High
I High
A High

What should I do?

5 steps
  1. Patch: Upgrade to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4.

  2. Validate all incoming tensor shapes and indices at the application boundary before passing to SparseAdd — reject tensors where indices second dimension does not match the corresponding shape tensor.

  3. Isolate TF inference workers in containers with no-new-privileges and seccomp profiles to contain blast radius.

  4. Audit inference APIs and gRPC endpoints that accept sparse tensor formats from external callers.

  5. Monitor for unexpected TF serving process crashes as a detection signal for exploitation attempts.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Article 9 - Risk management system
ISO 42001
A.6.2.6 - AI system security and resilience
NIST AI RMF
MANAGE 2.4 - Residual risks from third-party AI components are managed
OWASP LLM Top 10
LLM04 - Model Denial of Service

Frequently Asked Questions

What is CVE-2021-29609?

If your ML environment runs TensorFlow < 2.5.0 and accepts user-influenced sparse tensor inputs, patch immediately to 2.5.0 or the backported fixes (2.4.2, 2.3.3, 2.2.3, 2.1.4). Low attack complexity means any caller with tensor access to the runtime can trigger this. Shared GPU clusters and multi-tenant inference services are highest risk.

Is CVE-2021-29609 actively exploited?

Proof-of-concept exploit code is publicly available for CVE-2021-29609, increasing the risk of exploitation.

How to fix CVE-2021-29609?

1. Patch: Upgrade to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4. 2. Validate all incoming tensor shapes and indices at the application boundary before passing to SparseAdd — reject tensors where indices second dimension does not match the corresponding shape tensor. 3. Isolate TF inference workers in containers with no-new-privileges and seccomp profiles to contain blast radius. 4. Audit inference APIs and gRPC endpoints that accept sparse tensor formats from external callers. 5. Monitor for unexpected TF serving process crashes as a detection signal for exploitation attempts.

What systems are affected by CVE-2021-29609?

This vulnerability affects the following AI/ML architecture patterns: training pipelines, model serving, inference endpoints.

What is the CVSS score for CVE-2021-29609?

CVE-2021-29609 has a CVSS v3.1 base score of 7.8 (HIGH). The EPSS exploitation probability is 0.23%.

What is the AI security impact?

Affected AI Architectures

training pipelinesmodel servinginference endpoints

MITRE ATLAS Techniques

AML.T0010.001 AI Software
AML.T0043 Craft Adversarial Data
AML.T0049 Exploit Public-Facing Application

Compliance Controls Affected

EU AI Act: Article 9
ISO 42001: A.6.2.6
NIST AI RMF: MANAGE 2.4
OWASP LLM Top 10: LLM04

What are the technical details?

Original Advisory

TensorFlow is an end-to-end open source platform for machine learning. Incomplete validation in `SparseAdd` results in allowing attackers to exploit undefined behavior (dereferencing null pointers) as well as write outside of bounds of heap allocated data. The implementation(https://github.com/tensorflow/tensorflow/blob/656e7673b14acd7835dc778867f84916c6d1cac2/tensorflow/core/kernels/sparse_add_op.cc) has a large set of validation for the two sparse tensor inputs (6 tensors in total), but does not validate that the tensors are not empty or that the second dimension of `*_indices` matches the size of corresponding `*_shape`. This allows attackers to send tensor triples that represent invalid sparse tensors to abuse code assumptions that are not protected by validation. 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.

Exploitation Scenario

An adversary with access to a TensorFlow inference endpoint (TF Serving, custom gRPC API, or shared Jupyter environment) submits a crafted SparseTensor triple where the indices tensor shape does not match the corresponding shape tensor, or sends empty tensors. The SparseAdd kernel, lacking these validation checks, dereferences a null pointer or writes beyond heap-allocated bounds. At minimum this crashes the inference server (DoS); in a memory-unsafe runtime it enables heap exploitation for code execution on the ML host — from which the attacker can exfiltrate model weights, training data, or pivot to internal infrastructure.

Weaknesses (CWE)

CWE-476 — NULL Pointer Dereference: The product dereferences a pointer that it expects to be valid but is NULL.

  • [Implementation] For any pointers that could have been modified or provided from a function that can return NULL, check the pointer for NULL before use. When working with a multithreaded or otherwise asynchronous environment, ensure that proper locking APIs are used to lock before the check, and unlock when it has finished [REF-1484].
  • [Requirements] Select a programming language that is not susceptible to these issues.

Source: MITRE CWE corpus.

CVSS Vector

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

Timeline

Published
May 14, 2021
Last Modified
November 21, 2024
First Seen
May 14, 2021

Related Vulnerabilities