Skip to content

Fix SSP issue with HW exceptions from JIT helpers#107665

Merged
janvorli merged 1 commit intodotnet:mainfrom
janvorli:fix-ssp-issue-with-hw-exceptions
Sep 11, 2024
Merged

Fix SSP issue with HW exceptions from JIT helpers#107665
janvorli merged 1 commit intodotnet:mainfrom
janvorli:fix-ssp-issue-with-hw-exceptions

Conversation

@janvorli
Copy link
Copy Markdown
Member

@janvorli janvorli commented Sep 11, 2024

The recent change that was fixing bad SSP updating during exception handling with funceval has also modified the way SSP is extracted for hardware exceptions. That works fine for many cases, but there is a problem when the exception occurs in a JIT helper. The AjustContextForJITHelpers uses only the basic CONTEXT structure for unwinding to the managed caller and so the SSP is not properly updated. That makes it off by one slot when we set it when continuing execution after catch.
This change removes storing SSP for hardware exceptions in the FaultingExceptionFrame to mitigate the issue. It effectively returns to the way software exceptions use - scanning shadow stack for the instruction pointer of the frame to which it is going to resume after catch.

Close #107668

The recent change that was fixing bad SSP updating during exception
handling with funceval has also modified the way SSP is extracted for
hardware exceptions. That works fine for many cases, but there is a
problem when the exception occurs in a JIT helper. The
`AjustContextForJITHelpers` uses only the basic `CONTEXT` structure for
unwinding to the managed caller and so the SSP is not properly updated.
That makes it off by one slot when we set it when continuing execution
after catch.
This change removes storing SSP for hardware exceptions in the
FaultingExceptionFrame to mitigate the issue. It effectively returns to
the way software exceptions use - scanning shadow stack for the
instruction pointer of the frame to which it is going to resume after
catch.
@janvorli janvorli added this to the 9.0.0 milestone Sep 11, 2024
@janvorli janvorli requested a review from jkotas September 11, 2024 00:16
@janvorli janvorli self-assigned this Sep 11, 2024

save_reg_postrsp rcx, REDIRECT_FOR_THROW_CONTROL_FRAME_SIZE + 8h ; FaultingExceptionFrame
save_reg_postrsp rdx, REDIRECT_FOR_THROW_CONTROL_FRAME_SIZE + 10h ; Original RSP
save_reg_postrsp r8, REDIRECT_FOR_THROW_CONTROL_FRAME_SIZE + 18h ; SSP
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the code to pass the SSP to the target function instead of storing it in the FaultingExceptionFrame so that the FaultingExceptionFrame::Init can zero it by default that's needed in all cases other than the funceval redirection.

@janvorli
Copy link
Copy Markdown
Member Author

cc: @tommcdon - I've re-tested it with the funceval diagnostics tests to make sure it still works correctly.

@janvorli janvorli merged commit 6219d18 into dotnet:main Sep 11, 2024
@janvorli
Copy link
Copy Markdown
Member Author

/backport to release/9.0

@github-actions
Copy link
Copy Markdown
Contributor

Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10808095425

jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 17, 2024
The recent change that was fixing bad SSP updating during exception
handling with funceval has also modified the way SSP is extracted for
hardware exceptions. That works fine for many cases, but there is a
problem when the exception occurs in a JIT helper. The
`AjustContextForJITHelpers` uses only the basic `CONTEXT` structure for
unwinding to the managed caller and so the SSP is not properly updated.
That makes it off by one slot when we set it when continuing execution
after catch.
This change removes storing SSP for hardware exceptions in the
FaultingExceptionFrame to mitigate the issue. It effectively returns to
the way software exceptions use - scanning shadow stack for the
instruction pointer of the frame to which it is going to resume after
catch.

Co-authored-by: Jan Vorlicek <jan.vorlicek@volny,cz>
sirntar pushed a commit to sirntar/runtime that referenced this pull request Sep 30, 2024
The recent change that was fixing bad SSP updating during exception
handling with funceval has also modified the way SSP is extracted for
hardware exceptions. That works fine for many cases, but there is a
problem when the exception occurs in a JIT helper. The
`AjustContextForJITHelpers` uses only the basic `CONTEXT` structure for
unwinding to the managed caller and so the SSP is not properly updated.
That makes it off by one slot when we set it when continuing execution
after catch.
This change removes storing SSP for hardware exceptions in the
FaultingExceptionFrame to mitigate the issue. It effectively returns to
the way software exceptions use - scanning shadow stack for the
instruction pointer of the frame to which it is going to resume after
catch.

Co-authored-by: Jan Vorlicek <jan.vorlicek@volny,cz>
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test Failure: JIT/Regression/CLR-x86-JIT/V1-M09.5-PDC/b16335/b16335/b16335.dll

2 participants