CVE-2021-29531: TensorFlow: DoS crash via empty tensor in PNG encoding
MEDIUM PoC AVAILABLEAn 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 |
Do you use tensorflow? You're affected.
Severity & Risk
Attack Surface
Recommended Action
4 steps-
PATCH
Upgrade to TF 2.5.0 (or cherrypick releases 2.4.2, 2.3.3, 2.2.3, 2.1.4).
-
VALIDATE INPUTS
Add explicit shape checks before calling encode_png — assert tensor rank == 3 and all dims > 0.
-
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.
-
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:
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 References
- github.com/tensorflow/tensorflow/commit/26eb323554ffccd173e8a79a8c05c15b685ae4d1 Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-3qxp-qjq7-w4hf Exploit Patch 3rd Party
Timeline
Related Vulnerabilities
CVE-2020-15196 9.9 TensorFlow: heap OOB read in sparse/ragged count ops
Same package: tensorflow CVE-2020-15205 9.8 TensorFlow: heap overflow in StringNGrams, ASLR bypass
Same package: tensorflow CVE-2020-15208 9.8 TFLite: OOB read/write via tensor dimension mismatch
Same package: tensorflow CVE-2019-16778 9.8 TensorFlow: heap overflow in UnsortedSegmentSum op
Same package: tensorflow CVE-2022-23587 9.8 TensorFlow: integer overflow in Grappler enables RCE
Same package: tensorflow
AI Threat Alert