CVE-2021-37685: Heap OOB in TFLite
(updated )
TFLite’s expand_dims.cc
contains a vulnerability which allows reading one element outside of bounds of heap allocated data:
if (axis < 0) {
axis = input_dims.size + 1 + axis;
}
TF_LITE_ENSURE(context, axis <= input_dims.size);
TfLiteIntArray* output_dims = TfLiteIntArrayCreate(input_dims.size + 1);
for (int i = 0; i < output_dims->size; ++i) {
if (i < axis) {
output_dims->data[i] = input_dims.data[i];
} else if (i == axis) {
output_dims->data[i] = 1;
} else {
output_dims->data[i] = input_dims.data[i - 1];
}
}
If axis
is a large negative value (e.g., -100000
), then after the first if
it would still be negative. The check following the if
statement will pass and the for
loop would read one element before the start of input_dims.data
(when i = 0
).
References
- github.com/advisories/GHSA-c545-c4f9-rf6v
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-598.yaml
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-796.yaml
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-307.yaml
- github.com/tensorflow/tensorflow
- github.com/tensorflow/tensorflow/blob/149562d49faa709ea80df1d99fc41d005b81082a/tensorflow/lite/kernels/expand_dims.cc
- github.com/tensorflow/tensorflow/commit/d94ffe08a65400f898241c0374e9edc6fa8ed257
- github.com/tensorflow/tensorflow/security/advisories/GHSA-c545-c4f9-rf6v
- nvd.nist.gov/vuln/detail/CVE-2021-37685
Detect and mitigate CVE-2021-37685 with GitLab Dependency Scanning
Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →