crypto: propagate Error object on premature termination
PATCH 1/1 crypto: propagate Error object on premature termination
The way that premature termination was handled in TLS connections was changed to handle an ordering problem during graceful shutdown in the migration code.
Unfortunately one of the codepaths returned -1 to indicate an error condition, but failed to set the 'errp' parameter.
This broke error handling in the qio_channel_tls_handshake function, as the QTask callback would no longer see that an error was raised. As a result, the client will go on to try to use the already closed TLS connection, resulting in misleading errors.
This was evidenced in the I/O test 233 which showed changes such as
-qemu-nbd: Certificate does not match the hostname localhost
+qemu-nbd: Failed to read initial magic: Unable to read from socket: Connection reset by peer
--- crypto/tlssession.c | 8 +++++--- io/channel-tls.c | 13 +++++++------ 2 files changed, 12 insertions(+), 9 deletions(-)
crypto/tlssession.c +5 -3
@@ -569,8 +569,6 @@ qcrypto_tls_session_read(QCryptoTLSSession *session,if (ret <0 ) {if (ret ==GNUTLS_E_AGAIN ) {return QCRYPTO_TLS_SESSION_ERR_BLOCK ; - }else if (ret ==GNUTLS_E_PREMATURE_TERMINATION ) { -return QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ; }else {if (session->rerr) {error_propagate (errp, session->rerr);
@@ -580,7 +578,11 @@ qcrypto_tls_session_read(QCryptoTLSSession *session,"Cannot read from TLS channel: %s" , gnutls_strerror(ret)); } -return -1 ; +if (ret ==GNUTLS_E_PREMATURE_TERMINATION ) { +return QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ; + }else { +return -1 ; + } } }
io/channel-tls.c +7 -6
@@ -368,6 +368,7 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc,int flags, Error **errp) { +ERRP_GUARD ();QIOChannelTLS *tioc =QIO_CHANNEL_TLS (ioc);size_t i;ssize_t got =0 ;
@@ -384,13 +385,13 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc, }else {return QIO_CHANNEL_ERR_BLOCK ; } - }else if (ret ==QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ) { -if (qio_channel_tls_allow_premature_termination (tioc, flags)) { - ret =0 ; - }else { -return -1 ; - } }else if (ret <0 ) { +if (ret ==QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION && +qio_channel_tls_allow_premature_termination (tioc, flags)) { +error_free (*errp); + *errp =NULL ; +return got; + }return -1 ; } got += ret;
Signature · 1 line
2.50.1
Quoted 7 lines · Daniel P. Berrangé
The way that premature termination was handled in TLS connections was changed to handle an ordering problem during graceful shutdown in the migration code.
Unfortunately one of the codepaths returned -1 to indicate an error condition, but failed to set the 'errp' parameter.
Quoted 6 lines
This broke error handling in the
qio_channel_tls_handshakefunction, as the QTask callback would no longer see that an error was raised. As a result, the client will go on to try to use the already closed TLS connection, resulting in misleading errors.This was evidenced in the I/O test 233 which showed changes such as
Oops..
Quoted 50 lines
(quoted diff) +1
-1-qemu-nbd: Certificate does not match the hostname localhost +qemu-nbd: Failed to read initial magic: Unable to read from socket: Connection reset by peerFixes 7e0c22d585581b8083ffdeb332ea497218665dafSigned-off-by Daniel P. Berrangé <[email protected]>--- crypto/tlssession.c | 8 +++++--- io/channel-tls.c | 13 +++++++------ 2 files changed, 12 insertions(+), 9 deletions(-)crypto/tlssession.c +5
-3@@ -569,8 +569,6 @@ qcrypto_tls_session_read(QCryptoTLSSession *session,if (ret <0 ) {if (ret ==GNUTLS_E_AGAIN ) {return QCRYPTO_TLS_SESSION_ERR_BLOCK ; - }else if (ret ==GNUTLS_E_PREMATURE_TERMINATION ) { -return QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ; }else {if (session->rerr) {error_propagate (errp, session->rerr);@@ -580,7 +578,11 @@ qcrypto_tls_session_read(QCryptoTLSSession *session,"Cannot read from TLS channel: %s" , gnutls_strerror(ret)); } -return -1 ; +if (ret ==GNUTLS_E_PREMATURE_TERMINATION ) { +return QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ; + }else { +return -1 ; + } } }io/channel-tls.c +1
-0@@ -368,6 +368,7 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc,int flags, Error **errp) { +ERRP_GUARD ();QIOChannelTLS *tioc =QIO_CHANNEL_TLS (ioc);size_t i;ssize_t got =0 ;
io/channel-tls.c static ssize_t qio_channel_tls_readv(QIOChannel *ioc, · line 390
Quoted 7 lines
io/channel-tls.c +0
-4@@ -384,13 +385,13 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc, }else {return QIO_CHANNEL_ERR_BLOCK ; } - }else if (ret ==QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ) { -if (qio_channel_tls_allow_premature_termination (tioc, flags)) { - ret =0 ; - }else {
Would it be simpler to set error only here (and also we can have an explicit error message for the premature termination)?
No strong opinions.. feel free to use whatever version:
Thanks!
Quoted 15 lines
io/channel-tls.c +6
-2-return -1 ; - } }else if (ret <0 ) { +if (ret ==QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION && +qio_channel_tls_allow_premature_termination (tioc, flags)) { +error_free (*errp); + *errp =NULL ; +return got; + }return -1 ; } got += ret;Signature · 1 line
2.50.1
Signature · 1 line
Peter Xu
Quoted 69 lines · Peter Xu
Quoted 7 lines · Daniel P. Berrangé
The way that premature termination was handled in TLS connections was changed to handle an ordering problem during graceful shutdown in the migration code.
Unfortunately one of the codepaths returned -1 to indicate an error condition, but failed to set the 'errp' parameter.
Quoted 6 lines
This broke error handling in the
qio_channel_tls_handshakefunction, as the QTask callback would no longer see that an error was raised. As a result, the client will go on to try to use the already closed TLS connection, resulting in misleading errors.This was evidenced in the I/O test 233 which showed changes such as
Oops..
Quoted 52 lines
(quoted diff) +1
-1-qemu-nbd: Certificate does not match the hostname localhost +qemu-nbd: Failed to read initial magic: Unable to read from socket: Connection reset by peerFixes 7e0c22d585581b8083ffdeb332ea497218665dafSigned-off-by Daniel P. Berrangé <[email protected]>--- crypto/tlssession.c | 8 +++++--- io/channel-tls.c | 13 +++++++------ 2 files changed, 12 insertions(+), 9 deletions(-)crypto/tlssession.c +5
-3@@ -569,8 +569,6 @@ qcrypto_tls_session_read(QCryptoTLSSession *session,if (ret <0 ) {if (ret ==GNUTLS_E_AGAIN ) {return QCRYPTO_TLS_SESSION_ERR_BLOCK ; - }else if (ret ==GNUTLS_E_PREMATURE_TERMINATION ) { -return QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ; }else {if (session->rerr) {error_propagate (errp, session->rerr);@@ -580,7 +578,11 @@ qcrypto_tls_session_read(QCryptoTLSSession *session,"Cannot read from TLS channel: %s" , gnutls_strerror(ret)); } -return -1 ; +if (ret ==GNUTLS_E_PREMATURE_TERMINATION ) { +return QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ; + }else { +return -1 ; + } } }io/channel-tls.c +1
-0@@ -368,6 +368,7 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc,int flags, Error **errp) { +ERRP_GUARD ();QIOChannelTLS *tioc =QIO_CHANNEL_TLS (ioc);size_t i;ssize_t got =0 ;@@ -384,13 +385,13 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc, }else {return QIO_CHANNEL_ERR_BLOCK ;
Quoted 8 lines
io/channel-tls.c static ssize_t qio_channel_tls_readv(QIOChannel *ioc, · line 390
Quoted 5 lines
io/channel-tls.c +0
-4} - }else if (ret ==QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION ) { -if (qio_channel_tls_allow_premature_termination (tioc, flags)) { - ret =0 ; - }else {Would it be simpler to set error only here (and also we can have an explicit error message for the premature termination)?
I wanted to retain the original GNUTLS provided error message, which is not available here, so must set it in the tlssession.c file.
Quoted 6 lines
No strong opinions.. feel free to use whatever version:
Acked-by Peter Xu <[email protected]>Thanks!
Quoted 19 lines
Quoted 15 lines
io/channel-tls.c +6
-2-return -1 ; - } }else if (ret <0 ) { +if (ret ==QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION && +qio_channel_tls_allow_premature_termination (tioc, flags)) { +error_free (*errp); + *errp =NULL ; +return got; + }return -1 ; } got += ret;Signature · 1 line
2.50.1Signature · 1 line
Peter Xu
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 17 lines · Daniel P. Berrangé
The way that premature termination was handled in TLS connections was changed to handle an ordering problem during graceful shutdown in the migration code.
Unfortunately one of the codepaths returned -1 to indicate an error condition, but failed to set the 'errp' parameter.
This broke error handling in the
qio_channel_tls_handshakefunction, as the QTask callback would no longer see that an error was raised. As a result, the client will go on to try to use the already closed TLS connection, resulting in misleading errors.This was evidenced in the I/O test 233 which showed changes such as
(quoted diff) +1
-1-qemu-nbd: Certificate does not match the hostname localhost +qemu-nbd: Failed to read initial magic: Unable to read from socket: Connection reset by peer
Quoted 6 lines
Fixes 7e0c22d585581b8083ffdeb332ea497218665dafSigned-off-by Daniel P. Berrangé <[email protected]>--- crypto/tlssession.c | 8 +++++--- io/channel-tls.c | 13 +++++++------ 2 files changed, 12 insertions(+), 9 deletions(-)
Thanks; queued in my NBD tree, since I have further patches that will further alter the output of 233 to give more details about NBD devices.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org