-
Notifications
You must be signed in to change notification settings - Fork 150
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
make init_mechlist thread-safe #584
Comments
@vlmarek The proposed fix is in and of itself, not thread safe, as one thread could allocate and start using the mutex, and a second thread could allocate a new mutex, overwriting the pointer to the first one. So while the problem description is correct, it needs a different solution. |
@quanah wouldn't it be on the mutexes implementation to make sure that sasl_MUTEX_ALLOC() is itself thread safe and always returns the same pointer if multiple threads are racing to call it ? |
@simo5 the API isn't designed to allow callers to pass in a unique handle, so sasl_MUTEX_ALLOC() can't know it's being called multiple times for the same purpose. It's functionally like malloc, always returning a new object on every call. |
@hyc duh right! I was looking at the tree (the specific place) and not the forest ... |
libsasl2 isn't thread-safe until someone supplies viable callbacks via To get there, we might need to provide and document a single API entry point that users should call before libsasl2 is considered initialised. Probably a single one that does it for both client and server side. Getting this into 2.2 would give us a good opportunity to adjust our API and docs accordingly. |
Is there a reason why sasl2 can't use pthread_mutex by default instead of being simply thread unsafe? |
We should have a single documented entry point that initialises the library's mutexes, that would be the only thing people would have to make sure not to call concurrently. In pthread we have |
Right, some platforms may need that, but some platforms can be made safer by default, perhaps they should be. |
Fixes cyrusimap#584 Signed-off-by: Ondřej Kuzník <okuznik@symas.com>
Fixes cyrusimap#584 Signed-off-by: Ondřej Kuzník <okuznik@symas.com>
@mistotebe I don't think #803 completely fixed this for I think the patch only made it such that _sasl_common_init is thread-safe, but even before entering that, Here's a simple repro:
And I'm getting the following segfault:
In another more complicated code, I'm getting a similar segfault also due to cmechlist turning 0x00:
I think we might still need something similar to |
Originally opened as cyrusimap/cyrus-imapd#2813 by @vlmarek
With the following attached patch:
https://github.com/cyrusimap/cyrus-imapd/files/3331156/116-race-condition.txt
The text was updated successfully, but these errors were encountered: