Revert obsolete & broken workaround for GNUTLS thread safety bug
Subsystems (2)
cover Revert obsolete & broken workaround for GNUTLS thread safety bug
A year or so ago we introduced a workaround for a troubling GNUTLS thread safety problem that hits when a bidirectional TLS channel is used and "large" amounts of data are transferred triggering re-keying under TLS 1.3.
Unfortunately that workaround turned out to not work, and since it was close to final freeze we disabled it, rather than attempt last minute changes.
Fast forward a year, and GNUTLS has shipped a fix itself and RHEL at least has backported the fix to stable releases. A user who is still affected can workaround it by disabling TLS 1.3, or forcing use of a different cipher to avoid re-keying entirely.
Getting a viable workaround operating correctly in QEMU is going to be challenging and fragile long term, so not worth spending more time on.
Revert the broken workaround (which was already hardcoded to be disabled at build time).
Daniel P. Berrangé (4):
Revert "migration: activate TLS thread safety workaround" Revert "io: add support for activating TLS thread safety workaround" Revert "crypto: add tracing & warning about GNUTLS countermeasures" Revert "crypto: implement workaround for GNUTLS thread safety
problems"
crypto/tlssession.c | 103 ++---------------------------------- crypto/trace-events | 1 - include/crypto/tlssession.h | 14 ----- include/io/channel.h | 1 - io/channel-tls.c | 5 -- meson.build | 9 ---- migration/tls.c | 9 ---- 7 files changed, 3 insertions(+), 139 deletions(-)
Signature · 1 line
2.56.0
PATCH 1/4 Revert "migration: activate TLS thread safety workaround"
This reverts commit eb3618e9e259ef93f5a1a76867fbccae540fcd61.
The workaround for the GNUTLS bug was not correct and it was decided to rely on GNUTLS being patched by distros instead, or users manually disabling use of the problematic ciphers.
--- migration/tls.c | 9 --------- 1 file changed, 9 deletions(-)
migration/tls.c +0 -9
@@ -88,10 +88,6 @@ void migration_tls_channel_process_incoming(QIOChannel *ioc, Error **errp)trace_migration_tls_incoming_handshake_start ();qio_channel_set_name (QIO_CHANNEL (tioc),"migration-tls-incoming" ); -if (migrate_postcopy_ram () ||migrate_return_path ()) { -qio_channel_set_feature (QIO_CHANNEL (tioc), -QIO_CHANNEL_FEATURE_CONCURRENT_IO ); - } qio_channel_tls_handshake(tioc, migration_tls_incoming_handshake, NULL,
@@ -142,11 +138,6 @@ void migration_tls_channel_connect(MigrationState *s, QIOChannel *ioc,trace_migration_tls_outgoing_handshake_start ();qio_channel_set_name (QIO_CHANNEL (tioc),"migration-tls-outgoing" ); - -if (migrate_postcopy_ram () ||migrate_return_path ()) { -qio_channel_set_feature (QIO_CHANNEL (tioc), -QIO_CHANNEL_FEATURE_CONCURRENT_IO ); - } qio_channel_tls_handshake(tioc, migration_tls_outgoing_handshake, s,
Signature · 1 line
2.56.0
PATCH 2/4 Revert "io: add support for activating TLS thread safety workaround"
In reply to Daniel P. BerrangéThis reverts commit edea818371bd7179b55f38d3b113d342251d8f9b.
The workaround for the GNUTLS bug was not correct and it was decided to rely on GNUTLS being patched by distros instead, or users manually disabling use of the problematic ciphers.
--- include/io/channel.h | 1 - io/channel-tls.c | 5 ----- 2 files changed, 6 deletions(-)
include/io/channel.h +0 -1
@@ -47,7 +47,6 @@ enum QIOChannelFeature {QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY ,QIO_CHANNEL_FEATURE_READ_MSG_PEEK , QIO_CHANNEL_FEATURE_SEEKABLE, - QIO_CHANNEL_FEATURE_CONCURRENT_IO, };
io/channel-tls.c +0 -5
@@ -261,11 +261,6 @@ void qio_channel_tls_handshake(QIOChannelTLS *ioc, {QIOTask *task; -if (qio_channel_has_feature (QIO_CHANNEL (ioc), -QIO_CHANNEL_FEATURE_CONCURRENT_IO )) { -qcrypto_tls_session_require_thread_safety (ioc->session); - } - task =qio_task_new (OBJECT (ioc), func, opaque, destroy);
Signature · 1 line
2.56.0
PATCH 3/4 Revert "crypto: add tracing & warning about GNUTLS countermeasures"
In reply to Daniel P. BerrangéThis reverts commit 0db6f798024ea6f57ecf2020209b761b50a01d71.
The workaround for the GNUTLS bug was not correct and it was decided to rely on GNUTLS being patched by distros instead, or users manually disabling use of the problematic ciphers.
--- crypto/tlssession.c | 11 ----------- crypto/trace-events | 1 - 2 files changed, 12 deletions(-)
crypto/tlssession.c +0 -11
@@ -19,7 +19,6 @@*/ #include "qemu/osdep.h" -#include "qemu/error-report.h" #include "qemu/thread.h" #include "crypto/tlssession.h" #include "crypto/tlscredsanon.h"
@@ -572,20 +571,10 @@ qcrypto_tls_session_handshake(QCryptoTLSSession *session,* only have to protect against automatic rekeying * which doesn't trigger with CHACHA20 */ -trace_qcrypto_tls_session_parameters ( - session, - session->requireThreadSafety, -gnutls_protocol_get_version (session->handle), - cipher); -if (session->requireThreadSafety &&gnutls_protocol_get_version (session->handle) ==GNUTLS_TLS1_3 && cipher !=GNUTLS_CIPHER_CHACHA20_POLY1305 ) { -warn_report ("WARNING: activating thread safety countermeasures " -"for potentially broken GNUTLS with TLS1.3 cipher=%d" , - cipher); -trace_qcrypto_tls_session_bug1717_workaround (session); session->lockEnabled = true; }#endif
crypto/trace-events +0 -1
@@ -23,7 +23,6 @@ qcrypto_tls_session_new(void *session, void *creds, const char *hostname, const qcrypto_tls_session_check_creds(void *session, const char *status) "TLS session check creds session=%p status=%s" qcrypto_tls_session_check_x509_dn(void *session, const char *dname) "TLS session check x509 distinguished name session=%p dname=%s" qcrypto_tls_session_parameters(void *session, int threadSafety, int protocol, int cipher) "TLS session parameters session=%p threadSafety=%d protocol=%d cipher=%d" -qcrypto_tls_session_bug1717_workaround(void *session) "TLS session bug1717 workaround session=%p" # tls-cipher-suites.c qcrypto_tls_cipher_suite_priority(const char *name) "priority: %s"
Signature · 1 line
2.56.0
PATCH 4/4 Revert "crypto: implement workaround for GNUTLS thread safety problems"
In reply to Daniel P. BerrangéThis reverts commit 24ad5e19952b326796c8a3a1595c57ff180dab84.
The workaround for the GNUTLS bug was not correct and it was decided to rely on GNUTLS being patched by distros instead, or users manually disabling use of the problematic ciphers.
--- crypto/tlssession.c | 92 ++----------------------------------- include/crypto/tlssession.h | 14 ------ meson.build | 9 ---- 3 files changed, 3 insertions(+), 112 deletions(-)
crypto/tlssession.c +3 -89
@@ -19,7 +19,6 @@*/ #include "qemu/osdep.h" -#include "qemu/thread.h" #include "crypto/tlssession.h" #include "crypto/tlscredsanon.h" #include "crypto/tlscredspsk.h"
@@ -53,14 +52,6 @@ struct QCryptoTLSSession {*/ Error *rerr;Error *werr; - -/* -* Used to protect against broken GNUTLS thread safety -* https://gitlab.com/gnutls/gnutls/-/issues/1717 -*/ -bool requireThreadSafety; -bool lockEnabled; -QemuMutex lock; };
@@ -80,7 +71,6 @@ qcrypto_tls_session_free(QCryptoTLSSession *session)g_free (session->authzid);qcrypto_tls_creds_box_unref (session->credsbox);object_unref (OBJECT (session->creds)); -qemu_mutex_destroy (&session->lock);g_free (session); }
@@ -96,19 +86,10 @@ qcrypto_tls_session_push(void *opaque, const void *buf, size_t len)return -1 ; }; -if (session->lockEnabled) { -qemu_mutex_unlock (&session->lock); - } -error_free (session->werr); session->werr =NULL ; ret = session->writeFunc (buf, len, session->opaque, &session->werr); - -if (session->lockEnabled) { -qemu_mutex_lock (&session->lock); - } -if (ret ==QCRYPTO_TLS_SESSION_ERR_BLOCK ) { errno =EAGAIN ;return -1 ;
@@ -135,16 +116,7 @@ qcrypto_tls_session_pull(void *opaque, void *buf, size_t len)error_free (session->rerr); session->rerr =NULL ; -if (session->lockEnabled) { -qemu_mutex_unlock (&session->lock); - } - ret = session->readFunc (buf, len, session->opaque, &session->rerr); - -if (session->lockEnabled) { -qemu_mutex_lock (&session->lock); - } -if (ret ==QCRYPTO_TLS_SESSION_ERR_BLOCK ) { errno =EAGAIN ;return -1 ;
@@ -181,8 +153,6 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds, session->creds = creds;object_ref (OBJECT (creds)); -qemu_mutex_init (&session->lock); -if (creds->endpoint != endpoint) {error_setg (errp,"Credentials endpoint doesn't match session" ); goto error;
@@ -247,11 +217,6 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds,return NULL ; } -void qcrypto_tls_session_require_thread_safety (QCryptoTLSSession *sess) -{ - sess->requireThreadSafety = true; -} -static int qcrypto_tls_session_check_certificate (QCryptoTLSSession *session,Error **errp)
@@ -438,17 +403,7 @@ qcrypto_tls_session_write(QCryptoTLSSession *session,size_t len, Error **errp) { - ssize_t ret; - -if (session->lockEnabled) { -qemu_mutex_lock (&session->lock); - } - - ret =gnutls_record_send (session->handle, buf, len); - -if (session->lockEnabled) { -qemu_mutex_unlock (&session->lock); - } + ssize_t ret = gnutls_record_send(session->handle, buf, len);if (ret <0 ) {if (ret ==GNUTLS_E_AGAIN ) {
@@ -476,17 +431,7 @@ qcrypto_tls_session_read(QCryptoTLSSession *session,size_t len, Error **errp) { - ssize_t ret; - -if (session->lockEnabled) { -qemu_mutex_lock (&session->lock); - } - - ret =gnutls_record_recv (session->handle, buf, len); - -if (session->lockEnabled) { -qemu_mutex_unlock (&session->lock); - } + ssize_t ret = gnutls_record_recv(session->handle, buf, len);if (ret <0 ) {if (ret ==GNUTLS_E_AGAIN ) {
@@ -556,29 +501,8 @@ intqcrypto_tls_session_handshake (QCryptoTLSSession *session, Error **errp) { -int ret; - ret =gnutls_handshake (session->handle); - +int ret =gnutls_handshake (session->handle);if (!ret) { -#ifdef CONFIG_GNUTLS_BUG1717_WORKAROUND -gnutls_cipher_algorithm_t cipher = -gnutls_cipher_get (session->handle); - -/* -* Any use of rekeying in TLS 1.3 is unsafe for -* a gnutls with bug 1717, however, we know that -* QEMU won't initiate manual rekeying. Thus we -* only have to protect against automatic rekeying -* which doesn't trigger with CHACHA20 -*/ -if (session->requireThreadSafety && -gnutls_protocol_get_version (session->handle) == -GNUTLS_TLS1_3 && - cipher !=GNUTLS_CIPHER_CHACHA20_POLY1305 ) { - session->lockEnabled = true; - } -#endif - session->handshakeComplete = true;return QCRYPTO_TLS_HANDSHAKE_COMPLETE ; }
@@ -616,15 +540,8 @@ qcrypto_tls_session_bye(QCryptoTLSSession *session, Error **errp)return 0 ; } -if (session->lockEnabled) { -qemu_mutex_lock (&session->lock); - } ret =gnutls_bye (session->handle,GNUTLS_SHUT_WR ); -if (session->lockEnabled) { -qemu_mutex_unlock (&session->lock); - } -if (!ret) {return QCRYPTO_TLS_BYE_COMPLETE ; }
@@ -690,9 +607,6 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds G_GNUC_UNUSED,return NULL ; } -void qcrypto_tls_session_require_thread_safety (QCryptoTLSSession *sess) -{ -}void qcrypto_tls_session_free(QCryptoTLSSession *sess G_GNUC_UNUSED)
include/crypto/tlssession.h +0 -14
@@ -166,20 +166,6 @@ void qcrypto_tls_session_free(QCryptoTLSSession *sess);G_DEFINE_AUTOPTR_CLEANUP_FUNC (QCryptoTLSSession, qcrypto_tls_session_free) -/** -* qcrypto_tls_session_require_thread_safety: -* @sess: the TLS session object -* -* Mark that this TLS session will require thread safety -* for concurrent I/O in both directions. This must be -* called before the handshake is performed. -* -* This will activate a workaround for GNUTLS thread -* safety issues, where appropriate for the negotiated -* TLS session parameters. - */ -void qcrypto_tls_session_require_thread_safety (QCryptoTLSSession *sess); -/** * qcrypto_tls_session_check_credentials: * @sess: the TLS session object
meson.build +0 -9
@@ -1795,18 +1795,11 @@ endif gnutls = not_found gnutls_crypto = not_found -gnutls_bug1717_workaround = false if get_option('gnutls').enabled() or (get_option('gnutls').auto() and have_system) gnutls = dependency('gnutls', version: '>=3.7.5', method: 'pkg-config', required: get_option('gnutls')) gnutls_crypto = gnutls - - #if gnutls.found() and not get_option('gnutls-bug1717-workaround').disabled() - # XXX: when bug 1717 is resolved, add logic to probe for - # the GNUTLS fixed version number to handle the 'auto' case - # gnutls_bug1717_workaround = true - #endif endif # We prefer use of gnutls for crypto, unless the options
@@ -2533,7 +2526,6 @@ config_host_data.set('CONFIG_KEYUTILS', keyutils.found()) config_host_data.set('CONFIG_GETTID', has_gettid) config_host_data.set('CONFIG_GNUTLS', gnutls.found()) config_host_data.set('CONFIG_GNUTLS_CRYPTO', gnutls_crypto.found()) -config_host_data.set('CONFIG_GNUTLS_BUG1717_WORKAROUND', gnutls_bug1717_workaround) config_host_data.set('CONFIG_TASN1', tasn1.found()) config_host_data.set('CONFIG_GCRYPT', gcrypt.found()) config_host_data.set('CONFIG_NETTLE', nettle.found())
@@ -4911,7 +4903,6 @@ summary_info += {'TLS priority': get_option('tls_priority')} summary_info += {'GNUTLS support': gnutls} if gnutls.found() summary_info += {' GNUTLS crypto': gnutls_crypto.found()} - summary_info += {' GNUTLS bug 1717 workaround': gnutls_bug1717_workaround } endif summary_info += {'libgcrypt': gcrypt} summary_info += {'nettle': nettle}
Signature · 1 line
2.56.0
Quoted 21 lines · Daniel P. Berrangé
A year or so ago we introduced a workaround for a troubling GNUTLS thread safety problem that hits when a bidirectional TLS channel is used and "large" amounts of data are transferred triggering re-keying under TLS 1.3.
Unfortunately that workaround turned out to not work, and since it was close to final freeze we disabled it, rather than attempt last minute changes.
Fast forward a year, and GNUTLS has shipped a fix itself and RHEL at least has backported the fix to stable releases. A user who is still affected can workaround it by disabling TLS 1.3, or forcing use of a different cipher to avoid re-keying entirely.
Getting a viable workaround operating correctly in QEMU is going to be challenging and fragile long term, so not worth spending more time on.
Revert the broken workaround (which was already hardcoded to be disabled at build time).
Quoted 6 lines
Daniel P. Berrangé (4):
Revert "migration: activate TLS thread safety workaround" Revert "io: add support for activating TLS thread safety workaround" Revert "crypto: add tracing & warning about GNUTLS countermeasures" Revert "crypto: implement workaround for GNUTLS thread safety
problems"
Signature · 1 line
Peter Xu
Quoted 28 lines · Daniel P. Berrangé
A year or so ago we introduced a workaround for a troubling GNUTLS thread safety problem that hits when a bidirectional TLS channel is used and "large" amounts of data are transferred triggering re-keying under TLS 1.3.
Unfortunately that workaround turned out to not work, and since it was close to final freeze we disabled it, rather than attempt last minute changes.
Fast forward a year, and GNUTLS has shipped a fix itself and RHEL at least has backported the fix to stable releases. A user who is still affected can workaround it by disabling TLS 1.3, or forcing use of a different cipher to avoid re-keying entirely.
Getting a viable workaround operating correctly in QEMU is going to be challenging and fragile long term, so not worth spending more time on.
Revert the broken workaround (which was already hardcoded to be disabled at build time).
Daniel P. Berrangé (4):
Revert "migration: activate TLS thread safety workaround" Revert "io: add support for activating TLS thread safety workaround" Revert "crypto: add tracing & warning about GNUTLS countermeasures" Revert "crypto: implement workaround for GNUTLS thread safety
problems"
Quoted 8 lines
crypto/tlssession.c | 103 ++---------------------------------- crypto/trace-events | 1 - include/crypto/tlssession.h | 14 ----- include/io/channel.h | 1 - io/channel-tls.c | 5 -- meson.build | 9 ---- migration/tls.c | 9 ---- 7 files changed, 3 insertions(+), 139 deletions(-)