VYPR
High severityNVD Advisory· Published Aug 12, 2021· Updated Aug 4, 2024

Null pointer dereference and heap OOB read in TensorFlow

CVE-2021-37639

Description

TensorFlow is an end-to-end open source platform for machine learning. When restoring tensors via raw APIs, if the tensor name is not provided, TensorFlow can be tricked into dereferencing a null pointer. Alternatively, attackers can read memory outside the bounds of heap allocated data by providing some tensor names but not enough for a successful restoration. The implementation retrieves the tensor list corresponding to the tensor_name user controlled input and immediately retrieves the tensor at the restoration index (controlled via preferred_shard argument). This occurs without validating that the provided list has enough values. If the list is empty this results in dereferencing a null pointer (undefined behavior). If, however, the list has some elements, if the restoration index is outside the bounds this results in heap OOB read. We have patched the issue in GitHub commit 9e82dce6e6bd1f36a57e08fa85af213e2b2f2622. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
tensorflowPyPI
< 2.3.42.3.4
tensorflowPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflowPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-cpuPyPI
< 2.3.42.3.4
tensorflow-cpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-cpuPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-gpuPyPI
< 2.3.42.3.4
tensorflow-gpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-gpuPyPI
>= 2.5.0, < 2.5.12.5.1

Affected products

1

Patches

1
9e82dce6e6bd

Fix NPE in restoring code.

https://github.com/tensorflow/tensorflowMihai MaruseacAug 2, 2021via ghsa
1 file changed · +8 1
  • tensorflow/core/kernels/save_restore_tensor.cc+8 1 modified
    @@ -151,11 +151,18 @@ void RestoreTensor(OpKernelContext* context,
             context, size == 1,
             errors::InvalidArgument(
                 "Input 0 (file_pattern) must be a string scalar; got a tensor of ",
    -            size, "elements"));
    +            size, " elements"));
       }
       const string& file_pattern = file_pattern_t.flat<tstring>()(0);
     
       const Tensor& tensor_name_t = context->input(1);
    +  {
    +    const int64_t size = tensor_name_t.NumElements();
    +    OP_REQUIRES(context, size > restore_index,
    +                errors::InvalidArgument(
    +                    "Input 1 (file_pattern) must be a have at least ",
    +                    restore_index + 1, " elements"));
    +  }
       const string& tensor_name = tensor_name_t.flat<tstring>()(restore_index);
     
       // If we cannot find a cached reader we will allocate our own.
    

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

News mentions

0

No linked articles in our index yet.