CVE-2021-41219: TensorFlow: heap OOB in sparse matrix multiply
HIGH PoC AVAILABLETensorFlow versions prior to 2.7.0 contain a heap out-of-bounds access in sparse matrix multiplication triggered by crafting tensors with zero-dimension inputs. While local access is required, this is directly exploitable in shared training environments, Jupyter platforms, or multi-tenant ML infrastructure where users can submit custom operations. Upgrade to TensorFlow 2.7.0, 2.6.1, 2.5.2, or 2.4.4 immediately and audit shared ML environments for user-controlled sparse tensor inputs.
Risk Assessment
Risk is HIGH for shared training infrastructure or Jupyter-based ML platforms where multiple users can execute TensorFlow code. For isolated single-user environments, practical risk is MEDIUM. Low attack complexity combined with low privilege requirements means exploitation is straightforward once local or platform-level access is achieved. No active exploitation evidence in the wild; not in CISA KEV. Organizations running shared GPU clusters or MLaaS offerings face the greatest exposure.
Affected Systems
| Package | Ecosystem | Vulnerable Range | Patched |
|---|---|---|---|
| tensorflow | pip | — | No patch |
Do you use tensorflow? You're affected.
Severity & Risk
Attack Surface
Recommended Action
5 steps-
Upgrade TensorFlow to 2.7.0 (primary fix) or apply cherrypick patches to 2.6.1, 2.5.2, or 2.4.4 if a full upgrade is not immediately feasible.
-
Apply commit e6cf28c72ba2eb949ca950d834dd6d66bb01cfae directly if version pinning constraints prevent upgrading.
-
Validate tensor dimensions at pipeline ingestion boundaries before passing to sparse ops — reject any tensor with zero or negative dimensions.
-
In multi-tenant ML platforms, isolate TensorFlow workloads per user or team until patching is complete.
-
Detection: monitor TF worker processes for crashes or abnormal termination signals when processing sparse operations with atypical tensor shapes.
Classification
Compliance Impact
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2021-41219?
TensorFlow versions prior to 2.7.0 contain a heap out-of-bounds access in sparse matrix multiplication triggered by crafting tensors with zero-dimension inputs. While local access is required, this is directly exploitable in shared training environments, Jupyter platforms, or multi-tenant ML infrastructure where users can submit custom operations. Upgrade to TensorFlow 2.7.0, 2.6.1, 2.5.2, or 2.4.4 immediately and audit shared ML environments for user-controlled sparse tensor inputs.
Is CVE-2021-41219 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2021-41219, increasing the risk of exploitation.
How to fix CVE-2021-41219?
1. Upgrade TensorFlow to 2.7.0 (primary fix) or apply cherrypick patches to 2.6.1, 2.5.2, or 2.4.4 if a full upgrade is not immediately feasible. 2. Apply commit e6cf28c72ba2eb949ca950d834dd6d66bb01cfae directly if version pinning constraints prevent upgrading. 3. Validate tensor dimensions at pipeline ingestion boundaries before passing to sparse ops — reject any tensor with zero or negative dimensions. 4. In multi-tenant ML platforms, isolate TensorFlow workloads per user or team until patching is complete. 5. Detection: monitor TF worker processes for crashes or abnormal termination signals when processing sparse operations with atypical tensor shapes.
What systems are affected by CVE-2021-41219?
This vulnerability affects the following AI/ML architecture patterns: training pipelines, shared ML platforms, model serving.
What is the CVSS score for CVE-2021-41219?
CVE-2021-41219 has a CVSS v3.1 base score of 7.8 (HIGH). The EPSS exploitation probability is 0.02%.
Technical Details
NVD Description
TensorFlow is an open source platform for machine learning. In affected versions the code for sparse matrix multiplication is vulnerable to undefined behavior via binding a reference to `nullptr`. This occurs whenever the dimensions of `a` or `b` are 0 or less. In the case on one of these is 0, an empty output tensor should be allocated (to conserve the invariant that output tensors are always allocated when the operation is successful) but nothing should be written to it (that is, we should return early from the kernel implementation). Otherwise, attempts to write to this empty tensor would result in heap OOB access. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Exploitation Scenario
An adversary with access to a shared ML training platform — such as a data scientist on a multi-user Jupyter environment or a malicious insider on a GPU cluster — submits a training job invoking sparse matrix multiplication with a tensor where one dimension is set to 0. TensorFlow attempts to bind a reference to nullptr and then writes to the resulting empty output tensor, triggering heap OOB access. In a containerized training environment, this could crash the worker process (DoS to ongoing training runs) or, with additional heap grooming, achieve code execution within the TF process context, potentially exfiltrating model weights or training data resident in memory.
Weaknesses (CWE)
CVSS Vector
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H References
- github.com/tensorflow/tensorflow/commit/e6cf28c72ba2eb949ca950d834dd6d66bb01cfae Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-4f99-p9c2-3j8x Exploit Patch 3rd Party
- github.com/ARPSyndicate/cvemon Exploit
- github.com/adwisatya/SnykVulndb Exploit
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