Bad alloc in `StringNGrams` caused by integer conversion in TensorFlow
Key facts
- Attack vector
- Local
- Privileges required
- Low
- User interaction
- None
- Attack complexity
- Low
- Impact type
- —
- Confidentiality · integrity · availability
- None · None · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · CNA. Fix status from CNA and GitHub.
Summary
TensorFlow is an end-to-end open source platform for machine learning. In affected versions the implementation of `tf.raw_ops.StringNGrams` is vulnerable to an integer overflow issue caused by converting a signed integer value to an unsigned one and then allocating memory based on this value. The [implementation](https://github.com/tensorflow/tensorflow/blob/8d72537c6abf5a44103b57b9c2e22c14f5f49698/tensorflow/core/kernels/string_ngrams_op.cc#L184) calls `reserve` on a `tstring` with a value that sometimes can be negative if user supplies negative `ngram_widths`. The `reserve` method calls `TF_TString_Reserve` which has an `unsigned long` argument for the size of the buffer. Hence, the implicit conversion transforms the negative value to a large integer. We have patched the issue in GitHub commit c283e542a3f422420cfdb332414543b62fc4e4a5. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| tensorflow | 2.5.0 to before 2.5.1; 2.4.0 to before 2.4.3; before 2.3.4 | 2.5.1, 2.4.3, 2.3.4 | Patch available | CNA | |
| — | tensorflow (PyPI) | before 2.3.4 | 2.3.4 | Patch available | GHSA-h6jh-7gv5-28vg |
| — | tensorflow (PyPI) | 2.4.0 to before 2.4.3 | 2.4.3 | Patch available | GHSA-h6jh-7gv5-28vg |
| — | tensorflow (PyPI) | 2.5.0 to before 2.5.1 | 2.5.1 | Patch available | GHSA-h6jh-7gv5-28vg |
| — | tensorflow-cpu (PyPI) | before 2.3.4 | 2.3.4 | Patch available | GHSA-h6jh-7gv5-28vg |
| — | tensorflow-cpu (PyPI) | 2.4.0 to before 2.4.3 | 2.4.3 | Patch available | GHSA-h6jh-7gv5-28vg |
| — | tensorflow-cpu (PyPI) | 2.5.0 to before 2.5.1 | 2.5.1 | Patch available | GHSA-h6jh-7gv5-28vg |
| — | tensorflow-gpu (PyPI) | before 2.3.4 | 2.3.4 | Patch available | GHSA-h6jh-7gv5-28vg |
| — | tensorflow-gpu (PyPI) | 2.4.0 to before 2.4.3 | 2.4.3 | Patch available | GHSA-h6jh-7gv5-28vg |
| — | tensorflow-gpu (PyPI) | 2.5.0 to before 2.5.1 | 2.5.1 | Patch available | GHSA-h6jh-7gv5-28vg |
- tensorflow VendorGoogle Affected 2.5.0 to before 2.5.1; 2.4.0 to before 2.4.3; before 2.3.4 Fixed in 2.5.1, 2.4.3, 2.3.4 Patch available CNA
- tensorflow (PyPI) Vendor— Affected before 2.3.4 Fixed in 2.3.4 Patch available GHSA-h6jh-7gv5-28vg
- tensorflow (PyPI) Vendor— Affected 2.4.0 to before 2.4.3 Fixed in 2.4.3 Patch available GHSA-h6jh-7gv5-28vg
- tensorflow (PyPI) Vendor— Affected 2.5.0 to before 2.5.1 Fixed in 2.5.1 Patch available GHSA-h6jh-7gv5-28vg
- tensorflow-cpu (PyPI) Vendor— Affected before 2.3.4 Fixed in 2.3.4 Patch available GHSA-h6jh-7gv5-28vg
- tensorflow-cpu (PyPI) Vendor— Affected 2.4.0 to before 2.4.3 Fixed in 2.4.3 Patch available GHSA-h6jh-7gv5-28vg
- tensorflow-cpu (PyPI) Vendor— Affected 2.5.0 to before 2.5.1 Fixed in 2.5.1 Patch available GHSA-h6jh-7gv5-28vg
- tensorflow-gpu (PyPI) Vendor— Affected before 2.3.4 Fixed in 2.3.4 Patch available GHSA-h6jh-7gv5-28vg
- tensorflow-gpu (PyPI) Vendor— Affected 2.4.0 to before 2.4.3 Fixed in 2.4.3 Patch available GHSA-h6jh-7gv5-28vg
- tensorflow-gpu (PyPI) Vendor— Affected 2.5.0 to before 2.5.1 Fixed in 2.5.1 Patch available GHSA-h6jh-7gv5-28vg
CPE configurations NVD · 5
| CPE | Versions | Role | Vendor |
|---|---|---|---|
| cpe:2.3:a:google:tensorflow:*:*:*:*:*:*:*:* | 2.3.0 to before 2.3.4; 2.4.0 to before 2.4.3 | Vulnerable | |
| cpe:2.3:a:google:tensorflow:2.5.0:*:*:*:*:*:*:* | 2.5.0 | Vulnerable | |
| cpe:2.3:a:google:tensorflow:2.6.0:rc0:*:*:*:*:*:* | 2.6.0 rc0 | Vulnerable | |
| cpe:2.3:a:google:tensorflow:2.6.0:rc1:*:*:*:*:*:* | 2.6.0 rc1 | Vulnerable | |
| cpe:2.3:a:google:tensorflow:2.6.0:rc2:*:*:*:*:*:* | 2.6.0 rc2 | Vulnerable |
- cpe:2.3:a:google:tensorflow:*:*:*:*:*:*:*:* Versions 2.3.0 to before 2.3.4; 2.4.0 to before 2.4.3 Vulnerable ·Google
- cpe:2.3:a:google:tensorflow:2.5.0:*:*:*:*:*:*:* Versions 2.5.0 Vulnerable ·Google
- cpe:2.3:a:google:tensorflow:2.6.0:rc0:*:*:*:*:*:* Versions 2.6.0 rc0 Vulnerable ·Google
- cpe:2.3:a:google:tensorflow:2.6.0:rc1:*:*:*:*:*:* Versions 2.6.0 rc1 Vulnerable ·Google
- cpe:2.3:a:google:tensorflow:2.6.0:rc2:*:*:*:*:*:* Versions 2.6.0 rc2 Vulnerable ·Google
Remediation
- Fix · CNA tensorflow (tensorflow) Fixed in 2.5.1, 2.4.3, 2.3.4
- Fix · GHSA-h6jh-7gv5-28vg tensorflow (PyPI) Fixed in 2.3.4 Advisory →
- Fix · GHSA-h6jh-7gv5-28vg tensorflow (PyPI) Fixed in 2.4.3 Advisory →
- Fix · GHSA-h6jh-7gv5-28vg tensorflow (PyPI) Fixed in 2.5.1 Advisory →
- Fix · GHSA-h6jh-7gv5-28vg tensorflow-cpu (PyPI) Fixed in 2.3.4 Advisory →
- Fix · GHSA-h6jh-7gv5-28vg tensorflow-cpu (PyPI) Fixed in 2.4.3 Advisory →
- Fix · GHSA-h6jh-7gv5-28vg tensorflow-cpu (PyPI) Fixed in 2.5.1 Advisory →
- Fix · GHSA-h6jh-7gv5-28vg tensorflow-gpu (PyPI) Fixed in 2.3.4 Advisory →
- Fix · GHSA-h6jh-7gv5-28vg tensorflow-gpu (PyPI) Fixed in 2.4.3 Advisory →
- Fix · GHSA-h6jh-7gv5-28vg tensorflow-gpu (PyPI) Fixed in 2.5.1 Advisory →
Timeline
- 2026-10-02 Threatist record created from CVE-2021-37646
- 2026-10-03 Alias added: GHSA-h6jh-7gv5-28vg
References
Advisory 2
Other 4
- https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-559.yaml
- https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-757.yaml
- https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-268.yaml
- https://github.com/tensorflow/tensorflow
More Google Tensorflow vulnerabilities
- TI-2022-20241 FractionalMaxPool and FractionalAVGPool heap out-of-bounds acess in Tensorflow CVSS 3.1CRITICAL 9.8
- TI-2022-07640 Integer overflow in Tensorflow CVSS 3.1CRITICAL 9.8
- TI-2022-07627 Out of bounds read and write in Tensorflow CVSS 3.1HIGH 8.8
- TI-2022-07619 Out of bounds write in Tensorflow CVSS 3.1HIGH 8.8
- TI-2022-07613 Read and Write outside of bounds in TFLite CVSS 3.1HIGH 8.8
- TI-2022-07612 Integer overflow in TFLite CVSS 3.1HIGH 8.8
Sources
- CVE-2021-37646 · CVE Program
- CVE-2021-37646 · NVD
- FIRST EPSS
- GHSA-h6jh-7gv5-28vg · GitHub Advisory Database · CC BY 4.0
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences