VYPR
Moderate severityNVD Advisory· Published May 20, 2022· Updated Apr 22, 2025

Undefined behavior when users supply invalid resource handles in TensorFlow

CVE-2022-29207

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.

PackageAffected versionsPatched versions
tensorflowPyPI
< 2.6.42.6.4
tensorflowPyPI
>= 2.7.0, < 2.7.22.7.2
tensorflowPyPI
>= 2.8.0, < 2.8.12.8.1
tensorflow-cpuPyPI
< 2.6.42.6.4
tensorflow-cpuPyPI
>= 2.7.0, < 2.7.22.7.2
tensorflow-cpuPyPI
>= 2.8.0, < 2.8.12.8.1
tensorflow-gpuPyPI
< 2.6.42.6.4
tensorflow-gpuPyPI
>= 2.7.0, < 2.7.22.7.2
tensorflow-gpuPyPI
>= 2.8.0, < 2.8.12.8.1

Affected products

1

Patches

2
a5b89cd68c02

Fix empty resource handle vulnerability.

https://github.com/tensorflow/tensorflowAntonio SanchezApr 30, 2022via ghsa
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();
     
    
dbdd98c37bc2

Fix segfault from passing invalid input to tf.summary.flush()

https://github.com/tensorflow/tensorflowNick FeltApr 13, 2022via ghsa
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

News mentions

0

No linked articles in our index yet.