Bug 482819 - kwalletd6 sometimes crashed in QCA::PrivateKey::deriveKey when starting Proton VPN GUI
Summary: kwalletd6 sometimes crashed in QCA::PrivateKey::deriveKey when starting Proto...
Status: CONFIRMED
Alias: None
Product: qca
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 2.3.8
Platform: Fedora RPMs Linux
: NOR crash
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords: qt6
Depends on:
Blocks:
 
Reported: 2024-03-08 06:21 UTC by Matt Fagnani
Modified: 2024-04-02 11:56 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Older openssl config file which the problem happened with (11.02 KB, text/plain)
2024-03-31 18:48 UTC, Matt Fagnani
Details
ltrace output on kwalletd6 when running Proton VPN GUI twice (69.63 KB, text/plain)
2024-03-31 18:51 UTC, Matt Fagnani
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Fagnani 2024-03-08 06:21:21 UTC
SUMMARY

kwalletd6 sometimes crashed in QCA::PrivateKey::deriveKey when starting Proton VPN GUI. Crashes with the same trace happened three times when starting Proton VPN each of which was the first time I ran it in a Plasma 6.0.1 session in a Fedora 40 KDE Plasma installation.

Core was generated by `/usr/bin/kwalletd6 --pam-login 13 14'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f0fa37491dc in QCA::PrivateKey::deriveKey (this=this@entry=0x7ffe71c73640, theirs=...)
    at /usr/src/debug/qca-2.3.8-1.fc40.x86_64/src/qca_publickey.cpp:1030
1030        return static_cast<PKeyContext *>(context())->key()->deriveKey(*(theirContext->key()));
[Current thread is 1 (Thread 0x7f0fa37c79c0 (LWP 9448))]

(gdb) bt
#0  0x00007f0fa37491dc in QCA::PrivateKey::deriveKey (this=this@entry=0x7ffe71c73640, theirs=...)
    at /usr/src/debug/qca-2.3.8-1.fc40.x86_64/src/qca_publickey.cpp:1030
#1  0x000055f537f92992 in KWalletFreedesktopService::createSessionAlgorithmDhAes (this=0x7f0f8800a320, clientKey=...)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:424
#2  KWalletFreedesktopService::OpenSession
    (this=0x7f0f8800a320, algorithm=<optimized out>, input=<optimized out>, result=...)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:266
#3  0x000055f537fb7f43 in KWalletFreedesktopServiceAdaptor::OpenSession
    (this=0x55f539ee3fe0, algorithm=<optimized out>, input=<optimized out>, result=<optimized out>)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/kwalletfreedesktopserviceadaptor.cpp:63
#4  KWalletFreedesktopServiceAdaptor::qt_static_metacall
    (_o=0x55f539ee3fe0, _c=<optimized out>, _id=<optimized out>, _a=0x7ffe71c73978)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/moc_kwalletfreedesktopserviceadaptor.cpp:410
#5  0x000055f537fb8254 in KWalletFreedesktopServiceAdaptor::qt_metacall
    (this=0x55f539ee3fe0, _c=QMetaObject::InvokeMetaMethod, _id=6, _a=0x7ffe71c73978)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/moc_kwalletfreedesktopserviceadaptor.cpp:489
#6  0x00007f0fa2a7bb11 in QDBusConnectionPrivate::deliverCall
    (this=this@entry=0x7f0f88001690, object=object@entry=0x55f539ee3fe0, msg=..., metaTypes=..., slotIdx=11)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/dbus/qdbusintegrator.cpp:977
#7  0x00007f0fa2a7f675 in QDBusConnectionPrivate::activateCall
    (this=this@entry=0x7f0f88001690, object=0x55f539ee3fe0, flags=flags@entry=273, msg=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/dbus/qdbusintegrator.cpp:879
#8  0x00007f0fa2a802c6 in QDBusConnectionPrivate::activateCall
    (this=0x7f0f88001690, object=<optimized out>, flags=273, msg=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/dbus/qdbusintegrator.cpp:825
--Type <RET> for more, q to quit, c to continue without paging--c
#9  QDBusConnectionPrivate::activateObject (this=0x7f0f88001690, node=..., msg=..., pathStartPos=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/dbus/qdbusintegrator.cpp:1460
#10 0x00007f0fa2a8295a in QDBusActivateObjectEvent::placeMetaCall (this=0x7f0f8800adc0)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/dbus/qdbusintegrator.cpp:1580
#11 0x00007f0fa19e25a5 in QObject::event (this=0x7f0f8800a320, e=0x7f0f8800adc0)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/kernel/qobject.cpp:1437
#12 0x00007f0fa2d87f68 in QApplicationPrivate::notify_helper
    (this=<optimized out>, receiver=0x7f0f8800a320, e=0x7f0f8800adc0)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/widgets/kernel/qapplication.cpp:3296
#13 0x00007f0fa198f218 in QCoreApplication::notifyInternal2 (receiver=0x7f0f8800a320, event=0x7f0f8800adc0)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1121
#14 0x00007f0fa198f42d in QCoreApplication::sendEvent (receiver=<optimized out>, event=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1539
#15 0x00007f0fa1993147 in QCoreApplicationPrivate::sendPostedEvents (receiver=0x0, event_type=0, data=0x55f539b2d390)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1901
#16 0x00007f0fa199340d in QCoreApplication::sendPostedEvents (receiver=<optimized out>, event_type=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1760
#17 0x00007f0fa1c6751f in postEventSourceDispatch (s=0x55f539b2f450)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/kernel/qeventdispatcher_glib.cpp:243
#18 0x00007f0fa0ed626c in g_main_dispatch (context=0x7f0f88000f00) at ../glib/gmain.c:3344
#19 g_main_context_dispatch_unlocked (context=0x7f0f88000f00) at ../glib/gmain.c:4152
#20 0x00007f0fa0f372a8 in g_main_context_iterate_unlocked.isra.0
    (context=context@entry=0x7f0f88000f00, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>)
    at ../glib/gmain.c:4217
#21 0x00007f0fa0ed76e3 in g_main_context_iteration (context=0x7f0f88000f00, may_block=1) at ../glib/gmain.c:4282
#22 0x00007f0fa1c66de3 in QEventDispatcherGlib::processEvents (this=0x55f539b470d0, flags=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/kernel/qeventdispatcher_glib.cpp:393
#23 0x00007f0fa199c053 in QEventLoop::exec (this=this@entry=0x7ffe71c74250, flags=..., flags@entry=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/global/qflags.h:34
#24 0x00007f0fa1997ffc in QCoreApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/corelib/global/qflags.h:74
#25 0x00007f0fa21d37cd in QGuiApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/gui/kernel/qguiapplication.cpp:1925
#26 0x00007f0fa2d87ed9 in QApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-1.fc40.x86_64/src/widgets/kernel/qapplication.cpp:2574
#27 0x000055f537f78d95 in main (argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/main.cpp:221

Proton VPN GUI crashed with the following trace after the kwalletd6 crash.

Mar 07 23:34:49 plasmashell[11327]: Traceback (most recent call last):
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/secretstorage/util.py", line 48, in send_and_get_reply
Mar 07 23:34:49 plasmashell[11327]:     raise DBusErrorResponse(resp_msg)
Mar 07 23:34:49 plasmashell[11327]: jeepney.wrappers.DBusErrorResponse: [org.freedesktop.DBus.Error.NoReply] ('Remote peer disconnected',)
Mar 07 23:34:49 plasmashell[11327]: The above exception was the direct cause of the following exception:
Mar 07 23:34:49 plasmashell[11327]: Traceback (most recent call last):
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/bin/protonvpn-app", line 33, in <module>
Mar 07 23:34:49 plasmashell[11327]:     sys.exit(load_entry_point('proton-vpn-gtk-app==4.2.0', 'console_scripts', 'protonvpn-app')())
Mar 07 23:34:49 plasmashell[11327]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/vpn/app/gtk/__main__.py", line 34, in main
Mar 07 23:34:49 plasmashell[11327]:     controller = Controller.get(executor)
Mar 07 23:34:49 plasmashell[11327]:                  ^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/vpn/app/gtk/controller.py", line 56, in get
Mar 07 23:34:49 plasmashell[11327]:     executor.submit(controller.initialize_vpn_connector).result()
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib64/python3.12/concurrent/futures/_base.py", line 456, in result
Mar 07 23:34:49 plasmashell[11327]:     return self.__get_result()
Mar 07 23:34:49 plasmashell[11327]:            ^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib64/python3.12/concurrent/futures/_base.py", line 401, in __get_result
Mar 07 23:34:49 plasmashell[11327]:     raise self._exception
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/vpn/app/gtk/controller.py", line 89, in initialize_vpn_connector
Mar 07 23:34:49 plasmashell[11327]:     self._connector = await self._api.get_vpn_connector()
Mar 07 23:34:49 plasmashell[11327]:                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/vpn/core/api.py", line 53, in get_vpn_connector
Mar 07 23:34:49 plasmashell[11327]:     settings = await self.load_settings()
Mar 07 23:34:49 plasmashell[11327]:                ^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/vpn/core/api.py", line 63, in load_settings
Mar 07 23:34:49 plasmashell[11327]:     if self._session_holder.session.logged_in:
Mar 07 23:34:49 plasmashell[11327]:        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/vpn/core/session.py", line 71, in session
Mar 07 23:34:49 plasmashell[11327]:     self._session = self._proton_sso.get_default_session(
Mar 07 23:34:49 plasmashell[11327]:                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/sso/sso.py", line 192, in get_default_session
Mar 07 23:34:49 plasmashell[11327]:     sessions = self.sessions
Mar 07 23:34:49 plasmashell[11327]:                ^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/sso/sso.py", line 133, in sessions
Mar 07 23:34:49 plasmashell[11327]:     keyring_index = keyring[self.__keyring_index_name()]
Mar 07 23:34:49 plasmashell[11327]:                     ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/keyring/_base.py", line 65, in __getitem__
Mar 07 23:34:49 plasmashell[11327]:     return self._get_item(key)
Mar 07 23:34:49 plasmashell[11327]:            ^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/proton/keyring_linux/core/keyring_linux.py", line 45, in _get_item
Mar 07 23:34:49 plasmashell[11327]:     stored_data = self.__keyring_backend.get_password(
Mar 07 23:34:49 plasmashell[11327]:                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/keyring/backends/SecretService.py", line 83, in get_password
Mar 07 23:34:49 plasmashell[11327]:     return item.get_secret().decode('utf-8')
Mar 07 23:34:49 plasmashell[11327]:            ^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/secretstorage/item.py", line 99, in get_secret
Mar 07 23:34:49 plasmashell[11327]:     self.session = open_session(self.connection)
Mar 07 23:34:49 plasmashell[11327]:                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/secretstorage/util.py", line 80, in open_session
Mar 07 23:34:49 plasmashell[11327]:     output, result = service.call(
Mar 07 23:34:49 plasmashell[11327]:                      ^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/secretstorage/util.py", line 63, in call
Mar 07 23:34:49 plasmashell[11327]:     return self.send_and_get_reply(msg)
Mar 07 23:34:49 plasmashell[11327]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 07 23:34:49 plasmashell[11327]:   File "/usr/lib/python3.12/site-packages/secretstorage/util.py", line 58, in send_and_get_reply
Mar 07 23:34:49 plasmashell[11327]:     raise SecretServiceNotAvailableException(data) from resp
Mar 07 23:34:49 plasmashell[11327]: secretstorage.exceptions.SecretServiceNotAvailableException: Remote peer disconnected
Mar 07 23:34:49 systemd[9403]: app-protonvpn\x2dapp-9a55dbb58d2c40afa44b5f9a76aabf4b.scope: Consumed 1.028s CPU time.

This problem started after an update including Plasma 6.0.1 and qca-2.3.8-1.fc40 https://bodhi.fedoraproject.org/updates/FEDORA-2024-71a4de4732 Since the crashing function QCA::PrivateKey::deriveKey is in qca, that update might be involved.

When I ran Proton VPN right after the crash in the same session, I got a message that kwallet hadn't been opened and asking to enter the password. kwalletd6 and Proton VPN didn't crash after entering the password or when I ran Proton VPN again in the same Plasma session.

STEPS TO REPRODUCE
1. Boot a Fedora 40 KDE Plasma installation updated to 2024-3-8 with the updates-testing repo enabled
2. Log in to Plasma 6.0.1 on Wayland from sddm
3. Set up the Proton VPN repo and install the program using the instructions at https://protonvpn.com/support/official-linux-vpn-fedora/ Since Proton VPN doesn't build Fedora 40 packages yet as it's in a pre-release stage, I changed two lines in /etc/yum.repos.d/protonvpn-stable.repo to use the Fedora 39 repo before installing it.
baseurl = https://repo.protonvpn.com/fedora-39-stable
gpgkey = https://repo.protonvpn.com/fedora-39-stable/public_key.asc
5. Make a Proton VPN account at https://protonvpn.com/ There's a free plan available.
6. Start the Proton VPN GUI
7. Enter the Proton VPN user name and password that was previously made. The Proton VPN account information should be stored in kwallet.
8. Log out of Plasma
9. Log in to Plasma
10. Start the Proton VPN GUI

OBSERVED RESULT
kwalletd6 sometimes crashed in QCA::PrivateKey::deriveKey when starting Proton VPN GUI

EXPECTED RESULT
No crashes should've happened.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 40
(available in About System)
KDE Plasma Version: 6.0.1
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2

ADDITIONAL INFORMATION
Comment 1 Matt Fagnani 2024-03-08 22:37:20 UTC
I downgraded to qca-qt6-2.3.7-3.fc40, and the problem didn't happen after that. So the problem might be with qca 2.3.8.
Comment 2 Albert Astals Cid 2024-03-21 22:50:21 UTC
Cannot reproduce on my system

I tried following your steps but

1. Boot a Fedora 40 KDE Plasma installation updated to 2024-3-8 with the updates-testing repo enabled

got me blocked on how to get a Fedora 40 KDE Plasma ISO
Comment 3 Matt Fagnani 2024-03-22 04:25:20 UTC
You can download the Fedora 40 KDE Plasma live beta Fedora-KDE-Live-x86_64-40_Beta-1.10.iso from https://koji.fedoraproject.org/koji/buildinfo?buildID=2423953 You can boot that in a QEMU/KVM VM though I haven't tried to reproduce this in a VM or write it to a USB flash drive with Fedora Media Writer.

I disabled Use KWallet from the Secret Service interface from the KDE Wallet page in System Settings, and the problem didn't happen with that setting off. I think because I also have GNOME 46.0 installed the GNOME Keyring was used which doesn't have this problem.

In QCA::PrivateKey::deriveKey, for the pointer this, one of its three d pointers was null, and the pointer theirs had d = 0x75 for one of the three such pointers. If one of those d pointers were dereferenced, the crash might have resulted.

(gdb) p this
$1 = (QCA::PrivateKey * const) 0x7ffdce589db0
(gdb) p *this
$2 = {<QCA::PKey> = {<QCA::Algorithm> = {_vptr.Algorithm = 0x7f7a2ffeb598 <vtable for QCA::PrivateKey+16>, d = {
        d = 0x0}}, d = 0x55c5ffc37e80}, d = 0x7ffdce589ef0}
(gdb) p theirs
$3 = (const QCA::PublicKey &) @0x7ffdce589df0: {<QCA::PKey> = {<QCA::Algorithm> = {
      _vptr.Algorithm = 0x7f7a2ffea880 <vtable for QCA::DHPublicKey+16>, d = {d = 0x55c5ffb593b0}}, 
    d = 0x55c5ffc85740}, d = 0x75}
Comment 4 Albert Astals Cid 2024-03-22 22:50:36 UTC
unfortunately that image you linked seems to have a broken installer https://i.imgur.com/yZXIoG4.png
Comment 5 Matt Fagnani 2024-03-23 03:35:00 UTC
(In reply to Albert Astals Cid from comment #4)
> unfortunately that image you linked seems to have a broken installer
> https://i.imgur.com/yZXIoG4.png

That problem with the installer might be because you appeared to be using Virtualbox. I've read that Virtualbox support for the new kernel branches used in Fedora, which is 6.8 in Fedora 40 currently, lag behind by months. I haven't used Virtualbox though. You could search for the problem you saw at https://bugzilla.redhat.com/ and report it there if it hasn't been already.  You could also try to reproduce the problem in the live environment without installing.

I tried to reproduce the problem with that image in QEMU/KVM VM in GNOME Boxes and on bare metal, and the problem didn't happen. I installed Fedora Rawhide on my system in mid 2020 and upgraded to the next version every few months since then. My kwallet was likely created in 2020, so it's possible that there were some old keys or other data in it related to this problem. I deleted the Proton VPN data using kwalletmanager5 a week or so ago, and the problem still happened after that. The Proton VPN data in my kwallet should be new at least. Thanks.
Comment 6 Matt Fagnani 2024-03-24 13:18:31 UTC
I used kwalletmanager to export my wallet in encrypted form, then I deleted my wallet. I created a new wallet when I started Proton VPN GUI and logged in. kwalletd6 crashed each time when logging in to the Proton VPN server with the same trace. An error message was shown by the Proton VPN GUI which wasn't shown before, and the Proton VPN GUI didn't crash. So the problem didn't seem to be something old about my wallet specifically. 

I ran the GNOME Keyring GUI program seahorse (Passwords and Keys) in Plasma 6.0.2, and kwalletd6 crashed with what looked like the same type of trace. The problem appeared to be when deriving a private key during a Diffie-Hellman key exchange.

Core was generated by `/usr/bin/kwalletd6 --pam-login 13 14'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f53b93811dc in QCA::PrivateKey::deriveKey (this=this@entry=0x7ffecdfbcc90, theirs=...)
    at /usr/src/debug/qca-2.3.8-1.fc40.x86_64/src/qca_publickey.cpp:1030
1030        return static_cast<PKeyContext *>(context())->key()->deriveKey(*(theirContext->key()));
[Current thread is 1 (Thread 0x7f53b96a79c0 (LWP 1591))]
(gdb) bt
#0  0x00007f53b93811dc in QCA::PrivateKey::deriveKey (this=this@entry=0x7ffecdfbcc90, theirs=...)
    at /usr/src/debug/qca-2.3.8-1.fc40.x86_64/src/qca_publickey.cpp:1030
#1  0x000055629a2db992 in KWalletFreedesktopService::createSessionAlgorithmDhAes (this=0x7f53a000a320, clientKey=...)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:424
#2  KWalletFreedesktopService::OpenSession
    (this=0x7f53a000a320, algorithm=<optimized out>, input=<optimized out>, result=...)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:266
#3  0x000055629a300f43 in KWalletFreedesktopServiceAdaptor::OpenSession
    (this=0x55629c5681b0, algorithm=<optimized out>, input=<optimized out>, result=<optimized out>)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/kwalletfreedesktopserviceadaptor.cpp:63
#4  KWalletFreedesktopServiceAdaptor::qt_static_metacall
    (_o=0x55629c5681b0, _c=<optimized out>, _id=<optimized out>, _a=0x7ffecdfbcfc8)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/moc_kwalletfreedesktopserviceadaptor.cpp:410
#5  0x000055629a301254 in KWalletFreedesktopServiceAdaptor::qt_metacall
    (this=0x55629c5681b0, _c=QMetaObject::InvokeMetaMethod, _id=6, _a=0x7ffecdfbcfc8)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/moc_kwalletfreedesktopserviceadaptor.cpp:489
#6  0x00007f53b897bb11 in QDBusConnectionPrivate::deliverCall
    (this=this@entry=0x7f53a0001690, object=object@entry=0x55629c5681b0, msg=..., metaTypes=..., slotIdx=11)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:977
#7  0x00007f53b897f675 in QDBusConnectionPrivate::activateCall
    (this=this@entry=0x7f53a0001690, object=0x55629c5681b0, flags=flags@entry=273, msg=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:879
#8  0x00007f53b89802c6 in QDBusConnectionPrivate::activateCall
    (this=0x7f53a0001690, object=<optimized out>, flags=273, msg=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:825
--Type <RET> for more, q to quit, c to continue without paging--c
#9  QDBusConnectionPrivate::activateObject (this=0x7f53a0001690, node=..., msg=..., pathStartPos=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:1460
#10 0x00007f53b898295a in QDBusActivateObjectEvent::placeMetaCall (this=0x7f53a00043c0)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:1580
#11 0x00007f53b77e25a5 in QObject::event (this=0x7f53a000a320, e=0x7f53a00043c0)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qobject.cpp:1437
#12 0x00007f53b8b87f68 in QApplicationPrivate::notify_helper
    (this=<optimized out>, receiver=0x7f53a000a320, e=0x7f53a00043c0)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/widgets/kernel/qapplication.cpp:3296
#13 0x00007f53b778f218 in QCoreApplication::notifyInternal2 (receiver=0x7f53a000a320, event=0x7f53a00043c0)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1121
#14 0x00007f53b778f42d in QCoreApplication::sendEvent (receiver=<optimized out>, event=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1539
#15 0x00007f53b7793147 in QCoreApplicationPrivate::sendPostedEvents (receiver=0x0, event_type=0, data=0x55629c210390)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1901
#16 0x00007f53b779340d in QCoreApplication::sendPostedEvents (receiver=<optimized out>, event_type=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1760
#17 0x00007f53b7a6751f in postEventSourceDispatch (s=0x55629c212450)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qeventdispatcher_glib.cpp:243
#18 0x00007f53b6e9668c in g_main_context_dispatch_unlocked.lto_priv () at /lib64/libglib-2.0.so.0
#19 0x00007f53b6ef7788 in g_main_context_iterate_unlocked.isra () at /lib64/libglib-2.0.so.0
#20 0x00007f53b6e97b03 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#21 0x00007f53b7a66de3 in QEventDispatcherGlib::processEvents (this=0x55629c22a0d0, flags=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qeventdispatcher_glib.cpp:393
#22 0x00007f53b779c053 in QEventLoop::exec (this=this@entry=0x7ffecdfbd8a0, flags=..., flags@entry=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/global/qflags.h:34
#23 0x00007f53b7797ffc in QCoreApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/global/qflags.h:74
#24 0x00007f53b7fd37cd in QGuiApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/gui/kernel/qguiapplication.cpp:1925
#25 0x00007f53b8b87ed9 in QApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/widgets/kernel/qapplication.cpp:2574
#26 0x000055629a2c1d95 in main (argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/main.cpp:221

The variables this and theirs in QCA::PrivateKey::deriveKey had the same possible problems with their d pointers that I mentioned in comment 3.

(gdb) p this
$1 = (QCA::PrivateKey * const) 0x7ffecdfbcc90
(gdb) p *this
$2 = {<QCA::PKey> = {<QCA::Algorithm> = {_vptr.Algorithm = 0x7f53b93ed598 <vtable for QCA::PrivateKey+16>, d = {
        d = 0x0}}, d = 0x55629c5a72f0}, d = 0x91691df82edcec00}
(gdb) p theirs
$3 = (const QCA::PublicKey &) @0x7ffecdfbccd0: {<QCA::PKey> = {<QCA::Algorithm> = {
      _vptr.Algorithm = 0x7f53b93ec880 <vtable for QCA::DHPublicKey+16>, d = {d = 0x55629c554730}}, 
    d = 0x55629c59ab90}, d = 0x75}

The Proton VPN GUI and seahorse are both GTK programs using the Secret Service interface.
Comment 7 Matt Fagnani 2024-03-24 18:02:21 UTC
In frame 1 in KWalletFreedesktopService::createSessionAlgorithmDhAes, privateKey and publicKey had null d pointers and clientPublicKey had d = 0x75. Those keys were generated by qca functions.

(gdb) frame 1
#1  0x000055fc1a8bc992 in KWalletFreedesktopService::createSessionAlgorithmDhAes (this=0x7fcc2400a8a0, clientKey=...)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:424
424         const auto commonSecret = privateKey.deriveKey(clientPublicKey);
(gdb) l
419         }
420
421         auto privateKey = QCA::PrivateKey(keygen.createDH(dlGroup));
422         const auto publicKey = QCA::PublicKey(privateKey);
423         const auto clientPublicKey = QCA::DHPublicKey(dlGroup, QCA::BigInteger(QCA::SecureArray(clientKey)));
424         const auto commonSecret = privateKey.deriveKey(clientPublicKey);
425         const auto symmetricKey = QCA::HKDF().makeKey(commonSecret, {}, {}, FDO_SECRETS_CIPHER_KEY_SIZE);
426
427         return std::make_unique<KWalletFreedesktopSessionAlgorithmDhAes>(publicKey, symmetricKey);
428     }
(gdb) p privateKey
$5 = {<QCA::PKey> = {<QCA::Algorithm> = {_vptr.Algorithm = 0x7fcc3e18e598 <vtable for QCA::PrivateKey+16>, d = {
        d = 0x0}}, d = 0x55fc1c7b50e0}, d = 0x7ffff0079b90}
