76daa3
From 5813402bce6119ed5241d72e6000584a12a490ea Mon Sep 17 00:00:00 2001
76daa3
From: Eric Blake <eblake@redhat.com>
76daa3
Date: Mon, 10 Jul 2017 16:28:19 +0200
76daa3
Subject: [PATCH 4/4] qemu-nbd: Ignore SIGPIPE
76daa3
76daa3
RH-Author: Eric Blake <eblake@redhat.com>
76daa3
Message-id: <20170710162819.24843-1-eblake@redhat.com>
76daa3
Patchwork-id: 75717
76daa3
O-Subject: [RHEV-7.4.z qemu-kvm-rhev PATCH] qemu-nbd: Ignore SIGPIPE
76daa3
Bugzilla: 1469463
76daa3
RH-Acked-by: John Snow <jsnow@redhat.com>
76daa3
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
76daa3
From: Max Reitz <mreitz@redhat.com>
76daa3
76daa3
qemu proper has done so for 13 years
76daa3
(8a7ddc38a60648257dc0645ab4a05b33d6040063), qemu-img and qemu-io have
76daa3
done so for four years (526eda14a68d5b3596be715505289b541288ef2a).
76daa3
Ignoring this signal is especially important in qemu-nbd because
76daa3
otherwise a client can easily take down the qemu-nbd server by dropping
76daa3
the connection when the server wants to send something, for example:
76daa3
76daa3
$ qemu-nbd -x foo -f raw -t null-co:// &
76daa3
[1] 12726
76daa3
$ qemu-io -c quit nbd://localhost/bar
76daa3
can't open device nbd://localhost/bar: No export with name 'bar' available
76daa3
[1]  + 12726 broken pipe  qemu-nbd -x foo -f raw -t null-co://
76daa3
76daa3
In this case, the client sends an NBD_OPT_ABORT and closes the
76daa3
connection (because it is not required to wait for a reply), but the
76daa3
server replies with an NBD_REP_ACK (because it is required to reply).
76daa3
76daa3
Signed-off-by: Max Reitz <mreitz@redhat.com>
76daa3
Message-Id: <20170611123714.31292-1-mreitz@redhat.com>
76daa3
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
76daa3
(cherry picked from commit 041e32b8d9d076980b4e35317c0339e57ab888f1)
76daa3
Fixes CVE-2017-10664
76daa3
Signed-off-by: Eric Blake <eblake@redhat.com>
76daa3
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 qemu-nbd.c | 4 ++++
76daa3
 1 file changed, 4 insertions(+)
76daa3
76daa3
diff --git a/qemu-nbd.c b/qemu-nbd.c
76daa3
index 483dd77..5deb37e 100644
76daa3
--- a/qemu-nbd.c
76daa3
+++ b/qemu-nbd.c
76daa3
@@ -581,6 +581,10 @@ int main(int argc, char **argv)
76daa3
     sa_sigterm.sa_handler = termsig_handler;
76daa3
     sigaction(SIGTERM, &sa_sigterm, NULL);
76daa3
 
76daa3
+#ifdef CONFIG_POSIX
76daa3
+    signal(SIGPIPE, SIG_IGN);
76daa3
+#endif
76daa3
+
76daa3
     module_call_init(MODULE_INIT_TRACE);
76daa3
     qcrypto_init(&error_fatal);
76daa3
 
76daa3
-- 
76daa3
1.8.3.1
76daa3