diff mbox series

hostapd: fix race condition with wpa_supplicant_prepare_interface()

Message ID 20221013153823.332707-1-raphael.melotte@mind.be
State New
Headers show
Series hostapd: fix race condition with wpa_supplicant_prepare_interface() | expand

Commit Message

Raphaël Mélotte Oct. 13, 2022, 3:38 p.m. UTC
wpa_supplicant_prepare_interface() manually removes wpa_supplicant's
control interface, by calling wpa_supplicant_teardown_interface().
With the introduction of dynamic wifi configuration in commit
a5bc9787d4ef89c9e2593a191b3c4cf8702b41a3, we now call ubus to add a
new supplicant configuration if there is no wpa_supplicant.ifname
object yet, or if the list of interfaces to configure has changed (see
mac80211.sh).

If the network re-configuration is triggered multiple times in a row
successively, there are cases where the supplicant ubus object already
exists so we don't call config_add, but the supplicant control
interface is nevertheless always removed (as
wpa_supplicant_prepare_interface is always called). As a consequence,
this leaves the supplicant running without a control interface.

One way to reproduce the problem is:
- Configure 1 radio with 2 APs and one station interface.
- Check /var/run/wpa_supplicant: it contains the global interface and
the control interface for our station.
- Use the following command to trigger the bug:
"
/etc/init.d/network restart ; wifi ; sleep 10 ; /etc/init.d/network restart ; wifi
"
- Check /var/run/wpa_supplicant/ and see that it only contains the
global interface, no interface is created for our station.

While users are not expected to trigger reconfigurations so quickly,
in practice it might happen due to unfortunate chains of actions. When
this happens, it leaves the supplicant unusable for other processes
that want to use the control interface.

To fix it, remove wpa_supplicant_teardown_interface() entirely. The
config_remove and config_add ubus calls will anyway create and remove
the control interface as needed, so there is no need to remove it
manually.

Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
---
 package/network/services/hostapd/files/hostapd.sh | 6 ------
 1 file changed, 6 deletions(-)
diff mbox series

Patch

diff --git a/package/network/services/hostapd/files/hostapd.sh b/package/network/services/hostapd/files/hostapd.sh
index 7eeb74e984..e20725d62b 100644
--- a/package/network/services/hostapd/files/hostapd.sh
+++ b/package/network/services/hostapd/files/hostapd.sh
@@ -1196,11 +1196,6 @@  _wpa_supplicant_common() {
 	_config="${_rpath}-$ifname.conf"
 }
 
-wpa_supplicant_teardown_interface() {
-	_wpa_supplicant_common "$1"
-	rm -rf "$_rpath/$1" "$_config"
-}
-
 wpa_supplicant_prepare_interface() {
 	local ifname="$1"
 	_w_driver="$2"
@@ -1245,7 +1240,6 @@  wpa_supplicant_prepare_interface() {
 	else
 		[ -e "$multiap_flag_file" ] && rm "$multiap_flag_file"
 	fi
-	wpa_supplicant_teardown_interface "$ifname"
 	cat > "$_config" <<EOF
 ${scan_list:+freq_list=$scan_list}
 $ap_scan