GHSA-vqw6-72r7-fgw7

Suggest an improvement
Source
https://github.com/advisories/GHSA-vqw6-72r7-fgw7
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2021/05/GHSA-vqw6-72r7-fgw7/GHSA-vqw6-72r7-fgw7.json
JSON Data
https://api.test.osv.dev/v1/vulns/GHSA-vqw6-72r7-fgw7
Aliases
Published
2021-05-21T14:23:44Z
Modified
2024-10-31T21:01:31.399198Z
Severity
  • 2.5 (Low) CVSS_V3 - CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L CVSS Calculator
  • 2.0 (Low) CVSS_V4 - CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N CVSS Calculator
Summary
OOB read in `MatrixTriangularSolve`
Details

Impact

The implementation of MatrixTriangularSolve fails to terminate kernel execution if one validation condition fails:

void ValidateInputTensors(OpKernelContext* ctx, const Tensor& in0,
                            const Tensor& in1) override {
  OP_REQUIRES(
      ctx, in0.dims() >= 2,
      errors::InvalidArgument("In[0] ndims must be >= 2: ", in0.dims()));

  OP_REQUIRES(
      ctx, in1.dims() >= 2,
      errors::InvalidArgument("In[0] ndims must be >= 2: ", in1.dims()));
}

void Compute(OpKernelContext* ctx) override {
  const Tensor& in0 = ctx->input(0);
  const Tensor& in1 = ctx->input(1);

  ValidateInputTensors(ctx, in0, in1);

  MatMulBCast bcast(in0.shape().dim_sizes(), in1.shape().dim_sizes());
  ...
}

Since OP_REQUIRES only sets ctx->status() to a non-OK value and calls return, this allows malicious attackers to trigger an out of bounds read:

import tensorflow as tf
import numpy as np

matrix_array = np.array([])
matrix_tensor = tf.convert_to_tensor(np.reshape(matrix_array,(1,0)),dtype=tf.float32)
rhs_array = np.array([])
rhs_tensor = tf.convert_to_tensor(np.reshape(rhs_array,(0,1)),dtype=tf.float32)

tf.raw_ops.MatrixTriangularSolve(matrix=matrix_tensor,rhs=rhs_tensor,lower=False,adjoint=False)

As the two input tensors are empty, the OP_REQUIRES in ValidateInputTensors should fire and interrupt execution. However, given the implementation of OP_REQUIRES, after the in0.dims() >= 2 fails, execution moves to the initialization of the bcast object. This initialization is done with invalid data and results in heap OOB read.

Patches

We have patched the issue in GitHub commit 480641e3599775a8895254ffbc0fc45621334f68.

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.

For more information

Please consult our security guide for more information regarding the security model and how to contact us with issues and questions.

Attribution

This vulnerability has been reported by Ye Zhang and Yakun Zhang of Baidu X-Team.

Database specific
{
    "nvd_published_at": "2021-05-14T20:15:00Z",
    "cwe_ids": [
        "CWE-125"
    ],
    "severity": "LOW",
    "github_reviewed": true,
    "github_reviewed_at": "2021-05-18T21:14:11Z"
}
References

Affected packages

PyPI / tensorflow

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
2.1.4

Affected versions

0.*

0.12.0
0.12.1

1.*

1.0.0
1.0.1
1.1.0
1.2.0
1.2.1
1.3.0
1.4.0
1.4.1
1.5.0
1.5.1
1.6.0
1.7.0
1.7.1
1.8.0
1.9.0
1.10.0
1.10.1
1.11.0
1.12.0
1.12.2
1.12.3
1.13.1
1.13.2
1.14.0
1.15.0
1.15.2
1.15.3
1.15.4
1.15.5

2.*

2.0.0
2.0.1
2.0.2
2.0.3
2.0.4
2.1.0
2.1.1
2.1.2
2.1.3

PyPI / tensorflow

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.2.0
Fixed
2.2.3

Affected versions

2.*

2.2.0
2.2.1
2.2.2

PyPI / tensorflow

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.3.0
Fixed
2.3.3

Affected versions

2.*

2.3.0
2.3.1
2.3.2

PyPI / tensorflow

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.4.0
Fixed
2.4.2

Affected versions

2.*

2.4.0
2.4.1

PyPI / tensorflow-cpu

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
2.1.4

Affected versions

1.*

1.15.0

2.*

2.1.0
2.1.1
2.1.2
2.1.3

PyPI / tensorflow-cpu

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.2.0
Fixed
2.2.3

Affected versions

2.*

2.2.0
2.2.1
2.2.2

PyPI / tensorflow-cpu

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.3.0
Fixed
2.3.3

Affected versions

2.*

2.3.0
2.3.1
2.3.2

PyPI / tensorflow-cpu

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.4.0
Fixed
2.4.2

Affected versions

2.*

2.4.0
2.4.1

PyPI / tensorflow-gpu

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
2.1.4

Affected versions

0.*

0.12.0
0.12.1

1.*

1.0.0
1.0.1
1.1.0
1.2.0
1.2.1
1.3.0
1.4.0
1.4.1
1.5.0
1.5.1
1.6.0
1.7.0
1.7.1
1.8.0
1.9.0
1.10.0
1.10.1
1.11.0
1.12.0
1.12.2
1.12.3
1.13.1
1.13.2
1.14.0
1.15.0
1.15.2
1.15.3
1.15.4
1.15.5

2.*

2.0.0
2.0.1
2.0.2
2.0.3
2.0.4
2.1.0
2.1.1
2.1.2
2.1.3

PyPI / tensorflow-gpu

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.2.0
Fixed
2.2.3

Affected versions

2.*

2.2.0
2.2.1
2.2.2

PyPI / tensorflow-gpu

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.3.0
Fixed
2.3.3

Affected versions

2.*

2.3.0
2.3.1
2.3.2

PyPI / tensorflow-gpu

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.4.0
Fixed
2.4.2

Affected versions

2.*

2.4.0
2.4.1