Skip to content

Commit 4a02c9e

Browse files
committed
[BOLT] Fix thread-safety of PointerAuthCFIAnalyzer
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
1 parent dd41705 commit 4a02c9e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
#define BOLT_PASSES_POINTER_AUTH_CFI_ANALYZER
1414

1515
#include "bolt/Passes/BinaryPasses.h"
16+
#include <mutex>
1617

1718
namespace llvm {
1819
namespace bolt {
1920

2021
class PointerAuthCFIAnalyzer : public BinaryFunctionPass {
22+
// setIgnored() is not thread-safe, but the pass is running on functions in
23+
// parallel.
24+
std::mutex IgnoreMutex;
25+
2126
public:
2227
explicit PointerAuthCFIAnalyzer() : BinaryFunctionPass(false) {}
2328

bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction &BF) {
4747
// Not all functions have .cfi_negate_ra_state in them. But if one does,
4848
// we expect psign/pauth instructions to have the hasNegateRAState
4949
// annotation.
50+
std::lock_guard<std::mutex> Lock(IgnoreMutex);
5051
BF.setIgnored();
5152
if (opts::Verbosity >= 1)
5253
BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
@@ -73,6 +74,7 @@ bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction &BF) {
7374
BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
7475
<< BF.getPrintName()
7576
<< ": ptr signing inst encountered in Signed RA state\n";
77+
std::lock_guard<std::mutex> Lock(IgnoreMutex);
7678
BF.setIgnored();
7779
return false;
7880
}
@@ -84,6 +86,7 @@ bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction &BF) {
8486
<< BF.getPrintName()
8587
<< ": ptr authenticating inst encountered in Unsigned RA "
8688
"state\n";
89+
std::lock_guard<std::mutex> Lock(IgnoreMutex);
8790
BF.setIgnored();
8891
return false;
8992
}

0 commit comments

Comments
 (0)