Skip to content

Commit 20d1a07

Browse files
author
hjl
committed
libgcc/CET: Skip signal frames when unwinding shadow stack
When -fcf-protection -mcet is used, I got FAIL: g++.dg/eh/sighandle.C (gdb) bt #0 _Unwind_RaiseException (exc=exc@entry=0x416ed0) at /export/gnu/import/git/sources/gcc/libgcc/unwind.inc:140 #1 0x00007ffff7d9936b in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x403dd0 <typeinfo for int@@CXXABI_1.3>, dest=0x0) at /export/gnu/import/git/sources/gcc/libstdc++-v3/libsupc++/eh_throw.cc:90 #2 0x0000000000401255 in sighandler (signo=11, si=0x7fffffffd6f8, uc=0x7fffffffd5c0) at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:9 #3 <signal handler called> <<<< Signal frame which isn't on shadow stack #4 dosegv () at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:14 #5 0x00000000004012e3 in main () at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:30 (gdb) p frames $6 = 5 (gdb) frame count should be 4, not 5. This patch skips signal frames when unwinding shadow stack. gcc/testsuite/ PR libgcc/85334 * g++.dg/torture/pr85334.C: New test. libgcc/ PR libgcc/85334 * unwind-generic.h (_Unwind_Frames_Increment): New. * config/i386/shadow-stack-unwind.h (_Unwind_Frames_Increment): Likewise. * unwind.inc (_Unwind_RaiseException_Phase2): Increment frame count with _Unwind_Frames_Increment. (_Unwind_ForcedUnwind_Phase2): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259502 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 47b6cf6 commit 20d1a07

File tree

6 files changed

+63
-2
lines changed

6 files changed

+63
-2
lines changed

gcc/testsuite/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-04-19 H.J. Lu <[email protected]>
2+
3+
PR libgcc/85334
4+
* g++.dg/torture/pr85334.C: New test.
5+
16
2018-04-19 Jonathan Wakely <[email protected]>
27

38
PR c++/85464 - missing location for -Wignored-qualifiers diagnostic
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// { dg-do run { target { i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } } }
2+
// { dg-require-effective-target cet }
3+
// { dg-additional-options "-fexceptions -fnon-call-exceptions -fcf-protection -mcet" }
4+
5+
#include <signal.h>
6+
#include <stdlib.h>
7+
8+
void sighandler (int signo, siginfo_t * si, void * uc)
9+
{
10+
throw (5);
11+
}
12+
13+
char * dosegv ()
14+
{
15+
* ((volatile int *)0) = 12;
16+
return 0;
17+
}
18+
19+
int main ()
20+
{
21+
struct sigaction sa;
22+
int status;
23+
24+
sa.sa_sigaction = sighandler;
25+
sa.sa_flags = SA_SIGINFO;
26+
27+
status = sigaction (SIGSEGV, & sa, NULL);
28+
status = sigaction (SIGBUS, & sa, NULL);
29+
30+
try {
31+
dosegv ();
32+
}
33+
catch (int x) {
34+
return (x != 5);
35+
}
36+
37+
return 1;
38+
}

libgcc/ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2018-04-19 H.J. Lu <[email protected]>
2+
3+
PR libgcc/85334
4+
* unwind-generic.h (_Unwind_Frames_Increment): New.
5+
* config/i386/shadow-stack-unwind.h (_Unwind_Frames_Increment):
6+
Likewise.
7+
* unwind.inc (_Unwind_RaiseException_Phase2): Increment frame
8+
count with _Unwind_Frames_Increment.
9+
(_Unwind_ForcedUnwind_Phase2): Likewise.
10+
111
2018-04-19 H.J. Lu <[email protected]>
212

313
PR libgcc/85379

libgcc/config/i386/shadow-stack-unwind.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
4949
} \
5050
} \
5151
while (0)
52+
53+
/* Increment frame count. Skip signal frames. */
54+
#undef _Unwind_Frames_Increment
55+
#define _Unwind_Frames_Increment(context, frames) \
56+
if (!_Unwind_IsSignalFrame (context)) frames++

libgcc/unwind-generic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,7 @@ EXCEPTION_DISPOSITION _GCC_specific_handler (PEXCEPTION_RECORD, void *,
291291
/* Additional actions to unwind number of stack frames. */
292292
#define _Unwind_Frames_Extra(frames)
293293

294+
/* Increment frame count. */
295+
#define _Unwind_Frames_Increment(context, frames) frames++
296+
294297
#endif /* unwind.h */

libgcc/unwind.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ _Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc,
7373
gcc_assert (!match_handler);
7474

7575
uw_update_context (context, &fs);
76-
frames++;
76+
_Unwind_Frames_Increment (context, frames);
7777
}
7878

7979
*frames_p = frames;
@@ -190,7 +190,7 @@ _Unwind_ForcedUnwind_Phase2 (struct _Unwind_Exception *exc,
190190
/* Update cur_context to describe the same frame as fs, and discard
191191
the previous context if necessary. */
192192
uw_advance_context (context, &fs);
193-
frames++;
193+
_Unwind_Frames_Increment (context, frames);
194194
}
195195

196196
*frames_p = frames;

0 commit comments

Comments
 (0)