ElektraInitiative / libelektra

Elektra serves as a universal and secure framework to access configuration settings in a global, hierarchical key database.
https://www.libelektra.org
BSD 3-Clause "New" or "Revised" License
208 stars 123 forks source link

qt-gui segfaults when elektra is build with crypto plugins #675

Closed rautesamtr closed 8 years ago

rautesamtr commented 8 years ago

Building elektra with

cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED=ON \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DTOOLS=ALL \
    -DPLUGINS=ALL ..

leads to a segfault when starting the qt-gui. Building with -DPLUGINS="ALL;-crypto_gcrypt;-crypto_openssl" solves this for now.

lldb gives me the following backtrace:

* thread #1: tid = 19176, 0x00007fffd12018d0, name = 'qt-gui', stop reason = signal SIGSEGV: address access protected (fault address: 0x7fffd12018d0)
  * frame #0: 0x00007fffd12018d0
    frame #1: 0x00007ffff1a93079 libcrypto.so.1.0.0`ERR_get_state + 57
    frame #2: 0x00007ffff1a94269 libcrypto.so.1.0.0`ERR_peek_error + 9
    frame #3: 0x00007fffd0dee891 libelektra-crypto_openssl.so`elektraCryptoOpenSSLInit(errorKey=0x0000000001823d80) + 177 at openssl_operations.c:93
    frame #4: 0x00007fffd0defb72 libelektra-crypto_openssl.so`libelektra_cryptoopenssl_openssl_LTX_elektraPluginopen [inlined] elektraCryptoInit(errorKey=0x0000000001823d80) + 34 at crypto.c:38
    frame #5: 0x00007fffd0defb6a libelektra-crypto_openssl.so`libelektra_cryptoopenssl_openssl_LTX_elektraPluginopen(handle=<unavailable>, errorKey=0x0000000001823d80) + 26 at crypto.c:191
    frame #6: 0x00007ffff5a9655b libelektra-kdb.so.4`elektraPluginOpen(name=0x00007fffffffb400, modules=<unavailable>, config=<unavailable>, errorKey=0x0000000001823d80) + 251 at plugin.c:295
    frame #7: 0x00007ffff6b27f9f libelektratools.so.0`kdb::tools::Plugin::Plugin(this=0x000000000180a590, spec_=<unavailable>, modules=<unavailable>) + 239 at plugin.cpp:39
    frame #8: 0x00007ffff6b27d7c libelektratools.so.0`kdb::tools::Modules::load(this=<unavailable>, spec=<unavailable>) + 44 at modules.cpp:49
    frame #9: 0x00007ffff6b27c40 libelektratools.so.0`kdb::tools::Modules::load(this=<unavailable>, pluginName=<unavailable>, config=<unavailable>) + 224 at modules.cpp:44
    frame #10: 0x00007ffff6b27ad5 libelektratools.so.0`kdb::tools::Modules::load(this=<unavailable>, pluginName=<unavailable>) + 133 at modules.cpp:39
    frame #11: 0x000000000042073f qt-gui`GUIBackend::availablePlugins(this=<unavailable>, includeStorage=true, includeResolver=false) const + 511 at guibackend.cpp:221
    frame #12: 0x0000000000420f61 qt-gui`GUIBackend::nameFilters(this=<unavailable>) + 65 at guibackend.cpp:245
    frame #13: 0x000000000043c523 qt-gui`GUIBackend::qt_static_metacall(_o=<unavailable>, _c=<unavailable>, _id=<unavailable>, _a=0x00007fffffffb9c0) + 1123 at moc_guibackend.cpp:130
    frame #14: 0x000000000043c9b3 qt-gui`GUIBackend::qt_metacall(this=<unavailable>, _c=<unavailable>, _id=7, _a=<unavailable>) + 67 at moc_guibackend.cpp:193
    frame #15: 0x00007ffff785a039 libQt5Qml.so.5`??? + 137
    frame #16: 0x00007ffff77e0876 libQt5Qml.so.5`??? + 2150
    frame #17: 0x00007ffff77e2047 libQt5Qml.so.5`??? + 119
    frame #18: 0x00007ffff77e2c9d libQt5Qml.so.5`QV4::QObjectMethod::callInternal(QV4::CallData*) const + 2237
    frame #19: 0x00007ffff77f8e4a libQt5Qml.so.5`QV4::Runtime::callProperty(QV4::ExecutionEngine*, int, QV4::CallData*) + 634
    frame #20: 0x00007fffdcac70e9
    frame #21: 0x00007ffff779b9c3 libQt5Qml.so.5`??? + 1027
    frame #22: 0x00007ffff7883ec3 libQt5Qml.so.5`QQmlJavaScriptExpression::evaluate(QV4::CallData*, bool*) + 707
    frame #23: 0x00007ffff782b344 libQt5Qml.so.5`QQmlBoundSignalExpression::evaluate(void**) + 548
    frame #24: 0x00007ffff782c613 libQt5Qml.so.5`??? + 723
    frame #25: 0x00007ffff786325e libQt5Qml.so.5`QQmlNotifier::emitNotify(QQmlNotifierEndpoint*, void**) + 622
    frame #26: 0x00007ffff780e50c libQt5Qml.so.5`QQmlData::signalEmitted(QAbstractDeclarativeData*, QObject*, int, void**) + 924
    frame #27: 0x00007ffff5f452a0 libQt5Core.so.5`QMetaObject::activate(QObject*, int, int, void**) + 192
    frame #28: 0x00007ffff78953c8 libQt5Qml.so.5`??? + 2504
    frame #29: 0x00007ffff782126e libQt5Qml.so.5`QQmlComponentPrivate::complete(QQmlEnginePrivate*, QQmlComponentPrivate::ConstructionState*) + 126
    frame #30: 0x00007ffff7821337 libQt5Qml.so.5`QQmlComponentPrivate::completeCreate() + 87
    frame #31: 0x00007ffff78211a0 libQt5Qml.so.5`QQmlComponent::create(QQmlContext*) + 112
    frame #32: 0x00007ffff788ce52 libQt5Qml.so.5`QQmlApplicationEnginePrivate::_q_finishLoad(QObject*) + 626
    frame #33: 0x00007ffff788d0d2 libQt5Qml.so.5`QQmlApplicationEnginePrivate::startLoad(QUrl const&, QByteArray const&, bool) + 242
    frame #34: 0x00007ffff788d10d libQt5Qml.so.5`QQmlApplicationEngine::load(QUrl const&) + 45
    frame #35: 0x0000000000428452 qt-gui`main(argc=<unavailable>, argv=<unavailable>) + 1394 at main.cpp:74
    frame #36: 0x00007ffff4d60710 libc.so.6`__libc_start_main + 240
    frame #37: 0x0000000000414c89 qt-gui`_start + 41
