diff mbox series

Fix using invalid memory during driver deinit

Message ID 20240923152529.52740-1-ming@imkuang.com
State New
Headers show
Series Fix using invalid memory during driver deinit | expand

Commit Message

Ming Kuang Sept. 23, 2024, 3:25 p.m. UTC
We recorded the address of hapd_iface->bss[0]->drv_priv before calling
hostapd_free_hapd_data function and passed it to the
hostapd_deinit_driver function after the call.
However, the hostapd_free_hapd_data function may free the hapd->drv_priv
memory, which could lead to the hostapd_deinit_driver using an invalid
memory address that has already been freed.

Signed-off-by: Ming Kuang <ming@imkuang.com>
---
 src/ap/hostapd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
index 7d924893f..6c3bcdb78 100644
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -3627,8 +3627,6 @@  int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
 	}
 
 	wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
-	driver = hapd_iface->bss[0]->driver;
-	drv_priv = hapd_iface->bss[0]->drv_priv;
 
 	hapd_iface->driver_ap_teardown =
 		!!(hapd_iface->drv_flags &
@@ -3647,6 +3645,8 @@  int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
 		hostapd_free_hapd_data(hapd);
 	}
 
+	driver = hapd_iface->bss[0]->driver;
+	drv_priv = hapd_iface->bss[0]->drv_priv;
 	hostapd_deinit_driver(driver, drv_priv, hapd_iface);
 
 	/* From hostapd_cleanup_iface: These were initialized in