-
Notifications
You must be signed in to change notification settings - Fork 937
#1250 validate that the obtained dlopen handle is same as the originally discovered lib in maps #1261
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
#1250 validate that the obtained dlopen handle is same as the originally discovered lib in maps #1261
Conversation
…as the originally discovered lib in maps
src/symbols_linux.cpp
Outdated
| // Also, dlopen() ensures the library is fully loaded. | ||
| // Main executable and ld-linux interpreter cannot be dlopen'ed, but dlerror() returns NULL for them on some systems. | ||
| void* handle = dlopen(lib.file, RTLD_LAZY | RTLD_NOLOAD); | ||
| bool valid_handle = false; |
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.
If handle is not null, it is valid. I would rename the variable to reflect intent: "handle is to a different instance of the shared object, compared to what was parsed from /maps".
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.
renamed to original_handle
Signed-off-by: Bara' Hasheesh <bara.hasheesh@gmail.com>
src/symbols_linux.cpp
Outdated
| // Parse main executable regardless of dlopen result, since it cannot be unloaded. | ||
| bool is_main_exe = main_phdr >= lib.image_base && main_phdr < lib.map_end; | ||
| if (handle != NULL || dlerror() == NULL || is_main_exe) { | ||
| if (original_handle || dlerror() == NULL || is_main_exe) { |
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.
This is not correct: because of "dlerror() == NULL", condition will be still true, even if base address differs.
Fortunately, dlerror() should go away after Kerem's fix.
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.
That's correct
@krk change is required here
I will sync & resolve conflicts
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 branch synced & conflicts handled
# Conflicts: # src/symbols_linux.cpp
|
included here #1264 |
Description
This fixes fixes one of the potential problems discovered in the #1250
This change detects if the library was reloaded to a different location & marks the handle as invalid
Note: This solution isn't complete & needs to change handling of
dlerror() == nullto only be valid forldlibraryRelated issues
#1250
Motivation and context
Reduce effect of race conditions to async profiler
How has this been tested?
make testBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.