]> git.ipfire.org Git - thirdparty/qemu.git/commit
crypto: implement workaround for GNUTLS thread safety problems
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 18 Jul 2025 15:05:11 +0000 (16:05 +0100)
committerFabiano Rosas <farosas@suse.de>
Tue, 22 Jul 2025 22:39:29 +0000 (19:39 -0300)
commit24ad5e19952b326796c8a3a1595c57ff180dab84
tree57af55311a30ed447fad52704be6cbdab0ce5713
parenteaec556bc88cc1196f7bbf23d5de311aac1d812f
crypto: implement workaround for GNUTLS thread safety problems

When TLS 1.3 is negotiated on a TLS session, GNUTLS will perform
automatic rekeying of the session after 16 million records. This
is done for all algorithms except CHACHA20_POLY1305 which does
not require rekeying.

Unfortunately the rekeying breaks GNUTLS' promise that it is safe
to use a gnutls_session_t object concurrently from multiple threads
if they are exclusively calling gnutls_record_send/recv.

This patch implements a workaround for QEMU that adds a mutex lock
around any gnutls_record_send/recv call to serialize execution
within GNUTLS code. When GNUTLS calls into the push/pull functions
we can release the lock so the OS level I/O calls can at least
have some parallelism.

The big downside of this is that the actual encryption/decryption
code is fully serialized, which will halve performance of that
cipher operations if two threads are contending.

The workaround is not enabled by default, since most use of GNUTLS
in QEMU does not tickle the problem, only non-multifd migration
with a return path open is affected. Fortunately the migration
code also won't trigger the halving of performance, since only
the outbound channel diretion needs to sustain high data rates,
the inbound direction is low volume.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/qemu-devel/20250718150514.2635338-2-berrange@redhat.com
[add stub for qcrypto_tls_session_require_thread_safety; fix unused var]
Signed-off-by: Fabiano Rosas <farosas@suse.de>
crypto/tlssession.c
include/crypto/tlssession.h
meson.build
meson_options.txt
scripts/meson-buildoptions.sh