(gdb) p publicKey
$6 = {<QCA::PKey> = {<QCA::Algorithm> = {_vptr.Algorithm = 0x7fcc3e18e5b8 <vtable for QCA::PublicKey+16>, d = {
        d = 0x0}}, d = 0x55fc1c7dca80}, d = 0x7ffff0079b90}
(gdb) p clientPublicKey
$7 = {<QCA::PublicKey> = {<QCA::PKey> = {<QCA::Algorithm> = {
        _vptr.Algorithm = 0x7fcc3e18d880 <vtable for QCA::DHPublicKey+16>, d = {d = 0x55fc1c7dcaa0}}, 
      d = 0x55fc1c819ac0}, d = 0x75}, <No data fields>}
(gdb) p commonSecret
$8 = {<QCA::SecureArray> = {<QCA::MemoryRegion> = {_secure = 96, d = {
        d = 0x7fcc3bc3dc88 <_dbus_type_writer_write_basic+152>}}, <No data fields>}, <No data fields>}
(gdb) p symmetricKey
$9 = {<QCA::SecureArray> = {<QCA::MemoryRegion> = {_secure = 38, d = {
        d = 0x7ffff0079a50}}, <No data fields>}, <No data fields>}

I used evince (Document Viewer) to open an encrypted pdf in Plasma 6.0.2, and kwalletd6 crashed with the same kind of trace when the password dialog box appeared. I used GNOME Disks to mount a LUKS encrypted partition in Plasma 6.0.2, and kwalletd6 crashed with the same sort of trace. The problem might be with GTK programs using the Secret Service interface in Plasma and qca 2.3.8 generating keys with those null or invalid pointers.
Comment 8 Matt Fagnani 2024-03-25 18:14:08 UTC
I bisected this problem with qca from 2.3.7 to 2.3.8. The following first bad commit involved loading legacy openssl providers.

14eb1ae746c3c75afaef02b487ac65b3de85ad15 is the first bad commit
commit 14eb1ae746c3c75afaef02b487ac65b3de85ad15
Author: Fabian Vogt <fabian@ritter-vogt.de>
Date:   Fri Dec 22 13:36:00 2023 +0100

    plugins/qca-ossl: Actually try loading the legacy provider
    
    OSSL_PROVIDER_available returns true only for loaded providers, not whether
    a provider can be loaded. Use OSSL_PROVIDER_try_load instead, which also
    allows to keep the default fallback provider.

 plugins/qca-ossl/qca-ossl.cpp | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)
Comment 9 Albert Astals Cid 2024-03-25 23:38:20 UTC
I've been finally been able to install Fedora 40 and can't still reproduce the problem :/

Can you do this (with the version that crashes)

Open a terminal
Start kwalletmanager5 and press the close wallet button (force if needed)
killall kwalletd6 (run it twice to make sure it has not re-spawned itself)
valgrind kwalletd6 

Now in another terminal
kwalletmanager5 and press the open open wallet button
protonvpn-app

As far as i understand this is what makes it crash for you.

Then go to the terminal where you ran valgrind and attach the output here
Comment 10 Matt Fagnani 2024-03-26 01:02:02 UTC
My kwallet is opened automatically when I log in to Plasma with the same password. You could try installing GNOME 46.0 in your Fedora 40 installation as I have in case there's something from GNOME that's involved and running seahorse, evince, and GNOME disks in Plasma as I described. I tried running kwalletd6 under valgrind a week ago, but I only stopped kwalletd6 once before running it under valgrind so kwalletd6 kept restarting automatically and I didn't get it to crash under valgrind then. I followed your instructions. The valgrind report showed an invalid read and a crash due to a null pointer dereference in QCA::PrivateKey::deriveKey at the same line as in the gdb trace I reported originally, which I guess was the null d pointer in the variable this from privateKey in KWalletFreedesktopService::createSessionAlgorithmDhAes.

==121563== Memcheck, a memory error detector
==121563== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==121563== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==121563== Command: /usr/bin/kwalletd6
==121563== Parent PID: 119206
==121563== 
==121563== Conditional jump or move depends on uninitialised value(s)
==121563==    at 0x2BDA8B18: ???
==121563==    by 0x2C05E13F: ???
==121563== 
==121563== Conditional jump or move depends on uninitialised value(s)
==121563==    at 0x82E63F1: QtWaylandClient::QWaylandInputDevice::Keyboard::keyboard_key(unsigned int, unsigned int, unsigned int, unsigned int) (qwaylandinputdevice.cpp:1356)
==121563==    by 0xA488055: ffi_call_unix64 (unix64.S:104)
==121563==    by 0xA48469F: ffi_call_int.lto_priv.0 (ffi64.c:673)
==121563==    by 0xA4874ED: ffi_call (ffi64.c:710)
==121563==    by 0x8354F2D: wl_closure_invoke.constprop.0 (connection.c:1025)
==121563==    by 0x83557A2: dispatch_event.isra.0 (wayland-client.c:1631)
==121563==    by 0x8355A4B: UnknownInlinedFun (wayland-client.c:1777)
==121563==    by 0x8355A4B: wl_display_dispatch_queue_pending (wayland-client.c:2019)
==121563==    by 0x82CCCD1: QtWaylandClient::QWaylandDisplay::flushRequests() (qwaylanddisplay.cpp:229)
==121563==    by 0x62E45A4: QObject::event(QEvent*) (qobject.cpp:1437)
==121563==    by 0x5001F67: QApplicationPrivate::notify_helper(QObject*, QEvent*) (qapplication.cpp:3296)
==121563==    by 0x6291217: QCoreApplication::notifyInternal2(QObject*, QEvent*) (qcoreapplication.cpp:1121)
==121563==    by 0x6295146: QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (qcoreapplication.cpp:1901)
==121563== 
==121563== Invalid read of size 8
==121563==    at 0x4D981DC: QCA::PrivateKey::deriveKey(QCA::PublicKey const&) (qca_publickey.cpp:1030)
==121563==    by 0x141991: UnknownInlinedFun (kwalletfreedesktopservice.cpp:424)
==121563==    by 0x141991: KWalletFreedesktopService::OpenSession(QString const&, QDBusVariant const&, QDBusObjectPath&) (kwalletfreedesktopservice.cpp:266)
==121563==    by 0x166F42: UnknownInlinedFun (kwalletfreedesktopserviceadaptor.cpp:63)
==121563==    by 0x166F42: KWalletFreedesktopServiceAdaptor::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_kwalletfreedesktopserviceadaptor.cpp:410)
==121563==    by 0x167253: KWalletFreedesktopServiceAdaptor::qt_metacall(QMetaObject::Call, int, void**) (moc_kwalletfreedesktopserviceadaptor.cpp:489)
==121563==    by 0x5744B10: QDBusConnectionPrivate::deliverCall(QObject*, int, QDBusMessage const&, QList<QMetaType> const&, int) (qdbusintegrator.cpp:977)
==121563==    by 0x5748674: QDBusConnectionPrivate::activateCall(QObject*, int, QDBusMessage const&) [clone .part.0] (qdbusintegrator.cpp:879)
==121563==    by 0x57492C5: activateCall (qdbusintegrator.cpp:825)
==121563==    by 0x57492C5: QDBusConnectionPrivate::activateObject(QDBusConnectionPrivate::ObjectTreeNode&, QDBusMessage const&, int) (qdbusintegrator.cpp:1460)
==121563==    by 0x574B959: QDBusActivateObjectEvent::placeMetaCall(QObject*) (qdbusintegrator.cpp:1580)
==121563==    by 0x62E45A4: QObject::event(QEvent*) (qobject.cpp:1437)
==121563==    by 0x5001F67: QApplicationPrivate::notify_helper(QObject*, QEvent*) (qapplication.cpp:3296)
==121563==    by 0x6291217: QCoreApplication::notifyInternal2(QObject*, QEvent*) (qcoreapplication.cpp:1121)
==121563==    by 0x6295146: QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (qcoreapplication.cpp:1901)
==121563==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==121563== 
==121563== 
==121563== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==121563==  Access not within mapped region at address 0x0
==121563==    at 0x4D981DC: QCA::PrivateKey::deriveKey(QCA::PublicKey const&) (qca_publickey.cpp:1030)
==121563==    by 0x141991: UnknownInlinedFun (kwalletfreedesktopservice.cpp:424)
==121563==    by 0x141991: KWalletFreedesktopService::OpenSession(QString const&, QDBusVariant const&, QDBusObjectPath&) (kwalletfreedesktopservice.cpp:266)
==121563==    by 0x166F42: UnknownInlinedFun (kwalletfreedesktopserviceadaptor.cpp:63)
==121563==    by 0x166F42: KWalletFreedesktopServiceAdaptor::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_kwalletfreedesktopserviceadaptor.cpp:410)
==121563==    by 0x167253: KWalletFreedesktopServiceAdaptor::qt_metacall(QMetaObject::Call, int, void**) (moc_kwalletfreedesktopserviceadaptor.cpp:489)
==121563==    by 0x5744B10: QDBusConnectionPrivate::deliverCall(QObject*, int, QDBusMessage const&, QList<QMetaType> const&, int) (qdbusintegrator.cpp:977)
==121563==    by 0x5748674: QDBusConnectionPrivate::activateCall(QObject*, int, QDBusMessage const&) [clone .part.0] (qdbusintegrator.cpp:879)
==121563==    by 0x57492C5: activateCall (qdbusintegrator.cpp:825)
==121563==    by 0x57492C5: QDBusConnectionPrivate::activateObject(QDBusConnectionPrivate::ObjectTreeNode&, QDBusMessage const&, int) (qdbusintegrator.cpp:1460)
==121563==    by 0x574B959: QDBusActivateObjectEvent::placeMetaCall(QObject*) (qdbusintegrator.cpp:1580)
==121563==    by 0x62E45A4: QObject::event(QEvent*) (qobject.cpp:1437)
==121563==    by 0x5001F67: QApplicationPrivate::notify_helper(QObject*, QEvent*) (qapplication.cpp:3296)
==121563==    by 0x6291217: QCoreApplication::notifyInternal2(QObject*, QEvent*) (qcoreapplication.cpp:1121)
==121563==    by 0x6295146: QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (qcoreapplication.cpp:1901)
==121563==  If you believe this happened as a result of a stack
==121563==  overflow in your program's main thread (unlikely but
==121563==  possible), you can try to increase the size of the
==121563==  main thread stack using the --main-stacksize= flag.
==121563==  The main thread stack size used in this run was 8388608.
==121563== 
==121563== HEAP SUMMARY:
==121563==     in use at exit: 6,227,189 bytes in 40,136 blocks
==121563==   total heap usage: 277,504 allocs, 237,368 frees, 37,114,729 bytes allocated
==121563== 
==121563== LEAK SUMMARY:
==121563==    definitely lost: 512 bytes in 1 blocks
==121563==    indirectly lost: 1,357 bytes in 41 blocks
==121563==      possibly lost: 550,976 bytes in 65 blocks
==121563==    still reachable: 5,672,328 bytes in 40,008 blocks
==121563==                       of which reachable via heuristic:
==121563==                         newarray           : 10,000 bytes in 60 blocks
==121563==                         multipleinheritance: 2,080 bytes in 6 blocks
==121563==         suppressed: 0 bytes in 0 blocks
==121563== Rerun with --leak-check=full to see details of leaked memory
==121563== 
==121563== Use --track-origins=yes to see where uninitialised values come from
==121563== For lists of detected and suppressed errors, rerun with: -s
==121563== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
Comment 11 Albert Astals Cid 2024-03-26 22:14:42 UTC
Can you add these changes?

