qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] io: remove io watch if TLS channel is closed during handshake
@ 2023-07-12 16:55 Daniel P. Berrangé
  2023-07-17 10:47 ` Michael Tokarev
  2023-08-01 17:37 ` Michael Tokarev
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2023-07-12 16:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Michael Tokarev, Marc-André Lureau,
	qemu-stable, Mauro Matteo Cascella, jiangyegen

The TLS handshake make take some time to complete, during which time an
I/O watch might be registered with the main loop. If the owner of the
I/O channel invokes qio_channel_close() while the handshake is waiting
to continue the I/O watch must be removed. Failing to remove it will
later trigger the completion callback which the owner is not expecting
to receive. In the case of the VNC server, this results in a SEGV as
vnc_disconnect_start() tries to shutdown a client connection that is
already gone / NULL.

CVE-2023-3354
Reported-by: jiangyegen <jiangyegen@huawei.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---

In v2:

 - Use g_clear_handle_id to set source ID to zero

 include/io/channel-tls.h |  1 +
 io/channel-tls.c         | 18 ++++++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/io/channel-tls.h b/include/io/channel-tls.h
index 5672479e9e..26c67f17e2 100644
--- a/include/io/channel-tls.h
+++ b/include/io/channel-tls.h
@@ -48,6 +48,7 @@ struct QIOChannelTLS {
     QIOChannel *master;
     QCryptoTLSSession *session;
     QIOChannelShutdown shutdown;
+    guint hs_ioc_tag;
 };
 
 /**
diff --git a/io/channel-tls.c b/io/channel-tls.c
index 9805dd0a3f..847d5297c3 100644
--- a/io/channel-tls.c
+++ b/io/channel-tls.c
@@ -198,12 +198,13 @@ static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc,
         }
 
         trace_qio_channel_tls_handshake_pending(ioc, status);
-        qio_channel_add_watch_full(ioc->master,
-                                   condition,
-                                   qio_channel_tls_handshake_io,
-                                   data,
-                                   NULL,
-                                   context);
+        ioc->hs_ioc_tag =
+            qio_channel_add_watch_full(ioc->master,
+                                       condition,
+                                       qio_channel_tls_handshake_io,
+                                       data,
+                                       NULL,
+                                       context);
     }
 }
 
@@ -218,6 +219,7 @@ static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc,
     QIOChannelTLS *tioc = QIO_CHANNEL_TLS(
         qio_task_get_source(task));
 
+    tioc->hs_ioc_tag = 0;
     g_free(data);
     qio_channel_tls_handshake_task(tioc, task, context);
 
@@ -378,6 +380,10 @@ static int qio_channel_tls_close(QIOChannel *ioc,
 {
     QIOChannelTLS *tioc = QIO_CHANNEL_TLS(ioc);
 
+    if (tioc->hs_ioc_tag) {
+        g_clear_handle_id(&tioc->hs_ioc_tag, g_source_remove);
+    }
+
     return qio_channel_close(tioc->master, errp);
 }
 
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] io: remove io watch if TLS channel is closed during handshake
  2023-07-12 16:55 [PATCH v2] io: remove io watch if TLS channel is closed during handshake Daniel P. Berrangé
@ 2023-07-17 10:47 ` Michael Tokarev
  2023-08-01 17:37 ` Michael Tokarev
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Tokarev @ 2023-07-17 10:47 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Marc-André Lureau, qemu-stable, Mauro Matteo Cascella,
	jiangyegen

12.07.2023 19:55, Daniel P. Berrangé wrote:
> The TLS handshake make take some time to complete, during which time an
> I/O watch might be registered with the main loop. If the owner of the
> I/O channel invokes qio_channel_close() while the handshake is waiting
> to continue the I/O watch must be removed. Failing to remove it will
> later trigger the completion callback which the owner is not expecting
> to receive. In the case of the VNC server, this results in a SEGV as
> vnc_disconnect_start() tries to shutdown a client connection that is
> already gone / NULL.
> 
> CVE-2023-3354
> Reported-by: jiangyegen <jiangyegen@huawei.com>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
> 
> In v2:
> 
>   - Use g_clear_handle_id to set source ID to zero
> 
>   include/io/channel-tls.h |  1 +
>   io/channel-tls.c         | 18 ++++++++++++------
>   2 files changed, 13 insertions(+), 6 deletions(-)

I can't say I completely understand what's going on here,
but I tried to understand it.  And it looks like the patch
is doing the right thing.  Dunno if I can add my

Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>

Thank you for the good work Daniel!

/mjt


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] io: remove io watch if TLS channel is closed during handshake
  2023-07-12 16:55 [PATCH v2] io: remove io watch if TLS channel is closed during handshake Daniel P. Berrangé
  2023-07-17 10:47 ` Michael Tokarev
@ 2023-08-01 17:37 ` Michael Tokarev
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Tokarev @ 2023-08-01 17:37 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel
  Cc: Marc-André Lureau, qemu-stable, Mauro Matteo Cascella,
	jiangyegen

12.07.2023 19:55, Daniel P. Berrangé wrote:
> The TLS handshake make take some time to complete, during which time an
> I/O watch might be registered with the main loop. If the owner of the
> I/O channel invokes qio_channel_close() while the handshake is waiting
> to continue the I/O watch must be removed. Failing to remove it will
> later trigger the completion callback which the owner is not expecting
> to receive. In the case of the VNC server, this results in a SEGV as
> vnc_disconnect_start() tries to shutdown a client connection that is
> already gone / NULL.
> 
> CVE-2023-3354
> Reported-by: jiangyegen <jiangyegen@huawei.com>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Can we have this in 8.1 please?

What's needed to get this one into 8.1?

/mjt


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-01 17:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-12 16:55 [PATCH v2] io: remove io watch if TLS channel is closed during handshake Daniel P. Berrangé
2023-07-17 10:47 ` Michael Tokarev
2023-08-01 17:37 ` Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).