GHSA-g8wg-cjwc-xhhp
Vulnerability from github
8.4 (High) - CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N
Impact
It is possible to nest a tf.map_fn
within another tf.map_fn
call. However, if the input tensor is a RaggedTensor
and there is no function signature provided, code assumes the output is a fully specified tensor and fills output buffer with uninitialized contents from the heap:
python
import tensorflow as tf
x = tf.ragged.constant([[1,2,3], [4,5], [6]])
t = tf.map_fn(lambda r: tf.map_fn(lambda y: r, r), x)
z = tf.ragged.constant([[[1,2,3],[1,2,3],[1,2,3]],[[4,5],[4,5]],[[6]]])
The t
and z
outputs should be identical, however this is not the case. The last row of t
contains data from the heap which can be used to leak other memory information.
The bug lies in the conversion from a Variant
tensor to a RaggedTensor
. The implementation does not check that all inner shapes match and this results in the additional dimensions in the above example.
The same implementation can result in data loss, if input tensor is tweaked:
python
import tensorflow as tf
x = tf.ragged.constant([[1,2], [3,4,5], [6]])
t = tf.map_fn(lambda r: tf.map_fn(lambda y: r, r), x)
Here, the output tensor will only have 2 elements for each inner dimension.
Patches
We have patched the issue in GitHub commit 4e2565483d0ffcadc719bd44893fb7f609bb5f12.
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.
For more information
Please consult our security guide for more information regarding the security model and how to contact us with issues and questions.
Attribution
This vulnerability has been reported by Haris Sahovic.
{ "affected": [ { "package": { "ecosystem": "PyPI", "name": "tensorflow" }, "ranges": [ { "events": [ { "introduced": "0" }, { "fixed": "2.3.4" } ], "type": "ECOSYSTEM" } ] }, { "package": { "ecosystem": "PyPI", "name": "tensorflow" }, "ranges": [ { "events": [ { "introduced": "2.4.0" }, { "fixed": "2.4.3" } ], "type": "ECOSYSTEM" } ] }, { "package": { "ecosystem": "PyPI", "name": "tensorflow" }, "ranges": [ { "events": [ { "introduced": "2.5.0" }, { "fixed": "2.5.1" } ], "type": "ECOSYSTEM" } ], "versions": [ "2.5.0" ] }, { "package": { "ecosystem": "PyPI", "name": "tensorflow-cpu" }, "ranges": [ { "events": [ { "introduced": "0" }, { "fixed": "2.3.4" } ], "type": "ECOSYSTEM" } ] }, { "package": { "ecosystem": "PyPI", "name": "tensorflow-cpu" }, "ranges": [ { "events": [ { "introduced": "2.4.0" }, { "fixed": "2.4.3" } ], "type": "ECOSYSTEM" } ] }, { "package": { "ecosystem": "PyPI", "name": "tensorflow-cpu" }, "ranges": [ { "events": [ { "introduced": "2.5.0" }, { "fixed": "2.5.1" } ], "type": "ECOSYSTEM" } ], "versions": [ "2.5.0" ] }, { "package": { "ecosystem": "PyPI", "name": "tensorflow-gpu" }, "ranges": [ { "events": [ { "introduced": "0" }, { "fixed": "2.3.4" } ], "type": "ECOSYSTEM" } ] }, { "package": { "ecosystem": "PyPI", "name": "tensorflow-gpu" }, "ranges": [ { "events": [ { "introduced": "2.4.0" }, { "fixed": "2.4.3" } ], "type": "ECOSYSTEM" } ] }, { "package": { "ecosystem": "PyPI", "name": "tensorflow-gpu" }, "ranges": [ { "events": [ { "introduced": "2.5.0" }, { "fixed": "2.5.1" } ], "type": "ECOSYSTEM" } ], "versions": [ "2.5.0" ] } ], "aliases": [ "CVE-2021-37679" ], "database_specific": { "cwe_ids": [ "CWE-125", "CWE-681" ], "github_reviewed": true, "github_reviewed_at": "2021-08-24T16:17:59Z", "nvd_published_at": "2021-08-12T23:15:00Z", "severity": "HIGH" }, "details": "### Impact\nIt is possible to nest a `tf.map_fn` within another `tf.map_fn` call. However, if the input tensor is a `RaggedTensor` and there is no function signature provided, code assumes the output is a fully specified tensor and fills output buffer with uninitialized contents from the heap:\n\n```python\nimport tensorflow as tf\nx = tf.ragged.constant([[1,2,3], [4,5], [6]])\nt = tf.map_fn(lambda r: tf.map_fn(lambda y: r, r), x)\nz = tf.ragged.constant([[[1,2,3],[1,2,3],[1,2,3]],[[4,5],[4,5]],[[6]]])\n```\n \nThe `t` and `z` outputs should be identical, however this is not the case. The last row of `t` contains data from the heap which can be used to leak other memory information.\n\nThe bug lies in the conversion from a `Variant` tensor to a `RaggedTensor`. The [implementation](https://github.com/tensorflow/tensorflow/blob/460e000de3a83278fb00b61a16d161b1964f15f4/tensorflow/core/kernels/ragged_tensor_from_variant_op.cc#L177-L190) does not check that all inner shapes match and this results in the additional dimensions in the above example.\n\nThe same implementation can result in data loss, if input tensor is tweaked:\n\n```python\nimport tensorflow as tf\nx = tf.ragged.constant([[1,2], [3,4,5], [6]])\nt = tf.map_fn(lambda r: tf.map_fn(lambda y: r, r), x) \n```\n\nHere, the output tensor will only have 2 elements for each inner dimension.\n\n### Patches\nWe have patched the issue in GitHub commit [4e2565483d0ffcadc719bd44893fb7f609bb5f12](https://github.com/tensorflow/tensorflow/commit/4e2565483d0ffcadc719bd44893fb7f609bb5f12).\n\nThe 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.\n\n### For more information\nPlease consult [our security guide](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for more information regarding the security model and how to contact us with issues and questions.\n\n### Attribution\nThis vulnerability has been reported by Haris Sahovic.", "id": "GHSA-g8wg-cjwc-xhhp", "modified": "2024-11-13T21:15:11Z", "published": "2021-08-25T14:41:00Z", "references": [ { "type": "WEB", "url": "https://github.com/tensorflow/tensorflow/security/advisories/GHSA-g8wg-cjwc-xhhp" }, { "type": "ADVISORY", "url": "https://nvd.nist.gov/vuln/detail/CVE-2021-37679" }, { "type": "WEB", "url": "https://github.com/tensorflow/tensorflow/commit/4e2565483d0ffcadc719bd44893fb7f609bb5f12" }, { "type": "WEB", "url": "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-592.yaml" }, { "type": "WEB", "url": "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-790.yaml" }, { "type": "WEB", "url": "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-301.yaml" }, { "type": "PACKAGE", "url": "https://github.com/tensorflow/tensorflow" } ], "schema_version": "1.4.0", "severity": [ { "score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N", "type": "CVSS_V3" }, { "score": "CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N", "type": "CVSS_V4" } ], "summary": "Heap OOB in nested `tf.map_fn` with `RaggedTensor`s" }
Sightings
Author | Source | Type | Date |
---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or seen somewhere by the user.
- Confirmed: The vulnerability is confirmed from an analyst perspective.
- Exploited: This vulnerability was exploited and seen by the user reporting the sighting.
- Patched: This vulnerability was successfully patched by the user reporting the sighting.
- Not exploited: This vulnerability was not exploited or seen by the user reporting the sighting.
- Not confirmed: The user expresses doubt about the veracity of the vulnerability.
- Not patched: This vulnerability was not successfully patched by the user reporting the sighting.