chardev: close QIOChannel before unref'ing
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 5 Jan 2024 16:09:52 +0000 (16:09 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 9 Feb 2024 12:50:26 +0000 (12:50 +0000)
The chardev socket backend will unref the QIOChannel object while
it is still potentially open. When using TLS there could be a
pending TLS handshake taking place. If the channel is left open
then when the TLS handshake callback runs, it can end up accessing
free'd memory in the tcp_chr_tls_handshake method.

Closing the QIOChannel will unregister any pending handshake
source.

Reported-by: jiangyegen <jiangyegen@huawei.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
chardev/char-socket.c

index 73947da188d68d78fdb3ca78f4045db3519aab7a..7105753815255d89c6f3297f3b159ef42a69754e 100644 (file)
@@ -378,6 +378,10 @@ static void tcp_chr_free_connection(Chardev *chr)
                                  char_socket_yank_iochannel,
                                  QIO_CHANNEL(s->sioc));
     }
+
+    if (s->ioc) {
+        qio_channel_close(s->ioc, NULL);
+    }
     object_unref(OBJECT(s->sioc));
     s->sioc = NULL;
     object_unref(OBJECT(s->ioc));