[all-commits] [llvm/llvm-project] c71d77: [MC] Avoid UAF in WinCOFFObjectWriter with weak sy...
Tim Besard via All-commits
all-commits at lists.llvm.org
Sat Jul 16 03:26:14 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: c71d77876f52eae52312ce130b5f0c1472b0699b
https://github.com/llvm/llvm-project/commit/c71d77876f52eae52312ce130b5f0c1472b0699b
Author: Tim Besard <tim.besard at gmail.com>
Date: 2022-07-16 (Sat, 16 Jul 2022)
Changed paths:
M llvm/lib/MC/WinCOFFObjectWriter.cpp
A llvm/test/MC/COFF/weak-uaf.ll
Log Message:
-----------
[MC] Avoid UAF in WinCOFFObjectWriter with weak symbols.
When using weak symbols, the WinCOFFObjectWriter keeps a list (`WeakDefaults`)
that's used to make names unique. This list should be reset when the object
writer is reset, because otherwise reuse of the object writer can result in
freed symbols being accessed. With some added output, this becomes clear when
using `llc` in `--run-twice` mode:
```
$ ./llc --compile-twice -mtriple=x86_64-pc-win32 trivial.ll -filetype=obj
DefineSymbol::WeakDefaults
- .weak.foo.default
- .weak.bar.default
DefineSymbol::WeakDefaults
- .weak.foo.default
- áÑJij⌂ p§┼Ø┐☺
- .debug_macinfo.dw
- .weak.bar.default
```
This does not seem to leak into the output object file though, so I couldn't
come up with a test. I added one that just does `--run-twice` (and verified
that it does access freed memory), which should result in detecting the
invalid memory accesses when running under ASAN.
Observed in a Julia PR where we started using weak symbols:
https://github.com/JuliaLang/julia/pull/45649
Reviewed By: mstorsjo
Differential Revision: https://reviews.llvm.org/D129840
More information about the All-commits
mailing list