From bd2f06fe3199321e9412f53a23fc3e18fd9a5da4 Mon Sep 17 00:00:00 2001 From: Matthias Gerstner Date: Wed, 19 Jan 2022 15:31:54 +0100 Subject: [PATCH 3/4] dnsproxy: Avoid 100 % busy loop in TCP server case Once the TCP socket is connected and until the remote server is responding (if ever) connmand executes a 100 % CPU loop, since the connected socket will always be writable (G_IO_OUT). To fix this, modify the watch after the connection is established to remove the G_IO_OUT from the callback conditions. Fixes: CVE-2022-23098 --- src/dnsproxy.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/dnsproxy.c b/src/dnsproxy.c index c027bcb972c4..1ccf36a95a35 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -2360,6 +2360,18 @@ static gboolean tcp_server_event(GIOChannel *channel, GIOCondition condition, } } + /* + * Remove the G_IO_OUT flag from the watch, otherwise we end + * up in a busy loop, because the socket is constantly writable. + * + * There seems to be no better way in g_io to do that than + * re-adding the watch. + */ + g_source_remove(server->watch); + server->watch = g_io_add_watch(server->channel, + G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR, + tcp_server_event, server); + server->connected = true; server_list = g_slist_append(server_list, server); -- 2.34.1