Ask the linker where a library is loaded, not the maps file - #959
Open
JingMatrix wants to merge 1 commit into
Open
Ask the linker where a library is loaded, not the maps file#959JingMatrix wants to merge 1 commit into
JingMatrix wants to merge 1 commit into
Conversation
ElfImage guessed a library's base from the permission columns of /proc/self/maps, hunting for an r--p line followed by r-xp. The kernel never promised that shape and it does not hold -- Android 10 maps libart's text --xp -- and our own MAP_SHARED view of the file is itself an offset-0 line that can sort below the real load. The linker holds the answer already. do_dl_iterate_phdr walks solist in load order and hands over each module's realpath and program headers, so the base falls out of the first PT_LOAD: no parsing, and one less read of maps to be noticed by. Re-entering it from the do_dlopen hook is safe, since g_dl_mutex is recursive. One gap: the linker's own entry carries no program headers before Android 10, where get_libdl_info begins copying them and soinfo zeroes everything else, so /linker still falls back on 8.1 and 9. That fallback now takes the offset-0 private mapping and corroborates it with an executable one rather than guessing. Also here: an ELF magic check before parsing, and IsValid() no longer claims an image whose file never opened.
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.
ElfImageguessed a library's base from the permission columns of/proc/self/maps, hunting for anr--pline followed byr-xp. The kernel never promised that shape and it does not hold — Android 10 maps libart's text--xp— and our ownMAP_SHAREDview of the file is itself an offset-0 line that can sort below the real load.The linker holds the answer already.
do_dl_iterate_phdrwalkssolistin load order and hands over each module's realpath and program headers, so the base falls out of the firstPT_LOAD— no parsing, and one less read of maps to be noticed by. Re-entering it from thedo_dlopenhook is safe, sinceg_dl_mutexis recursive.One gap: the linker's own entry carries no program headers before Android 10, where
get_libdl_infobegins copying them andsoinfozeroes everything else, so/linkerstill falls back on 8.1 and 9. That fallback now takes the offset-0 private mapping and corroborates it with an executable one rather than guessing.Also here: an ELF magic check before parsing, and
IsValid()no longer claims an image whose file never opened.