VYPR
Low severityNVD Advisory· Published May 14, 2021· Updated Aug 3, 2024

Session operations in eager mode lead to null pointer dereferences

CVE-2021-29518

Description

TensorFlow is an end-to-end open source platform for machine learning. In eager mode (default in TF 2.0 and later), session operations are invalid. However, users could still call the raw ops associated with them and trigger a null pointer dereference. The implementation(https://github.com/tensorflow/tensorflow/blob/eebb96c2830d48597d055d247c0e9aebaea94cd5/tensorflow/core/kernels/session_ops.cc#L104) dereferences the session state pointer without checking if it is valid. Thus, in eager mode, ctx->session_state() is nullptr and the call of the member function is undefined behavior. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.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.1.42.1.4
tensorflowPyPI
>= 2.2.0, < 2.2.32.2.3
tensorflowPyPI
>= 2.3.0, < 2.3.32.3.3
tensorflowPyPI
>= 2.4.0, < 2.4.22.4.2
tensorflow-cpuPyPI
< 2.1.42.1.4
tensorflow-cpuPyPI
>= 2.2.0, < 2.2.32.2.3
tensorflow-cpuPyPI
>= 2.3.0, < 2.3.32.3.3
tensorflow-cpuPyPI
>= 2.4.0, < 2.4.22.4.2
tensorflow-gpuPyPI
< 2.1.42.1.4
tensorflow-gpuPyPI
>= 2.2.0, < 2.2.32.2.3
tensorflow-gpuPyPI
>= 2.3.0, < 2.3.32.3.3
tensorflow-gpuPyPI
>= 2.4.0, < 2.4.22.4.2

Affected products

1

Patches

1
ff70c47a396e

Fix `tf.raw_ops.GetSessionTensor` and `tf.raw_ops.DeleteSessionTensor` null pointer dereferences.

https://github.com/tensorflow/tensorflowAmit PatankarApr 13, 2021via ghsa
1 file changed · +10 4
  • tensorflow/core/kernels/session_ops.cc+10 4 modified
    @@ -91,7 +91,6 @@ TF_CALL_NUMBER_TYPES(REGISTER_GPU_KERNEL);
     REGISTER_GPU_KERNEL(bool);
     #undef REGISTER_GPU_KERNEL
     
    -
     class GetSessionTensorOp : public OpKernel {
      public:
       explicit GetSessionTensorOp(OpKernelConstruction* context)
    @@ -101,7 +100,11 @@ class GetSessionTensorOp : public OpKernel {
         const Tensor& handle = ctx->input(0);
         const string& name = handle.scalar<tstring>()();
         Tensor val;
    -    OP_REQUIRES_OK(ctx, ctx->session_state()->GetTensor(name, &val));
    +    auto session_state = ctx->session_state();
    +    OP_REQUIRES(ctx, session_state != nullptr,
    +                errors::FailedPrecondition(
    +                    "GetSessionTensor called on null session state"));
    +    OP_REQUIRES_OK(ctx, session_state->GetTensor(name, &val));
         ctx->set_output(0, val);
       }
     
    @@ -122,7 +125,6 @@ TF_CALL_NUMBER_TYPES(REGISTER_GPU_KERNEL);
     REGISTER_GPU_KERNEL(bool);
     #undef REGISTER_GPU_KERNEL
     
    -
     class DeleteSessionTensorOp : public OpKernel {
      public:
       explicit DeleteSessionTensorOp(OpKernelConstruction* context)
    @@ -131,7 +133,11 @@ class DeleteSessionTensorOp : public OpKernel {
       void Compute(OpKernelContext* ctx) override {
         const Tensor& handle = ctx->input(0);
         const string& name = handle.scalar<tstring>()();
    -    OP_REQUIRES_OK(ctx, ctx->session_state()->DeleteTensor(name));
    +    auto session_state = ctx->session_state();
    +    OP_REQUIRES(ctx, session_state != nullptr,
    +                errors::FailedPrecondition(
    +                    "DeleteSessionTensor called on null session state"));
    +    OP_REQUIRES_OK(ctx, session_state->DeleteTensor(name));
       }
     
       TF_DISALLOW_COPY_AND_ASSIGN(DeleteSessionTensorOp);
    

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.