-
Notifications
You must be signed in to change notification settings - Fork 11
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
Crash: Tor together with testing server responses #1587
Comments
If we do not find the root cause of this issue there are two hacks coming to my mind.
|
This part of the crash log shows that the crash happened while trying to free the Tor runtime:
In particular, it is something around where the native method is being resolved, as we are still inside
Note also that it is being run on the IO dispatcher. The dispose method was made Lines 15 to 18 in 7914f95
The only other thread doing something interesting in the log is this one:
That is fetching a preference inside a dispatcher. I don't know which one. However, it also looks like the crash log is incomplete:
(Note how @HonzaR is there any way to get more of the log? In particular, we are not seeing anything in the logs related to server testing (other than maybe that preference fetch), so there's not much to work on here (though I'm going to spend some time looking into the |
Yes, I'll get more logs. The Kotlin logs and tracing logs from the Rust side. |
@str4d I'm attaching a new crash log file. Unfortunately, the Android SDK level 27, on which we're able to reproduce the crash, does not print the Rust trancing logs, as we recently discovered with @nuttycom. We should probably check that, too. But the new log at least adds the Kotlin logs. |
@HonzaR explained how the server switcher works to me, and now I'm almost certain that the bug is a UAF. In order to satisfy Rust lifetime rules, these two methods MUST NOT be called in parallel: Lines 15 to 23 in 7398cbc
The problem is that:
Thus, if the app has called |
@HonzaR pointed me to this mutex: Lines 68 to 84 in 618e8eb
The mutex does not enforce the necessary Rust lifetime rules, because it only gates access to the TorClient handle, not to using it. Specifically,
|
The fix here is to EDIT: an extra Mutex does not help because then you get the following race condition:
|
@str4d I've tried several improvements on the Kotlin side to get rid of this error on the impacted API 27. Non of it helped, unfortunately. I've also tried play a bit with threading, logged all possible states, or simplify the entire Kotlin implementation. It's always the same, any time we try to stop I believe that we need to handle this inside the Rust part. From my point of view as a Rust API consumer, when I use any API that provides a disposal method, then the disposal method ( |
This was added to the `TorClient.dispose()` JNI pathway because that native coded did not require access to `JNIEnv` or `JClass`. However, it turns out that this annotation was only added in Android 8 for system usage [0], and was not CTS-tested public API until Android 14. For whatever reason, in API 27 (Android 8.1) the native method symbol can't be found, but in API 28 and above it can be. The performance cost of regular JNI is no longer necessary to worry about given that we now keep a `TorClient` around long-term as part of `SdkSynchronizer`, so instead of doing anything complex to preserve it on API 28+ we just remove the `@CriticalNative` annotation and adjust the native method's signature to take (and ignore) the extra arguments. Closes #1587. [0]: https://developer.android.com/reference/dalvik/annotation/optimization/CriticalNative
The current SDK state causes the Zashi and the Demo app to crash in the scenario described below.
NOTE: It seems that only the Android API level 27 is impacted.
NOTE 2: The crash happens only when Tor and server switching are called simultaneously.
Can you reliably reproduce the issue?
If so, please list the steps to reproduce below:
Actual behavior + errors
tor_server_switch_api_27_crash.mp4
crash_tor_server_switch_api_27.txt
Any extra information that might be useful in the debugging process.
Reproducible on both emulators and physical devices.
The text was updated successfully, but these errors were encountered: