Blame SOURCES/kvm-nbd-server-CVE-2017-15118-Stack-smash-on-large-expor.patch

4a2fec
From dd7511a6effe839c73ed8f71ceaa3c53f16ebdbd Mon Sep 17 00:00:00 2001
4a2fec
From: Eric Blake <eblake@redhat.com>
4a2fec
Date: Wed, 13 Dec 2017 18:17:30 +0100
4a2fec
Subject: [PATCH 5/6] nbd/server: CVE-2017-15118 Stack smash on large export
4a2fec
 name
4a2fec
4a2fec
RH-Author: Eric Blake <eblake@redhat.com>
4a2fec
Message-id: <20171213181730.1278-3-eblake@redhat.com>
4a2fec
Patchwork-id: 78393
4a2fec
O-Subject: [RHEV-7.5 qemu-kvm-rhev PATCH 2/2] nbd/server: CVE-2017-15118 Stack smash on large export name
4a2fec
Bugzilla: 1516545 1518548
4a2fec
CVE: CVE-2017-15118/20171128
4a2fec
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
RH-Acked-by: John Snow <jsnow@redhat.com>
4a2fec
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
4a2fec
Introduced in commit f37708f6b8 (2.10).  The NBD spec says a client
4a2fec
can request export names up to 4096 bytes in length, even though
4a2fec
they should not expect success on names longer than 256.  However,
4a2fec
qemu hard-codes the limit of 256, and fails to filter out a client
4a2fec
that probes for a longer name; the result is a stack smash that can
4a2fec
potentially give an attacker arbitrary control over the qemu
4a2fec
process.
4a2fec
4a2fec
The smash can be easily demonstrated with this client:
4a2fec
$ qemu-io f raw nbd://localhost:10809/$(printf %3000d 1 | tr ' ' a)
4a2fec
4a2fec
If the qemu NBD server binary (whether the standalone qemu-nbd, or
4a2fec
the builtin server of QMP nbd-server-start) was compiled with
4a2fec
-fstack-protector-strong, the ability to exploit the stack smash
4a2fec
into arbitrary execution is a lot more difficult (but still
4a2fec
theoretically possible to a determined attacker, perhaps in
4a2fec
combination with other CVEs).  Still, crashing a running qemu (and
4a2fec
losing the VM) is bad enough, even if the attacker did not obtain
4a2fec
full execution control.
4a2fec
4a2fec
CC: qemu-stable@nongnu.org
4a2fec
Signed-off-by: Eric Blake <eblake@redhat.com>
4a2fec
(cherry picked from commit 51ae4f8455c9e32c54770c4ebc25bf86a8128183)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 nbd/server.c | 4 ++++
4a2fec
 1 file changed, 4 insertions(+)
4a2fec
4a2fec
diff --git a/nbd/server.c b/nbd/server.c
4a2fec
index b93cb88..56aed3a 100644
4a2fec
--- a/nbd/server.c
4a2fec
+++ b/nbd/server.c
4a2fec
@@ -393,6 +393,10 @@ static int nbd_negotiate_handle_info(NBDClient *client, uint32_t length,
4a2fec
         msg = "name length is incorrect";
4a2fec
         goto invalid;
4a2fec
     }
4a2fec
+    if (namelen >= sizeof(name)) {
4a2fec
+        msg = "name too long for qemu";
4a2fec
+        goto invalid;
4a2fec
+    }
4a2fec
     if (nbd_read(client->ioc, name, namelen, errp) < 0) {
4a2fec
         return -EIO;
4a2fec
     }
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec