Blame SOURCES/0012-Avoids-unlimited-agent-connections.patch

ad412c
From 6e5b9924b172be4f33c7fc264a8ff1d6109b79fe Mon Sep 17 00:00:00 2001
ad412c
From: Frediano Ziglio <freddy77@gmail.com>
ad412c
Date: Sun, 20 Sep 2020 08:05:37 +0100
ad412c
Subject: [PATCH vd_agent_linux 12/17] Avoids unlimited agent connections
ad412c
ad412c
Limit the number of agents that can be connected.
ad412c
Avoids reaching the maximum number of files in a process.
ad412c
Beside one file descriptor per agent the daemon open just some
ad412c
other fixed number of files.
ad412c
ad412c
This issue was reported by SUSE security team.
ad412c
ad412c
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
ad412c
---
ad412c
 src/udscs.c | 12 ++++++++++++
ad412c
 1 file changed, 12 insertions(+)
ad412c
ad412c
diff --git a/src/udscs.c b/src/udscs.c
ad412c
index 7c99eed..3df67b3 100644
ad412c
--- a/src/udscs.c
ad412c
+++ b/src/udscs.c
ad412c
@@ -30,6 +30,12 @@
ad412c
 #include "vdagentd-proto-strings.h"
ad412c
 #include "vdagent-connection.h"
ad412c
 
ad412c
+// Maximum number of connected agents.
ad412c
+// Avoid DoS from agents.
ad412c
+// As each connection end up taking a file descriptor is good to have a limit
ad412c
+// less than the number of file descriptors in the process (by default 1024).
ad412c
+#define MAX_CONNECTED_AGENTS 128
ad412c
+
ad412c
 struct _UdscsConnection {
ad412c
     VDAgentConnection parent_instance;
ad412c
     int debug;
ad412c
@@ -254,6 +260,12 @@ static gboolean udscs_server_accept_cb(GSocketService    *service,
ad412c
     struct udscs_server *server = user_data;
ad412c
     UdscsConnection *new_conn;
ad412c
 
ad412c
+    /* prevents DoS having too many agents attached */
ad412c
+    if (g_list_length(server->connections) >= MAX_CONNECTED_AGENTS) {
ad412c
+        syslog(LOG_ERR, "Too many agents connected");
ad412c
+        return TRUE;
ad412c
+    }
ad412c
+
ad412c
     new_conn = g_object_new(UDSCS_TYPE_CONNECTION, NULL);
ad412c
     new_conn->debug = server->debug;
ad412c
     new_conn->read_callback = server->read_callback;
ad412c
-- 
ad412c
2.26.2
ad412c