@@ -35,13 +35,56 @@ namespace __asan {
35
35
36
36
void AsanOnDeadlySignal (int signo, void *siginfo, void *context) {
37
37
ScopedDeadlySignal signal_scope (GetCurrentThread ());
38
+ int code = (int )((siginfo_t *)siginfo)->si_code ;
38
39
// Write the first message using fd=2, just in case.
39
40
// It may actually fail to write in case stderr is closed.
40
41
internal_write (2 , SanitizerToolName, internal_strlen (SanitizerToolName));
41
42
static const char kDeadlySignal [] = " :DEADLYSIGNAL\n " ;
42
43
internal_write (2 , kDeadlySignal , sizeof (kDeadlySignal ) - 1 );
43
44
SignalContext sig = SignalContext::Create (siginfo, context);
44
- if (IsStackOverflow (((siginfo_t *)siginfo)->si_code , sig))
45
+
46
+ // Access at a reasonable offset above SP, or slightly below it (to account
47
+ // for x86_64 or PowerPC redzone, ARM push of multiple registers, etc) is
48
+ // probably a stack overflow.
49
+ #ifdef __s390__
50
+ // On s390, the fault address in siginfo points to start of the page, not
51
+ // to the precise word that was accessed. Mask off the low bits of sp to
52
+ // take it into account.
53
+ bool IsStackAccess = sig.addr >= (sig.sp & ~0xFFF ) &&
54
+ sig.addr < sig.sp + 0xFFFF ;
55
+ #else
56
+ bool IsStackAccess = sig.addr + 512 > sig.sp && sig.addr < sig.sp + 0xFFFF ;
57
+ #endif
58
+
59
+ #if __powerpc__
60
+ // Large stack frames can be allocated with e.g.
61
+ // lis r0,-10000
62
+ // stdux r1,r1,r0 # store sp to [sp-10000] and update sp by -10000
63
+ // If the store faults then sp will not have been updated, so test above
64
+ // will not work, because the fault address will be more than just "slightly"
65
+ // below sp.
66
+ if (!IsStackAccess && IsAccessibleMemoryRange (sig.pc , 4 )) {
67
+ u32 inst = *(unsigned *)sig.pc ;
68
+ u32 ra = (inst >> 16 ) & 0x1F ;
69
+ u32 opcd = inst >> 26 ;
70
+ u32 xo = (inst >> 1 ) & 0x3FF ;
71
+ // Check for store-with-update to sp. The instructions we accept are:
72
+ // stbu rs,d(ra) stbux rs,ra,rb
73
+ // sthu rs,d(ra) sthux rs,ra,rb
74
+ // stwu rs,d(ra) stwux rs,ra,rb
75
+ // stdu rs,ds(ra) stdux rs,ra,rb
76
+ // where ra is r1 (the stack pointer).
77
+ if (ra == 1 &&
78
+ (opcd == 39 || opcd == 45 || opcd == 37 || opcd == 62 ||
79
+ (opcd == 31 && (xo == 247 || xo == 439 || xo == 183 || xo == 181 ))))
80
+ IsStackAccess = true ;
81
+ }
82
+ #endif // __powerpc__
83
+
84
+ // We also check si_code to filter out SEGV caused by something else other
85
+ // then hitting the guard page or unmapped memory, like, for example,
86
+ // unaligned memory access.
87
+ if (IsStackAccess && (code == si_SEGV_MAPERR || code == si_SEGV_ACCERR))
45
88
ReportStackOverflow (sig);
46
89
else
47
90
ReportDeadlySignal (signo, sig);
0 commit comments