Commit fd73e87
[release/9.0-staging] Fix return address hijacking with CET (#109548)
* Fix return address hijacking with CET
There is a problematic case when return address is hijacked while in a
managed method that tail calls a GC write barrier and when CET is
enabled. The write barrier code can change while the handler for the
hijacked address is executed from the vectored exception handler.
When the vectored exception handler then returns to the write barrier to
re-execute the `ret` instruction that has triggered the vectored
exception handler due to the main stack containing a different address
than the shadow stack (now with the main stack fixed), the instruction
may no longer be `ret` due to the change of the write barrier change.
This change fixes it by setting the context to return to from the
vectored exception handler to point to the caller and setting the Rsp
and SSP to match that. That way, the write barrier code no longer
matters.
* Add equivalent change to nativeaot
* Add missing ifdef
---------
Co-authored-by: Jan Vorlicek (from Dev Box) <janvorli@microsoft.com>1 parent 329fdab commit fd73e87
File tree
3 files changed
+29
-16
lines changed- src/coreclr
- nativeaot/Runtime
- windows
- vm
3 files changed
+29
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
488 | 491 | | |
489 | 492 | | |
490 | 493 | | |
| |||
539 | 542 | | |
540 | 543 | | |
541 | 544 | | |
| 545 | + | |
| 546 | + | |
542 | 547 | | |
543 | 548 | | |
544 | 549 | | |
545 | 550 | | |
546 | | - | |
547 | 551 | | |
548 | 552 | | |
549 | 553 | | |
550 | 554 | | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | 555 | | |
559 | 556 | | |
560 | 557 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6533 | 6533 | | |
6534 | 6534 | | |
6535 | 6535 | | |
| 6536 | + | |
| 6537 | + | |
6536 | 6538 | | |
6537 | 6539 | | |
6538 | 6540 | | |
6539 | 6541 | | |
6540 | | - | |
6541 | 6542 | | |
6542 | 6543 | | |
6543 | 6544 | | |
6544 | 6545 | | |
6545 | 6546 | | |
6546 | 6547 | | |
6547 | 6548 | | |
6548 | | - | |
6549 | | - | |
6550 | | - | |
6551 | | - | |
6552 | | - | |
6553 | | - | |
6554 | | - | |
6555 | 6549 | | |
6556 | 6550 | | |
6557 | 6551 | | |
| |||
0 commit comments