Unpoison alloca used in stack adjustments when ASAN#839
Closed
KJTsanaktsidis wants to merge 1 commit into
Closed
Conversation
The pattern for several of the architectures is for ffi_call_int to stack-allocate some arguments + the registers, and then ffi_call_$ARCH will pop the top of that structure into registers, and then adjust the stack pointer such that the alloca'd buffer _becomes_ the stack-passed arguments for the function being called. If libffi is compiled with ASAN, then there will be a redzone inserted after the alloca'd buffer which is marked as poisoned. This redzone appears beyond the end of $sp upon entry to the called function. If the called function does anything to use this stack memory, ASAN will notice that it's poisoned and report an error. This commit fixes the situation (on the architectures that I have access to) by manually unpoisoning the alloca'd buffer's redzone. The alternative approach would be to disable instrumentation for ffi_call_int altogether, which I can also do if we think that's preferable.
Member
|
Thank you for this work. My preference, however, is to disable instrumentation. Can you generate a patch for this along the lines of what was discussed in #255 ? |
Contributor
Author
|
Easily done - I opened a new PR with that: #858 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pattern for several of the architectures is for ffi_call_int to stack-allocate some arguments + the registers, and then ffi_call_$ARCH will pop the top of that structure into registers, and then adjust the stack pointer such that the alloca'd buffer becomes the stack-passed arguments for the function being called.
If libffi is compiled with ASAN, then there will be a redzone inserted after the alloca'd buffer which is marked as poisoned. This redzone appears beyond the end of $sp upon entry to the called function.
If the called function does anything to use this stack memory, ASAN will notice that it's poisoned and report an error.
This commit fixes the situation (on the architectures that I have access to) by manually unpoisoning the alloca'd buffer's redzone. The alternative approach would be to disable instrumentation for ffi_call_int altogether, which I can also do if we think that's preferable.
This should fix the issue reported in #255