TensorFlow is an end-to-end open source platform for machine learning. In affected versions when running shape functions, some functions (such as MutableHashTableShape
) produce extra output information in the form of a ShapeAndType
struct. The shapes embedded in this struct are owned by an inference context that is cleaned up almost immediately; if the upstream code attempts to access this shape information, it can trigger a segfault. ShapeRefiner
is mitigating this for normal output shapes by cloning them (and thus putting the newly created shape under ownership of an inference context that will not die), but we were not doing the same for shapes and types. This commit fixes that by doing similar logic on output shapes and types. We have patched the issue in GitHub commit ee119d4a498979525046fba1c3dd3f13a039fbb1. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.
Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code.
Name | Vendor | Start Version | End Version |
---|---|---|---|
Tensorflow | 2.3.0 (including) | 2.3.4 (excluding) | |
Tensorflow | 2.4.0 (including) | 2.4.3 (excluding) | |
Tensorflow | 2.5.0 (including) | 2.5.0 (including) | |
Tensorflow | 2.6.0-rc0 (including) | 2.6.0-rc0 (including) | |
Tensorflow | 2.6.0-rc1 (including) | 2.6.0-rc1 (including) | |
Tensorflow | 2.6.0-rc2 (including) | 2.6.0-rc2 (including) |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system’s reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process. If the newly allocated data happens to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.