Skip to contentSkip to conversation

char: fix missing return in error path for chardev TLS init

PATCH Applied Daniel P. Berrange 3 participants 3 messages Sep 30, 2016 – Oct 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 char: fix missing return in error path for chardev TLS init

If the qio_channel_tls_new_(server|client) methods fail, we disconnect the client. Unfortunately a missing return means we then go on to try and run the TLS handshake on a NULL I/O channel. This gives predictably segfaulty results.

The main way to trigger this is to request a bogus TLS priority string for the TLS credentials. e.g.

-object tls-creds-x509,id=tls0,priority=wibble,...

Most other ways appear impossible to trigger except perhaps if OOM conditions cause gnutls initialization to fail.

---
 qemu-char.c | 1 +
 1 file changed, 1 insertion(+)
qemu-char.c +1 -0
index fb456ce..48a45ef 100644
@@ -3132,6 +3132,7 @@ static void tcp_chr_tls_init(CharDriverState *chr)
     if (tioc == NULL) {
         error_free(err);
         tcp_chr_disconnect(chr);
+        return;
     }
     object_unref(OBJECT(s->ioc));
     s->ioc = QIO_CHANNEL(tioc);
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Daniel P. Berrange

If the qio_channel_tls_new_(server|client) methods fail, we disconnect the client. Unfortunately a missing return means we then go on to try and run the TLS handshake on a NULL I/O channel. This gives predictably segfaulty results.

The main way to trigger this is to request a bogus TLS priority string for the TLS credentials. e.g.

-object tls-creds-x509,id=tls0,priority=wibble,...

Quoted 8 lines

Most other ways appear impossible to trigger except perhaps if OOM conditions cause gnutls initialization to fail.

---
 qemu-char.c | 1 +
 1 file changed, 1 insertion(+)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Daniel P. Berrange
Quoted 5 lines · Daniel P. Berrange

If the qio_channel_tls_new_(server|client) methods fail, we disconnect the client. Unfortunately a missing return means we then go on to try and run the TLS handshake on a NULL I/O channel. This gives predictably segfaulty results.

Applied to -trivial, thanks!

/mjt