CVE-2022-41894: Tensorflow Buffer Overflow Vulnerability

HIGH
Advisory Identifier: GHSA-h6q3-vv32-2cq5
CVSS 7.1
CWE-120
Published
Advisory Summary

CVE-2022-41894 is a HIGH (CVSS 7.1) buffer overflow vulnerability (CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')) affecting Tensorflow libraries in the PyPI ecosystem. The issue involves buffer overflow in `conv_3d_transpose` on tflite. Remediation is available by upgrading affected packages to version 2.8.4, 2.9.3, 2.10.1.

CVE-2022-41894 at a Glance

CVE Identifier CVE-2022-41894
GHSA Identifier GHSA-h6q3-vv32-2cq5
Severity HIGH
CVSS v3.1 Base Score 7.1
CWE Classification CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
Affected Product Tensorflow
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2022-41894

To remediate this vulnerability, upgrade all affected Tensorflow dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

tensorflow fixed: 2.8.4
pip install tensorflow>=2.8.4
tensorflow fixed: 2.9.3
pip install tensorflow>=2.9.3
tensorflow fixed: 2.10.1
pip install tensorflow>=2.10.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show tensorflow

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2022-41894, inspect your installed packages using pip:

pip show tensorflow

Analyze the terminal output to locate any version of Tensorflow in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.8.4), your application is affected.

Note: The pip show tensorflow command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow'), where the product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer. In Tensorflow, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact The reference kernel of the [`CONV_3D_TRANSPOSE`](https://github.com/tensorflow/tensorflow/blob/091e63f0ea33def7ecad661a5ac01dcafbafa90b/tensorflow/lite/kernels/internal/reference/conv3d_transpose.h#L121) TensorFlow Lite operator wrongly increments the data_ptr when adding the bias to the result. Instead of `data_ptr += num_channels;` it should be `data_ptr += output_num_channels;` as if the number of input channels is different than the number of output channels, the wrong result will be returned and a buffer overflow will occur if num_channels > output_num_channels. An attacker can craft a model with a specific number of input channels in a way similar to the attached example script. It is then possible to write specific values through the bias of the layer outside the bounds of the buffer. This attack only works if the reference kernel resolver is used in the interpreter (i.e. `experimental_op_resolver_type=tf.lite.experimental.OpResolverType.BUILTIN_REF` is used). ```python import tensorflow as tf model = tf.keras.Sequential( [ tf.keras.layers.InputLayer(input_shape=(2, 2, 2, 1024), batch_size=1), tf.keras.layers.Conv3DTranspose( filters=8, kernel_size=(2, 2, 2), padding="same", data_format="channels_last", ), ] ) converter = tf.lite.TFLiteConverter.from_keras_model(model) tflite_model = converter.convert() interpreter = tf.lite.Interpreter( model_content=tflite_model, experimental_op_resolver_type=tf.lite.experimental.OpResolverType.BUILTIN_REF, ) interpreter.allocate_tensors() interpreter.set_tensor( interpreter.get_input_details()[0]["index"], tf.zeros(shape=[1, 2, 2, 2, 1024]) ) interpreter.invoke() ``` ### Patches We have patched the issue in GitHub commit [72c0bdcb25305b0b36842d746cc61d72658d2941](https://github.com/tensorflow/tensorflow/commit/72c0bdcb25305b0b36842d746cc61d72658d2941). The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range. ### For more information Please 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. ### Attribution This vulnerability has been reported by Thibaut Goetghebuer-Planchon, Arm Ltd.

CVE-2022-41894 Affected Tensorflow Versions

3 component(s)
Fixed Versions:
2.8.42.9.32.10.1
Product / Package Ecosystem Affected Versions Fixed Version
tensorflow
PyPI
< 2.8.4
2.8.4
tensorflow
PyPI
≥ 2.9.0
< 2.9.3
2.9.3
tensorflow
PyPI
≥ 2.10.0
< 2.10.1
2.10.1

References

Frequently Asked Questions

What is CVE-2022-41894?
CVE-2022-41894 is a security vulnerability in Tensorflow involving Buffer overflow in `CONV_3D_TRANSPOSE` on TFLite under CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow').
Which Tensorflow versions are affected?
Affected versions include releases prior to 2.8.4, 2.9.3, 2.10.1 across affected packages: tensorflow.
What version fixes CVE-2022-41894?
Upgrading to 2.8.4, 2.9.3, 2.10.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is tensorflow affected?
Yes, tensorflow is affected in releases prior to 2.8.4, 2.9.3, 2.10.1. Upgrade your dependency to 2.8.4, 2.9.3, 2.10.1 or later.
What is the CVSS score of CVE-2022-41894?
CVE-2022-41894 has a CVSS v3.1 base score of 7.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-41894?
CVE-2022-41894 is classified under CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') (The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer.).
How can I check PyPI dependencies for CVE-2022-41894?
Run the dependency tree command: 'pip show tensorflow'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-h6q3-vv32-2cq5",
  "modified" : "2022-11-21T20:44:24Z",
  "published" : "2022-11-21T20:44:24Z",
  "aliases" : [ "CVE-2022-41894" ],
  "summary" : "Buffer overflow in `CONV_3D_TRANSPOSE` on TFLite",
  "details" : "### Impact\nThe reference kernel of the [`CONV_3D_TRANSPOSE`](https://github.com/tensorflow/tensorflow/blob/091e63f0ea33def7ecad661a5ac01dcafbafa90b/tensorflow/lite/kernels/internal/reference/conv3d_transpose.h#L121) TensorFlow Lite operator wrongly increments the data_ptr when adding the bias to the result.\n\nInstead of `data_ptr += num_channels;` it should be `data_ptr += output_num_channels;` as if the number of input channels is different than the number of output channels, the wrong result will be returned and a buffer overflow will occur if num_channels > output_num_channels.\n\nAn attacker can craft a model with a specific number of input channels in a way similar to the attached example script. It is then possible to write specific values through the bias of the layer outside the bounds of the buffer. This attack only works if the reference kernel resolver is used in the interpreter (i.e. `experimental_op_resolver_type=tf.lite.experimental.OpResolverType.BUILTIN_REF` is used).\n```python\nimport tensorflow as tf\nmodel = tf.keras.Sequential(\n    [\n        tf.keras.layers.InputLayer(input_shape=(2, 2, 2, 1024), batch_size=1),\n        tf.keras.layers.Conv3DTranspose(\n            filters=8,\n            kernel_size=(2, 2, 2),\n            padding=\"same\",\n            data_format=\"channels_last\",\n        ),\n    ]\n)\n\nconverter = tf.lite.TFLiteConverter.from_keras_model(model)\ntflite_model = converter.convert()\n\ninterpreter = tf.lite.Interpreter(\n    model_content=tflite_model,\n    experimental_op_resolver_type=tf.lite.experimental.OpResolverType.BUILTIN_REF,\n)\n\ninterpreter.allocate_tensors()\ninterpreter.set_tensor(\n    interpreter.get_input_details()[0][\"index\"], tf.zeros(shape=[1, 2, 2, 2, 1024])\n)\ninterpreter.invoke()\n```\n\n### Patches\nWe have patched the issue in GitHub commit [72c0bdcb25305b0b36842d746cc61d72658d2941](https://github.com/tensorflow/tensorflow/commit/72c0bdcb25305b0b36842d746cc61d72658d2941).\n\nThe fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.\n\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\n### Attribution\nThis vulnerability has been reported by Thibaut Goetghebuer-Planchon, Arm Ltd.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.8.4"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.9.0"
      }, {
        "fixed" : "2.9.3"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.10.0"
      }, {
        "fixed" : "2.10.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/tensorflow/tensorflow/security/advisories/GHSA-h6q3-vv32-2cq5"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-41894"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/tensorflow/tensorflow/commit/72c0bdcb25305b0b36842d746cc61d72658d2941"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/tensorflow/tensorflow"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/tensorflow/tensorflow/blob/091e63f0ea33def7ecad661a5ac01dcafbafa90b/tensorflow/lite/kernels/internal/reference/conv3d_transpose.h#L121"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-120" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-11-21T20:44:24Z",
    "nvd_published_at" : "2022-11-18T22:15:00Z"
  }
}