Integer overflow in Tensorflow
Description
Tensorflow is an Open Source Machine Learning Framework. The implementation of OpLevelCostEstimator::CalculateOutputSize is vulnerable to an integer overflow if an attacker can create an operation which would involve tensors with large enough number of elements. We can have a large enough number of dimensions in output_shape.dim() or just a small number of dimensions being large enough to cause an overflow in the multiplication. 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.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
tensorflowPyPI | < 2.5.3 | 2.5.3 |
tensorflowPyPI | >= 2.6.0, < 2.6.3 | 2.6.3 |
tensorflowPyPI | >= 2.7.0, < 2.7.1 | 2.7.1 |
tensorflow-cpuPyPI | < 2.5.3 | 2.5.3 |
tensorflow-cpuPyPI | >= 2.6.0, < 2.6.3 | 2.6.3 |
tensorflow-cpuPyPI | >= 2.7.0, < 2.7.1 | 2.7.1 |
tensorflow-gpuPyPI | < 2.5.3 | 2.5.3 |
tensorflow-gpuPyPI | >= 2.6.0, < 2.6.3 | 2.6.3 |
tensorflow-gpuPyPI | >= 2.7.0, < 2.7.1 | 2.7.1 |
Affected products
1- Range: >= 2.7.0, < 2.7.1
Patches
1b9bd6cfd1c50Prevent integer overflow in `OpLevelCostEstimator::CalculateOutputSize`.
2 files changed · +10 −1
tensorflow/core/grappler/costs/BUILD+1 −0 modified@@ -340,6 +340,7 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:protos_all_cc", "//tensorflow/core/grappler/clusters:utils", + "//tensorflow/core/util:overflow", ] + tf_protos_grappler(), )
tensorflow/core/grappler/costs/op_level_cost_estimator.cc+9 −1 modified@@ -27,6 +27,7 @@ limitations under the License. #include "tensorflow/core/grappler/costs/op_context.h" #include "tensorflow/core/grappler/costs/utils.h" #include "tensorflow/core/platform/errors.h" +#include "tensorflow/core/util/overflow.h" namespace tensorflow { namespace grappler { @@ -1607,7 +1608,14 @@ int64_t OpLevelCostEstimator::CalculateOutputSize(const OpInfo& op_info, auto output_shape = MaybeGetMinimumShape(original_output_shape, num_dims, found_unknown_shapes); for (const auto& dim : output_shape.dim()) { - output_size *= dim.size(); + int64_t new_output_size = + MultiplyWithoutOverflow(output_size, dim.size()); + if (new_output_size < 0) { + VLOG(1) << "Overflow encountered when estimating cost, multiplying " + << output_size << " with " << dim.size(); + return -1; + } + output_size = new_output_size; } total_output_size += output_size; VLOG(1) << "Output Size: " << output_size
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
7- github.com/advisories/GHSA-wm93-f238-7v37ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2022-23576ghsaADVISORY
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2022-85.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2022-140.yamlghsaWEB
- github.com/tensorflow/tensorflow/blob/a1320ec1eac186da1d03f033109191f715b2b130/tensorflow/core/grappler/costs/op_level_cost_estimator.ccghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/commit/b9bd6cfd1c50e6807846af9a86f9b83cafc9c8aeghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/security/advisories/GHSA-wm93-f238-7v37ghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.