{"id":"CVE-2022-21728","aliases":["CVE-2022-21728","GHSA-6gmv-pjp9-p8w8","BIT-TENSORFLOW-2022-21728","PYSEC-2022-107","PYSEC-2022-52","PYSEC-2026-3121"],"related":[],"kind":"vulnerability","state":"published","title":"Out of bounds read in Tensorflow","summary":"Tensorflow is an Open Source Machine Learning Framework. The implementation of shape inference for `ReverseSequence` does not fully validate the value of `batch_dim` and can result in a heap OOB read. There is a check to make sure the value of `batch_dim` does not go over the rank of the input, but there is no check for negative values. Negative dimensions are allowed in some cases to mimic Python's negative indexing (i.e., indexing from the end of the array), however if the value is too negative then the implementation of `Dim` would access elements before the start of an array. The fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, as these are also affected and still in supported range.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Tensorflow is an Open Source Machine Learning Framework. The implementation of shape inference for `ReverseSequence` does not fully validate the value of `batch_dim` and can result in a heap OOB read. There is a check to make sure the value of `batch_dim` does not go over the rank of the input, but there is no check for negative values. Negative dimensions are allowed in some cases to mimic Python's negative indexing (i.e., indexing from the end of the array), however if the value is too negative then the implementation of `Dim` would access elements before the start of an array. The fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, as these are also affected and still in supported range.","source":"cvelist"},{"lang":"en","text":"### Impact \nThe [implementation of shape inference for `ReverseSequence`](https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/ops/array_ops.cc#L1636-L1671) does not fully validate the value of `batch_dim` and can result in a heap OOB read:\n\n```python\nimport tensorflow as tf\n\n@tf.function\ndef test():\n  y = tf.raw_ops.ReverseSequence(\n    input = ['aaa','bbb'],\n    seq_lengths = [1,1,1],\n    seq_dim = -10,\n    batch_dim = -10 )\n  return y\n    \ntest()\n```\n\nThere is a check to make sure the value of `batch_dim` does not go over the rank of the input, but there is no check for negative values:\n\n```cc\n  const int32_t input_rank = c->Rank(input);\n  if (batch_dim >= input_rank) {\n    return errors::InvalidArgument( \n        \"batch_dim must be < input rank: \", batch_dim, \" vs. \", input_rank);\n  }\n  // ...\n  \n  DimensionHandle batch_dim_dim = c->Dim(input, batch_dim);\n``` \n    \nNegative dimensions are allowed in some cases to mimic Python's negative indexing (i.e., indexing from the end of the array), however if the value is too negative then [the implementation of `Dim`](https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/framework/shape_inference.h#L415-L428) would access elements before the start of an array:\n\n```cc\n  DimensionHandle Dim(ShapeHandle s, int64_t idx) {\n    if (!s.Handle() || s->rank_ == kUnknownRank) {\n      return UnknownDim();\n    }\n    return DimKnownRank(s, idx);\n  } \n·\n  static DimensionHandle DimKnownRank(ShapeHandle s, int64_t idx) {\n    CHECK_NE(s->rank_, kUnknownRank);\n    if (idx < 0) {\n      return s->dims_[s->dims_.size() + idx];\n    }\n    return s->dims_[idx];\n  }\n```\n\n### Patches\nWe have patched the issue in GitHub commit [37c01fb5e25c3d80213060460196406c43d31995](https://github.com/tensorflow/tensorflow/commit/37c01fb5e25c3d80213060460196406c43d31995).\n\nThe fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, 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 Yu Tian of Qihoo 360 AIVul Team.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Tensorflow es un marco de aprendizaje automático de código abierto. La implementación de la inferencia de forma para \"ReverseSequence\" no comprueba completamente el valor de \"batch_dim\" y puede resultar en una lectura OOB del montón. Se presenta una comprobación para asegurarse de que el valor de \"batch_dim\" no supera el rango de la entrada, pero no hay ninguna comprobación para los valores negativos. Las dimensiones negativas son permitidas en algunos casos para imitar la indexación negativa de Python (es decir, la indexación desde el final del array), sin embargo si el valor es demasiado negativo entonces la implementación de \"Dim\" accedería a elementos antes del inicio de un array. La corrección será incluida en TensorFlow versión 2.8.0. También seleccionaremos este commit en TensorFlow versión 2.7.1, TensorFlow versión 2.6.3, y TensorFlow versión 2.5.3, ya que estos también están afectados y aún están en el rango admitido","source":"nvd"}],"published":"2022-02-03T10:55:55.000Z","modified":"2026-09-10T03:49:16.984Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:H","score":8.1,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:H","score":8.1,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:H","score":8.1,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:H/SC:N/SI:N/SA:N","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:H","score":8.1,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:L/Au:S/C:P/I:N/A:P","score":5.5,"rating":"MEDIUM"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:H","score":8.1,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:H/SC:N/SI:N/SA:N"},{"scorer":"Bitnami Vulnerability Database","scheme":"rating","rating":"HIGH"}],"cwes":["CWE-125"],"affected":[{"ranges":[{"version":"n/a","status":"affected"}],"source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.5.3"}],"ecosystem":"PyPI","package":"tensorflow","purl":"pkg:pypi/tensorflow","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.3"}],"ecosystem":"PyPI","package":"tensorflow","purl":"pkg:pypi/tensorflow","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.7.0","status":"affected","fixed":"2.7.1"}],"ecosystem":"PyPI","package":"tensorflow","purl":"pkg:pypi/tensorflow","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.5.3"}],"ecosystem":"PyPI","package":"tensorflow-cpu","purl":"pkg:pypi/tensorflow-cpu","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.3"}],"ecosystem":"PyPI","package":"tensorflow-cpu","purl":"pkg:pypi/tensorflow-cpu","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.7.0","status":"affected","fixed":"2.7.1"}],"ecosystem":"PyPI","package":"tensorflow-cpu","purl":"pkg:pypi/tensorflow-cpu","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.5.3"}],"ecosystem":"PyPI","package":"tensorflow-gpu","purl":"pkg:pypi/tensorflow-gpu","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.3"}],"ecosystem":"PyPI","package":"tensorflow-gpu","purl":"pkg:pypi/tensorflow-gpu","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.7.0","status":"affected","fixed":"2.7.1"}],"ecosystem":"PyPI","package":"tensorflow-gpu","purl":"pkg:pypi/tensorflow-gpu","source":"ghsa"},{"ranges":[{"status":"affected","lastAffected":"2.5.2"},{"status":"affected","introduced":"2.6.0","lastAffected":"2.6.2"},{"status":"affected","version":"2.7.0"}],"vendor":"google","product":"tensorflow","cpe":"cpe:2.3:a:google:tensorflow:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"37c01fb5e25c3d80213060460196406c43d31995"},{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.5.3"},{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.3"}],"ecosystem":"PyPI","package":"tensorflow-gpu","purl":"pkg:pypi/tensorflow-gpu","repo":"https://github.com/tensorflow/tensorflow","source":"pysec"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"37c01fb5e25c3d80213060460196406c43d31995"},{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.5.3"},{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.3"}],"ecosystem":"PyPI","package":"tensorflow-cpu","purl":"pkg:pypi/tensorflow-cpu","repo":"https://github.com/tensorflow/tensorflow","source":"pysec"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.5.3"},{"type":"ecosystem","introduced":"2.6.0","status":"affected","fixed":"2.6.3"},{"type":"ecosystem","introduced":"2.7.0","status":"affected","fixed":"2.7.1"}],"ecosystem":"PyPI","package":"tensorflow","purl":"pkg:pypi/tensorflow","source":"pysec"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"2.5.3"},{"type":"semver","introduced":"2.6.0","status":"affected","fixed":"2.6.3"},{"type":"semver","introduced":"2.7.0","status":"affected","fixed":"2.7.1"}],"ecosystem":"Bitnami","package":"tensorflow","purl":"pkg:bitnami/tensorflow","source":"bitnami"}],"references":[{"url":"https://github.com/tensorflow/tensorflow/security/advisories/GHSA-6gmv-pjp9-p8w8","tags":["advisory","patch","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/tensorflow/tensorflow/commit/37c01fb5e25c3d80213060460196406c43d31995","tags":["advisory","fix","patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/framework/shape_inference.h#L415-L428","tags":["advisory","exploit","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/ops/array_ops.cc#L1636-L1671","tags":["advisory","exploit","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2022-21728","tags":["advisory","web"],"sources":["ghsa","pysec","bitnami"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2022-52.yaml","tags":["web"],"sources":["ghsa","pysec"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2022-107.yaml","tags":["web"],"sources":["ghsa","pysec"]},{"url":"https://github.com/tensorflow/tensorflow","tags":["web"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/tensorflow","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-6gmv-pjp9-p8w8","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2025-04-25T15:47:32.997Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2022-21728","url":"https://www.cve.org/CVERecord?id=CVE-2022-21728","licence":"CVE Terms of Use","modified":"2025-05-05T16:32:41.878Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-6gmv-pjp9-p8w8","url":"https://github.com/advisories/GHSA-6gmv-pjp9-p8w8","licence":"CC-BY-4.0","modified":"2026-09-10T03:49:16.984Z"},{"source":"nvd","name":"NVD","id":"CVE-2022-21728","url":"https://nvd.nist.gov/vuln/detail/CVE-2022-21728","licence":"Public domain","modified":"2026-06-17T04:26:52.233Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2022-107","url":"https://osv.dev/vulnerability/PYSEC-2022-107","licence":"CC-BY-4.0","modified":"2026-07-13T16:43:13.231Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2022-52","url":"https://osv.dev/vulnerability/PYSEC-2022-52","licence":"CC-BY-4.0","modified":"2026-07-13T16:43:13.231Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-3121","url":"https://osv.dev/vulnerability/PYSEC-2026-3121","licence":"CC-BY-4.0","modified":"2026-07-13T16:43:13.231Z"},{"source":"bitnami","name":"Bitnami Vulnerability Database","id":"BIT-TENSORFLOW-2022-21728","url":"https://osv.dev/vulnerability/BIT-TENSORFLOW-2022-21728","licence":"Apache-2.0","modified":"2026-09-08T08:48:25.244Z"}],"updatedAt":"2026-11-25T22:58:09.471Z","epss":{"score":0.01172,"percentile":0.6835,"date":"2026-12-01T12:00:22.000Z"}}