Blame SOURCES/kvm-io-Ignore-websocket-PING-and-PONG-frames.patch

4a2fec
From 137479576664767db121c512db49f4c40789fa52 Mon Sep 17 00:00:00 2001
4a2fec
From: "Daniel P. Berrange" <berrange@redhat.com>
4a2fec
Date: Wed, 20 Dec 2017 17:56:50 +0100
4a2fec
Subject: [PATCH 10/42] io: Ignore websocket PING and PONG frames
4a2fec
4a2fec
RH-Author: Daniel P. Berrange <berrange@redhat.com>
4a2fec
Message-id: <20171220175702.29663-9-berrange@redhat.com>
4a2fec
Patchwork-id: 78460
4a2fec
O-Subject: [RHV-7.5 qemu-kvm-rhev PATCH v2 08/20] io: Ignore websocket PING and PONG frames
4a2fec
Bugzilla: 1518649
4a2fec
RH-Acked-by: John Snow <jsnow@redhat.com>
4a2fec
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
From: Brandon Carpenter <brandon.carpenter@cypherpath.com>
4a2fec
4a2fec
Keep pings and gratuitous pongs generated by web browsers from killing
4a2fec
websocket connections.
4a2fec
4a2fec
Signed-off-by: Brandon Carpenter <brandon.carpenter@cypherpath.com>
4a2fec
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
4a2fec
(cherry picked from commit 01af17fc002414ee1ac0800babfb0edc2bef1a7d)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 io/channel-websock.c | 21 +++++++++++++++++----
4a2fec
 1 file changed, 17 insertions(+), 4 deletions(-)
4a2fec
4a2fec
diff --git a/io/channel-websock.c b/io/channel-websock.c
4a2fec
index b19b5d9..bfe4008 100644
4a2fec
--- a/io/channel-websock.c
4a2fec
+++ b/io/channel-websock.c
4a2fec
@@ -115,6 +115,7 @@
4a2fec
 #define QIO_CHANNEL_WEBSOCK_HEADER_FIELD_OPCODE 0x0f
4a2fec
 #define QIO_CHANNEL_WEBSOCK_HEADER_FIELD_HAS_MASK 0x80
4a2fec
 #define QIO_CHANNEL_WEBSOCK_HEADER_FIELD_PAYLOAD_LEN 0x7f
4a2fec
+#define QIO_CHANNEL_WEBSOCK_CONTROL_OPCODE_MASK 0x8
4a2fec
 
4a2fec
 typedef struct QIOChannelWebsockHeader QIOChannelWebsockHeader;
4a2fec
 
4a2fec
@@ -659,8 +660,11 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,
4a2fec
             return -1;
4a2fec
         }
4a2fec
     } else {
4a2fec
-        if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {
4a2fec
-            error_setg(errp, "only binary websocket frames are supported");
4a2fec
+        if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME &&
4a2fec
+            opcode != QIO_CHANNEL_WEBSOCK_OPCODE_PING &&
4a2fec
+            opcode != QIO_CHANNEL_WEBSOCK_OPCODE_PONG) {
4a2fec
+            error_setg(errp, "unsupported opcode: %#04x; only binary, ping, "
4a2fec
+                             "and pong websocket frames are supported", opcode);
4a2fec
             return -1;
4a2fec
         }
4a2fec
     }
4a2fec
@@ -673,6 +677,9 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,
4a2fec
         ioc->payload_remain = payload_len;
4a2fec
         header_size = QIO_CHANNEL_WEBSOCK_HEADER_LEN_7_BIT;
4a2fec
         ioc->mask = header->u.m;
4a2fec
+    } else if (opcode & QIO_CHANNEL_WEBSOCK_CONTROL_OPCODE_MASK) {
4a2fec
+        error_setg(errp, "websocket control frame is too large");
4a2fec
+        return -1;
4a2fec
     } else if (payload_len == QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_16_BIT &&
4a2fec
                ioc->encinput.offset >= QIO_CHANNEL_WEBSOCK_HEADER_LEN_16_BIT) {
4a2fec
         ioc->payload_remain = be16_to_cpu(header->u.s16.l16);
4a2fec
@@ -728,9 +735,15 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,
4a2fec
         }
4a2fec
     }
4a2fec
 
4a2fec
+    /* Drop the payload of ping/pong packets */
4a2fec
+    if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {
4a2fec
+        if (payload_len) {
4a2fec
+            buffer_reserve(&ioc->rawinput, payload_len);
4a2fec
+            buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len);
4a2fec
+        }
4a2fec
+    }
4a2fec
+
4a2fec
     if (payload_len) {
4a2fec
-        buffer_reserve(&ioc->rawinput, payload_len);
4a2fec
-        buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len);
4a2fec
         buffer_advance(&ioc->encinput, payload_len);
4a2fec
     }
4a2fec
     return 0;
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec