CVE-2021-41228: Tensorflow Code Injection Vulnerability

MODERATE
Advisory Identifier: GHSA-3rcw-9p9x-582v
CVSS 7.5
CWE-78 CWE-94
Published
Advisory Summary

CVE-2021-41228 is a MODERATE (CVSS 7.5) code injection vulnerability (CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) affecting Tensorflow libraries in the PyPI ecosystem. The issue involves code injection in `saved_model_cli`. Remediation is available by upgrading affected packages to version 2.5.2, 2.4.4, 2.6.1.

CVE-2021-41228 at a Glance

CVE Identifier CVE-2021-41228
GHSA Identifier GHSA-3rcw-9p9x-582v
Severity MODERATE
CVSS v3.1 Base Score 7.5
CWE Classification CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Affected Product Tensorflow
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

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

Attack Vector Local (AV:L)
Attack Complexity High (AC:H)
Privileges Required High (PR:H)
User Interaction None (UI:N)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2021-41228

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.5.2
pip install tensorflow>=2.5.2
tensorflow fixed: 2.4.4
pip install tensorflow>=2.4.4
tensorflow fixed: 2.6.1
pip install tensorflow>=2.6.1
tensorflow-cpu fixed: 2.5.2
pip install tensorflow-cpu>=2.5.2
tensorflow-cpu fixed: 2.4.4
pip install tensorflow-cpu>=2.4.4
tensorflow-cpu fixed: 2.6.1
pip install tensorflow-cpu>=2.6.1
tensorflow-gpu fixed: 2.5.2
pip install tensorflow-gpu>=2.5.2
tensorflow-gpu fixed: 2.4.4
pip install tensorflow-gpu>=2.4.4
tensorflow-gpu fixed: 2.6.1
pip install tensorflow-gpu>=2.6.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-2021-41228, 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.5.2), 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-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where the product constructs all or part of an os command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended os command when it is sent to a downstream component. 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 TensorFlow's `saved_model_cli` tool is vulnerable to a code injection as it [calls `eval` on user supplied strings](https://github.com/tensorflow/tensorflow/blob/87462bfac761435a46641ff2f10ad0b6e5414a4b/tensorflow/python/tools/saved_model_cli.py#L524-L550) ```python def preprocess_input_exprs_arg_string(input_exprs_str): ... for input_raw in filter(bool, input_exprs_str.split(';')): ... input_key, expr = input_raw.split('=', 1) input_dict[input_key] = eval(expr) ... ``` This can be used by attackers to run arbitrary code on the plaform where the CLI tool runs. However, given that the tool is always run manually, the impact of this is not severe. We have patched this by adding a `safe` flag which defaults to `True` and an explicit warning for users. ### Patches We have patched the issue in GitHub commit [8b202f08d52e8206af2bdb2112a62fafbc546ec7](https://github.com/tensorflow/tensorflow/commit/8b202f08d52e8206af2bdb2112a62fafbc546ec7). The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.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 Omer Kaspi from Vdoo.

CVE-2021-41228 Affected Tensorflow Versions

9 component(s)
Fixed Versions:
2.5.22.4.42.6.1
Product / Package Ecosystem Affected Versions Fixed Version
tensorflow
PyPI
≥ 2.5.0
< 2.5.2
2.5.2
tensorflow
PyPI
< 2.4.4
2.4.4
tensorflow
PyPI
≥ 2.6.0
< 2.6.1
2.6.1
tensorflow-cpu
PyPI
≥ 2.5.0
< 2.5.2
2.5.2
tensorflow-cpu
PyPI
< 2.4.4
2.4.4
tensorflow-cpu
PyPI
≥ 2.6.0
< 2.6.1
2.6.1
tensorflow-gpu
PyPI
≥ 2.5.0
< 2.5.2
2.5.2
tensorflow-gpu
PyPI
< 2.4.4
2.4.4
tensorflow-gpu
PyPI
≥ 2.6.0
< 2.6.1
2.6.1

References

Frequently Asked Questions

What is CVE-2021-41228?
CVE-2021-41228 is a security vulnerability in Tensorflow involving Code injection in `saved_model_cli` under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Which Tensorflow versions are affected?
Affected versions include releases prior to 2.5.2, 2.4.4, 2.6.1 across affected packages: tensorflow, tensorflow-cpu, tensorflow-gpu.
What version fixes CVE-2021-41228?
Upgrading to 2.5.2, 2.4.4, 2.6.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.5.2, 2.4.4, 2.6.1. Upgrade your dependency to 2.5.2, 2.4.4, 2.6.1 or later.
Is tensorflow-cpu affected?
Yes, tensorflow-cpu is affected in releases prior to 2.5.2, 2.4.4, 2.6.1. Upgrade your dependency to 2.5.2, 2.4.4, 2.6.1 or later.
What is the CVSS score of CVE-2021-41228?
CVE-2021-41228 has a CVSS v3.1 base score of 7.5 (MODERATE) with vector string CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2021-41228?
CVE-2021-41228 is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.).
How can I check PyPI dependencies for CVE-2021-41228?
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-3rcw-9p9x-582v",
  "modified" : "2024-11-13T22:06:49Z",
  "published" : "2021-11-10T16:54:02Z",
  "aliases" : [ "CVE-2021-41228" ],
  "summary" : "Code injection in `saved_model_cli`",
  "details" : "### Impact\nTensorFlow's `saved_model_cli` tool is vulnerable to a code injection as it [calls `eval` on user supplied strings](https://github.com/tensorflow/tensorflow/blob/87462bfac761435a46641ff2f10ad0b6e5414a4b/tensorflow/python/tools/saved_model_cli.py#L524-L550)\n  \n```python\ndef preprocess_input_exprs_arg_string(input_exprs_str):\n  ... \n  for input_raw in filter(bool, input_exprs_str.split(';')):\n    ...\n    input_key, expr = input_raw.split('=', 1)\n    input_dict[input_key] = eval(expr)\n  ...\n``` \n  \nThis can be used by attackers to run arbitrary code on the plaform where the CLI tool runs.\nHowever, given that the tool is always run manually, the impact of this is not severe. We have patched this by adding a `safe` flag which defaults to `True` and an explicit warning for users. \n\n### Patches\nWe have patched the issue in GitHub commit [8b202f08d52e8206af2bdb2112a62fafbc546ec7](https://github.com/tensorflow/tensorflow/commit/8b202f08d52e8206af2bdb2112a62fafbc546ec7).\n\nThe fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.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 Omer Kaspi from Vdoo.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:C/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:L/AC:L/AT:P/PR:H/UI:N/VC:N/VI:N/VA:N/SC:H/SI:H/SA:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.5.0"
      }, {
        "fixed" : "2.5.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.4.4"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.6.0"
      }, {
        "fixed" : "2.6.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow-cpu"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.5.0"
      }, {
        "fixed" : "2.5.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow-cpu"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.4.4"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow-cpu"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.6.0"
      }, {
        "fixed" : "2.6.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow-gpu"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.5.0"
      }, {
        "fixed" : "2.5.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow-gpu"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.4.4"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "tensorflow-gpu"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.6.0"
      }, {
        "fixed" : "2.6.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/tensorflow/tensorflow/security/advisories/GHSA-3rcw-9p9x-582v"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-41228"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/tensorflow/tensorflow/commit/8b202f08d52e8206af2bdb2112a62fafbc546ec7"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-637.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-835.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-420.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/tensorflow/tensorflow"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-78", "CWE-94" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-11-08T21:43:17Z",
    "nvd_published_at" : "2021-11-05T23:15:00Z"
  }
}