From fb4ba71952ba0f565398b064be1829041c7f8763 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Wed, 3 May 2017 19:53:52 +0200 Subject: [PATCH] main: Don't init nl80211 if we're terminating Don't enter nl80211_appeared if we're already terminating and inside the 1 second timeout. This fixes a potential crash in device_free() caused by a netdev_init() and a netdev_exit() happening without netdev_shutdown in between. netdev_shutdown has already run if terminating is true. src/main.c:main() Opening nl80211 interface src/eap.c:__eap_method_enable() src/eap-wsc.c:eap_wsc_init() src/eap-md5.c:eap_md5_init() src/eap-tls.c:eap_tls_init() src/eap-ttls.c:eap_ttls_init() src/eap-mschapv2.c:eap_mschapv2_init() Terminate src/main.c:nl80211_appeared() Found nl80211 interface src/netdev.c:netdev_init() Opening route netlink socket src/wiphy.c:protocol_features_callback() Found split wiphy dump support src/wiphy.c:regulatory_info_callback() Regulatory alpha2 is 00 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:parse_supported_bands() src/wiphy.c:parse_supported_frequencies() src/wiphy.c:parse_supported_frequencies() src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad1 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad1 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad1 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad1 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad1 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad1 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad0 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad0 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad0 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad0 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad0 src/wiphy.c:wiphy_dump_callback() src/wiphy.c:wiphy_is_managed() whitelist filtered phy: rad0 Wiphy: 2, Name: rad2 Bands: 2.4 GHz 5 GHz Ciphers: CCMP TKIP BIP src/netdev.c:netdev_create_from_genl() Created interface wln2[6] src/netdev.c:netdev_initial_up_cb() Interface 6 initialized src/device.c:device_enter_state() Old State: off, new state: autoconnect src/scan.c:scan_periodic_start() Starting periodic scan for ifindex: 6 src/scan.c:scan_notify() Scan notification 33 src/netdev.c:netdev_operstate_dormant_cb() netdev: 6, success: 1 src/scan.c:scan_periodic_done() src/scan.c:scan_periodic_done() Periodic scan triggered for ifindex: 6 src/eap.c:__eap_method_disable() src/eap-wsc.c:eap_wsc_exit() src/eap-md5.c:eap_md5_exit() src/eap-tls.c:eap_tls_exit() src/eap-ttls.c:eap_ttls_exit() src/eap-mschapv2.c:eap_mschapv2_exit() src/main.c:nl80211_vanished() Lost nl80211 interface src/wsc.c:wsc_exit() src/scan.c:scan_exit() src/scan.c:scan_context_free() sc: 0x5434ab0 src/netdev.c:netdev_exit() Closing route netlink socket src/wiphy.c:wiphy_free() Freeing wiphy rad2[2] device_list isn't empty! src/device.c:device_free() (crash here) --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.c b/src/main.c index b21413cc..f7f22eaf 100644 --- a/src/main.c +++ b/src/main.c @@ -53,6 +53,7 @@ static const char *nointerfaces; static const char *phys; static const char *nophys; static const char *config_dir; +static bool terminating; static void main_loop_quit(struct l_timeout *timeout, void *user_data) { @@ -61,6 +62,11 @@ static void main_loop_quit(struct l_timeout *timeout, void *user_data) void iwd_shutdown(void) { + if (terminating) + return; + + terminating = true; + dbus_shutdown(); netdev_shutdown(); @@ -122,6 +128,9 @@ static void nl80211_appeared(void *user_data) { struct l_genl_family *nl80211 = user_data; + if (terminating) + return; + l_debug("Found nl80211 interface"); if (!wiphy_init(nl80211, phys, nophys))