talsec / Free-RASP-Android

Library for improving app security and threat monitoring on Android mobile devices.
https://github.com/talsec/Free-RASP-Community
MIT License
143 stars 10 forks source link

Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed #18

Closed fanjavaid closed 11 months ago

fanjavaid commented 1 year ago

Hello, I implemented the library version 6.0.0 and I got the following crashes:

When I check my universal APK, I have the libpolarssl.so both in x86 and x64. However I distribute the app as Bundle in the Google Play Console.

I had tried to add exception handler when called at com.aheaditec.talsec_security.security.api.Talsec.start but the crash still exist.

Is the Library for android support for x86? And any insight why the crash happens?

Thank you

msikyna commented 1 year ago

Hello @fanjavaid,

The library should support both x86 and x64. The library (aar) contains libpolarssl.so for all ABIs (x86, x86_64, armeabi-v7a, arm64-v8a). Can you check on which devices the crash occurs? Is it a general problem for all x64 devices, or it only occurs on some devices? You can also inspect your bundle file (.aab) if the base/lib directory contains libpolarssl.so for all ABIs. We will try to look into this issue but I’m not sure if we will be able to reproduce this issue.

Best regards, Talsec Team

fanjavaid commented 1 year ago

Hello @msikyna

Here is the details about the devices:

Screenshot 2023-06-22 at 10 52 55 Screenshot 2023-06-22 at 10 52 47

Well, the Bundle file contains for all ABIS : x86_64, x86, arm64-v8a, armeabi-v7a.

🔴  Oh, in my exception above (my question) it is trying to lookup in the arm directory & yes it is not available in my Bundle file.

Or do you have any suggestion how to handle it? I believe App crashes when invoke Talsec.start(), but I can't catch the Exception. Crash still exists.

Thank you

rpavliuk commented 1 year ago

We have, I guess, a similar issue:

Fatal Exception: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.signnow.android-9yrhDsO0RpoyrWxEyG4MXA==/base.apk"],nativeLibraryDirectories=[/data/app/com.signnow.android-9yrhDsO0RpoyrWxEyG4MXA==/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libpolarssl.so" at java.lang.Runtime.loadLibrary0(Runtime.java:1011) at java.lang.System.loadLibrary(System.java:1657) at com.aheaditec.talsec.security.b2.<clinit>(SourceFile:1) at com.aheaditec.talsec.security.a2.<init>(SourceFile:6) at com.aheaditec.talsec.security.a2.a(SourceFile:4) at com.aheaditec.talsec_security.security.api.Talsec.start(SourceFile:1) at com.signnow.app.app.SignNowApp.setTalsecLibrary(SignNowApp.kt:128) at com.signnow.app.app.SignNowApp.onCreate(SignNowApp.kt:64) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740) at android.app.ActivityThread.-wrap1() at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

It is our first release with your library. At this time it occurred only on Nexus 5X devices. I have researched SO a bit and found a similar issue. I don't want to try the solution on my current users. Can you provide some information about this error? Or maybe I can safely use this solution?

Also, I need to mention that I have this block in my build.gradle file. Because I have some native libraries:

ndk {
            abiFilters.addAll(
                listOf(
                    "arm64-v8a", "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
                )
            )
        }
msikyna commented 1 year ago

Hello @fanjavaid , @rpavliuk ,

we are looking at the issue. Thank you for details.

Kind regards, Talsec team

rpavliuk commented 1 year ago

@msikyna Can we help you with framing this bug?

xprikryl2 commented 1 year ago

Hello @fanjavaid,

We've managed to provide a partial solution. The native library libpolarssl.so is no longer required in the freeRASP workflow, so the bug mentioned above shouldn't occur anymore.

Nevertheless, there are still other native libraries that are crucial for freeRASP (libsecurity.so and libclib.so) that can also be problematic. I found a lot of open issues regarding this problem (eg. Xiaomi native library load, App bundle UnsatisfiedLinkError, App Bundle native crash, and many others). It looks like there are still some issues during native library loading.

I also stumbled upon two proposed solutions, but I haven't had the possibility to test them out yet.

  1. Disabling bundle ABI split in the build.gradle as described here. This will slightly increase the size of a bundle.
    bundle {
    abi {
        // This property is set to true by default.
        enableSplit = false
    }
    }
  2. In the stack trace of this issue above, the application is trying to load a native library from the app directory in the filesystem. That usually means that the native libraries are compressed and extracted to the filesystem during the installation. You can try to modify your extractNativeLibs and If you’re using App Bundle, also set android.bundle.enableUncompressedNativeLibs=true along with the extractNativeLibs configuration option.
  3. There is also a GH project ReLinker that tries to solve issues with native libraries linking.

If you manage to try one of the proposed solutions above or if you find a new one, please share your findings with us.

Best regards, Talsec Team

rpavliuk commented 1 year ago

Thank you so much, we will try to update your library and discuss the suggested solutions. I will update you after the release of our app

rpavliuk commented 1 year ago

We have tried to update the library to the latest version, but this exception still occurs:

Fatal Exception: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.signnow.android-tvn2uhQIOfml5bFibF2NLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.signnow.android-tvn2uhQIOfml5bFibF2NLQ==/lib/arm64, /system/lib64, /system/product/lib64]]] couldn't find "libsecurity.so" at java.lang.Runtime.loadLibrary0(Runtime.java:1067) at java.lang.Runtime.loadLibrary0(Runtime.java:1007) at java.lang.System.loadLibrary(System.java:1667) at com.aheaditec.talsec.security.a2.<clinit>(SourceFile:1) at com.aheaditec.talsec.security.z1.<init>(SourceFile:6) at com.aheaditec.talsec.security.z1.a(SourceFile:4) at com.aheaditec.talsec_security.security.api.Talsec.start(SourceFile:4) at com.signnow.app.app.SignNowApp.setTalsecLibrary(SignNowApp.kt:129) at com.signnow.app.app.SignNowApp.onCreate(SignNowApp.kt:64) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1182) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6460) at android.app.ActivityThread.access$1300(ActivityThread.java:219) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

But I want to notice that this crash occurs on the device Mainline brand Google. So, this can be an emulator, in this case, it's not an issue for us. Also, we will check the recommensations from the message above, maybe we can use it in our project. We will monitor this crash and update you if we will find something interesting.

Thanks!

rpavliuk commented 1 year ago

@msikyna After monitoring this crash for some time we can conclude that it happens more on Emulators or already Rooted devices. So, it is not affecting us, because we plan to block these devices anyway. But after the update we have encountered a new crash. I have created a separate issue for it.

fanjavaid commented 11 months ago

Hello, after releasing the updated version with workarounds above, the issue about UnsatisfiedLinkError was not happening. But, like @rpavliuk there is a new issue: Fatal Exception: java.lang.RuntimeException: Package manager has died in the latest Talsec version.

msikyna commented 11 months ago

Hello @rpavliuk , @fanjavaid , thank you for reporting the issue! We are looking into it.

Kind regards, Talsec team