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.

Risk Assessment

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.

Affected Systems

Package Ecosystem Vulnerable Range Patched
tensorflow pip No patch
195.0K OpenSSF 7.2 3.7K dependents Pushed today 4% patched ~1372d to patch Full package profile →

Do you use tensorflow? You're affected.

Severity & Risk

CVSS 3.1
5.5 / 10
EPSS
0.0%
chance of exploitation in 30 days
Higher than 1% 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, CISA SSVC, EPSS, trickest/cve, and Nuclei templates.

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

Recommended Action

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.

Classification

Compliance Impact

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.01%.

Technical Details

NVD Description

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)

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