CVE-2021-41196: TensorFlow Keras Pooling Layers Segfault Vulnerability
Summary
CVE-2021-41196: TensorFlow is an open source platform for machine learning. Affects tensorflow-cpu across 5 version ranges.
< 2.4.4
>= 2.5.0, < 2.5.2
>= 2.6.0, < 2.6.1
>= 2.7.0rc0, < 2.7.0
< 12b1ff82b3f26ff8de17e58703231d5a02ef1b8b
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow · PyPI
- tensorflow · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-41196 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
TensorFlow is an open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models. TensorFlow includes a high-level API called Keras, which simplifies the process of building neural networks. Keras pooling layers are commonly used in machine learning models to reduce the spatial dimensions of input data. However, a vulnerability has been discovered in TensorFlow's implementation of Keras pooling layers that can lead to a segmentation fault (segfault) under certain conditions.
Vulnerability Detail
The vulnerability in TensorFlow's Keras pooling layers arises when the size of the pool is set to 0 or when a dimension is negative. This is due to a lack of validation in TensorFlow's implementation of pooling operations, where the values in the sliding window are not checked to be strictly positive. As a result, when these invalid parameters are used, it can trigger a segfault, causing the program to crash. An attacker could potentially exploit this vulnerability to cause a denial-of-service (DoS) attack or execute arbitrary code.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow-cpu==2.21.0"
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 2.4.42.4.4pip install --upgrade "tensorflow-cpu==2.4.4" -
>= 2.5.0, < 2.5.22.5.2pip install --upgrade "tensorflow-cpu==2.5.2" -
>= 2.6.0, < 2.6.12.6.1pip install --upgrade "tensorflow-cpu==2.6.1" -
>= 2.7.0rc0, < 2.7.02.7.0pip install --upgrade "tensorflow-cpu==2.7.0"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a workaround, users can ensure that the size of the pool is greater than 0 and that all dimensions are positive before using the Keras pooling layers. Here is an example code snippet that demonstrates the workaround:
from tensorflow.keras.layers import MaxPooling2D
pool_size = (2, 2)
if pool_size[0] > 0 and pool_size[1] > 0:
pooling_layer = MaxPooling2D(pool_size=pool_size)
# Continue with the rest of the code
else:
# Handle the invalid pool size
# ... (e.g., raise an exception, log an error, etc.)
By performing this check, you can prevent the usage of invalid pool sizes and mitigate the risk of triggering a segfault.
Conclusion
In conclusion, the TensorFlow Keras pooling layers segfault vulnerability can be mitigated by updating to the fixed versions of TensorFlow or by implementing the provided workaround. It is important to promptly address this vulnerability to prevent potential crashes and mitigate the risk of exploitation. For further support on vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for tensorflow-cpu →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models.
Keras pooling layers are a type of layer in TensorFlow's high-level API, Keras, that are used to reduce the spatial dimensions of input data in machine learning models.
The vulnerability arises when the size of the pool is set to 0 or when a dimension is negative. This is due to a lack of validation in TensorFlow's implementation of pooling operations.
The vulnerability can lead to a segmentation fault (segfault), causing the program to crash. An attacker could potentially exploit this vulnerability to cause a denial-of-service (DoS) attack or execute arbitrary code.
To fix the vulnerability, users should update their TensorFlow installation to one of the fixed versions: TensorFlow 2.7.0, TensorFlow 2.6.1, TensorFlow 2.5.2, or TensorFlow 2.4.4.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-cpu.