Skip to contentSkip to conversation

Leave a control interface directory without permission to remove it

PATCH New Christopher Griffin 1 participant 1 message Nov 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Leave a control interface directory without permission to remove it

hostapd and wpa_supplicant try to remove their control interface directory when the last interface using it goes away, and report any failure other than ENOTEMPTY as an error. A process that dropped its privileges, as OpenWrt runs both (user network, in a jail), cannot remove a directory that was created for it in a root-owned parent (/var/run/hostapd), so every time the last interface goes it logs

rmdir[ctrl_interface=/var/run/hostapd]: Permission denied

The directory is not this process's to remove, as when it is not empty:
treat EACCES and EPERM the same way, at debug level, with the reason.

Assisted-by Claude:claude-opus-5-5

---
Tested on OpenWrt (hostapd jailed as user network) on an Arista W-118, with the change as a package patch: removing the last BSS logged the rmdir error before, and nothing at error level after.

---
 hostapd/ctrl_iface.c             | 24 ++++++++++++++----------
 wpa_supplicant/ctrl_iface_unix.c |  9 +++++----
 2 files changed, 19 insertions(+), 14 deletions(-)
hostapd/ctrl_iface.c +14 -10
index c53e33b..0a683d7 100644
@@ -5260,9 +5260,11 @@ void hostapd_mld_ctrl_iface_deinit(struct hostapd_mld *mld)
 
 		if (mld->ctrl_interface &&
 		    rmdir(mld->ctrl_interface) < 0) {
-			if (errno == ENOTEMPTY) {
+			if (errno == ENOTEMPTY || errno == EACCES ||
+			    errno == EPERM) {
 				wpa_printf(MSG_DEBUG,
-					   "MLD control interface directory not empty - leaving it behind");
+					   "MLD control interface directory %s not removed (%s) - leaving it behind",
+					   mld->ctrl_interface, strerror(errno));
 			} else {
 				wpa_printf(MSG_ERROR,
 					   "rmdir[ctrl_interface=%s]: %s",
@@ -5608,10 +5610,11 @@ void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
 
 		if (hapd->conf->ctrl_interface &&
 		    rmdir(hapd->conf->ctrl_interface) < 0) {
-			if (errno == ENOTEMPTY) {
-				wpa_printf(MSG_DEBUG, "Control interface "
-					   "directory not empty - leaving it "
-					   "behind");
+			if (errno == ENOTEMPTY || errno == EACCES ||
+			    errno == EPERM) {
+				wpa_printf(MSG_DEBUG,
+					   "Control interface directory %s not removed (%s) - leaving it behind",
+					   hapd->conf->ctrl_interface, strerror(errno));
 			} else {
 				wpa_printf(MSG_ERROR,
 					   "rmdir[ctrl_interface=%s]: %s",
@@ -6399,10 +6402,11 @@ void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces)
 
 		if (interfaces->global_iface_path &&
 		    rmdir(interfaces->global_iface_path) < 0) {
-			if (errno == ENOTEMPTY) {
-				wpa_printf(MSG_DEBUG, "Control interface "
-					   "directory not empty - leaving it "
-					   "behind");
+			if (errno == ENOTEMPTY || errno == EACCES ||
+			    errno == EPERM) {
+				wpa_printf(MSG_DEBUG,
+					   "Control interface directory %s not removed (%s) - leaving it behind",
+					   interfaces->global_iface_path, strerror(errno));
 			} else {
 				wpa_printf(MSG_ERROR,
 					   "rmdir[ctrl_interface=%s]: %s",
wpa_supplicant/ctrl_iface_unix.c +5 -4
index 6f5991a..0fa6c88 100644
@@ -890,10 +890,11 @@ void wpa_supplicant_ctrl_iface_deinit(struct wpa_supplicant *wpa_s,
 			dir = buf;
 
 		if (rmdir(dir) < 0) {
-			if (errno == ENOTEMPTY) {
-				wpa_printf(MSG_DEBUG, "Control interface "
-					   "directory not empty - leaving it "
-					   "behind");
+			if (errno == ENOTEMPTY || errno == EACCES ||
+			    errno == EPERM) {
+				wpa_printf(MSG_DEBUG,
+					   "Control interface directory %s not removed (%s) - leaving it behind",
+					   dir, strerror(errno));
 			} else {
 				wpa_printf(MSG_ERROR,
 					   "rmdir[ctrl_interface=%s]: %s",

---
base-commit: 412ff0d7f4d2b346df63be52c4201ee7ab0dc804
change-id: 20261104-b136-ctrl-dir-permission-a757720c4150

Best regards,

Signature · 1 line
Christopher Griffin <[email protected]>