diff options
author | Benjamin Maxwell <benjamin.maxwell@arm.com> | 2023-10-18 14:52:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-18 14:52:22 +0100 |
commit | b0b8e83e668ac02f81874c3548c8eb8dbf3c33f0 (patch) | |
tree | 20a1e99168403dc2288e0db9c5c7b729480a8555 /llvm/docs/tutorial | |
parent | 28e4f97320b6d3cb198f9865b6379ea1ca988cf8 (diff) | |
download | llvm-b0b8e83e668ac02f81874c3548c8eb8dbf3c33f0.zip llvm-b0b8e83e668ac02f81874c3548c8eb8dbf3c33f0.tar.gz llvm-b0b8e83e668ac02f81874c3548c8eb8dbf3c33f0.tar.bz2 |
[mlir] Fix use-after-free bugs in {RankedTensorType|VectorType}::Builder (#68969)
Previously, these would set their ArrayRef members to reference their
storage SmallVectors after a copy-on-write (COW) operation. This leads
to a use-after-free if the builder is copied and the original destroyed
(as the new builder would still reference the old SmallVector).
This could easily accidentally occur in code like (annotated):
```c++
// 1. `VectorType::Builder(type)` constructs a new temporary builder
// 2. `.dropDim(0)` updates the temporary builder by reference, and returns a `VectorType::Builder&`
// - Modifying the shape is a COW operation, so `storage` is used, and `shape` updated the reference it
// 3. Assigning the reference to `auto` copies the builder (via the default C++ copy ctor)
// - There's no special handling for `shape` and `storage`, so the new shape points to the old builder's `storage`
auto newType = VectorType::Builder(type).dropDim(0);
// 4. When this line is reached the original temporary builder is destroyed
// - Actually constructing the vector type is now a use-after-free
VectorType newVectorType = VectorType(newType);
```
This is fixed with these changes by using `CopyOnWriteArrayRef<T>`,
which implements the same functionality, but ensures no
dangling references are possible if it's copied.
---
The VectorType::Builder also set the ArrayRef<bool> scalableDims member
to a temporary SmallVector when the provided scalableDims are empty.
This again leads to a use-after-free, and is unnecessary as
VectorType::get already handles being passed an empty scalableDims
array.
These bugs were in-part caught by UBSAN, see:
https://lab.llvm.org/buildbot/#/builders/5/builds/37355
Diffstat (limited to 'llvm/docs/tutorial')
0 files changed, 0 insertions, 0 deletions