diff options
| author | Gergely Balint <gergely.balint@arm.com> | 2025-10-28 09:15:35 +0000 |
|---|---|---|
| committer | Gergely Balint <gergely.balint@arm.com> | 2025-10-28 09:59:59 +0000 |
| commit | 4a02c9ee50ecbf020047800ff29976308df7b55b (patch) | |
| tree | 61ebb983f18f81d76e176ed68bb121778f22ccd7 | |
| parent | dd4170545141f76b1d0825e1a8d060a1689aaa41 (diff) | |
[BOLT] Fix thread-safety of PointerAuthCFIAnalyzerusers/bgergely0/bolt-thread-safe-ignore
The pass calls setIgnored() on functions in parallel, but setIgnored is
not thread safe. The patch adds a mutex to guard setIgnored calls.
Fixes: #165362
| -rw-r--r-- | bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h | 5 | ||||
| -rw-r--r-- | bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp | 3 |
2 files changed, 8 insertions, 0 deletions
diff --git a/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h b/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h index e63de077fad1..54da398f0b2b 100644 --- a/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h +++ b/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h @@ -13,11 +13,16 @@ #define BOLT_PASSES_POINTER_AUTH_CFI_ANALYZER #include "bolt/Passes/BinaryPasses.h" +#include <mutex> namespace llvm { namespace bolt { class PointerAuthCFIAnalyzer : public BinaryFunctionPass { + // setIgnored() is not thread-safe, but the pass is running on functions in + // parallel. + std::mutex IgnoreMutex; + public: explicit PointerAuthCFIAnalyzer() : BinaryFunctionPass(false) {} diff --git a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp index 17486536202b..68913a4785af 100644 --- a/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp +++ b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp @@ -47,6 +47,7 @@ bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction &BF) { // Not all functions have .cfi_negate_ra_state in them. But if one does, // we expect psign/pauth instructions to have the hasNegateRAState // annotation. + std::lock_guard<std::mutex> Lock(IgnoreMutex); BF.setIgnored(); if (opts::Verbosity >= 1) BC.outs() << "BOLT-INFO: inconsistent RAStates in function " @@ -73,6 +74,7 @@ bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction &BF) { BC.outs() << "BOLT-INFO: inconsistent RAStates in function " << BF.getPrintName() << ": ptr signing inst encountered in Signed RA state\n"; + std::lock_guard<std::mutex> Lock(IgnoreMutex); BF.setIgnored(); return false; } @@ -84,6 +86,7 @@ bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction &BF) { << BF.getPrintName() << ": ptr authenticating inst encountered in Unsigned RA " "state\n"; + std::lock_guard<std::mutex> Lock(IgnoreMutex); BF.setIgnored(); return false; } |
