-
Notifications
You must be signed in to change notification settings - Fork 638
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
BUG: RTLD_GLOBAL dlopen flag causes segfaults w/ pynacl & libsodium #1878
Comments
Thanks for the report! It's unclear what, if anything, pyzmq should do to address this. Seems like some kind of name mangling or something, but I wouldn't know how to go about it.
Do you mean libzmq? I don't think pyzmq can do anything about how libsodium is loaded when it's not bundled. |
@minrk Sorry for the confusion. The issue we ran into is using PyNaCl with pyzmq when pyzmq does not have libsodium bundled. In this scenario importing pyzmq makes tweetnacl's functions global. Then when using PyNaCl, calls to libsodium result in functions from tweetnacl get called which causes segfaults. The proposed workaround was setting RTLD_DEEPBIND when importing the libsodium provided by PyNaCl. Does that make sense? |
I think it does, but I don't quite understand what I can do about it in pyzmq (or those building pyzmq for pynacl), since it's when pynacl loads the symbol. I wonder if some amount of symbol name mangling in pyzmq's bundled libzmq would help avoid the collision. Would it perhaps be better to build pyzmq linked against libzmq and libsodium, and then bundle libzmq but not libsodium, so the shared libsodium ought to be used? This is a level of linking and loading I'm not experienced with, so I'm not sure what I can do about these things. |
tweetnacl is now gone, and all pyzmq builds actually use libsodium (test with pyzmq v26 prereleases). Does that help? Sorry, I still don't understand the details of this issue, but it if tweetnacl was the problem, it may not come up anymore. |
What pyzmq version?
25.1.0
What libzmq version?
4.3.4
Python version (and how it was installed)
Python 3.10.9
OS
Linux
What happened?
When pyzmq is built without bundling libsodium, tweetnacl is bundled. Pyzmq performs a dlopen of libzmq with the
RTLD_GLOBAL
which causes tweetnacl's functions to resolved rather than libsodium's functions. This will cause segfaults if using PyNaCl with pyzmq.Code to reproduce bug
nacl_test.py
Running nacl_test.py will result in a segfault:
The segfault is called because libsodium's
crypto_secretbox_detached
callscrypto_core_hsalsa20
bit it's tweetnacl's version ofcrypto_core_hsalsa20
instead of libsodium's version.More info
To work around the issue you can make sure to import nacl before pyzmq.. That'll allow nacl to work properly, however I'm un-suer if it would have any adverse effects on pyzmq with curve support. I suspect it may.
Another work around is to make sure libsodium's dlopen call uses the
RTLD_DEEPBIND
flag. This could also have adverse effects.The text was updated successfully, but these errors were encountered: