Vulnerability: CHECK-fail in LSTM with zero-length input in TensorFlow ### Impact
Running an LSTM/GRU model where the LSTM/GRU layer receives an input with zero-length results in a `CHECK` failure when using the CUDA backend.

This can result in a query-of-death vulnerability, via denial of service, if users can control the input to the layer.

### Patches
We have patched the issue in GitHub commit [14755416e364f17fb1870882fa778c7fec7f16e3](https://github.com/tensorflow/tensorflow/commit/14755416e364f17fb1870882fa778c7fec7f16e3) and will release TensorFlow 2.4.0 containing the patch. TensorFlow nightly packages after this commit will also have the issue resolved.

Since this issue also impacts TF versions before 2.4, we will patch all releases between 1.15 and 2.3 inclusive.

### For more information
Please consult [our security guide](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for more information regarding the security model and how to contact us with issues and questions.
Vulnerability ID: GHSA-m648-33qf-v3gp
CWE: CWE-20
Severity score: 4.4
Project: https://github.com/tensorflow/tensorflow
Published: 2020-12-10
File: tensorflow/stream_executor/cuda/cuda_dnn.cc
Commit message: Prevent CHECK-fail in LSTM/GRU with zero-length input.

PiperOrigin-RevId: 346239181
Change-Id: I5f233dbc076aab7bb4e31ba24f5abd4eaf99ea4f
Commit author: Mihai Maruseac

Vulnerable version (before fix):
 class CudnnRnnSequenceTensorDescriptor   static port::StatusOr<CudnnRnnSequenceTensorDescriptor> Create(       GpuExecutor* parent, int max_seq_length, int batch_size, int data_size,       cudnnDataType_t data_type) {     CHECK_GT(max_seq_length, 0);     int dims[] = {batch_size, data_size, 1};     int strides[] = {dims[1] * dims[2], dims[2], 1};     TensorDescriptor tensor_desc = CreateTensorDescriptor(); class CudnnRnnSequenceTensorDescriptor       GpuExecutor* parent, int max_seq_length, int batch_size, int data_size,       const absl::Span<const int>& seq_lengths, bool time_major,       cudnnDataType_t data_type) {     CHECK_GT(max_seq_length, 0);     int dims[] = {batch_size, data_size, 1};     int strides[] = {dims[1] * dims[2], dims[2], 1};     TensorDescriptor tensor_desc = CreateTensorDescriptor();

Fixed version (after fix):
 class CudnnRnnSequenceTensorDescriptor   static port::StatusOr<CudnnRnnSequenceTensorDescriptor> Create(       GpuExecutor* parent, int max_seq_length, int batch_size, int data_size,       cudnnDataType_t data_type) {     if (max_seq_length <= 0) {       return port::Status(port::error::INVALID_ARGUMENT, "max_seq_length <= 0");     }     int dims[] = {batch_size, data_size, 1};     int strides[] = {dims[1] * dims[2], dims[2], 1};     TensorDescriptor tensor_desc = CreateTensorDescriptor(); class CudnnRnnSequenceTensorDescriptor       GpuExecutor* parent, int max_seq_length, int batch_size, int data_size,       const absl::Span<const int>& seq_lengths, bool time_major,       cudnnDataType_t data_type) {     if (max_seq_length <= 0) {       return port::Status(port::error::INVALID_ARGUMENT, "max_seq_length <= 0");     }     int dims[] = {batch_size, data_size, 1};     int strides[] = {dims[1] * dims[2], dims[2], 1};     TensorDescriptor tensor_desc = CreateTensorDescriptor();

Patch:
patch: @@ -1468,7 +1468,9 @@ class CudnnRnnSequenceTensorDescriptor
   static port::StatusOr<CudnnRnnSequenceTensorDescriptor> Create(
       GpuExecutor* parent, int max_seq_length, int batch_size, int data_size,
       cudnnDataType_t data_type) {
-    CHECK_GT(max_seq_length, 0);
+    if (max_seq_length <= 0) {
+      return port::Status(port::error::INVALID_ARGUMENT, "max_seq_length <= 0");
+    }
     int dims[] = {batch_size, data_size, 1};
     int strides[] = {dims[1] * dims[2], dims[2], 1};
     TensorDescriptor tensor_desc = CreateTensorDescriptor();
@@ -1486,7 +1488,9 @@ class CudnnRnnSequenceTensorDescriptor
       GpuExecutor* parent, int max_seq_length, int batch_size, int data_size,
       const absl::Span<const int>& seq_lengths, bool time_major,
       cudnnDataType_t data_type) {
-    CHECK_GT(max_seq_length, 0);
+    if (max_seq_length <= 0) {
+      return port::Status(port::error::INVALID_ARGUMENT, "max_seq_length <= 0");
+    }
     int dims[] = {batch_size, data_size, 1};
     int strides[] = {dims[1] * dims[2], dims[2], 1};
     TensorDescriptor tensor_desc = CreateTensorDescriptor();
path: tensorflow/stream_executor/cuda/cuda_dnn.cc