DroidGuard: Fix native library conflict on concurrent handle requests#3378
Open
unpluggederan wants to merge 1 commit intomicrog:masterfrom
Open
DroidGuard: Fix native library conflict on concurrent handle requests#3378unpluggederan wants to merge 1 commit intomicrog:masterfrom
unpluggederan wants to merge 1 commit intomicrog:masterfrom
Conversation
Cache the DexClassLoader instance statically so that concurrent DroidGuard handle requests for the same VM key reuse the same classloader instead of creating a new one that conflicts on the native library. Without this fix, dual-SIM devices crash with UnsatisfiedLinkError when both SIMs trigger DroidGuard simultaneously (e.g. during RCS provisioning), because Android doesn't allow the same .so to be loaded by two different classloaders.
Member
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.
Cache the DexClassLoader instance statically so that concurrent DroidGuard handle requests for the same VM key reuse the same classloader instead of creating a new one that conflicts on the native library.
Without this fix, dual-SIM devices crash with UnsatisfiedLinkError when both SIMs trigger DroidGuard simultaneously (e.g. during RCS provisioning), because Android doesn't allow the same .so to be loaded by two different classloaders.
The loadClass() method does have synchronization and caching, but it doesn't quite cover this case.
classMap is per-instance, so a fresh HandleProxyFactory starts with an empty cache and won't find anything.
weakClassMap is static but it's a WeakHashMap, so the entry can get garbage collected between calls if nothing else holds a strong reference to the class
When both miss, a new DexClassLoader gets created for the same APK, and that's when Android complains about the native lib already being loaded. So the synchronization prevents them from running truly in parallel inside loadClass(), but the second caller still ends up creating a new classloader because neither cache reliably had the entry.