[PATCH] systemd: Sandbox the wpa_supplicant service units
ARAVIND OR
aravindor at gmail.com
Sun Nov 29 20:58:33 PST 2026
From: Aravind O R <aravindor at gmail.com>
wpa_supplicant runs as root and parses frames, EAPOL and EAP from peers
that have not been authenticated. Memory corruption bugs reachable that
way have been found before (e.g., advisories 2015-1, 2020-2, 2021-1 and
2026-1 on https://w1.fi/security/). The systemd units do not restrict
the process at all, so an exploitable bug gives full root: loading
kernel modules, writing /usr and /etc, setting kernel.core_pattern, and
so on.
Add systemd sandboxing settings to the four units. The process still
runs as uid 0, so this is not full containment, but it removes several
direct ways to take over the system (loading kernel modules, changing
kernel tunables, writing /usr and /etc). Each setting was chosen from
what wpa_supplicant does on Linux, so that existing configurations keep
working:
- CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_CHOWN
CAP_DAC_OVERRIDE: nl80211/rtnetlink and interface configuration, packet
sockets, lchown() of the ctrl_interface directory and socket for
GROUP=, and permission to reply to ctrl_interface clients run by other
users (wpa_cli binds its socket as that user, with that user's umask)
and to read certificates and keys owned by other users. All other
capabilities are dropped.
- NoNewPrivileges=yes: wpa_supplicant does not execute other programs,
so nothing depends on gaining privileges through exec.
- ProtectSystem=full with ReadWritePaths=-/etc/wpa_supplicant: /usr,
/boot and /etc are read-only except for the configuration directory,
so update_config=1 and SAVE_CONFIG keep working. /run, /var and /tmp
stay writable.
- ProtectHome=read-only: certificates and keys under /home (e.g., paths
set by NetworkManager) can still be read.
- ProtectKernelTunables=yes with ReadWritePaths= for
/proc/sys/net/ipv4/conf and /proc/sys/net/ipv6/conf: the nl80211
driver writes the Data frame filters (drop_unicast_in_l2_multicast,
drop_gratuitous_arp, drop_unsolicited_na) there, and since commit
19a3b55 ("wpa_supplicant: Always enable Data frame filtering") on every
connection. With ProtectKernelTunables=yes alone, these writes fail
(logged as an error) and the filters are not applied.
- RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK AF_PACKET
AF_ALG: every address family wpa_supplicant passes to socket() on
Linux (AF_ALG for CONFIG_TLS=linux). AF_BRIDGE is only used as an
rtnetlink message family over AF_NETLINK, which this setting does not
filter, and AF_LINK/PF_ROUTE are only used on BSD. There is no IP
address restriction, so WPS ER, DPP Controller and the UDP control
interface keep working.
- ProtectKernelModules, ProtectKernelLogs, ProtectControlGroups,
ProtectHostname, LockPersonality, MemoryDenyWriteExecute,
RestrictNamespaces, RestrictRealtime, RestrictSUIDSGID,
SystemCallArchitectures=native and SystemCallFilter=@system-service
(with SystemCallErrorNumber=EPERM, so an unexpected call fails instead
of killing the process).
Files that wpa_supplicant writes at runtime now need to be under
/etc/wpa_supplicant, /run, /var or /tmp. This affects a pac_file in /etc
outside /etc/wpa_supplicant (as in the example configuration) and -T,
which writes to trace_marker under /sys; such setups need a drop-in with
ReadWritePaths=.
Some common settings are left out on purpose: PrivateTmp= breaks
wpa_cli, whose reply socket is in /tmp; PrivateDevices= hides
/dev/rfkill and TPM devices; IPAddressDeny= breaks WPS ER and DPP
Controller; ProtectSystem=strict breaks ctrl_interface and log file
locations outside the configuration directory; ProtectClock= adds
nothing beyond the capability bounding set and system call filter
above, and before systemd 252 it implies a device allow-list that
blocks /dev/rfkill.
Signed-off-by: Aravind O R <aravindor at gmail.com>
---
The patch is attached (git format-patch output for git am) because it
is sent from Gmail's web interface, which would wrap the long lines of
an inline patch.
This picks up Topi Miettinen's 2019 patch
(https://patchwork.ozlabs.org/project/hostap/patch/be41ccf0-8b00-63fd-cce4-559ceea6f5e5@gmail.com/)
and tries to answer the questions raised on it: the Type= line is not
moved, there is no IP address restriction (WPS ER and DPP Controller are
tested below), AF_ALG is allowed, and AF_BRIDGE/AF_LINK are not needed.
Testing: the units generated from main and from this patch, in
containers that boot systemd as PID 1 on Fedora 45 (systemd 262),
Debian 12 (systemd 252) and Ubuntu 22.04 (systemd 249), with hostapd and
wpa_supplicant built from main (wpa_supplicant: defconfig plus
CONFIG_WPS_ER, CONFIG_MESH and CONFIG_DEBUG_SYSLOG). Every check below
gave the same result with and without the patch:
- wpa_supplicant-wired@ against hostapd (driver=wired) over a veth pair:
EAP-TLS with the CA, client certificate and key in a 0700 home
directory of another user; wpa_cli run by a member of the
ctrl_interface GROUP=; SET_NETWORK and SAVE_CONFIG; DPP_CONTROLLER_START
and a TCP connection to port 8908; WPS_ER_START (UDP 1900 and the HTTP
listener)
- a CONFIG_TLS=linux build (crypto through AF_ALG): PEAP/MSCHAPv2. It
fails as expected when AF_ALG is removed from RestrictAddressFamilies=.
- wpa_supplicant.service over D-Bus the way NetworkManager uses it
(CreateInterface, AddNetwork, SelectNetwork), with -u and with
-u -s -O /run/wpa_supplicant: PEAP over the wired driver and WPA2-PSK
over nl80211
- mac80211_hwsim: wpa_supplicant@ with WPA2-PSK and PMF, mac_addr=1, and
all four Data frame filter sysctls set to 1 after the connection;
wpa_supplicant-nl80211@ with SAE; P2P autonomous GO with a legacy
client; AP mode (mode=2) with a client; mesh with SAE
- /dev/rfkill: in the containers wpa_supplicant cannot find the phy in
sysfs, so it never opens /dev/rfkill there, with or without the
patch. Instead, a probe unit with the same [Service] settings and
ExecStart= replaced by a read of /dev/rfkill was used: it can read it
(with ProtectClock=yes added, it cannot on systemd 249).
With ProtectKernelTunables=yes and no ReadWritePaths= exception (as in
the hardening block openSUSE adds to its units), the four sysctls stay 0.
systemd-analyze security wpa_supplicant.service goes from 9.6 UNSAFE to
3.8 OK.
DevicePolicy=closed with DeviceAllow=/dev/rfkill r (as iwd does) would
also take away raw access to block devices. It is not in this patch
because TPM-backed keys need device access; I can send it separately if
that is of interest.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-systemd-Sandbox-the-wpa_supplicant-service-units.patch
Type: text/x-patch
Size: 13629 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/hostap/attachments/20261130/c183ebc3/attachment-0001.bin>
More information about the Hostap
mailing list