[PATCH] wpa_ctrl: Align client socket permissions with daemon permissions

soeren at soeren-tempel.net soeren at soeren-tempel.net
Thu Nov 26 02:21:03 PST 2026


From: Sören Tempel <soeren at soeren-tempel.net>

I was recently made aware that wpa_supplicant can be run as an
unprivileged user [1]. In this case, the client DGRAM socket created
by wpa_cli must also be writable for that unprivileged user as wpa_cli
will otherwise not be able to receive responses from the daemon.

To achieve this, this change looks up the owner/group of the daemon
socket in /var/run/wpa_supplicant and attempts to apply these to the
client socket. Changing the group, even if the owner cannot be changed.

Further, for the use case that both (the user using wpa_cli and
wpa_supplicant itself) are in the same unprivileged group, the client
socket file must also be writable by the group owner. The Android code
path seems to solve a similar issue, would be open for solutions to
align the two more closely.

WDYT?

[1]: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/111527

Signed-off-by: Sören Tempel <soeren at soeren-tempel.net>
---
 src/common/wpa_ctrl.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c
index 7e197f094..408985dba 100644
--- a/src/common/wpa_ctrl.c
+++ b/src/common/wpa_ctrl.c
@@ -203,6 +203,20 @@ try_again:
 		}
 		return ctrl;
 	}
+#else
+	/* Change ownership of our local socket to that of the ctrl
+	 * socket. Needed if wpa_supplicant isn't running as root. */
+	struct stat ctrl_stat;
+	if (stat(ctrl_path, &ctrl_stat) == -1) {
+		close(ctrl->s);
+		os_free(ctrl);
+		return NULL;
+	}
+	/* Set group even if we do not have privileges to change owner */
+	lchown(ctrl->local.sun_path, ctrl_stat.st_uid, ctrl_stat.st_gid);
+	if (lchown(ctrl->local.sun_path, -1, ctrl_stat.st_gid) == 0) {
+		chmod(ctrl->local.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+	}
 #endif /* ANDROID */
 
 	ctrl->dest.sun_family = AF_UNIX;



More information about the Hostap mailing list