Skip to content
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

Prevent concurrent calls to Tor API #59

Merged
merged 4 commits into from
Dec 9, 2021

Conversation

akwizgran
Copy link
Contributor

@akwizgran akwizgran commented Dec 2, 2021

This PR prevents the crashes seen in #57 and Tor #32729 by preventing concurrent calls to the Tor API. Concurrent calls are prevented in two ways:

  1. Move the call to mainConfigurationFree() onto the same thread as runMain() to ensure it's never called before runMain() has returned, per the comments in tor_api.h.

  2. Use a static lock to prevent different TorService instances within the same process from making concurrent native calls. It was previously possible for this to happen because the native calls are made from a background thread that may (briefly) outlive the TorService instance that launched it.

Edit: The crashes seen in #57 seem to be caused by file descriptor reuse and are not fixed by this PR.

grote and others added 4 commits November 26, 2021 09:24
E/fdsan: attempted to close file descriptor, expected to be unowned, actually owned
The lock is static to ensure that if the TorService instance is destroyed and a new instance is created (eg when unbinding and then re-binding), the background threads created by the two instances don't concurrently call into the process's Tor library.
@eighthave
Copy link
Member

Pushed this for a CI run here: https://gitlab.com/eighthave/tor-android/-/pipelines/421253873

@eighthave
Copy link
Member

This passed the CI (if rebased on before #55) https://gitlab.com/eighthave/tor-android/-/pipelines/421879534

@eighthave
Copy link
Member

@bitmold @n8fr8 do you want to test this with Orbot first? Or shall we just merge it?

@n8fr8
Copy link
Member

n8fr8 commented Dec 3, 2021

@bitmold @n8fr8 do you want to test this with Orbot first? Or shall we just merge it?

please merge

@eighthave
Copy link
Member

@eighthave eighthave merged commit 5933913 into guardianproject:master Dec 9, 2021
eighthave added a commit to eighthave/tor-android that referenced this pull request Dec 17, 2021
This unnests the try/finally block that was added in pull guardianproject#59, and moves it
to the main try block, where it now handles the whole shutdown procedure.

* guardianproject#61 (comment)
* guardianproject#57
* guardianproject#59
syphyr pushed a commit to syphyr/tor that referenced this pull request Dec 17, 2021
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
eighthave added a commit to eighthave/tor-android that referenced this pull request Dec 21, 2021
This unnests the try/finally block that was added in pull guardianproject#59, and moves it
to the main try block, where it now handles the whole shutdown procedure.

* guardianproject#61 (comment)
* guardianproject#57
* guardianproject#59
syphyr pushed a commit to syphyr/tor that referenced this pull request Dec 21, 2021
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jan 21, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jan 25, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Feb 4, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Mar 11, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Mar 18, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Apr 27, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jun 4, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jun 16, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jun 17, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jul 25, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jul 26, 2022
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
uniqx pushed a commit to uniqx/tor that referenced this pull request Oct 14, 2023
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Nov 3, 2023
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Nov 9, 2023
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
uniqx pushed a commit to uniqx/tor that referenced this pull request Nov 14, 2023
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Dec 8, 2023
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jan 21, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jan 30, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Feb 28, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
bitmold pushed a commit to bitmold/tor that referenced this pull request Apr 7, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
bitmold pushed a commit to bitmold/tor that referenced this pull request Apr 7, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
bitmold pushed a commit to bitmold/tor that referenced this pull request Apr 7, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Apr 9, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Apr 10, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Apr 13, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Apr 16, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Apr 29, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request May 2, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
bitmold pushed a commit to bitmold/tor that referenced this pull request May 3, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
uniqx pushed a commit to uniqx/tor that referenced this pull request May 7, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jun 1, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jun 6, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jun 19, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
uniqx pushed a commit to uniqx/tor that referenced this pull request Jul 15, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Aug 6, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Oct 17, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Oct 24, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Oct 31, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Nov 19, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
uniqx pushed a commit to uniqx/tor that referenced this pull request Dec 3, 2024
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
syphyr pushed a commit to syphyr/tor that referenced this pull request Jan 22, 2025
This is here as an experiment in case it is useful in Java space.  It is
looking like there are better ways to handle the shutdown, so my guess is
that this will not be useful.

* guardianproject/tor-android#59
* guardianproject/tor-android#61 (comment)
* guardianproject/tor-android#57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants