-
Notifications
You must be signed in to change notification settings - Fork 918
Protect patching with an open handle #1264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protect patching with an open handle #1264
Conversation
…as the originally discovered lib in maps
Signed-off-by: Bara' Hasheesh <[email protected]>
# Conflicts: # src/symbols_linux.cpp
Tested that after this PR the test in asprof-reproducers does not fail anymore, and fails in |
Also tested the crash in the stress test by @Baraa-Hasheesh, and could not reproduce the issue anymore after this PR |
Co-authored-by: Bara' Hasheesh <[email protected]> Signed-off-by: Francesco Andreuzzi <[email protected]>
Let's add minimal reproducers as cpp unit tests. |
@krk Adapted test from @Baraa-Hasheesh's repo |
10c0a73
to
42879e3
Compare
1258b41
to
ff43185
Compare
src/symbols_linux.cpp
Outdated
// Protect library from unloading while parsing in-memory ELF program headers. | ||
// Also, dlopen() ensures the library is fully loaded. | ||
_lib_handle = dlopen(stripped_name, RTLD_LAZY | RTLD_NOLOAD); | ||
_valid = isValidHandle(cc, _lib_handle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the best name, IMO.
Any non-null handle is valid, but what we really check here is whether it is the same shared library that was seen at CodeCache creation time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkHandleConsistency
isHandleConsistent
I'll think about it, let me know if you have any preference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apangin all comments addressed |
100 commits, 140 comments, 5 contributors. That was an epic PR. Thanks everyone involved! |
Description
In this PR I introduce additional protection during patches. The main change is a new function
isSafeToPatch
, which combines the checks introduced in #1261, #1263, #1243, and can be used in other parts of the code likeMallocTracer
.Thanks @Baraa-Hasheesh for the discussion and feedback on the code.
Related issues
#1250, #1256
Motivation and context
Keeping an open handle makes sure we the library cannot be unloaded while the patch is being made, thus providing additional protection against the failures in the linked issues.
How has this been tested?
make test
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.