https://pastebin.com/raw/ryCpqQyb

I'm trying to figure out which of the 4 pointers involved in that line is a null pointer

I'm assuming you know what that file means, if not tell me and i'll try to explain it a bit better
Comment 12 Albert Astals Cid 2024-03-26 22:15:11 UTC
Once you compile with those changes do the same valgrind thing.
Comment 13 Matt Fagnani 2024-03-27 02:11:45 UTC
I built qca 2.3.8 with your patch added. I reproduced the crash first without using valgrind. The crash happened on the line with static_cast<PKeyContext *>(context())->key() Since context() looked to be run with out a pointer to an object, I guess the pointer this might've been used which had the null d pointer.

Core was generated by `/usr/bin/kwalletd6 --pam-login 13 14'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007efd2af813fc in QCA::PrivateKey::deriveKey (this=this@entry=0x7ffdccf553f0, theirs=...)
    at /usr/src/debug/qca-2.3.8-2.fc40.x86_64/src/qca_publickey.cpp:1033
1033        qDebug() << static_cast<PKeyContext *>(context())->key();
[Current thread is 1 (Thread 0x7efd2b28f9c0 (LWP 76549))]
(gdb) l
1028    SymmetricKey PrivateKey::deriveKey(const PublicKey &theirs)
1029    {
1030        const PKeyContext *theirContext = static_cast<const PKeyContext *>(theirs.context());
1031        qDebug() << context();
1032        qDebug() << theirContext;
1033        qDebug() << static_cast<PKeyContext *>(context())->key();
1034        qDebug() << theirContext->key();
1035        return static_cast<PKeyContext *>(context())->key()->deriveKey(*(theirContext->key()));
1036    }
1037
(gdb) bt
#0  0x00007efd2af813fc in QCA::PrivateKey::deriveKey (this=this@entry=0x7ffdccf553f0, theirs=...)
    at /usr/src/debug/qca-2.3.8-2.fc40.x86_64/src/qca_publickey.cpp:1033
#1  0x00005592e8316992 in KWalletFreedesktopService::createSessionAlgorithmDhAes (this=0x7efd1000a540, clientKey=...)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:424
#2  KWalletFreedesktopService::OpenSession
    (this=0x7efd1000a540, algorithm=<optimized out>, input=<optimized out>, result=...)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:266
#3  0x00005592e833bf43 in KWalletFreedesktopServiceAdaptor::OpenSession
    (this=0x5592e90d2eb0, algorithm=<optimized out>, input=<optimized out>, result=<optimized out>)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/kwalletfreedesktopserviceadaptor.cpp:63
#4  KWalletFreedesktopServiceAdaptor::qt_static_metacall
    (_o=0x5592e90d2eb0, _c=<optimized out>, _id=<optimized out>, _a=0x7ffdccf55728)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/moc_kwalletfreedesktopserviceadaptor.cpp:410
#5  0x00005592e833c254 in KWalletFreedesktopServiceAdaptor::qt_metacall
    (this=0x5592e90d2eb0, _c=QMetaObject::InvokeMetaMethod, _id=6, _a=0x7ffdccf55728)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/redhat-linux-build/src/runtime/kwalletd/moc_kwalletfreedesktopserviceadaptor.cpp:489
#6  0x00007efd2a57bb11 in QDBusConnectionPrivate::deliverCall
    (this=this@entry=0x7efd10001690, object=object@entry=0x5592e90d2eb0, msg=..., metaTypes=..., slotIdx=11)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:977
#7  0x00007efd2a57f675 in QDBusConnectionPrivate::activateCall
    (this=this@entry=0x7efd10001690, object=0x5592e90d2eb0, flags=flags@entry=273, msg=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:879
#8  0x00007efd2a5802c6 in QDBusConnectionPrivate::activateCall
    (this=0x7efd10001690, object=<optimized out>, flags=273, msg=...)
--Type <RET> for more, q to quit, c to continue without paging--c
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:825
#9  QDBusConnectionPrivate::activateObject (this=0x7efd10001690, node=..., msg=..., pathStartPos=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:1460
#10 0x00007efd2a58295a in QDBusActivateObjectEvent::placeMetaCall (this=0x7efd1000afe0)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/dbus/qdbusintegrator.cpp:1580
#11 0x00007efd293e25a5 in QObject::event (this=0x7efd1000a540, e=0x7efd1000afe0)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qobject.cpp:1437
#12 0x00007efd2a787f68 in QApplicationPrivate::notify_helper
    (this=<optimized out>, receiver=0x7efd1000a540, e=0x7efd1000afe0)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/widgets/kernel/qapplication.cpp:3296
#13 0x00007efd2938f218 in QCoreApplication::notifyInternal2 (receiver=0x7efd1000a540, event=0x7efd1000afe0)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1121
#14 0x00007efd2938f42d in QCoreApplication::sendEvent (receiver=<optimized out>, event=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1539
#15 0x00007efd29393147 in QCoreApplicationPrivate::sendPostedEvents (receiver=0x0, event_type=0, data=0x5592e8d7e390)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1901
#16 0x00007efd2939340d in QCoreApplication::sendPostedEvents (receiver=<optimized out>, event_type=<optimized out>)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qcoreapplication.cpp:1760
#17 0x00007efd2966751f in postEventSourceDispatch (s=0x5592e8d80450)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qeventdispatcher_glib.cpp:243
#18 0x00007efd289be68c in g_main_dispatch (context=0x7efd10000f00) at ../glib/gmain.c:3344
#19 g_main_context_dispatch_unlocked (context=0x7efd10000f00) at ../glib/gmain.c:4152
#20 0x00007efd28a1f788 in g_main_context_iterate_unlocked.isra.0
    (context=context@entry=0x7efd10000f00, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>)
    at ../glib/gmain.c:4217
#21 0x00007efd289bfb03 in g_main_context_iteration (context=0x7efd10000f00, may_block=1) at ../glib/gmain.c:4282
#22 0x00007efd29666de3 in QEventDispatcherGlib::processEvents (this=0x5592e8d980d0, flags=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/kernel/qeventdispatcher_glib.cpp:393
#23 0x00007efd2939c053 in QEventLoop::exec (this=this@entry=0x7ffdccf56000, flags=..., flags@entry=...)
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/global/qflags.h:34
#24 0x00007efd29397ffc in QCoreApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/corelib/global/qflags.h:74
#25 0x00007efd29bd37cd in QGuiApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/gui/kernel/qguiapplication.cpp:1925
#26 0x00007efd2a787ed9 in QApplication::exec ()
    at /usr/src/debug/qt6-qtbase-6.6.2-6.fc40.x86_64/src/widgets/kernel/qapplication.cpp:2574
#27 0x00005592e82fcd95 in main (argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/main.cpp:221

I ran the steps you gave with kwalletd6 under valgrind. The crash was at a null address in QCA::PrivateKey::deriveKey at qca_publickey.cpp:1033.

==83336== Memcheck, a memory error detector
==83336== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==83336== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==83336== Command: /usr/bin/kwalletd6
==83336== Parent PID: 83306
==83336== 
==83336== Invalid read of size 16
==83336==    at 0x6210B77: UnknownInlinedFun (emmintrin.h:706)
==83336==    by 0x6210B77: aeshash128_lt16 (qhash.cpp:630)
==83336==    by 0x6210B77: aeshash128(unsigned char const*, unsigned long, unsigned long, unsigned long) (qhash.cpp:771)
==83336==    by 0x56B8F4F: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56BAB4A: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56BE694: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56ABA04: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56C6EE5: KSharedConfig::openConfig(QString const&, QFlags<KConfig::OpenFlag>, QStandardPaths::StandardLocation) (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x2BD42CA8: ??? (in /usr/lib64/qt6/plugins/styles/breeze6.so)
==83336==    by 0x2BD72EAD: ??? (in /usr/lib64/qt6/plugins/styles/breeze6.so)
==83336==    by 0x50AB9CD: qLoadPlugin<QStyle, QStylePlugin> (qfactoryloader_p.h:99)
==83336==    by 0x50AB9CD: QStyleFactory::create(QString const&) (qstylefactory.cpp:77)
==83336==    by 0x5007BCF: QApplication::style() (qapplication.cpp:919)
==83336==    by 0x50081C0: QApplicationPrivate::initialize() (qapplication.cpp:539)
==83336==    by 0x50083E4: QApplicationPrivate::init() (qapplication.cpp:486)
==83336==  Address 0x2be195e1 is 113 bytes inside a block of size 128 alloc'd
==83336==    at 0x484280F: malloc (vg_replace_malloc.c:442)
==83336==    by 0x63C3BB0: UnknownInlinedFun (qarraydata.cpp:139)
==83336==    by 0x63C3BB0: QArrayData::allocate(QArrayData**, long long, long long, long long, QArrayData::AllocationOption) (qarraydata.cpp:189)
==83336==    by 0x63593CC: allocate (qarraydata.h:106)
==83336==    by 0x63593CC: QByteArray::reallocData(long long, QArrayData::AllocationOption) (qbytearray.cpp:1927)
==83336==    by 0x635958A: QByteArray::resize(long long) (qbytearray.cpp:1866)
==83336==    by 0x62576FF: QIODevice::readAll() (qiodevice.cpp:1262)
==83336==    by 0x56BD852: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56ABA04: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56C6EE5: KSharedConfig::openConfig(QString const&, QFlags<KConfig::OpenFlag>, QStandardPaths::StandardLocation) (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x2BD42CA8: ??? (in /usr/lib64/qt6/plugins/styles/breeze6.so)
==83336==    by 0x2BD72EAD: ??? (in /usr/lib64/qt6/plugins/styles/breeze6.so)
==83336==    by 0x50AB9CD: qLoadPlugin<QStyle, QStylePlugin> (qfactoryloader_p.h:99)
==83336==    by 0x50AB9CD: QStyleFactory::create(QString const&) (qstylefactory.cpp:77)
==83336==    by 0x5007BCF: QApplication::style() (qapplication.cpp:919)
==83336== 
==83336== Invalid read of size 16
==83336==    at 0x6210B77: UnknownInlinedFun (emmintrin.h:706)
==83336==    by 0x6210B77: aeshash128_lt16 (qhash.cpp:630)
==83336==    by 0x6210B77: aeshash128(unsigned char const*, unsigned long, unsigned long, unsigned long) (qhash.cpp:771)
==83336==    by 0x56B8F4F: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56B95F1: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56BB01F: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56BE694: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56ABA04: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56C6EE5: KSharedConfig::openConfig(QString const&, QFlags<KConfig::OpenFlag>, QStandardPaths::StandardLocation) (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x2BD42CA8: ??? (in /usr/lib64/qt6/plugins/styles/breeze6.so)
==83336==    by 0x2BD72EAD: ??? (in /usr/lib64/qt6/plugins/styles/breeze6.so)
==83336==    by 0x50AB9CD: qLoadPlugin<QStyle, QStylePlugin> (qfactoryloader_p.h:99)
==83336==    by 0x50AB9CD: QStyleFactory::create(QString const&) (qstylefactory.cpp:77)
==83336==    by 0x5007BCF: QApplication::style() (qapplication.cpp:919)
==83336==    by 0x50081C0: QApplicationPrivate::initialize() (qapplication.cpp:539)
==83336==  Address 0x2be195e1 is 113 bytes inside a block of size 128 alloc'd
==83336==    at 0x484280F: malloc (vg_replace_malloc.c:442)
==83336==    by 0x63C3BB0: UnknownInlinedFun (qarraydata.cpp:139)
==83336==    by 0x63C3BB0: QArrayData::allocate(QArrayData**, long long, long long, long long, QArrayData::AllocationOption) (qarraydata.cpp:189)
==83336==    by 0x63593CC: allocate (qarraydata.h:106)
==83336==    by 0x63593CC: QByteArray::reallocData(long long, QArrayData::AllocationOption) (qbytearray.cpp:1927)
==83336==    by 0x635958A: QByteArray::resize(long long) (qbytearray.cpp:1866)
==83336==    by 0x62576FF: QIODevice::readAll() (qiodevice.cpp:1262)
==83336==    by 0x56BD852: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56ABA04: ??? (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x56C6EE5: KSharedConfig::openConfig(QString const&, QFlags<KConfig::OpenFlag>, QStandardPaths::StandardLocation) (in /usr/lib64/libKF6ConfigCore.so.6.0.0)
==83336==    by 0x2BD42CA8: ??? (in /usr/lib64/qt6/plugins/styles/breeze6.so)
==83336==    by 0x2BD72EAD: ??? (in /usr/lib64/qt6/plugins/styles/breeze6.so)
==83336==    by 0x50AB9CD: qLoadPlugin<QStyle, QStylePlugin> (qfactoryloader_p.h:99)
==83336==    by 0x50AB9CD: QStyleFactory::create(QString const&) (qstylefactory.cpp:77)
==83336==    by 0x5007BCF: QApplication::style() (qapplication.cpp:919)
==83336== 
==83336== Conditional jump or move depends on uninitialised value(s)
==83336==    at 0x2BDA8B18: ???
==83336==    by 0x2C05E8DF: ???
==83336== 
==83336== Conditional jump or move depends on uninitialised value(s)
==83336==    at 0x82E63F1: QtWaylandClient::QWaylandInputDevice::Keyboard::keyboard_key(unsigned int, unsigned int, unsigned int, unsigned int) (qwaylandinputdevice.cpp:1356)
==83336==    by 0xA488055: ffi_call_unix64 (unix64.S:104)
==83336==    by 0xA48469F: ffi_call_int.lto_priv.0 (ffi64.c:673)
==83336==    by 0xA4874ED: ffi_call (ffi64.c:710)
==83336==    by 0x8354F2D: wl_closure_invoke.constprop.0 (connection.c:1025)
==83336==    by 0x83557A2: dispatch_event.isra.0 (wayland-client.c:1631)
==83336==    by 0x8355A4B: UnknownInlinedFun (wayland-client.c:1777)
==83336==    by 0x8355A4B: wl_display_dispatch_queue_pending (wayland-client.c:2019)
==83336==    by 0x82CCCD1: QtWaylandClient::QWaylandDisplay::flushRequests() (qwaylanddisplay.cpp:229)
==83336==    by 0x62E45A4: QObject::event(QEvent*) (qobject.cpp:1437)
==83336==    by 0x5001F67: QApplicationPrivate::notify_helper(QObject*, QEvent*) (qapplication.cpp:3296)
==83336==    by 0x6291217: QCoreApplication::notifyInternal2(QObject*, QEvent*) (qcoreapplication.cpp:1121)
==83336==    by 0x6295146: QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (qcoreapplication.cpp:1901)
==83336== 
==83336== Invalid read of size 8
==83336==    at 0x4D983FC: QCA::PrivateKey::deriveKey(QCA::PublicKey const&) (qca_publickey.cpp:1033)
==83336==    by 0x141991: UnknownInlinedFun (kwalletfreedesktopservice.cpp:424)
==83336==    by 0x141991: KWalletFreedesktopService::OpenSession(QString const&, QDBusVariant const&, QDBusObjectPath&) (kwalletfreedesktopservice.cpp:266)
==83336==    by 0x166F42: UnknownInlinedFun (kwalletfreedesktopserviceadaptor.cpp:63)
==83336==    by 0x166F42: KWalletFreedesktopServiceAdaptor::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_kwalletfreedesktopserviceadaptor.cpp:410)
==83336==    by 0x167253: KWalletFreedesktopServiceAdaptor::qt_metacall(QMetaObject::Call, int, void**) (moc_kwalletfreedesktopserviceadaptor.cpp:489)
==83336==    by 0x5744B10: QDBusConnectionPrivate::deliverCall(QObject*, int, QDBusMessage const&, QList<QMetaType> const&, int) (qdbusintegrator.cpp:977)
==83336==    by 0x5748674: QDBusConnectionPrivate::activateCall(QObject*, int, QDBusMessage const&) [clone .part.0] (qdbusintegrator.cpp:879)
==83336==    by 0x57492C5: activateCall (qdbusintegrator.cpp:825)
==83336==    by 0x57492C5: QDBusConnectionPrivate::activateObject(QDBusConnectionPrivate::ObjectTreeNode&, QDBusMessage const&, int) (qdbusintegrator.cpp:1460)
==83336==    by 0x574B959: QDBusActivateObjectEvent::placeMetaCall(QObject*) (qdbusintegrator.cpp:1580)
==83336==    by 0x62E45A4: QObject::event(QEvent*) (qobject.cpp:1437)
==83336==    by 0x5001F67: QApplicationPrivate::notify_helper(QObject*, QEvent*) (qapplication.cpp:3296)
==83336==    by 0x6291217: QCoreApplication::notifyInternal2(QObject*, QEvent*) (qcoreapplication.cpp:1121)
==83336==    by 0x6295146: QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (qcoreapplication.cpp:1901)
==83336==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==83336== 
==83336== 
==83336== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==83336==  Access not within mapped region at address 0x0
==83336==    at 0x4D983FC: QCA::PrivateKey::deriveKey(QCA::PublicKey const&) (qca_publickey.cpp:1033)
==83336==    by 0x141991: UnknownInlinedFun (kwalletfreedesktopservice.cpp:424)
==83336==    by 0x141991: KWalletFreedesktopService::OpenSession(QString const&, QDBusVariant const&, QDBusObjectPath&) (kwalletfreedesktopservice.cpp:266)
==83336==    by 0x166F42: UnknownInlinedFun (kwalletfreedesktopserviceadaptor.cpp:63)
==83336==    by 0x166F42: KWalletFreedesktopServiceAdaptor::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_kwalletfreedesktopserviceadaptor.cpp:410)
==83336==    by 0x167253: KWalletFreedesktopServiceAdaptor::qt_metacall(QMetaObject::Call, int, void**) (moc_kwalletfreedesktopserviceadaptor.cpp:489)
==83336==    by 0x5744B10: QDBusConnectionPrivate::deliverCall(QObject*, int, QDBusMessage const&, QList<QMetaType> const&, int) (qdbusintegrator.cpp:977)
==83336==    by 0x5748674: QDBusConnectionPrivate::activateCall(QObject*, int, QDBusMessage const&) [clone .part.0] (qdbusintegrator.cpp:879)
==83336==    by 0x57492C5: activateCall (qdbusintegrator.cpp:825)
==83336==    by 0x57492C5: QDBusConnectionPrivate::activateObject(QDBusConnectionPrivate::ObjectTreeNode&, QDBusMessage const&, int) (qdbusintegrator.cpp:1460)
==83336==    by 0x574B959: QDBusActivateObjectEvent::placeMetaCall(QObject*) (qdbusintegrator.cpp:1580)
==83336==    by 0x62E45A4: QObject::event(QEvent*) (qobject.cpp:1437)
==83336==    by 0x5001F67: QApplicationPrivate::notify_helper(QObject*, QEvent*) (qapplication.cpp:3296)
==83336==    by 0x6291217: QCoreApplication::notifyInternal2(QObject*, QEvent*) (qcoreapplication.cpp:1121)
==83336==    by 0x6295146: QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (qcoreapplication.cpp:1901)
==83336==  If you believe this happened as a result of a stack
==83336==  overflow in your program's main thread (unlikely but
==83336==  possible), you can try to increase the size of the
==83336==  main thread stack using the --main-stacksize= flag.
==83336==  The main thread stack size used in this run was 8388608.
==83336== 
==83336== HEAP SUMMARY:
==83336==     in use at exit: 6,225,266 bytes in 40,139 blocks
==83336==   total heap usage: 277,987 allocs, 237,848 frees, 37,477,388 bytes allocated
==83336== 
==83336== LEAK SUMMARY:
==83336==    definitely lost: 512 bytes in 1 blocks
==83336==    indirectly lost: 1,357 bytes in 41 blocks
==83336==      possibly lost: 550,976 bytes in 65 blocks
==83336==    still reachable: 5,670,405 bytes in 40,011 blocks
==83336==                       of which reachable via heuristic:
==83336==                         newarray           : 10,000 bytes in 60 blocks
==83336==                         multipleinheritance: 2,080 bytes in 6 blocks
==83336==         suppressed: 0 bytes in 0 blocks
==83336== Rerun with --leak-check=full to see details of leaked memory
==83336== 
==83336== Use --track-origins=yes to see where uninitialised values come from
==83336== For lists of detected and suppressed errors, rerun with: -s
==83336== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 from 0)

plasmashell crashed when I ran protonvpn-app in Konsole with kwalletd6 under valgrind which I hadn't seen before.
Comment 14 Matt Fagnani 2024-03-27 04:11:08 UTC
I ran the steps like in comment 9 with the qca 2.3.8 build with the patch, but instead with 
export QT_LOGGING_RULES="*.debug=true" 
kwalletd6 &

The end of the output appeared to show that the first line added by the patch context() had a null pointer, and then kwalletd6 crashed on the third line with static_cast<PKeyContext *>(context())->key()
...
qt.core.library: "/usr/lib64/qt6/plugins/crypto/libqca-ossl.so" loaded library
QObject(0x0)
opensslQCAPlugin::MyPKeyContext(0x556d5ce55020)

[1]+  Segmentation fault      (core dumped) kwalletd6

I reported the plasmashell crash I mentioned in my previous comment at https://bugs.kde.org/show_bug.cgi?id=484565
Comment 15 Albert Astals Cid 2024-03-27 19:13:41 UTC
This is super curious as why i can't reproduce this.

Just to confirm, you are fully

dnf upgrade

right?

Can you try compiling this simple program? 

You may need to install qca-qt6-devel qt6-qtbase-devel and some other packages (hope not more)

Create a folder named test
inside put this https://pastebin.com/raw/P7nihcR5 named main.cpp
and this https://pastebin.com/raw/6QuAQCyS named test.pro

then go into a terminal inside that folder and run
qmake6 && make && ./test 

What is the output?
Comment 16 Matt Fagnani 2024-03-27 20:35:34 UTC
Yes, my system is fully updated with the updates-testing repo enabled. I ran those steps with the qca 2.3.8 build with your patch which gave me the following output. privateKey.context() appeared to have a non-null pointer.

qmake6 && make && ./test 
Info: creating stash file /programs/qca/test/.qmake.stash
[2]+  Done                    kate test.pro
g++ -c -pipe -g -Wall -Wextra -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I/usr/include/qt6/QtCrypto -I/usr/include/qt6 -I/usr/include/qt6/QtGui -I/usr/include/qt6/QtCore -I. -I/usr/lib64/qt6/mkspecs/linux-g++ -o main.o main.cpp
g++ -Wl,-rpath-link,/usr/lib64 -o test  main.o   -lqca-qt6 /usr/lib64/libQt6Gui.so /usr/lib64/libQt6Core.so -lpthread -lGLX -lOpenGL   
opensslQCAPlugin::MyPKeyContext(0xc34710)
Comment 17 Matt Fagnani 2024-03-28 21:47:11 UTC
In KWalletFreedesktopService::createSessionAlgorithmDhAes at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:415 there is const auto dlGroup = QCA::DLGroup(keygen.createDLGroup(QCA::IETF_1024)); If QCA::IETF_1024 means that 1024 bit DH keys are used, this might not be allowed by the default crypto policy in Fedora which I'm using. man crypto-policies shows for the DEFAULT policy "The Diffie-Hellman parameters are accepted if they are at least 2048 bits long." The private key and public key generated might have had null pointers because the key size wasn't large enough for the default crypto policy.
Comment 18 Albert Astals Cid 2024-03-29 09:20:47 UTC
(In reply to Matt Fagnani from comment #17)
> In KWalletFreedesktopService::createSessionAlgorithmDhAes at
> /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/
> kwalletfreedesktopservice.cpp:415 there is const auto dlGroup =
> QCA::DLGroup(keygen.createDLGroup(QCA::IETF_1024)); If QCA::IETF_1024 means
> that 1024 bit DH keys are used, this might not be allowed by the default
> crypto policy in Fedora which I'm using. man crypto-policies shows for the
> DEFAULT policy "The Diffie-Hellman parameters are accepted if they are at
> least 2048 bits long." The private key and public key generated might have
> had null pointers because the key size wasn't large enough for the default
> crypto policy.

But i'm using that in my test program too and that works, so there's no reason why it would not work inside kwallet :/

Let me try to contact the author of that commit you mention as the one causing the regression to see if he has any idea of what may be happening.
Comment 19 Matt Fagnani 2024-03-30 15:33:15 UTC
I tried setting the legacy fedora crypto policy which allows DH keys >= 1024 bits with sudo update-crypto-policies --set LEGACY and rebooting but the problem still happened. I also built kwallet with const auto dlGroup = QCA::DLGroup(keygen.createDLGroup(QCA::IETF_2048)); at /usr/src/debug/kf6-kwallet-6.0.0-1.fc40.x86_64/src/runtime/kwalletd/kwalletfreedesktopservice.cpp:415, but the problem happened with that change too.

I created my wallet with "Classic, blowfish encrypted file" in the kwallet wizard. Blowfish is listed on the OpenSSL legacy providers page at https://www.openssl.org/docs/man3.0/man7/OSSL_PROVIDER-legacy.html Since the first bad commit involved OpenSSL legacy providers, could the use of Blowfish be involved in this problem somehow?
Comment 20 Fabian Vogt 2024-03-30 19:14:00 UTC
(In reply to Matt Fagnani from comment #8)
> I bisected this problem with qca from 2.3.7 to 2.3.8. The following first
> bad commit involved loading legacy openssl providers.
> 
> 14eb1ae746c3c75afaef02b487ac65b3de85ad15 is the first bad commit
> commit 14eb1ae746c3c75afaef02b487ac65b3de85ad15
> Author: Fabian Vogt <fabian@ritter-vogt.de>
> Date:   Fri Dec 22 13:36:00 2023 +0100
> 
>     plugins/qca-ossl: Actually try loading the legacy provider
>     
>     OSSL_PROVIDER_available returns true only for loaded providers, not
> whether
>     a provider can be loaded. Use OSSL_PROVIDER_try_load instead, which also
>     allows to keep the default fallback provider.
> 
>  plugins/qca-ossl/qca-ossl.cpp | 24 +++++-------------------
>  1 file changed, 5 insertions(+), 19 deletions(-)

My theory is that without this commit, using kwalletd6 with OpenSSL >= 3.0 will just fail early enough that the broken code path is not even reached. Comment 19 is one major reason why that would be the case. You could confirm that by creating an OpenSSL config which forces loading of default and legacy providers:

$ cat openssl.cnf 
openssl_conf = openssl_init
[openssl_init]
providers = provider_sect
[provider_sect]
default = default_sect
legacy = legacy_sect
[default_sect]
activate = 1
[legacy_sect]
activate = 1

And then trying kwallet6 with old qca + "OPENSSL_CONF=openssl.cnf kwallet6".

Locally I extracted the createSessionAlgorithmDhAes method into a standalone executable (like comment 15, but more) and ran ltrace on that to get an overview on the used code paths in qca and libcrypto. The call most likely to fail is qca-ossl.cpp:DHKeyMaker::run() -> DH_generate_key, so I simulated that by hardcoding a failure code at that point. The result is a segfault identical to the one observed here.

Please do an ltrace of kwalletd6 by running "ltrace -fCl 'libcrypto*' kwalletd6" and quote the output here. If some call fails, that should be visible.

Question is why it fails on your system while it does not fail here. Maybe there's an additional check for the parameter length in your OpenSSL version? Upstream only checks for < 512: https://github.com/openssl/openssl/blob/56e63f570bd5a479439bc6f6a2499f6b86ded341/crypto/dh/dh_key.c#L286
Comment 21 Matt Fagnani 2024-03-31 03:21:51 UTC
I created an OpenPGP key in KGpg. I exported my Blowfish encrypted wallet, and then I deleted it in kwalletmanager. I created a new wallet with my OpenPGP key in kwalletmanager. The Proton VPN GUI and kwalletd6 didn't crash when I started the Proton VPN GUI, but when I tried to log in to Proton VPN, kwalletd6 crashed with the same trace and an error popup like "Something went wrong. We're sorry, a problem occurred" was shown in Proton VPN GUI. I think the problem occurred when logging in instead of starting because the wallet was empty at that point. This test and the following were with qca 2.3.8 plus the patch in comment 11.

In another Plasma session, I closed the new wallet encrypted with the OpenPGP key in kwalletmanager. I ran killall kwalletd6 twice as suggested in comment 9. I ran OPENSSL_CONF=openssl.cnf kwalletd6 I opened the wallet in kwalletmanager. I ran Proton VPN GUI and logged in. The login completed without the kwalletd6 crash or the Proton VPN error happening. So this test supports your theory.

I closed the wallet again in kwalletmanager. I ran killall kwalletd6 twice. I ran ltrace -fCl 'libcrypto*' kwalletd6. Proton VPN crashed when starting, and kwalletd6 also crashed as shown in the following output.

kf.wallet.kwalletd: Lacking a socket, pipe: 0 env: 0
[pid 67660] +++ exited (status 0) +++
[pid 67659] +++ exited (status 0) +++
[pid 67658] +++ exited (status 0) +++
[pid 67657] +++ exited (status 0) +++
[pid 67656] +++ exited (status 0) +++
[pid 67655] +++ exited (status 0) +++
[pid 67702] +++ exited (status 0) +++
[pid 67703] --- Called exec() ---
[pid 67645] --- SIGCHLD (Child exited) ---
[pid 67703] +++ exited (status 0) +++
[pid 67708] +++ exited (status 0) +++
[pid 67709] --- Called exec() ---
[pid 67645] --- SIGCHLD (Child exited) ---
[pid 67709] +++ exited (status 0) +++
[pid 67710] +++ exited (status 0) +++
[pid 67711] --- Called exec() ---
[pid 67645] --- SIGCHLD (Child exited) ---
[pid 67711] +++ exited (status 0) +++
[pid 67712] +++ exited (status 0) +++
[pid 67713] --- Called exec() ---
[pid 67645] --- SIGCHLD (Child exited) ---
[pid 67713] +++ exited (status 0) +++
[pid 67714] +++ exited (status 0) +++
[pid 67715] --- Called exec() ---
[pid 67645] --- SIGCHLD (Child exited) ---
[pid 67715] +++ exited (status 0) +++
[pid 67716] +++ exited (status 0) +++
[pid 67717] --- Called exec() ---
[pid 67645] --- SIGCHLD (Child exited) ---
[pid 67717] +++ exited (status 0) +++
[pid 67731] +++ exited (status 0) +++
[pid 67732] --- Called exec() ---
[pid 67645] --- SIGCHLD (Child exited) ---
[pid 67732] +++ exited (status 0) +++
[pid 67645] libQt6Core.so.6->OSSL_PROVIDER_load(0, 0x7f8f9fe97499, 0x55d2a3168010, 2) = 0x7f8f78001ff0
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_new(0, 0x7f8f9e313480, 0, 0)      = 0x55d2a347f150
[pid 67645] libQt6Core.so.6->EVP_MD_fetch(0, 0x7f8f9fe993b4, 0x7f8f9fe99415, 0x55d2a347f150) = 0x55d2a3525340
[pid 67645] libQt6Core.so.6->EVP_DigestInit_ex(0x55d2a347f150, 0x55d2a3525340, 0, 0) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_reset(0x55d2a347f150, 0, 0xffffffee, 0) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestInit_ex(0x55d2a347f150, 0x55d2a3525340, 0, 4) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestUpdate(0x55d2a347f150, 0x55d2a34961c0, 9, 0x55d2a34961c0) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_new(0x55d2a31ea910, 1, 0x55d2a31eaab8, 3) = 0x55d2a3526430
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_copy_ex(0x55d2a3526430, 0x55d2a347f150, 72, 0x55d2a3526430) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_get_size(0x55d2a3525340, -1025, 0x55d2a3168010, 2) = 16
[pid 67645] libQt6Core.so.6->EVP_DigestFinal_ex(0x55d2a3526430, 0x55d2a31eaab8, 0, 2) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_free(0x55d2a3526430, 0, 0xcbbdf5df, 0x6f4d0cef) = 3
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_reset(0x55d2a347f150, 0, 0xffffffee, 0) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestInit_ex(0x55d2a347f150, 0x55d2a3525340, 0, 4) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestUpdate(0x55d2a347f150, 0x55d2a35263f0, 18, 0x55d2a35263f0) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_new(0x55d2a31ea910, 1, 0x55d2a31eaab8, 2) = 0x55d2a35263e0
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_copy_ex(0x55d2a35263e0, 0x55d2a347f150, 72, 0x55d2a35263e0) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_get_size(0x55d2a3525340, -1025, 0x55d2a3168010, 2) = 16
[pid 67645] libQt6Core.so.6->EVP_DigestFinal_ex(0x55d2a35263e0, 0x55d2a31eaab8, 0, 2) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_free(0x55d2a35263e0, 0, 0x5d349bcd, 0x77b40417) = 3
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_reset(0x55d2a347f150, 0, 0xffffffee, 0) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestInit_ex(0x55d2a347f150, 0x55d2a3525340, 0, 4) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestUpdate(0x55d2a347f150, 0x55d2a34961c0, 9, 0x55d2a34961c0) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_new(0x55d2a31ea910, 1, 0x55d2a31eaab8, 3) = 0x55d2a35263e0
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_copy_ex(0x55d2a35263e0, 0x55d2a347f150, 72, 0x55d2a35263e0) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_get_size(0x55d2a3525340, -1025, 0x55d2a3168010, 2) = 16
[pid 67645] libQt6Core.so.6->EVP_DigestFinal_ex(0x55d2a35263e0, 0x55d2a31eaab8, 0, 2) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_free(0x55d2a35263e0, 0, 0x732c9dae, 0x53e03c09) = 3
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_reset(0x55d2a347f150, 0x1000000, 0xffffffee, 0) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestInit_ex(0x55d2a347f150, 0x55d2a3525340, 0, 4) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestUpdate(0x55d2a347f150, 0x55d2a3526490, 14, 0x55d2a3526490) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_new(0x55d2a31ea910, 1, 0x55d2a31eaab8, 3) = 0x55d2a3526480
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_copy_ex(0x55d2a3526480, 0x55d2a347f150, 72, 0x55d2a3526480) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_get_size(0x55d2a3525340, -1025, 0x55d2a3168010, 2) = 16
[pid 67645] libQt6Core.so.6->EVP_DigestFinal_ex(0x55d2a3526480, 0x55d2a31eaab8, 0, 2) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_free(0x55d2a3526480, 0, 0x537ff04d, 0x8df18c35) = 3
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_reset(0x55d2a347f150, 0x5d005b0004000000, 0xffffffee, 0) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestInit_ex(0x55d2a347f150, 0x55d2a3525340, 0, 4) = 1
[pid 67645] libQt6Core.so.6->EVP_DigestUpdate(0x55d2a347f150, 0x55d2a353e030, 46, 0x55d2a353e030) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_new(0x55d2a31ea910, 1, 0x55d2a31eaab8, 7) = 0x55d2a3526480
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_copy_ex(0x55d2a3526480, 0x55d2a347f150, 72, 0x55d2a3526480) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_get_size(0x55d2a3525340, -1025, 0x55d2a3168010, 2) = 16
[pid 67645] libQt6Core.so.6->EVP_DigestFinal_ex(0x55d2a3526480, 0x55d2a31eaab8, 0, 2) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_free(0x55d2a3526480, 0, 0x808c8b58, 0x54be220b) = 3
[pid 67736] +++ exited (status 0) +++
[pid 67737] --- Called exec() ---
[pid 67645] --- SIGCHLD (Child exited) ---
[pid 67737] +++ exited (status 0) +++
[pid 67645] libQt6Core.so.6->OSSL_PROVIDER_unload(0x7f8f78001ff0, 0x55d2a34da980, 0xfffffffa, 0x7f8f9f5f2b20) = 1
[pid 67645] libQt6Core.so.6->EVP_MD_CTX_free(0x55d2a347f150, 0, 0, 0)     = 3
[pid 67645] libQt6Core.so.6->EVP_MD_free(0x55d2a3525340, 0x55d2a347f140, 0x55d2a347f, 1) = 1
[pid 67645] --- SIGSEGV (Segmentation fault) ---
[pid 67650] +++ killed by SIGSEGV +++
[pid 67654] +++ killed by SIGSEGV +++
[pid 67653] +++ killed by SIGSEGV +++
[pid 67652] +++ killed by SIGSEGV +++
[pid 67651] +++ killed by SIGSEGV +++
[pid 67649] +++ killed by SIGSEGV +++
[pid 67648] +++ killed by SIGSEGV +++
[pid 67647] +++ killed by SIGSEGV +++
[pid 67646] +++ killed by SIGSEGV +++
[pid 67645] +++ killed by SIGSEGV +++


Before those tests, I attached gdb to kwalletd6 with gdb -p $(pidof kwalletd6). I set a breakpoint with b kwalletfreedesktopservice.cpp:415. I stepped through each line. In the line auto privateKey = QCA::PrivateKey(keygen.createDH(dlGroup)); I saw that the provider and algorithm had null pointers.

(gdb) s
QCA::KeyGenerator::createDH (this=this@entry=0x7fffd8d8f0c0, domain=..., provider=...)
    at /usr/src/debug/qca-2.3.8-2.fc40.x86_64/src/qca_publickey.cpp:1265
1265        d->key         = PrivateKey();
(gdb) l
1260    PrivateKey KeyGenerator::createDH(const DLGroup &domain, const QString &provider)
1261    {
1262        if (isBusy())
1263            return PrivateKey();
1264
1265        d->key         = PrivateKey();
1266        d->wasBlocking = d->blocking;
1267        d->k           = static_cast<DHContext *>(getContext(QStringLiteral("dh"), provider));
1268        d->dest        = static_cast<PKeyContext *>(getContext(QStringLiteral("pkey"), d->k->provider()));
1269
(gdb) p d
$7 = (QCA::KeyGenerator::Private *) 0x55bcd8644770
(gdb) p d->key
$8 = {<QCA::PKey> = {<QCA::Algorithm> = {_vptr.Algorithm = 0x7fb661b8a578 <vtable for QCA::PrivateKey+16>, d = {
        d = 0x0}}, d = 0x55bcd834ac70}, d = 0x69007800710076}
(gdb) p domain
$9 = (const QCA::DLGroup &) @0x7fffd8d8f048: {d = 0x55bcd86155d0}
(gdb) p domain->d
$10 = (QCA::DLGroup::Private *) 0x55bcd86155d0
(gdb) p *(domain->d)
$11 = {p = {d = {d = 0x55bcd86151d0}}, q = {d = {d = 0x55bcd8617f90}}, g = {d = {d = 0x55bcd835ba30}}}
(gdb) p provider
$12 = (const QString &) @0x7fffd8d8f180: {d = {d = 0x0, ptr = 0x0, size = 0}, static _empty = 0 u'\000'}
(gdb) p provider->d
$13 = {d = 0x0, ptr = 0x0, size = 0}
...
gdb) s
QCA::Algorithm::operator= (this=0x55bcd8644790, from=...)
    at /usr/src/debug/qca-2.3.8-2.fc40.x86_64/src/qca_core.cpp:1310
1310    {
(gdb) l
1305    Algorithm::~Algorithm()
1306    {
1307    }
1308
1309    Algorithm &Algorithm::operator=(const Algorithm &from)
1310    {
1311        d = from.d;
1312        return *this;
1313    }
1314
(gdb) p from
$21 = (const QCA::Algorithm &) @0x7fffd8d8ef60: {_vptr.Algorithm = 0x7fb661b8a578 <vtable for QCA::PrivateKey+16>, d = {
    d = 0x0}}
(gdb) p from.d
$22 = {d = 0x0}
(gdb) p *this
$23 = {_vptr.Algorithm = 0x7fb661b8a578 <vtable for QCA::PrivateKey+16>, d = {d = 0x0}}

The programs checked various providers after that, but possibly no provider was selected due to the issue you mentioned. Then, the private key had the null pointer and kwalletd6 crashed as before.

Fedora's default crypto policy has a minimum DH key size of 2048 as I mentioned in comment 17. The DH keys generated in KWalletFreedesktopService::createSessionAlgorithmDhAes used QCA::IETF_1024. Could that be an additional check leading to the legacy providers' path being used? Thanks.
Comment 22 Matt Fagnani 2024-03-31 04:58:06 UTC
I think I've found why the problem happened on my system but not yours. The openssl config file /etc/pki/tls/openssl.cnf was last modified in September 2020 at the time I ran a SCAP Workbench remediation script which modified /etc/pki/tls/openssl.cnf to add lines about the Fedora crypto policies. /etc/pki/tls/openssl.cnf wasn't updated since then because rpm doesn't change config files that don't match those in the update. I moved /etc/pki/tls/openssl.cnf to /etc/pki/tls/openssl.cnf.rpmold and moved /etc/pki/tls/openssl.cnf.rpmnew from February 2024 to /etc/pki/tls/openssl.cnf. I rebooted. kwalletd6 didn't crash when I started Proton VPN GUI or logged in using it on the next boot using the new openssl config file. The newer openssl config has a section not in the older one which shows that the legacy providers are disabled unless certain lines in the following are uncommented. 

# Uncomment the sections that start with ## below to enable the legacy provider.
# Loading the legacy provider enables support for the following algorithms:
# Hashing Algorithms / Message Digests: MD2, MD4, MDC2, WHIRLPOOL, RIPEMD160
# Symmetric Ciphers: Blowfish, CAST, DES, IDEA, RC2, RC4,RC5, SEED
# Key Derivation Function (KDF): PBKDF1
# In general it is not recommended to use the above mentioned algorithms for
# security critical operations, as they are cryptographically weak or vulnerable
# to side-channel attacks and as such have been deprecated.

[provider_sect]
default = default_sect
##legacy = legacy_sect
##
[default_sect]
activate = 1

##[legacy_sect]
##activate = 1
Comment 23 Fabian Vogt 2024-03-31 18:11:11 UTC
(In reply to Matt Fagnani from comment #21)
> I created an OpenPGP key in KGpg. I exported my Blowfish encrypted wallet,
> and then I deleted it in kwalletmanager. I created a new wallet with my
> OpenPGP key in kwalletmanager. The Proton VPN GUI and kwalletd6 didn't crash
> when I started the Proton VPN GUI, but when I tried to log in to Proton VPN,
> kwalletd6 crashed with the same trace and an error popup like "Something
> went wrong. We're sorry, a problem occurred" was shown in Proton VPN GUI. I
> think the problem occurred when logging in instead of starting because the
> wallet was empty at that point. This test and the following were with qca
> 2.3.8 plus the patch in comment 11.
> 
> In another Plasma session, I closed the new wallet encrypted with the
> OpenPGP key in kwalletmanager. I ran killall kwalletd6 twice as suggested in
> comment 9. I ran OPENSSL_CONF=openssl.cnf kwalletd6 I opened the wallet in
> kwalletmanager. I ran Proton VPN GUI and logged in. The login completed
> without the kwalletd6 crash or the Proton VPN error happening. So this test
> supports your theory.

Not sure. That openssl.cnf should be a noop and be equivalent to qca 2.3.8
with upstream default openssl config. Can you try with an empty file for OPENSSL_CONF?

> I closed the wallet again in kwalletmanager. I ran killall kwalletd6 twice.
> I ran ltrace -fCl 'libcrypto*' kwalletd6. Proton VPN crashed when starting,
> and kwalletd6 also crashed as shown in the following output.
> 
> kf.wallet.kwalletd: Lacking a socket, pipe: 0 env: 0
> ...

For some weird reason it only logs QtCore -> OpenSSL calls, but not those coming from QCA...
Please try "ltrace -fCe 'DH_*+OSSL_*' kwalletd6"

> Before those tests, I attached gdb to kwalletd6 with gdb -p $(pidof
> kwalletd6). I set a breakpoint with b kwalletfreedesktopservice.cpp:415. I
> stepped through each line. In the line auto privateKey =
> QCA::PrivateKey(keygen.createDH(dlGroup)); I saw that the provider and
> algorithm had null pointers.

FWICT that might be fine.

> Fedora's default crypto policy has a minimum DH key size of 2048 as I
> mentioned in comment 17. The DH keys generated in
> KWalletFreedesktopService::createSessionAlgorithmDhAes used QCA::IETF_1024.

AFAICT the crypto policies only affect SSL/TLS, not use of DH_* directly.

> Could that be an additional check leading to the legacy providers' path
> being used? Thanks.

I don't think providers have anything to do with DH_* methods which are part of OpenSSL core.

(In reply to Matt Fagnani from comment #22)
> I think I've found why the problem happened on my system but not yours. The
> openssl config file /etc/pki/tls/openssl.cnf was last modified in September
> 2020 at the time I ran a SCAP Workbench remediation script which modified
> /etc/pki/tls/openssl.cnf to add lines about the Fedora crypto policies.
> /etc/pki/tls/openssl.cnf wasn't updated since then because rpm doesn't
> change config files that don't match those in the update. I moved
> /etc/pki/tls/openssl.cnf to /etc/pki/tls/openssl.cnf.rpmold and moved
> /etc/pki/tls/openssl.cnf.rpmnew from February 2024 to
> /etc/pki/tls/openssl.cnf. I rebooted. kwalletd6 didn't crash when I started
> Proton VPN GUI or logged in using it on the next boot using the new openssl
> config file. The newer openssl config has a section not in the older one
> which shows that the legacy providers are disabled unless certain lines in
> the following are uncommented. 

That's actually the upstream default and is a noop. Can you attach the full cnf file that triggers the issue?
Comment 24 Matt Fagnani 2024-03-31 18:48:10 UTC
Created attachment 167996 [details]
Older openssl config file which the problem happened with

Thanks. I created an empty file empty.cnf. I closed the wallet in kwalletmanager. I ran killall kwalletd6 twice in Konsole. I ran OPENSSL_CONF=empty.cnf kwalletd6 I opened the wallet. I ran Proton VPN GUI which didn't appear, and kwalletd6 crashed with the same trace as before.

I'm attaching the older openssl config file /etc/pki/tls/openssl.cnf from 2020 which the problem happened with. The older config doesn't mention providers. Could the lack of the section enabling default providers in the older config have led to the problem?
Comment 25 Matt Fagnani 2024-03-31 18:51:33 UTC
Created attachment 167997 [details]
ltrace output on kwalletd6 when running Proton VPN GUI twice

I ran ltrace -fCe 'DH_*+OSSL_*' kwalletd6 with the newer default /etc/pki/tls/openssl.cnf. I ran Proton VPN GUI which didn't appear, but kwalletd6 didn't crash. I ran Proton VPN GUI again, and it showed up normally. The ltrace output seemed to show the legacy providers being checked then the DH functions being run.
Comment 26 Matt Fagnani 2024-03-31 19:40:50 UTC
I switched /etc/pki/tls/openssl.cnf back to the old config and rebooted. I closed the wallet and ran killall kwalletd6 twice. I ran ltrace -fCe 'DH_*+OSSL_*' kwalletd6 I opened the wallet. I ran protonvpn-app which crashed. kwalletd6 crashed after some of the DH functions as shown in the output.

ltrace -fCe 'DH_*+OSSL_*' kwalletd6
kf.wallet.kwalletd: Lacking a socket, pipe: 0 env: 0
[pid 3618] +++ exited (status 0) +++
[pid 3617] +++ exited (status 0) +++
[pid 3616] +++ exited (status 0) +++
[pid 3615] +++ exited (status 0) +++
[pid 3614] +++ exited (status 0) +++
[pid 3613] +++ exited (status 0) +++
[pid 3654] +++ exited (status 0) +++
[pid 3603] --- SIGCHLD (Child exited) ---
[pid 3655] --- Called exec() ---
[pid 3655] +++ exited (status 0) +++
[pid 3656] +++ exited (status 0) +++
[pid 3603] --- SIGCHLD (Child exited) ---
[pid 3657] --- Called exec() ---
[pid 3657] +++ exited (status 0) +++
[pid 3658] +++ exited (status 0) +++
[pid 3603] --- SIGCHLD (Child exited) ---
[pid 3659] --- Called exec() ---
[pid 3659] +++ exited (status 0) +++
[pid 3660] +++ exited (status 0) +++
[pid 3603] --- SIGCHLD (Child exited) ---
[pid 3661] --- Called exec() ---
[pid 3661] +++ exited (status 0) +++
[pid 3662] +++ exited (status 0) +++
[pid 3603] --- SIGCHLD (Child exited) ---
[pid 3663] --- Called exec() ---
[pid 3663] +++ exited (status 0) +++
[pid 3664] +++ exited (status 0) +++
[pid 3603] --- SIGCHLD (Child exited) ---
[pid 3665] --- Called exec() ---
[pid 3665] +++ exited (status 0) +++
[pid 3677] +++ exited (status 0) +++
[pid 3603] --- SIGCHLD (Child exited) ---
[pid 3678] --- Called exec() ---
[pid 3678] +++ exited (status 0) +++
[pid 3603] libQt6Core.so.6->OSSL_PROVIDER_load(0, 0x7fb30e297499, 0x55d4cee99010, 1) = 0x7fb2e8001ff0
[pid 3682] +++ exited (status 0) +++
[pid 3603] --- SIGCHLD (Child exited) ---
[pid 3683] --- Called exec() ---
[pid 3683] +++ exited (status 0) +++
[pid 3603] libQt6Core.so.6->OSSL_PROVIDER_unload(0x7fb2e8001ff0, 0x55d4cf2530c0, 0xfffffffa, 0x7fb30d9f3b20) = 1
[pid 3603] libqca-ossl.so->OSSL_PROVIDER_try_load(0, 0x7fb2f19a10f1, 1, 0x7fb30d9f3ac0 <unfinished ...>
[pid 3603] legacy.so->OSSL_LIB_CTX_new_child(0x55d4cf2504b0, 0x7fb30c89f300, 24, 0x55d4cf26ac60) = 0x55d4cf25cfb0
[pid 3603] <... OSSL_PROVIDER_try_load resumed> )                         = 0x55d4cf2504b0
[pid 3603] libqca-ossl.so->DH_new(0x55d4cf205910, 0x55d4cf2059f0, 0x55d4cf25a630, 0) = 0x7fb2f400bd30
[pid 3603] libqca-ossl.so->DH_set0_pqg(0x7fb2f400bd30, 0x55d4cf24a2b0, 0, 0x55d4cf24a2d0) = 1
[pid 3603] libqca-ossl.so->DH_generate_key(0x7fb2f400bd30, 0x7fb30c8511c0, 16, 0xb10b8f96a080e01d) = 0
[pid 3603] libqca-ossl.so->DH_free(0x7fb2f400bd30, 0x55d4cf205c30, 0x55d19269ff25, 6) = 12
[pid 3603] libqca-ossl.so->DH_new(0x55d4cf205c08, 0, 1, 2)                = 0x7fb2f400bd30
[pid 3603] libqca-ossl.so->DH_set0_key(0x7fb2f400bd30, 0x55d4cf206bf0, 0, 1) = 1
[pid 3603] libqca-ossl.so->DH_set0_pqg(0x7fb2f400bd30, 0x55d4cf206160, 0, 0x55d4cf206180) = 1
[pid 3603] --- SIGSEGV (Segmentation fault) ---
[pid 3608] +++ killed by SIGSEGV +++
[pid 3606] +++ killed by SIGSEGV +++
[pid 3611] +++ killed by SIGSEGV +++
[pid 3612] +++ killed by SIGSEGV +++
[pid 3610] +++ killed by SIGSEGV +++
[pid 3609] +++ killed by SIGSEGV +++
[pid 3607] +++ killed by SIGSEGV +++
[pid 3605] +++ killed by SIGSEGV +++
[pid 3604] +++ killed by SIGSEGV +++
[pid 3603] +++ killed by SIGSEGV +++
Comment 27 Fabian Vogt 2024-03-31 20:12:19 UTC
(In reply to Matt Fagnani from comment #26)
> I switched /etc/pki/tls/openssl.cnf back to the old config and rebooted. I
> closed the wallet and ran killall kwalletd6 twice. I ran ltrace -fCe
> 'DH_*+OSSL_*' kwalletd6 I opened the wallet. I ran protonvpn-app which
> crashed. kwalletd6 crashed after some of the DH functions as shown in the
> output.
> 
> ltrace -fCe 'DH_*+OSSL_*' kwalletd6
...
> [pid 3603] libQt6Core.so.6->OSSL_PROVIDER_load(0, 0x7fb30e297499,
> 0x55d4cee99010, 1) = 0x7fb2e8001ff0
> [pid 3682] +++ exited (status 0) +++
> [pid 3603] --- SIGCHLD (Child exited) ---
> [pid 3683] --- Called exec() ---
> [pid 3683] +++ exited (status 0) +++
> [pid 3603] libQt6Core.so.6->OSSL_PROVIDER_unload(0x7fb2e8001ff0,
> 0x55d4cf2530c0, 0xfffffffa, 0x7fb30d9f3b20) = 1

This caught my attention now, I don't get this here. Looking at the code, this is only in Qt since https://github.com/qt/qtbase/commit/ddb1c75afe474e399fe9f5f839a9ac3873dee247 and would actually explain what happens.

By default, OpenSSL loads the "DEFAULT" provider, but only if no other provider was loaded. That disables this logic:

https://www.openssl.org/docs/manmaster/man7/OSSL_PROVIDER-default.html:
> Automatic loading of the default provider only occurs a maximum of once; if the default provider is explicitly unloaded then the default provider will not be automatically loaded again.

It appears like Fedora backported the linked Qt commit, so Qt itself loads and unloads the DEFAULT provider.

> [pid 3603] libqca-ossl.so->OSSL_PROVIDER_try_load(0, 0x7fb2f19a10f1, 1,
> 0x7fb30d9f3ac0 <unfinished ...>
> [pid 3603] legacy.so->OSSL_LIB_CTX_new_child(0x55d4cf2504b0, 0x7fb30c89f300,
> 24, 0x55d4cf26ac60) = 0x55d4cf25cfb0
> [pid 3603] <... OSSL_PROVIDER_try_load resumed> )                         =
> 0x55d4cf2504b0
> [pid 3603] libqca-ossl.so->DH_new(0x55d4cf205910, 0x55d4cf2059f0,
> 0x55d4cf25a630, 0) = 0x7fb2f400bd30
> [pid 3603] libqca-ossl.so->DH_set0_pqg(0x7fb2f400bd30, 0x55d4cf24a2b0, 0,
> 0x55d4cf24a2d0) = 1
> [pid 3603] libqca-ossl.so->DH_generate_key(0x7fb2f400bd30, 0x7fb30c8511c0,
> 16, 0xb10b8f96a080e01d) = 0

As expected, DH_generate_key fails, causing the returned key to be null.

The Qt behavior also explains why it works with the config in comments 20 and 22, those load the default provider explicitly.

I'll leave a comment on https://bugreports.qt.io/browse/QTBUG-118227. I'm not sure whether this is the right fix, but this should work:

diff --git a/plugins/qca-ossl/qca-ossl.cpp b/plugins/qca-ossl/qca-ossl.cpp
index f41fcbb5..0176da3b 100644
--- a/plugins/qca-ossl/qca-ossl.cpp
+++ b/plugins/qca-ossl/qca-ossl.cpp
@@ -6637,6 +6637,8 @@ public:
         if (OSSL_PROVIDER_try_load(nullptr, "legacy", 1)) {
             s_legacyProviderAvailable = true;
         }
+        // No idea how to report failure here...
+        OSSL_PROVIDER_try_load(nullptr, "default", 1);
 #else
         s_legacyProviderAvailable = true;
 #endif
Comment 28 Matt Fagnani 2024-04-01 02:30:05 UTC
I built qca 2.3.8 with your patch and the one in comment 11 and upgraded to it. I logged out and in. Using the steps as before, I ran kwalletd6 with the old config like OPENSSL_CONF=/etc/pki/tls/openssl.cnf.rpmold kwalletd6. protonvpn-app started normally and kwalletd6 didn't crash. I did likewise with the empty config, and protonvpn-app and kwalletd6 didn't crash. Thanks. The patch for https://bugreports.qt.io/browse/QTBUG-118227 looks like it was included in Qt 6.6.1 there and I'm using 6.6.2.
Comment 29 Fabian Vogt 2024-04-02 11:56:04 UTC
Ok, that confirms it. I'll ask around to figure out how both Qt and QCA should use the provider API.