markus2330 commented 8 years ago

Then better not build with crypto plugins. They are currently experimental and do not have functionality.

markus2330 commented 8 years ago

To be more specific: ALL;-EXPERIMENTAL is default, and adding any other plugin is "at your own risk".

Nevertheless thanks for reporting and @petermax2 it would be good if you can investigate.

petermax2 commented 8 years ago

@sirblackheart I can reproduce the dump.

According to the backtrace, the call of ERR_peek_error () caused the problem. It is part of the OpenSSL library and tells whether or not OpenSSL holds an error in its internal queue.

     thread #1: tid = 25250, 0x00007fffc6aa9610, name = 'qt-gui', stop reason = signal SIGSEGV: address access protected (fault address: 0x7fffc6aa9610)
      * frame #0: 0x00007fffc6aa9610
        frame #1: 0x00007ffff2a7adfc libcrypto.so.10`ERR_get_state + 60
        frame #2: 0x00007ffff2a7b116 libcrypto.so.10`??? + 38
        frame #3: 0x00007fffc6729d30 libelektra-crypto_openssl.so`elektraCryptoOpenSSLInit(errorKey=0x00000000017c6170) + 144 at openssl_operations.c:93

It is either a faulty setup in elektraCryptoOpenSSLInit or a bug in OpenSSL (which is less likely). I am going to investigate.

Thx for reporting!

petermax2 commented 8 years ago

@markus2330 BTW I have a bad feeling that this might be a concurrency/bad library setup issue... You know like when we talked about to not have the Elektra user setting up his/her application to do the OpenSSL/gcrypt initialization but put the initialization into the plugin open functions.

markus2330 commented 8 years ago

Yes, seems like that you are not supposed to call ERR_peek_error in this state? Did you already test with libcrypto.so.1.0.0?

petermax2 commented 8 years ago

The guys at libcurl had or have the same problem, see https://curl.haxx.se/mail/lib-2012-03/0008.html.

markus2330 commented 8 years ago

Good to know, thank you!

markus2330 commented 8 years ago

@sirblackheart When you test #759, can you also check if this issue is fixed? (hopefully fixed by #767)

rautesamtr commented 8 years ago

Looks good! No crash on starting or closing the gui. screenshot from 2016-06-11 14-28-30

@petermax2 thanks for fixing it!