CVE-2021-29531: TensorFlow: DoS crash via empty tensor in PNG encoding

MEDIUM PoC AVAILABLE
Published May 14, 2021
CISO Take

An attacker with local access can crash any TensorFlow process by passing an empty tensor to the PNG encoding op, triggering an abort via CHECK_NOTNULL. Patch immediately to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4 — shared ML environments (multi-tenant Jupyter, serving clusters) are most exposed. No data exfiltration or code execution; risk is pure availability disruption.

What is the risk?

Medium overall, but context-dependent. CVSS 5.5 reflects local-only access requirement, which limits internet-scale exposure. However, in shared ML infrastructure — GPU clusters, JupyterHub deployments, TF Serving endpoints that accept raw image ops — a low-privileged insider or tenant can repeatedly crash processes with zero complexity. Availability impact is HIGH (abort-level crash). No confidentiality or integrity risk.

What systems are affected?

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

Do you use TensorFlow? You're affected.

How severe is it?

CVSS 3.1
5.5 / 10
EPSS
0.2%
chance of exploitation in 30 days
Higher than 9% of all CVEs
Exploitation Status
Exploit Available
Exploitation: MEDIUM
Sophistication
Trivial
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 None
I None
A High

What should I do?

4 steps
  1. PATCH

    Upgrade to TF 2.5.0 (or cherrypick releases 2.4.2, 2.3.3, 2.2.3, 2.1.4).

  2. VALIDATE INPUTS

    Add explicit shape checks before calling encode_png — assert tensor rank == 3 and all dims > 0.

  3. HARDEN SERVING

    If using TF Serving, restrict accepted op sets and validate tensor shapes at the API gateway layer before they reach the TF runtime.

  4. MONITOR

    Alert on unexpected TensorFlow process aborts (SIGABRT) in serving or training infrastructure — repeated crashes may indicate active exploitation.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Article 15 - Accuracy, robustness and cybersecurity for high-risk AI systems
ISO 42001
A.6.2.6 - AI system availability and resilience
NIST AI RMF
MANAGE-2.2 - Mechanisms to sustain AI system value with ongoing monitoring
OWASP LLM Top 10
LLM04 - Model Denial of Service

Frequently Asked Questions

What is CVE-2021-29531?

An attacker with local access can crash any TensorFlow process by passing an empty tensor to the PNG encoding op, triggering an abort via CHECK_NOTNULL. Patch immediately to TF 2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4 — shared ML environments (multi-tenant Jupyter, serving clusters) are most exposed. No data exfiltration or code execution; risk is pure availability disruption.

Is CVE-2021-29531 actively exploited?

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

How to fix CVE-2021-29531?

1. PATCH: Upgrade to TF 2.5.0 (or cherrypick releases 2.4.2, 2.3.3, 2.2.3, 2.1.4). 2. VALIDATE INPUTS: Add explicit shape checks before calling encode_png — assert tensor rank == 3 and all dims > 0. 3. HARDEN SERVING: If using TF Serving, restrict accepted op sets and validate tensor shapes at the API gateway layer before they reach the TF runtime. 4. MONITOR: Alert on unexpected TensorFlow process aborts (SIGABRT) in serving or training infrastructure — repeated crashes may indicate active exploitation.

What systems are affected by CVE-2021-29531?

This vulnerability affects the following AI/ML architecture patterns: image processing pipelines, model serving, training pipelines, data preprocessing.

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

CVE-2021-29531 has a CVSS v3.1 base score of 5.5 (MEDIUM). The EPSS exploitation probability is 0.19%.

What is the AI security impact?

Affected AI Architectures

image processing pipelinesmodel servingtraining pipelinesdata preprocessing

MITRE ATLAS Techniques

AML.T0029 Denial of AI Service
AML.T0034 Cost Harvesting
AML.T0049 Exploit Public-Facing Application

Compliance Controls Affected

EU AI Act: Article 15
ISO 42001: A.6.2.6
NIST AI RMF: MANAGE-2.2
OWASP LLM Top 10: LLM04

What are the technical details?

Original Advisory

TensorFlow is an end-to-end open source platform for machine learning. An attacker can trigger a `CHECK` fail in PNG encoding by providing an empty input tensor as the pixel data. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/e312e0791ce486a80c9d23110841525c6f7c3289/tensorflow/core/kernels/image/encode_png_op.cc#L57-L60) only validates that the total number of pixels in the image does not overflow. Thus, an attacker can send an empty matrix for encoding. However, if the tensor is empty, then the associated buffer is `nullptr`. Hence, when calling `png::WriteImageToBuffer`(https://github.com/tensorflow/tensorflow/blob/e312e0791ce486a80c9d23110841525c6f7c3289/tensorflow/core/kernels/image/encode_png_op.cc#L79-L93), the first argument (i.e., `image.flat<T>().data()`) is `NULL`. This then triggers the `CHECK_NOTNULL` in the first line of `png::WriteImageToBuffer`(https://github.com/tensorflow/tensorflow/blob/e312e0791ce486a80c9d23110841525c6f7c3289/tensorflow/core/lib/png/png_io.cc#L345-L349). Since `image` is null, this results in `abort` being called after printing the stacktrace. Effectively, this allows an attacker to mount a denial of service attack. 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 shared ML platform (e.g., a multi-tenant JupyterHub or an internal TF Serving endpoint) submits a TF graph that calls tf.image.encode_png with a zero-dimensional or empty tensor. The TF runtime passes a NULL buffer pointer to png::WriteImageToBuffer, which immediately fires CHECK_NOTNULL and calls abort(), crashing the process. In a serving context, this kills the inference server — taking down all concurrent users. The attack requires no elevated privileges, no ML expertise, and is repeatable in a loop to sustain a DoS.

Weaknesses (CWE)

CWE-754 — Improper Check for Unusual or Exceptional Conditions: The product does not check or incorrectly checks for unusual or exceptional conditions that are not expected to occur frequently during day to day operation of the product.

  • [Requirements] Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. Choose languages with features such as exception handling that force the programmer to anticipate unusual conditions that may generate exceptions. Custom exceptions may need to be developed to handle unusual business-logic conditions. Be careful not to pass sensitive exceptions back to the user (CWE-209, CWE-248).
  • [Implementation] Check the results of all functions that return a value and verify that the value is expected.

Source: MITRE CWE corpus.

CVSS Vector

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

Timeline

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

Related Vulnerabilities