diff --git a/core/sap/src/sap_api_link_cntl.c b/core/sap/src/sap_api_link_cntl.c index 5f28397ca706..8e26df2ac775 100644 --- a/core/sap/src/sap_api_link_cntl.c +++ b/core/sap/src/sap_api_link_cntl.c @@ -1266,6 +1266,22 @@ void sap_scan_event_callback(struct wlan_objmgr_vdev *vdev, bool success = false; eCsrScanStatus scan_status = eCSR_SCAN_FAILURE; mac_handle_t mac_handle; + QDF_STATUS status; + + /* + * It may happen that the SAP was deleted before the scan + * cb was called. Here the sap context which was passed as an + * arg to the ACS cb is used after free then, and there is no way + * currently to validate the pointer. Now try get vdev ref before + * the weight calculation algo kicks in, and return if the + * reference cannot be taken to avoid use after free for SAP-context + */ + status = wlan_objmgr_vdev_try_get_ref(vdev, WLAN_LEGACY_SAP_ID); + if (QDF_IS_STATUS_ERROR(status)) { + sap_err("Hotspot fail, vdev ref get error"); + return; + } + wlan_objmgr_vdev_release_ref(vdev, WLAN_LEGACY_SAP_ID); session_id = wlan_vdev_get_id(vdev); scan_id = event->scan_id;