Skip to content

Commit

Permalink
[AUTO-CHERRYPICK] Fix qemu CVE-2023-3354 - branch main (microsoft#6851)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Behrens <[email protected]>
  • Loading branch information
CBL-Mariner-Bot and fintelia committed Nov 27, 2023
1 parent 5a2713c commit 01e2d39
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
83 changes: 83 additions & 0 deletions SPECS/qemu/CVE-2023-3354.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
From 10be627d2b5ec2d6b3dce045144aa739eef678b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <[email protected]>
Date: Tue, 20 Jun 2023 09:45:34 +0100
Subject: [PATCH] io: remove io watch if TLS channel is closed during handshake
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 <[email protected]>
Signed-off-by: Daniel P. Berrangé <[email protected]>
---
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.34.1

6 changes: 5 additions & 1 deletion SPECS/qemu/qemu.spec
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Obsoletes: %{name}-system-unicore32-core <= %{version}-%{release}
Summary: QEMU is a FAST! processor emulator
Name: qemu
Version: 6.2.0
Release: 18%{?dist}
Release: 19%{?dist}
License: BSD AND CC-BY AND GPLv2+ AND LGPLv2+ AND MIT
Vendor: Microsoft Corporation
Distribution: Mariner
Expand Down Expand Up @@ -274,6 +274,7 @@ Patch1013: CVE-2022-3165.patch
# https://gitlab.com/qemu-project/qemu/-/issues/541
Patch1014: CVE-2021-3750.patch
Patch1015: CVE-2022-36648.patch
Patch1016: CVE-2023-3354.patch

# alsa audio output
BuildRequires: alsa-lib-devel
Expand Down Expand Up @@ -2308,6 +2309,9 @@ useradd -r -u 107 -g qemu -G kvm -d / -s %{_sbindir}/nologin \


%changelog
* Mon Oct 30 2023 Jonathan Behrens <[email protected]> - 6.2.0-19
- Address CVE-2023-3354

* Wed Sep 20 2023 Jon Slobodzian <[email protected]> - 6.2.0-18
- Recompile with stack-protection fixed gcc version (CVE-2023-4039)

Expand Down

0 comments on commit 01e2d39

Please sign in to comment.