Segfault due to negative splits in `SplitV`
Description
TensorFlow is an open source platform for machine learning. In affected versions the implementation of SplitV can trigger a segfault is an attacker supplies negative arguments. This occurs whenever size_splits contains more than one value and at least one value is negative. 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.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
tensorflowPyPI | >= 2.6.0, < 2.6.1 | 2.6.1 |
tensorflowPyPI | >= 2.5.0, < 2.5.2 | 2.5.2 |
tensorflowPyPI | < 2.4.4 | 2.4.4 |
tensorflow-cpuPyPI | >= 2.6.0, < 2.6.1 | 2.6.1 |
tensorflow-cpuPyPI | >= 2.5.0, < 2.5.2 | 2.5.2 |
tensorflow-cpuPyPI | < 2.4.4 | 2.4.4 |
tensorflow-gpuPyPI | >= 2.6.0, < 2.6.1 | 2.6.1 |
tensorflow-gpuPyPI | >= 2.5.0, < 2.5.2 | 2.5.2 |
tensorflow-gpuPyPI | < 2.4.4 | 2.4.4 |
Affected products
1- Range: >= 2.6.0, < 2.6.1
Patches
125d622ffc432A negative size in one of the split sizes allowed the computed size of another
3 files changed · +31 −0
tensorflow/core/kernels/split_v_op.cc+7 −0 modified@@ -138,6 +138,13 @@ class SplitVOpBase : public OpKernel { (*split_sizes_vec)[neg_one_dim] = input_size_split_dim - determined_size; } + for (int i = 0; i < split_sizes_vec->size(); ++i) { + const Tlen& split_size = (*split_sizes_vec)[i]; + OP_REQUIRES(context, split_size >= Tlen(0), + errors::InvalidArgument("Split size at index ", i, + " must be >= 0. Got: ", split_size)); + } + // Special case 2: split along the 1st dimension. The requirements are that // either we are splitting the outer dimension of two or more such that // every outer subpart is aligned or that the split sizes mean that they are
tensorflow/core/ops/array_ops.cc+6 −0 modified@@ -681,6 +681,12 @@ REGISTER_OP("SplitV") if (data[i] == -1 && c->ValueKnown(split_dim_size)) { size = split_dim_size - total_size; } + // If we have a negative known size (either explicit, or computed + // via -1), then the split sizes are invalid. + if (size < -1 || (size == -1 && c->ValueKnown(split_dim_size))) { + return errors::InvalidArgument("Split size at index ", i, + " must be >= 0. Got: ", size); + } TF_RETURN_IF_ERROR( c->ReplaceDim(input, split_dim, c->MakeDim(size), &output_shape)); c->set_output(i, output_shape);
tensorflow/python/kernel_tests/split_op_test.py+18 −0 modified@@ -384,6 +384,24 @@ def testNonexistentDimTensor(self): "must have exactly one element"): sess.run(y, {x: np.array([], dtype=np.int32), splits: [4, 11, 15]}) + @test_util.run_in_graph_and_eager_modes + def testNegativeSizes(self): + x = constant_op.constant([1, 2, 3], dtypes.float32) + # A size of -1 signifies to determine size based on sum of other splits. + with self.assertRaisesRegex((ValueError, errors_impl.InvalidArgumentError), + "Split size at index 1 must be >= 0. Got: -2"): + splits = [-1, -2] + self.evaluate(array_ops.split(x, splits, axis=0)) + + @test_util.run_in_graph_and_eager_modes + def testBadSplitSizes(self): + x = constant_op.constant([1, 2], dtypes.float32) + with self.assertRaisesRegex((ValueError, errors_impl.InvalidArgumentError), + "Determined shape must either match input" + "|can't split axis"): + splits = [1, 2] + self.evaluate(array_ops.split(x, splits, axis=0)) + if __name__ == "__main__": test.main()
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-cpf4-wx82-gxp6ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-41222ghsaADVISORY
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-631.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-829.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-414.yamlghsaWEB
- github.com/tensorflow/tensorflow/commit/25d622ffc432acc736b14ca3904177579e733cc6ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/security/advisories/GHSA-cpf4-wx82-gxp6ghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.