Segfault in Tensorflow
Description
In Tensorflow before version 2.4.0, an attacker can pass an invalid axis value to tf.quantization.quantize_and_dequantize. This results in accessing a dimension outside the rank of the input tensor in the C++ kernel implementation. However, dim_size only does a DCHECK to validate the argument and then uses it to access the corresponding element of an array. Since in normal builds, DCHECK-like macros are no-ops, this results in segfault and access out of bounds of the array. The issue is patched in eccb7ec454e6617738554a255d77f08e60ee0808 and TensorFlow 2.4.0 will be released containing the patch. TensorFlow nightly packages after this commit will also have the issue resolved.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
tensorflowPyPI | < 2.4.0 | 2.4.0 |
tensorflow-cpuPyPI | < 2.4.0 | 2.4.0 |
tensorflow-gpuPyPI | < 2.4.0 | 2.4.0 |
Affected products
1- Range: < 2.4.0
Patches
1eccb7ec454e6Prevent segfault in `quantize_and_dequantize`
2 files changed · +20 −0
tensorflow/core/kernels/quantize_and_dequantize_op.cc+4 −0 modified@@ -71,6 +71,10 @@ class QuantizeAndDequantizeV2Op : public OpKernel { void Compute(OpKernelContext* ctx) override { const Tensor& input = ctx->input(0); + OP_REQUIRES( + ctx, (axis_ == -1 || axis_ < input.shape().dims()), + errors::InvalidArgument("Shape must be at least rank ", axis_ + 1, + " but is rank ", input.shape().dims())); const int depth = (axis_ == -1) ? 1 : input.dim_size(axis_); Tensor input_min_tensor; Tensor input_max_tensor;
tensorflow/python/kernel_tests/array_ops_test.py+16 −0 modified@@ -1628,6 +1628,22 @@ def testAxis(self): axis=(axis - 4))) self.assertAllClose(fake_quantized, expected) + def testBadAxis(self): + input_tensor = [2.5, 2.5] + input_min = [0, 0] + input_max = [1, 1] + error_message_pattern = "Shape must be at least rank 11 but is rank 1" + # TODO(b/171260356): Eager mode and graph mode throw different error types + error = errors.InvalidArgumentError if context.executing_eagerly( + ) else ValueError + with self.assertRaisesRegex(error, error_message_pattern): + self.evaluate( + array_ops.quantize_and_dequantize_v2( + input=input_tensor, + input_min=input_min, + input_max=input_max, + axis=10)) + def testQuantizeDequantizeGrad(self): shape = (2, 2) max_threshold = 0
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
8- github.com/advisories/GHSA-rrfp-j2mp-hq9cghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2020-15265ghsaADVISORY
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2020-295.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2020-330.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2020-138.yamlghsaWEB
- github.com/tensorflow/tensorflow/commit/eccb7ec454e6617738554a255d77f08e60ee0808ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/issues/42105ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/security/advisories/GHSA-rrfp-j2mp-hq9cghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.