From patchwork Mon Dec 10 12:59:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 204868 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 46B492C0168 for ; Tue, 11 Dec 2012 00:00:36 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 0F2B09C0F5; Mon, 10 Dec 2012 08:00:32 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IJ5txHTazoYa; Mon, 10 Dec 2012 08:00:31 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id DE9A89C13D; Mon, 10 Dec 2012 08:00:26 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 89C6C9C0F5 for ; Mon, 10 Dec 2012 08:00:25 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xezAN7+EHnbj for ; Mon, 10 Dec 2012 08:00:20 -0500 (EST) Received: from ht1.hostedexchange.local (ht1.myhostedexchange.com [69.50.2.37]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "HT1", Issuer "HT1" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 05D999C13D for ; Mon, 10 Dec 2012 08:00:19 -0500 (EST) Received: from sven-desktop.home.narfation.org (77.5.254.13) by ht1.hostedexchange.local (172.16.69.39) with Microsoft SMTP Server (TLS) id 8.3.279.5; Mon, 10 Dec 2012 05:00:18 -0800 From: To: Subject: [PATCH-resent] nl80211: Run TKIP countermeasures in correct hostapd_data context Date: Mon, 10 Dec 2012 13:59:22 +0100 Message-ID: <1355144362-11965-1-git-send-email-sven@open-mesh.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 Cc: Sven Eckelmann , marek@open-mesh.com X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Sven Eckelmann hostapd can run with different VIF when using nl80211. Events about MIC failures have to be processed in context of the VIF which received it and not in context of the primary VIF. Otherwise the station belonging to this VIF may not be found in the primary VIF station hash and therefore no countermeasures are started or the countermeasures are started for the wrong VIF. Signed-hostap: Sven Eckelmann Signed-hostap: Simon Wunderlich --- src/drivers/driver_nl80211.c | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 297f677..a8143e5 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -201,6 +201,7 @@ struct i802_bss { int freq; + void *ctx; struct nl_handle *nl_preq, *nl_mgmt; struct nl_cb *nl_cb; @@ -1529,7 +1530,7 @@ static void mlme_event(struct wpa_driver_nl80211_data *drv, } -static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data *drv, +static void mlme_event_michael_mic_failure(struct i802_bss *bss, struct nlattr *tb[]) { union wpa_event_data data; @@ -1561,7 +1562,7 @@ static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data *drv, wpa_printf(MSG_DEBUG, "nl80211: Key Id %d", key_id); } - wpa_supplicant_event(drv->ctx, EVENT_MICHAEL_MIC_FAILURE, &data); + wpa_supplicant_event(bss->ctx, EVENT_MICHAEL_MIC_FAILURE, &data); } @@ -2168,9 +2169,11 @@ static void nl80211_spurious_frame(struct i802_bss *bss, struct nlattr **tb, } -static void do_process_drv_event(struct wpa_driver_nl80211_data *drv, - int cmd, struct nlattr **tb) +static void do_process_drv_event(struct i802_bss *bss, int cmd, + struct nlattr **tb) { + struct wpa_driver_nl80211_data *drv = bss->drv; + if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED && (cmd == NL80211_CMD_NEW_SCAN_RESULTS || cmd == NL80211_CMD_SCAN_ABORTED)) { @@ -2243,7 +2246,7 @@ static void do_process_drv_event(struct wpa_driver_nl80211_data *drv, tb[NL80211_ATTR_DISCONNECTED_BY_AP]); break; case NL80211_CMD_MICHAEL_MIC_FAILURE: - mlme_event_michael_mic_failure(drv, tb); + mlme_event_michael_mic_failure(bss, tb); break; case NL80211_CMD_JOIN_IBSS: mlme_event_join_ibss(drv, tb); @@ -2298,21 +2301,25 @@ static int process_drv_event(struct nl_msg *msg, void *arg) struct wpa_driver_nl80211_data *drv = arg; struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); struct nlattr *tb[NL80211_ATTR_MAX + 1]; + struct i802_bss *bss; + int ifidx = -1; nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); - if (tb[NL80211_ATTR_IFINDEX]) { - int ifindex = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); - if (ifindex != drv->ifindex && !have_ifidx(drv, ifindex)) { - wpa_printf(MSG_DEBUG, "nl80211: Ignored event (cmd=%d)" - " for foreign interface (ifindex %d)", - gnlh->cmd, ifindex); + if (tb[NL80211_ATTR_IFINDEX]) + ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); + + for (bss = &drv->first_bss; bss; bss = bss->next) { + if (ifidx == -1 || ifidx == bss->ifindex) { + do_process_drv_event(bss, gnlh->cmd, tb); return NL_SKIP; } } - do_process_drv_event(drv, gnlh->cmd, tb); + wpa_printf(MSG_DEBUG, "nl80211: Ignored event (cmd=%d)" + " for foreign interface (ifindex %d)", + gnlh->cmd, ifidx); return NL_SKIP; } @@ -2324,6 +2331,7 @@ static int process_global_event(struct nl_msg *msg, void *arg) struct nlattr *tb[NL80211_ATTR_MAX + 1]; struct wpa_driver_nl80211_data *drv, *tmp; int ifidx = -1; + struct i802_bss *bss; nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); @@ -2333,9 +2341,12 @@ static int process_global_event(struct nl_msg *msg, void *arg) dl_list_for_each_safe(drv, tmp, &global->interfaces, struct wpa_driver_nl80211_data, list) { - if (ifidx == -1 || ifidx == drv->ifindex || - have_ifidx(drv, ifidx)) - do_process_drv_event(drv, gnlh->cmd, tb); + for (bss = &drv->first_bss; bss; bss = bss->next) { + if (ifidx == -1 || ifidx == bss->ifindex) { + do_process_drv_event(bss, gnlh->cmd, tb); + return NL_SKIP; + } + } } return NL_SKIP; @@ -3069,6 +3080,8 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, drv->ctx = ctx; bss = &drv->first_bss; bss->drv = drv; + bss->ctx = ctx; + os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); drv->monitor_ifidx = -1; drv->monitor_sock = -1; @@ -8106,6 +8119,7 @@ static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, new_bss->drv = drv; new_bss->next = drv->first_bss.next; new_bss->freq = drv->first_bss.freq; + new_bss->ctx = bss_ctx; drv->first_bss.next = new_bss; if (drv_priv) *drv_priv = new_bss;