Skip to contentSkip to conversation

plugins/wifi: Fix GSupplicantInterface socket leak during teardown

PATCH Superseded Doemela 1 participant 4 messages Aug 30 – Sep 21

lore
Share & tools
lore

Doemela

author
#0 lore raw

PATCH v6 1/1 plugins/wifi: Fix GSupplicantInterface socket leak during teardown

During interface teardown GSupplicantInterface resources are not properly canceled leading to a socket file descriptor leak. Fix this by ensuring g_supplicant_interface_cancel is always executed when an interface is removed.

---
Changes in v6:
- Fixed stray empty line deletion formatting error before 'if (wifi)' to ensure clean upstream application.

Changes in v5:
- Restored the required 'wifi->interface = NULL;' line that was accidentally dropped in v4.
- Adjusted description tone to use imperative language.

Changes in v4:
- Restored the missing patch commit description text.
- Fixed the stray empty line deletion formatting error.

---
 plugins/wifi.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
plugins/wifi.c +8 -7
index 9ce7b5a3..d0b60bea 100644
@@ -2734,8 +2734,10 @@ static void interface_state(GSupplicantInterface *interface)
 
 static void interface_removed(GSupplicantInterface *interface)
 {
-	const char *ifname = g_supplicant_interface_get_ifname(interface);
-	struct wifi_data *wifi;
+	struct connman_wifi *wifi;
+	const char *ifname;
+
+	ifname = g_supplicant_interface_get_ifname(interface);
 
 	DBG("ifname %s", ifname);
 
@@ -2747,12 +2749,11 @@ static void interface_removed(GSupplicantInterface *interface)
 	if (wifi && wifi->tethering)
 		return;
 
-	if (!wifi || !wifi->device) {
-		DBG("wifi interface already removed");
-		return;
-	}
+	if (wifi != NULL && wifi->device != NULL)
+		connman_device_set_powered(wifi->device, FALSE);
 
-	connman_device_set_powered(wifi->device, false);
+	g_supplicant_interface_set_data(interface, NULL);
+	g_supplicant_interface_cancel(interface);
 
 	check_p2p_technology();
 }
Signature · 1 line
2.47.3
author
#1 lore raw

Friendly ping on this series. The fd leak is reproducible on embedded systems (LibreELEC) with kernel-space WireGuard, eventually hitting the 1024 fd limit and crashing ConnMan. Happy to rework anything that's in the way of merging.

--
Doemela

author
#2 lore raw

PATCH v7 1/1 plugins/wifi: Fix GSupplicantInterface socket leak during teardown

In reply to Doemela

Cancel any pending GSupplicantInterface DBus calls and drop the interface reference in the interface_removed() early-return paths. Without this, ConnMan leaks file descriptors on Wi-Fi teardown cycles, eventually hitting the 1024 fd limit and crashing.

Verified on LibreELEC 13 nightly 20260920-b68ee23 (ConnMan 2.0, iwd backend) with kernel-space WireGuard connection cycles:

- Without patch: fd count 22 -> 49+, monotonically rising, no recovery
- With patch: fd count returns to baseline (22) after each cycle

Changes in v7:
- Fix compile error: use 'struct wifi_data' instead of nonexistent 'struct connman_wifi' in interface_removed()

---
 plugins/wifi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
plugins/wifi.c +7 -6
index 9ce7b5a3..d17588be 100644
@@ -2734,8 +2734,10 @@ static void interface_state(GSupplicantInterface *interface)
 
 static void interface_removed(GSupplicantInterface *interface)
 {
-	const char *ifname = g_supplicant_interface_get_ifname(interface);
 	struct wifi_data *wifi;
+	const char *ifname;
+
+	ifname = g_supplicant_interface_get_ifname(interface);
 
 	DBG("ifname %s", ifname);
 
@@ -2747,12 +2749,11 @@ static void interface_removed(GSupplicantInterface *interface)
 	if (wifi && wifi->tethering)
 		return;
 
-	if (!wifi || !wifi->device) {
-		DBG("wifi interface already removed");
-		return;
-	}
+	if (wifi != NULL && wifi->device != NULL)
+		connman_device_set_powered(wifi->device, FALSE);
 
-	connman_device_set_powered(wifi->device, false);
+	g_supplicant_interface_set_data(interface, NULL);
+	g_supplicant_interface_cancel(interface);
 
 	check_p2p_technology();
 }
Signature · 1 line
2.47.3
author
#3 lore raw

PATCH v8 1/1 plugins/wifi: Fix GSupplicantInterface socket leak during teardown

Cancel any pending GSupplicantInterface DBus calls and drop the interface reference in the interface_removed() early-return paths. Without this, ConnMan leaks file descriptors on Wi-Fi teardown cycles, eventually hitting the 1024 fd limit and crashing.

---
Verified on LibreELEC 13 nightly 20260920-b68ee23 (ConnMan 2.0, iwd backend) with kernel-space WireGuard connection cycles:

- Without patch: fd count 22 -> 49+, monotonically rising, no recovery
- With patch: fd count returns to baseline (22) after each cycle

Changes in v8:
- Move testing commentary below the --- separator
- Add Signed-off-by line

Changes in v7:
- Fix compile error: use 'struct wifi_data' instead of nonexistent 'struct connman_wifi' in interface_removed()

---
 plugins/wifi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
plugins/wifi.c +7 -6
index 9ce7b5a3..d17588be 100644
@@ -2734,8 +2734,10 @@ static void interface_state(GSupplicantInterface *interface)
 
 static void interface_removed(GSupplicantInterface *interface)
 {
-	const char *ifname = g_supplicant_interface_get_ifname(interface);
 	struct wifi_data *wifi;
+	const char *ifname;
+
+	ifname = g_supplicant_interface_get_ifname(interface);
 
 	DBG("ifname %s", ifname);
 
@@ -2747,12 +2749,11 @@ static void interface_removed(GSupplicantInterface *interface)
 	if (wifi && wifi->tethering)
 		return;
 
-	if (!wifi || !wifi->device) {
-		DBG("wifi interface already removed");
-		return;
-	}
+	if (wifi != NULL && wifi->device != NULL)
+		connman_device_set_powered(wifi->device, FALSE);
 
-	connman_device_set_powered(wifi->device, false);
+	g_supplicant_interface_set_data(interface, NULL);
+	g_supplicant_interface_cancel(interface);
 
 	check_p2p_technology();
 }
Signature · 1 line
2.47.3