[PATCH v2] wpa_supplicant: Denitialize the driver if the last user went away

Jouni Malinen j
Sat Nov 1 08:08:14 PDT 2014

On Thu, Oct 30, 2014 at 09:24:50AM +0100, Lubomir Rintel wrote:
> It might be that the underlying infrastrucutre went away and the state is no
> longer valid. We ought to reinitialize it once a device appears again.
> This is the case when the nl80211 devices disappear and cfg8011 is remoed
> afterwards. The netlink handle is no longer valid (returns ENOENT) and a new
> one needs to be open if it's loaded back.

This is not the way the global_init/global_deinit was originally meant
to be used, i.e., the assumption was more like this getting initialized
once and then remain available even if no interfaces are enabled, e.g.,
for get_interfaces() call to work.

> diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
> @@ -3925,6 +3925,25 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
> +/* Deinitialize the driver if we're the last user. */
> +static void wpa_drv_cleanup(struct wpa_supplicant *wpa_s)
> +{
> +	struct wpa_global *global = wpa_s->global;
> +	struct wpa_supplicant *iface;
> +	int i;
> +
> +	for (iface = global->ifaces; iface; iface = iface->next)
> +		if (iface != wpa_s && iface->driver == wpa_s->driver)
> +			return;
> +
> +	for (i = 0; wpa_drivers[i]; i++)
> +		if (global->drv_priv[i] == wpa_s->global_drv_priv)
> +			global->drv_priv[i] = NULL;
> +
> +	if (wpa_s->driver->global_deinit)

That would be a NULL pointer dereference if interface initialization
fails early enough (wpa_s->driver == NULL in that case).

In addition to this, there is something wrong in how the global deinit
gets handled, i.e., at least one more place can trigger a SIGSEGV when
running through mac80211_hwsim test cases. As such, I cannot really
apply this until those issues have been found and fixed. Then again, I'm
not sure whether this is really the best way of handling the issue which
I'm assuming is the main reason for this patch, i.e., need to
re-initialize some socket for the case of cfg80211 getting reloaded.
Jouni Malinen                                            PGP id EFC895FA

More information about the Hostap mailing list