mirror of
https://github.com/intel/llvm.git
synced 2026-02-05 04:46:27 +08:00
[tsan] On arm64e, strip out ptrauth bits from incoming PCs
Differential Revision: https://reviews.llvm.org/D86378
This commit is contained in:
@@ -18,4 +18,6 @@
|
||||
#define ptrauth_string_discriminator(__string) ((int)0)
|
||||
#endif
|
||||
|
||||
#define STRIP_PC(pc) ((uptr)ptrauth_strip(pc, 0))
|
||||
|
||||
#endif // SANITIZER_PTRAUTH_H
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "tsan_rtl.h"
|
||||
#include "tsan_interceptors.h"
|
||||
#include "sanitizer_common/sanitizer_ptrauth.h"
|
||||
|
||||
namespace __tsan {
|
||||
|
||||
@@ -57,13 +58,13 @@ uptr TagFromShadowStackFrame(uptr pc) {
|
||||
#if !SANITIZER_GO
|
||||
|
||||
typedef void(*AccessFunc)(ThreadState *, uptr, uptr, int);
|
||||
void ExternalAccess(void *addr, void *caller_pc, void *tag, AccessFunc access) {
|
||||
void ExternalAccess(void *addr, uptr caller_pc, void *tag, AccessFunc access) {
|
||||
CHECK_LT(tag, atomic_load(&used_tags, memory_order_relaxed));
|
||||
ThreadState *thr = cur_thread();
|
||||
if (caller_pc) FuncEntry(thr, (uptr)caller_pc);
|
||||
if (caller_pc) FuncEntry(thr, caller_pc);
|
||||
InsertShadowStackFrameForTag(thr, (uptr)tag);
|
||||
bool in_ignored_lib;
|
||||
if (!caller_pc || !libignore()->IsIgnored((uptr)caller_pc, &in_ignored_lib)) {
|
||||
if (!caller_pc || !libignore()->IsIgnored(caller_pc, &in_ignored_lib)) {
|
||||
access(thr, CALLERPC, (uptr)addr, kSizeLog1);
|
||||
}
|
||||
FuncExit(thr);
|
||||
@@ -110,12 +111,12 @@ void __tsan_external_assign_tag(void *addr, void *tag) {
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void __tsan_external_read(void *addr, void *caller_pc, void *tag) {
|
||||
ExternalAccess(addr, caller_pc, tag, MemoryRead);
|
||||
ExternalAccess(addr, STRIP_PC(caller_pc), tag, MemoryRead);
|
||||
}
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void __tsan_external_write(void *addr, void *caller_pc, void *tag) {
|
||||
ExternalAccess(addr, caller_pc, tag, MemoryWrite);
|
||||
ExternalAccess(addr, STRIP_PC(caller_pc), tag, MemoryWrite);
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "tsan_interface_ann.h"
|
||||
#include "tsan_rtl.h"
|
||||
#include "sanitizer_common/sanitizer_internal_defs.h"
|
||||
#include "sanitizer_common/sanitizer_ptrauth.h"
|
||||
|
||||
#define CALLERPC ((uptr)__builtin_return_address(0))
|
||||
|
||||
@@ -43,13 +44,13 @@ void __tsan_write16(void *addr) {
|
||||
}
|
||||
|
||||
void __tsan_read16_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr + 8, kSizeLog8);
|
||||
MemoryRead(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog8);
|
||||
MemoryRead(cur_thread(), STRIP_PC(pc), (uptr)addr + 8, kSizeLog8);
|
||||
}
|
||||
|
||||
void __tsan_write16_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr + 8, kSizeLog8);
|
||||
MemoryWrite(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog8);
|
||||
MemoryWrite(cur_thread(), STRIP_PC(pc), (uptr)addr + 8, kSizeLog8);
|
||||
}
|
||||
|
||||
// __tsan_unaligned_read/write calls are emitted by compiler.
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "tsan_interface.h"
|
||||
#include "tsan_rtl.h"
|
||||
#include "sanitizer_common/sanitizer_ptrauth.h"
|
||||
|
||||
#define CALLERPC ((uptr)__builtin_return_address(0))
|
||||
|
||||
@@ -50,35 +51,35 @@ void __tsan_write8(void *addr) {
|
||||
}
|
||||
|
||||
void __tsan_read1_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog1);
|
||||
MemoryRead(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog1);
|
||||
}
|
||||
|
||||
void __tsan_read2_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog2);
|
||||
MemoryRead(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog2);
|
||||
}
|
||||
|
||||
void __tsan_read4_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog4);
|
||||
MemoryRead(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog4);
|
||||
}
|
||||
|
||||
void __tsan_read8_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
|
||||
MemoryRead(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog8);
|
||||
}
|
||||
|
||||
void __tsan_write1_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog1);
|
||||
MemoryWrite(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog1);
|
||||
}
|
||||
|
||||
void __tsan_write2_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog2);
|
||||
MemoryWrite(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog2);
|
||||
}
|
||||
|
||||
void __tsan_write4_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog4);
|
||||
MemoryWrite(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog4);
|
||||
}
|
||||
|
||||
void __tsan_write8_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
|
||||
MemoryWrite(cur_thread(), STRIP_PC(pc), (uptr)addr, kSizeLog8);
|
||||
}
|
||||
|
||||
void __tsan_vptr_update(void **vptr_p, void *new_val) {
|
||||
@@ -100,7 +101,7 @@ void __tsan_vptr_read(void **vptr_p) {
|
||||
}
|
||||
|
||||
void __tsan_func_entry(void *pc) {
|
||||
FuncEntry(cur_thread(), (uptr)pc);
|
||||
FuncEntry(cur_thread(), STRIP_PC(pc));
|
||||
}
|
||||
|
||||
void __tsan_func_exit() {
|
||||
@@ -124,9 +125,9 @@ void __tsan_write_range(void *addr, uptr size) {
|
||||
}
|
||||
|
||||
void __tsan_read_range_pc(void *addr, uptr size, void *pc) {
|
||||
MemoryAccessRange(cur_thread(), (uptr)pc, (uptr)addr, size, false);
|
||||
MemoryAccessRange(cur_thread(), STRIP_PC(pc), (uptr)addr, size, false);
|
||||
}
|
||||
|
||||
void __tsan_write_range_pc(void *addr, uptr size, void *pc) {
|
||||
MemoryAccessRange(cur_thread(), (uptr)pc, (uptr)addr, size, true);
|
||||
MemoryAccessRange(cur_thread(), STRIP_PC(pc), (uptr)addr, size, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user