Blame SOURCES/0011-Avoids-uncontrolled-active_xfers-allocations.patch

93d60d
From b173eba1698138f92b08d4deeaac4d2979a67bbf Mon Sep 17 00:00:00 2001
93d60d
From: Frediano Ziglio <freddy77@gmail.com>
93d60d
Date: Fri, 2 Oct 2020 12:27:59 +0100
93d60d
Subject: [PATCH vd_agent_linux 11/17] Avoids uncontrolled "active_xfers"
93d60d
 allocations
93d60d
93d60d
Limit the number of active file transfers possibly causing DoSes
93d60d
consuming memory in "active_xfers".
93d60d
93d60d
This issue was reported by SUSE security team.
93d60d
93d60d
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
93d60d
Acked-by: Uri Lublin <uril@redhat.com>
93d60d
---
93d60d
 src/vdagentd/vdagentd.c | 23 +++++++++++++++++++++++
93d60d
 1 file changed, 23 insertions(+)
93d60d
93d60d
diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
93d60d
index 8961a99..b31941d 100644
93d60d
--- a/src/vdagentd/vdagentd.c
93d60d
+++ b/src/vdagentd/vdagentd.c
93d60d
@@ -47,6 +47,14 @@
93d60d
 
93d60d
 #define DEFAULT_UINPUT_DEVICE "/dev/uinput"
93d60d
 
93d60d
+// Maximum number of transfers active at any time.
93d60d
+// Avoid DoS from client.
93d60d
+// As each transfer could likely end up taking a file descriptor
93d60d
+// it is good to have a limit less than the number of file descriptors
93d60d
+// in the process (by default 1024). The daemon do not open file
93d60d
+// descriptors for the transfers but the agents do.
93d60d
+#define MAX_ACTIVE_TRANSFERS 128
93d60d
+
93d60d
 struct agent_data {
93d60d
     char *session;
93d60d
     int width;
93d60d
@@ -380,6 +388,21 @@ static void do_client_file_xfer(VirtioPort *vport,
93d60d
                "Cancelling client file-xfer request %u",
93d60d
                s->id, VD_AGENT_FILE_XFER_STATUS_SESSION_LOCKED, NULL, 0);
93d60d
             return;
93d60d
+        } else if (g_hash_table_size(active_xfers) >= MAX_ACTIVE_TRANSFERS) {
93d60d
+            VDAgentFileXferStatusError error = {
93d60d
+                GUINT32_TO_LE(VD_AGENT_FILE_XFER_STATUS_ERROR_GLIB_IO),
93d60d
+                GUINT32_TO_LE(G_IO_ERROR_TOO_MANY_OPEN_FILES),
93d60d
+            };
93d60d
+            size_t detail_size = sizeof(error);
93d60d
+            if (!VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
93d60d
+                                         VD_AGENT_CAP_FILE_XFER_DETAILED_ERRORS)) {
93d60d
+                detail_size = 0;
93d60d
+            }
93d60d
+            send_file_xfer_status(vport,
93d60d
+               "Too many transfers ongoing. "
93d60d
+               "Cancelling client file-xfer request %u",
93d60d
+               s->id, VD_AGENT_FILE_XFER_STATUS_ERROR, (void*) &error, detail_size);
93d60d
+            return;
93d60d
         }
93d60d
         msg_type = VDAGENTD_FILE_XFER_START;
93d60d
         id = s->id;
93d60d
-- 
93d60d
2.26.2
93d60d