Skip to contentSkip to conversation

Resource leaks and Asus routers

PATCH New Ed Rose | Tewke 1 participant 3 messages Mar 12

lore
Share & tools
lore
#0 lore raw

cover Resource leaks and Asus routers

Hi all,

This is my first time submitting a patch to a mailing list so I apologise if I've made mistakes with formatting.

This short patch series fixes a couple of bugs that we've discovered in Connman that are triggered by a weird hack some mainstream routers have implemented. I'll attach a link to an article below on the topic, but the TL;DR is that Asus routers intentionally try to crash a buggy windows service that handles Proxy Auto-configuration by adding DHCP option 252 with the contents '\n' (apparently for performance reasons). Connman unfortunately tries to use this value and gets itself into a loop of failing online checks, breaking online detection and triggering the second bug.

The second bug is a memory and file descriptor leak that occurs due to the wispr_portal_context not being unreffed under some conditions, notably when it fails to resolve a proxy.

The result of both of these together is that connman eventually exhausts its fd limit and is unable to function.

Here is a link to a blog post explaining the strange DHCP behaviour:
https://nuxx.net/blog/2022/12/23/how-asus-and-a-microsoft-bug-almost-broke-remote-work/

This bug is super easy to replicate if you have a router that allows configuring DHCP. Ensure connman is configured to perform online checks and set option 252 with a payload of '\n' (0x0a). Watch the file descriptor list in /proc/<pid>/fd grow.

Ed Rose (2):
wispr: Ensure memory cleaned up in all cases
dhcp: Ignore empty DHCP Option 252

 src/dhcp.c  | 7 +++++--
 src/wispr.c | 3 ++-
 2 files changed, 7 insertions(+), 3 deletions(-)

--
2.43.0

#1 lore raw

PATCH 1/2 wispr: Ensure memory cleaned up in all cases

If connman_proxy_lookup fails to resolve a proxy, the code path fails to unref the connman_wispr_portal_context resulting in a resource leak of both memory and file descriptors. This can lead to connman hitting it's OS fd limit and becoming non-functional.

Resolve this by ensuring the reference count for the portal context is always decremented, even in error cases.

---
 src/wispr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/wispr.c +2 -1
index a40cf353..a8e16b7e 100644
@@ -1303,7 +1303,7 @@ static void proxy_callback(const char *proxy, void *user_data)
 
 		portal_manage_failure_status(wp_context, 0, "no valid proxy");
 
-		return;
+		goto done;
 	}
 
 	DBG("proxy %s", proxy);
@@ -1328,6 +1328,7 @@ static void proxy_callback(const char *proxy, void *user_data)
 					xml_wispr_parser_callback, wp_context);
 
 	wispr_portal_request_portal(wp_context);
+done:
 	wispr_portal_context_unref(wp_context);
 }
 

--
2.43.0

#2 lore raw

PATCH 2/2 dhcp: Ignore empty DHCP Option 252

In reply to Ed Rose | Tewke

Some routers, notably Asus, intentionally send a DHCP option 252 (proxy autoconfiguration) with a payload of '\n'. This seems to be to workaround an overly chatty windows service and improve performance.

Connman would check the length of the string and then strip it before using the value. This changes the order so the string is stripped first, then the length is checked to allow us to ignore values that contain only whitespace.

---
 src/dhcp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/dhcp.c +5 -2
index c84f1de4..163a347f 100644
@@ -352,7 +352,7 @@ static bool apply_lease_available_on_network(GDHCPClient *dhcp_client,
 
 	option = g_dhcp_client_get_option(dhcp_client, 252);
 	if (option)
-		pac = g_strdup(option->data);
+		pac = g_strstrip(g_strdup(option->data));
 
 	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER);
 	ns_entries = g_list_length(option);
@@ -418,11 +418,14 @@ static bool apply_lease_available_on_network(GDHCPClient *dhcp_client,
 		g_strfreev(timeservers);
 	}
 
-	if (g_strcmp0(pac, dhcp->pac) != 0) {
+	if (pac && strlen(pac) && g_strcmp0(pac, dhcp->pac) != 0) {
 		g_free(dhcp->pac);
 		dhcp->pac = pac;
 
 		__connman_service_set_proxy_autoconfig(service, dhcp->pac);
+	} else if (pac) {
+		g_free(pac);
+		pac = NULL;
 	}
 
 	if (connman_setting_get_bool("Enable6to4"))

--
2.43.0