{"id":"CVE-2021-29542","published":"2021-05-14T19:11:17Z","modified":"2024-08-03T22:11:05Z","title":"Heap buffer overflow in `StringNGrams`","vendor":"tensorflow","product":"tensorflow","tier":"tail","description":{"text":"TensorFlow is an end-to-end open source platform for machine learning. An attacker can cause a heap buffer overflow by passing crafted inputs to `tf.raw_ops.StringNGrams`. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/1cdd4da14282210cc759e468d9781741ac7d01bf/tensorflow/core/kernels/string_ngrams_op.cc#L171-L185) fails to consider corner cases where input would be split in such a way that the generated tokens should only contain padding elements. If input is such that `num_tokens` is 0, then, for `data_start_index=0` (when left padding is present), the marked line would result in reading `data[-1]`. 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.","provenance":"source","from":"CVE.org"},"cvss":{"score":2.5,"severity":"LOW","version":"3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L","provenance":"source","from":"CVE.org CNA"},"epss":{"score":0.00198,"percentile":0.05549,"provenance":"source"},"cwes":[{"id":"CWE-131","name":"Incorrect Calculation of Buffer Size"}],"references":[{"url":"https://github.com/tensorflow/tensorflow/security/advisories/GHSA-4hrh-9vmp-2jgg","tags":["x_refsource_CONFIRM"]},{"url":"https://github.com/tensorflow/tensorflow/commit/ba424dd8f16f7110eea526a8086f1a155f14f22b","tags":["x_refsource_MISC"]}],"priority":{"score":2.9,"factors":[{"name":"EPSS percentile","points":1.11},{"name":"CVSS severity","points":1.75}]},"vendorSlug":"tensorflow","affectedVersions":[{"vendor":"tensorflow","product":"tensorflow","versions":["< 2.1.4",">= 2.2.0, < 2.2.3",">= 2.3.0, < 2.3.3",">= 2.4.0, < 2.4.2"]}],"affected":[{"ecosystem":"PyPI","package":"tensorflow","vulnerableRanges":["<2.1.4",">=2.2.0, <2.2.3",">=2.3.0, <2.3.3",">=2.4.0, <2.4.2"],"patched":["2.1.4","2.2.3","2.3.3","2.4.2"],"from":["GHSA-4hrh-9vmp-2jgg","PYSEC-2021-179"],"provenance":"source"},{"ecosystem":"PyPI","package":"tensorflow-cpu","vulnerableRanges":["<2.1.4",">=2.2.0, <2.2.3",">=2.3.0, <2.3.3",">=2.4.0, <2.4.2"],"patched":["2.1.4","2.2.3","2.3.3","2.4.2"],"from":["GHSA-4hrh-9vmp-2jgg","PYSEC-2021-470"],"provenance":"source"},{"ecosystem":"PyPI","package":"tensorflow-gpu","vulnerableRanges":["<2.1.4",">=2.2.0, <2.2.3",">=2.3.0, <2.3.3",">=2.4.0, <2.4.2"],"patched":["2.1.4","2.2.3","2.3.3","2.4.2"],"from":["GHSA-4hrh-9vmp-2jgg","PYSEC-2021-668"],"provenance":"source"}],"summary":{"text":"A heap buffer overflow in the StringNGrams op of TensorFlow's machine learning platform, where the implementation mishandles inputs that split into only padding tokens and so reads out of bounds in the heap. An attacker who can supply crafted inputs to tf.raw_ops.StringNGrams can trigger the flaw, with the attack requiring local access and high attack complexity, and a low-privilege account while no user interaction is needed.","provenance":"ai","model":"claude-haiku-5-5","generatedAt":"2026-11-20T22:22:56Z"},"euvd":{"id":"EUVD-2021-0283","exploited":false,"provenance":"source"},"lineage":{"familyId":"fam-tensorflow-cve-2020-15205","parents":[{"from":"CVE-2020-15205","to":"CVE-2021-29542","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["tensorflow/core/kernels/string_ngrams_op.cc"],"commits":["https://github.com/tensorflow/tensorflow/commit/0462de5b544ed4731aa2fb23946ac22c01856b80","https://github.com/tensorflow/tensorflow/commit/ba424dd8f16f7110eea526a8086f1a155f14f22b"],"basis":"shared function","functions":["StringNGramsOp"]}]}],"children":[{"from":"CVE-2021-29542","to":"CVE-2021-37646","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["tensorflow/core/kernels/string_ngrams_op.cc"],"commits":["https://github.com/tensorflow/tensorflow/commit/ba424dd8f16f7110eea526a8086f1a155f14f22b","https://github.com/tensorflow/tensorflow/commit/c283e542a3f422420cfdb332414543b62fc4e4a5"],"basis":"shared function","functions":["StringNGramsOp"]}]},{"from":"CVE-2021-29542","to":"CVE-2022-21733","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["tensorflow/core/kernels/string_ngrams_op.cc"],"commits":["https://github.com/tensorflow/tensorflow/commit/ba424dd8f16f7110eea526a8086f1a155f14f22b","https://github.com/tensorflow/tensorflow/commit/f68fdab93fb7f4ddb4eb438c8fe052753c9413e8"],"basis":"shared function","functions":["StringNGramsOp"]}]}]}}