From 95f93f977513a6182aaef64c7f7040e0b8ded719 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Jul 05 2017 07:07:32 +0000 Subject: import qemu-kvm-1.5.3-126.el7_3.10 --- diff --git a/SOURCES/kvm-nbd-Fix-regression-on-resiliency-to-port-scan.patch b/SOURCES/kvm-nbd-Fix-regression-on-resiliency-to-port-scan.patch new file mode 100644 index 0000000..928ceab --- /dev/null +++ b/SOURCES/kvm-nbd-Fix-regression-on-resiliency-to-port-scan.patch @@ -0,0 +1,217 @@ +From 8ead1a8129b42b14a6ccddbf4c24535b3cb80209 Mon Sep 17 00:00:00 2001 +From: Eric Blake +Date: Fri, 9 Jun 2017 22:07:15 +0200 +Subject: [PATCH 2/2] nbd: Fix regression on resiliency to port scan + +RH-Author: Eric Blake +Message-id: <20170609220715.29645-3-eblake@redhat.com> +Patchwork-id: 75578 +O-Subject: [RHEL-7.3.z qemu-kvm PATCH 2/2] nbd: Fix regression on resiliency to port scan +Bugzilla: 1460179 +RH-Acked-by: Paolo Bonzini +RH-Acked-by: Stefan Hajnoczi +RH-Acked-by: Thomas Huth + +Back in qemu 2.5, qemu-nbd was immune to port probes (a transient +server would not quit, regardless of how many probe connections +came and went, until a connection actually negotiated). But we +broke that in commit ee7d7aa when removing the return value to +nbd_client_new(), although that patch also introduced a bug causing +an assertion failure on a client that fails negotiation. We then +made it worse during refactoring in commit 1a6245a (a segfault +before we could even assert); the (masked) assertion was cleaned +up in d3780c2 (still in 2.6), and just recently we finally fixed +the segfault ("nbd: Fully intialize client in case of failed +negotiation"). But that still means that ever since we added +TLS support to qemu-nbd, we have been vulnerable to an ill-timed +port-scan being able to cause a denial of service by taking down +qemu-nbd before a real client has a chance to connect. + +Since negotiation is now handled asynchronously via coroutines, +we no longer have a synchronous point of return by re-adding a +return value to nbd_client_new(). So this patch instead wires +things up to pass the negotiation status through the close_fn +callback function. + +Simple test across two terminals: +$ qemu-nbd -f raw -p 30001 file +$ nmap 127.0.0.1 -p 30001 && \ + qemu-io -c 'r 0 512' -f raw nbd://localhost:30001 + +Note that this patch does not change what constitutes successful +negotiation (thus, a client must enter transmission phase before +that client can be considered as a reason to terminate the server +when the connection ends). Perhaps we may want to tweak things +in a later patch to also treat a client that uses NBD_OPT_ABORT +as being a 'successful' negotiation (the client correctly talked +the NBD protocol, and informed us it was not going to use our +export after all), but that's a discussion for another day. + +Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1451614 + +Signed-off-by: Eric Blake +Message-Id: <20170608222617.20376-1-eblake@redhat.com> +(cherry picked from commit ???) +https://bugzilla.redhat.com/show_bug.cgi?id=1460179 +Signed-off-by: Miroslav Rezanina + +Conflicts: + blockdev-nbd.c - context + include/block/nbd.h - context with nbd_client_new parameters, + nbd_client_close not static + nbd/server.c - in nbd.c instead, context, comment to nbd_client_new + matching different parameters + qemu-nbd.c - context +--- + blockdev-nbd.c | 7 ++++++- + include/block/nbd.h | 5 +++-- + nbd.c | 25 ++++++++++++++++--------- + qemu-nbd.c | 4 ++-- + 4 files changed, 27 insertions(+), 14 deletions(-) + +diff --git a/blockdev-nbd.c b/blockdev-nbd.c +index 922cf56..dc7cffa 100644 +--- a/blockdev-nbd.c ++++ b/blockdev-nbd.c +@@ -21,6 +21,11 @@ + + static int server_fd = -1; + ++static void nbd_blockdev_client_closed(NBDClient *client, bool ignored) ++{ ++ nbd_client_put(client); ++} ++ + static void nbd_accept(void *opaque) + { + struct sockaddr_in addr; +@@ -28,7 +33,7 @@ static void nbd_accept(void *opaque) + + int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len); + if (fd >= 0) { +- nbd_client_new(NULL, fd, nbd_client_put); ++ nbd_client_new(NULL, fd, nbd_blockdev_client_closed); + } + } + +diff --git a/include/block/nbd.h b/include/block/nbd.h +index 92e360e..963c7ce 100644 +--- a/include/block/nbd.h ++++ b/include/block/nbd.h +@@ -92,8 +92,9 @@ NBDExport *nbd_export_find(const char *name); + void nbd_export_set_name(NBDExport *exp, const char *name); + void nbd_export_close_all(void); + +-void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *)); +-void nbd_client_close(NBDClient *client); ++void nbd_client_new(NBDExport *exp, int csock, ++ void (*close_fn)(NBDClient *, bool)); ++void nbd_client_close(NBDClient *client, bool negotiated); + void nbd_client_get(NBDClient *client); + void nbd_client_put(NBDClient *client); + +diff --git a/nbd.c b/nbd.c +index b5cdc1b..c3d554d 100644 +--- a/nbd.c ++++ b/nbd.c +@@ -105,7 +105,7 @@ static QTAILQ_HEAD(, NBDExport) exports = QTAILQ_HEAD_INITIALIZER(exports); + + struct NBDClient { + int refcount; +- void (*close)(NBDClient *client); ++ void (*close_fn)(NBDClient *client, bool negotiated); + + NBDExport *exp; + int sock; +@@ -862,7 +862,7 @@ void nbd_client_put(NBDClient *client) + } + } + +-void nbd_client_close(NBDClient *client) ++void nbd_client_close(NBDClient *client, bool negotiated) + { + if (client->closing) { + return; +@@ -876,8 +876,8 @@ void nbd_client_close(NBDClient *client) + shutdown(client->sock, 2); + + /* Also tell the client, so that they release their reference. */ +- if (client->close) { +- client->close(client); ++ if (client->close_fn) { ++ client->close_fn(client, negotiated); + } + } + +@@ -964,7 +964,7 @@ void nbd_export_close(NBDExport *exp) + + nbd_export_get(exp); + QTAILQ_FOREACH_SAFE(client, &exp->clients, next, next) { +- nbd_client_close(client); ++ nbd_client_close(client, true); + } + nbd_export_set_name(exp, NULL); + nbd_export_put(exp); +@@ -1244,7 +1244,7 @@ done: + + out: + nbd_request_put(req); +- nbd_client_close(client); ++ nbd_client_close(client, true); + } + + static int nbd_can_read(void *opaque) +@@ -1285,7 +1285,7 @@ static coroutine_fn void nbd_co_client_start(void *opaque) + qemu_set_nonblock(client->sock); + qemu_co_mutex_init(&client->send_lock); + if (nbd_negotiate(data)) { +- nbd_client_close(client); ++ nbd_client_close(client, false); + goto out; + } + qemu_set_fd_handler2(client->sock, nbd_can_read, nbd_read, NULL, client); +@@ -1294,7 +1294,14 @@ out: + g_free(data); + } + +-void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *)) ++/* ++ * Create a new client listener on the given export @exp, using the ++ * given socket @csock. Begin servicing it in a coroutine. When the ++ * connection closes, call @close_fn with an indication of whether the ++ * client completed negotiation. ++ */ ++void nbd_client_new(NBDExport *exp, int csock, ++ void (*close_fn)(NBDClient *, bool)) + { + NBDClient *client; + NBDClientNewData *data = g_new(NBDClientNewData, 1); +@@ -1303,7 +1310,7 @@ void nbd_client_new(NBDExport *exp, int csock, void (*close_fn)(NBDClient *)) + client->refcount = 1; + client->exp = exp; + client->sock = csock; +- client->close = close_fn; ++ client->close_fn = close_fn; + + data->client = client; + data->co = qemu_coroutine_create(nbd_co_client_start); +diff --git a/qemu-nbd.c b/qemu-nbd.c +index cde7431..e0f4517 100644 +--- a/qemu-nbd.c ++++ b/qemu-nbd.c +@@ -276,10 +276,10 @@ static void nbd_export_closed(NBDExport *exp) + state = TERMINATED; + } + +-static void nbd_client_closed(NBDClient *client) ++static void nbd_client_closed(NBDClient *client, bool negotiated) + { + nb_fds--; +- if (nb_fds == 0 && !persistent && state == RUNNING) { ++ if (negotiated && nb_fds == 0 && !persistent && state == RUNNING) { + state = TERMINATE; + } + qemu_notify_event(); +-- +1.8.3.1 + diff --git a/SOURCES/kvm-nbd-Fully-initialize-client-in-case-of-failed-negoti.patch b/SOURCES/kvm-nbd-Fully-initialize-client-in-case-of-failed-negoti.patch new file mode 100644 index 0000000..765e2e7 --- /dev/null +++ b/SOURCES/kvm-nbd-Fully-initialize-client-in-case-of-failed-negoti.patch @@ -0,0 +1,97 @@ +From e34b480cd9a1fb23e361a514c98439672140bd37 Mon Sep 17 00:00:00 2001 +From: Eric Blake +Date: Fri, 9 Jun 2017 22:07:14 +0200 +Subject: [PATCH 1/2] nbd: Fully initialize client in case of failed + negotiation + +RH-Author: Eric Blake +Message-id: <20170609220715.29645-2-eblake@redhat.com> +Patchwork-id: 75580 +O-Subject: [RHEL-7.3.z qemu-kvm PATCH 1/2] nbd: Fully initialize client in case of failed negotiation +Bugzilla: 1460179 +RH-Acked-by: Paolo Bonzini +RH-Acked-by: Stefan Hajnoczi +RH-Acked-by: Thomas Huth + +If a non-NBD client connects to qemu-nbd, we would end up with +a SIGSEGV in nbd_client_put() because we were trying to +unregister the client's association to the export, even though +we skipped inserting the client into that list. Easy trigger +in two terminals: + +$ qemu-nbd -p 30001 --format=raw file +$ nmap 127.0.0.1 -p 30001 + +nmap claims that it thinks it connected to a pago-services1 +server (which probably means nmap could be updated to learn the +NBD protocol and give a more accurate diagnosis of the open +port - but that's not our problem), then terminates immediately, +so our call to nbd_negotiate() fails. The fix is to reorder +nbd_co_client_start() to ensure that all initialization occurs +before we ever try talking to a client in nbd_negotiate(), so +that the teardown sequence on negotiation failure doesn't fault +while dereferencing a half-initialized object. + +While debugging this, I also noticed that nbd_update_server_watch() +called by nbd_client_closed() was still adding a channel to accept +the next client, even when the state was no longer RUNNING. That +is fixed by making nbd_can_accept() pay attention to the current +state. + +Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1451614 + +Signed-off-by: Eric Blake +Message-Id: <20170527030421.28366-1-eblake@redhat.com> +Signed-off-by: Paolo Bonzini +(cherry picked from commit ???) +https://bugzilla.redhat.com/show_bug.cgi?id=1460179 +Signed-off-by: Miroslav Rezanina + +Conflicts: + nbd/server.c - code lives in nbd.c instead, with older handlers +--- + nbd.c | 6 ++---- + qemu-nbd.c | 2 +- + 2 files changed, 3 insertions(+), 5 deletions(-) + +diff --git a/nbd.c b/nbd.c +index 8a32e18..b5cdc1b 100644 +--- a/nbd.c ++++ b/nbd.c +@@ -1280,18 +1280,16 @@ static coroutine_fn void nbd_co_client_start(void *opaque) + + if (exp) { + nbd_export_get(exp); ++ QTAILQ_INSERT_TAIL(&exp->clients, client, next); + } + qemu_set_nonblock(client->sock); ++ qemu_co_mutex_init(&client->send_lock); + if (nbd_negotiate(data)) { + nbd_client_close(client); + goto out; + } +- qemu_co_mutex_init(&client->send_lock); + qemu_set_fd_handler2(client->sock, nbd_can_read, nbd_read, NULL, client); + +- if (exp) { +- QTAILQ_INSERT_TAIL(&exp->clients, client, next); +- } + out: + g_free(data); + } +diff --git a/qemu-nbd.c b/qemu-nbd.c +index 047dd49..cde7431 100644 +--- a/qemu-nbd.c ++++ b/qemu-nbd.c +@@ -267,7 +267,7 @@ out: + + static int nbd_can_accept(void *opaque) + { +- return nb_fds < shared; ++ return state == RUNNING && nb_fds < shared; + } + + static void nbd_export_closed(NBDExport *exp) +-- +1.8.3.1 + diff --git a/SPECS/qemu-kvm.spec b/SPECS/qemu-kvm.spec index e9786e4..69085fe 100644 --- a/SPECS/qemu-kvm.spec +++ b/SPECS/qemu-kvm.spec @@ -76,7 +76,7 @@ Obsoletes: %1 < %{obsoletes_version} \ Summary: QEMU is a FAST! processor emulator Name: %{pkgname}%{?pkgsuffix} Version: 1.5.3 -Release: 126%{?dist}.9 +Release: 126%{?dist}.10 # Epoch because we pushed a qemu-1.0 package. AIUI this can't ever be dropped Epoch: 10 License: GPLv2+ and LGPLv2+ and BSD @@ -3486,6 +3486,10 @@ Patch1713: kvm-serial-remove-watch-on-reset.patch Patch1714: kvm-char-change-qemu_chr_fe_add_watch-to-return-unsigned.patch # For bz#1452332 - RHEL 7.2 based VM (Virtual Machine) hung for several hours apparently waiting for lock held by main_loop Patch1715: kvm-spice-fix-spice_chr_add_watch-pre-condition.patch +# For bz#1460179 - CVE-2017-9524 qemu-kvm: Qemu: nbd: segmentation fault due to client non-negotiation [rhel-7.3.z] +Patch1716: kvm-nbd-Fully-initialize-client-in-case-of-failed-negoti.patch +# For bz#1460179 - CVE-2017-9524 qemu-kvm: Qemu: nbd: segmentation fault due to client non-negotiation [rhel-7.3.z] +Patch1717: kvm-nbd-Fix-regression-on-resiliency-to-port-scan.patch BuildRequires: zlib-devel @@ -5381,6 +5385,8 @@ cp %{SOURCE18} pc-bios # keep "make check" happy %patch1713 -p1 %patch1714 -p1 %patch1715 -p1 +%patch1716 -p1 +%patch1717 -p1 %build buildarch="%{kvm_target}-softmmu" @@ -5826,6 +5832,12 @@ sh %{_sysconfdir}/sysconfig/modules/kvm.modules &> /dev/null || : %{_mandir}/man8/qemu-nbd.8* %changelog +* Fri Jun 16 2017 Miroslav Rezanina - 1.5.3-126.el7_3.10 +- kvm-nbd-Fully-initialize-client-in-case-of-failed-negoti.patch [bz#1460179] +- kvm-nbd-Fix-regression-on-resiliency-to-port-scan.patch [bz#1460179] +- Resolves: bz#1460179 + (CVE-2017-9524 qemu-kvm: Qemu: nbd: segmentation fault due to client non-negotiation [rhel-7.3.z]) + * Tue Jun 06 2017 Miroslav Rezanina - 1.5.3-126.el7_3.9 - kvm-spice-fix-spice_chr_add_watch-pre-condition.patch [bz#1452332] - Resolves: bz#1452332