Undefined behavior when users supply invalid resource handles in TensorFlow
Description
TensorFlow is an open source platform for machine learning. Prior to versions 2.9.0, 2.8.1, 2.7.2, and 2.6.4, multiple TensorFlow operations misbehave in eager mode when the resource handle provided to them is invalid. In graph mode, it would have been impossible to perform these API calls, but migration to TF 2.x eager mode opened up this vulnerability. If the resource handle is empty, then a reference is bound to a null pointer inside TensorFlow codebase (various codepaths). This is undefined behavior. Versions 2.9.0, 2.8.1, 2.7.2, and 2.6.4 contain a patch for this issue.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
tensorflowPyPI | < 2.6.4 | 2.6.4 |
tensorflowPyPI | >= 2.7.0, < 2.7.2 | 2.7.2 |
tensorflowPyPI | >= 2.8.0, < 2.8.1 | 2.8.1 |
tensorflow-cpuPyPI | < 2.6.4 | 2.6.4 |
tensorflow-cpuPyPI | >= 2.7.0, < 2.7.2 | 2.7.2 |
tensorflow-cpuPyPI | >= 2.8.0, < 2.8.1 | 2.8.1 |
tensorflow-gpuPyPI | < 2.6.4 | 2.6.4 |
tensorflow-gpuPyPI | >= 2.7.0, < 2.7.2 | 2.7.2 |
tensorflow-gpuPyPI | >= 2.8.0, < 2.8.1 | 2.8.1 |
Affected products
1- Range: < 2.6.4
Patches
2a5b89cd68c02Fix empty resource handle vulnerability.
1 file changed · +3 −0
tensorflow/core/common_runtime/eager/execute.cc+3 −0 modified@@ -304,6 +304,9 @@ Status GetDeviceForInput(const EagerOperation& op, const EagerContext& ctx, const Tensor* tensor; // TODO(fishx): Avoid blocking here. TF_RETURN_IF_ERROR(tensor_handle->Tensor(&tensor)); + if (tensor->NumElements() == 0) { + return errors::InvalidArgument("Empty resource handle"); + } const ResourceHandle& handle = tensor->flat<ResourceHandle>()(0); device_name = handle.device();
dbdd98c37bc2Fix segfault from passing invalid input to tf.summary.flush()
2 files changed · +29 −4
tensorflow/python/kernel_tests/summary_ops/summary_ops_test.py+6 −4 modified@@ -985,10 +985,12 @@ def testFlushFunction(self): self.assertEqual(3, get_total()) summary_ops.flush(writer=writer) self.assertEqual(4, get_total()) - summary_ops.write('tag', 1, step=0) - self.assertEqual(4, get_total()) - summary_ops.flush(writer=writer._resource) # pylint:disable=protected-access - self.assertEqual(5, get_total()) + + # Regression test for b/228097117. + def testFlushFunction_disallowsInvalidWriterInput(self): + with context.eager_mode(): + with self.assertRaisesRegex(ValueError, 'Invalid argument to flush'): + summary_ops.flush(writer=()) @test_util.assert_no_new_tensors def testNoMemoryLeak_graphMode(self):
tensorflow/python/ops/summary_ops_v2.py+23 −0 modified@@ -1111,12 +1111,35 @@ def flush(writer=None, name=None): Returns: The created `tf.Operation`. """ + del name # unused if writer is None: writer = _summary_state.writer if writer is None: return control_flow_ops.no_op() if isinstance(writer, SummaryWriter): return writer.flush() + raise ValueError("Invalid argument to flush(): %r" % (writer,)) + + +def legacy_raw_flush(writer=None, name=None): + """Legacy version of flush() that accepts a raw resource tensor for `writer`. + + Do not use this function in any new code. Not supported and not part of the + public TF APIs. + + Args: + writer: The `tf.summary.SummaryWriter` to flush. If None, the current + default writer will be used instead; if there is no current writer, this + returns `tf.no_op`. For this legacy version only, also accepts a raw + resource tensor pointing to the underlying C++ writer resource. + name: Ignored legacy argument for a name for the operation. + + Returns: + The created `tf.Operation`. + """ + if writer is None or isinstance(writer, SummaryWriter): + # Forward to the TF2 implementation of flush() when possible. + return flush(writer, name) else: # Legacy fallback in case we were passed a raw resource tensor. with ops.device("cpu: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
9- github.com/advisories/GHSA-5wpj-c6f7-24x8ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2022-29207ghsaADVISORY
- github.com/tensorflow/tensorflow/commit/a5b89cd68c02329d793356bda85d079e9e69b4e7ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/commit/dbdd98c37bc25249e8f288bd30d01e118a7b4498ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/releases/tag/v2.6.4ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/releases/tag/v2.7.2ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/releases/tag/v2.8.1ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/releases/tag/v2.9.0ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/security/advisories/GHSA-5wpj-c6f7-24x8ghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.