|
50 | 50 | __unw_resume((cursor)); \
|
51 | 51 | } while (0)
|
52 | 52 | #elif defined(_LIBUNWIND_TARGET_I386)
|
| 53 | +#define __cet_ss_step_size 4 |
53 | 54 | #define __unw_phase2_resume(cursor, fn) \
|
54 | 55 | do { \
|
55 | 56 | _LIBUNWIND_POP_CET_SSP((fn)); \
|
|
61 | 62 | "d"(cetJumpAddress)); \
|
62 | 63 | } while (0)
|
63 | 64 | #elif defined(_LIBUNWIND_TARGET_X86_64)
|
| 65 | +#define __cet_ss_step_size 8 |
64 | 66 | #define __unw_phase2_resume(cursor, fn) \
|
65 | 67 | do { \
|
66 | 68 | _LIBUNWIND_POP_CET_SSP((fn)); \
|
@@ -177,6 +179,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
|
177 | 179 | // uc is initialized by __unw_getcontext in the parent frame. The first stack
|
178 | 180 | // frame walked is unwind_phase2.
|
179 | 181 | unsigned framesWalked = 1;
|
| 182 | +#ifdef _LIBUNWIND_USE_CET |
| 183 | + unsigned long shadowStackTop = _get_ssp(); |
| 184 | +#endif |
180 | 185 | // Walk each frame until we reach where search phase said to stop.
|
181 | 186 | while (true) {
|
182 | 187 |
|
@@ -228,6 +233,20 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
|
228 | 233 | }
|
229 | 234 | #endif
|
230 | 235 |
|
| 236 | +// In CET enabled environment, we check return address stored in normal stack |
| 237 | +// against return address stored in CET shadow stack, if the 2 addresses don't |
| 238 | +// match, it means return address in normal stack has been corrupted, we return |
| 239 | +// _URC_FATAL_PHASE2_ERROR. |
| 240 | +#ifdef _LIBUNWIND_USE_CET |
| 241 | + if (shadowStackTop != 0) { |
| 242 | + unw_word_t retInNormalStack; |
| 243 | + __unw_get_reg(cursor, UNW_REG_IP, &retInNormalStack); |
| 244 | + unsigned long retInShadowStack = *( |
| 245 | + unsigned long *)(shadowStackTop + __cet_ss_step_size * framesWalked); |
| 246 | + if (retInNormalStack != retInShadowStack) |
| 247 | + return _URC_FATAL_PHASE2_ERROR; |
| 248 | + } |
| 249 | +#endif |
231 | 250 | ++framesWalked;
|
232 | 251 | // If there is a personality routine, tell it we are unwinding.
|
233 | 252 | if (frameInfo.handler != 0) {
|
|
0 commit comments