CVE-2022-21728: Out of bounds read in Tensorflow
Impact The implementation of shape inference for ReverseSequence does not fully validate the value of batchdim and can result in a heap OOB read:
python import tensorflow as tf
@tf.function def test(): y = tf.rawops.ReverseSequence( input = ['aaa','bbb'], seqlengths = [1,1,1], seqdim = -10, batchdim = -10 ) return y test()
There is a check to make sure the value of batchdim does not go over the rank of the input, but there is no check for negative values:
cc const int32t inputrank = c->Rank(input); if (batchdim >= inputrank) { return errors::InvalidArgument( "batchdim must be < input rank: ", batchdim, " vs. ", inputrank); } // ... DimensionHandle batchdimdim = c->Dim(input, batchdim); Negative dimensions are allowed in some cases to mimic Python's negative indexing (i.e., indexing from the end of the array), however if the value is too negative then the implementation of Dim would access elements before the start of an array:
cc DimensionHandle Dim(ShapeHandle s, int64t idx) { if (!s.Handle() || s->rank == kUnknownRank) { return UnknownDim(); } return DimKnownRank(s, idx); } · static DimensionHandle DimKnownRank(ShapeHandle s, int64t idx) { CHECKNE(s->rank, kUnknownRank); if (idx < 0) { return s->dims[s->dims.size() + idx]; } return s->dims[idx]; }
Patches We have patched the issue in GitHub commit 37c01fb5e25c3d80213060460196406c43d31995.
The fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, 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 Yu Tian of Qihoo 360 AIVul Team.
Other sources
Tensorflow is an Open Source Machine Learning Framework. The implementation of shape inference for ReverseSequence does not fully validate the value of batchdim and can result in a heap OOB read. There is a check to make sure the value of batchdim does not go over the rank of the input, but there is no check for negative values. Negative dimensions are allowed in some cases to mimic Python's negative indexing (i.e., indexing from the end of the array), however if the value is too negative then the implementation of Dim would access elements before the start of an array. The fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, as these are also affected and still in supported range.
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2022-21728?
CVE-2022-21728 has a medium severity rating due to its potential for causing heap out-of-bounds access.
How do I fix CVE-2022-21728?
To fix CVE-2022-21728, update TensorFlow to version 2.7.1 or higher.
Which versions of TensorFlow are affected by CVE-2022-21728?
Versions of TensorFlow from 2.5.0 through 2.7.0 are affected by CVE-2022-21728.
Is there a patch available for CVE-2022-21728?
Yes, patches are available in TensorFlow versions 2.5.3, 2.6.3, and 2.7.1.
What could happen if CVE-2022-21728 is exploited?
Exploitation of CVE-2022-21728 may lead to arbitrary code execution or application crashes due to out-of-bounds memory access.