Skip to contentSkip to conversation

ath9k_htc: properly set MAC address and BSSID mask

PATCH In review Mathy Vanhoef 6 participants 12 messages Nov 26, 2013 – Dec 9, 2013 Qualcomm Atheros ATH9K wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ath9k_htc: properly set MAC address and BSSID mask

From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +17 -8
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
 	struct ath9k_vif_iter_data *iter_data = data;
 	int i;
 
-	for (i = 0; i < ETH_ALEN; i++)
-		iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	if (iter_data->hw_macaddr != NULL) {
+		for (i = 0; i < ETH_ALEN; i++)
+			iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	} else {
+		iter_data->hw_macaddr = mac;
+	}
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
 				     struct ieee80211_vif *vif)
 {
 	struct ath_common *common = ath9k_hw_common(priv->ah);
 	struct ath9k_vif_iter_data iter_data;
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
-	iter_data.hw_macaddr = common->macaddr;
+	iter_data.hw_macaddr = NULL;
 	memset(&iter_data.mask, 0xff, ETH_ALEN);
 
 	if (vif)
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
 		ath9k_htc_bssid_iter, &iter_data);
 
 	memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+	if (iter_data.hw_macaddr)
+		memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
 	ath_hw_setbssidmask(common);
 }
 
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
 		goto out;
 	}
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	priv->vif_slot |= (1 << avp->index);
 	priv->nvifs++;
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
 
 	ath9k_htc_set_opmode(priv);
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	/*
 	 * Stop ANI only if there are no associated station interfaces.
drivers/net/wireless/ath/ath9k/main.c +3 -2
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
 	struct ath_common *common = ath9k_hw_common(ah);
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
 	memset(iter_data, 0, sizeof(*iter_data));
 	memset(&iter_data->mask, 0xff, ETH_ALEN);

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

#1 lore raw

Hi Mathy,

thank you for your work!
suddenly this patch do not apply on top of
git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git

can you please update it.

Am 26.11.2013 19:13, schrieb Mathy Vanhoef:

Quoted 104 lines

From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +11 -6
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8
 *mac, struct ieee80211_vif *vif)
     struct ath9k_vif_iter_data *iter_data = data;
     int i;
 
-    for (i = 0; i < ETH_ALEN; i++)
-        iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+    if (iter_data->hw_macaddr != NULL) {
+        for (i = 0; i < ETH_ALEN; i++)
+            iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+    } else {
+        iter_data->hw_macaddr = mac;
+    }
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
                      struct ieee80211_vif *vif)
 {
     struct ath_common *common = ath9k_hw_common(priv->ah);
     struct ath9k_vif_iter_data iter_data;
 
     /*
-     * Use the hardware MAC address as reference, the hardware uses it
-     * together with the BSSID mask when matching addresses.
+     * Pick the MAC address of the first interface as the new hardware
+     * MAC address. The hardware will use it together with the BSSID mask
+     * when matching addresses.
      */
-    iter_data.hw_macaddr = common->macaddr;
+    iter_data.hw_macaddr = NULL;
     memset(&iter_data.mask, 0xff, ETH_ALEN);
 

if (vif)

drivers/net/wireless/ath/ath9k/htc_drv_main.c +5 -1
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct
 ath9k_htc_priv *priv,
         ath9k_htc_bssid_iter, &iter_data);
 
     memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+    if (iter_data.hw_macaddr)
+        memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
     ath_hw_setbssidmask(common);
 }
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct
 ieee80211_hw *hw,
         goto out;
     }
 
-    ath9k_htc_set_bssid_mask(priv, vif);
+    ath9k_htc_set_mac_bssid_mask(priv, vif);
 
     priv->vif_slot |= (1 << avp->index);
     priv->nvifs++;
drivers/net/wireless/ath/ath9k/htc_drv_main.c +1 -1
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct
 ieee80211_hw *hw,
 
     ath9k_htc_set_opmode(priv);
 
-    ath9k_htc_set_bssid_mask(priv, vif);
+    ath9k_htc_set_mac_bssid_mask(priv, vif);
 
     /*

* Stop ANI only if there are no associated station interfaces.

drivers/net/wireless/ath/ath9k/main.c +3 -2
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
     struct ath_common *common = ath9k_hw_common(ah);
 
     /*
-     * Use the hardware MAC address as reference, the hardware uses it
-     * together with the BSSID mask when matching addresses.
+     * Pick the MAC address of the first interface as the new hardware
+     * MAC address. The hardware will use it together with the BSSID mask
+     * when matching addresses.
      */
     memset(iter_data, 0, sizeof(*iter_data));
     memset(&iter_data->mask, 0xff, ETH_ALEN);

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

Signature · 4 lines
To unsubscribe from this list: send the line "unsubscribe
linux-wireless" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Regards,
Oleksij
#2 lore raw

Hi Oleksij,

It appears something went wrong with tabs/spaces when sending the patch over mail. It should work this time.

--
From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +17 -8
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
 	struct ath9k_vif_iter_data *iter_data = data;
 	int i;
 
-	for (i = 0; i < ETH_ALEN; i++)
-		iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	if (iter_data->hw_macaddr != NULL) {
+		for (i = 0; i < ETH_ALEN; i++)
+			iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	} else {
+		iter_data->hw_macaddr = mac;
+	}
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
 				     struct ieee80211_vif *vif)
 {
 	struct ath_common *common = ath9k_hw_common(priv->ah);
 	struct ath9k_vif_iter_data iter_data;
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
-	iter_data.hw_macaddr = common->macaddr;
+	iter_data.hw_macaddr = NULL;
 	memset(&iter_data.mask, 0xff, ETH_ALEN);
 
 	if (vif)
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
 		ath9k_htc_bssid_iter, &iter_data);
 
 	memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+	if (iter_data.hw_macaddr)
+		memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
 	ath_hw_setbssidmask(common);
 }
 
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
 		goto out;
 	}
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	priv->vif_slot |= (1 << avp->index);
 	priv->nvifs++;
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
 
 	ath9k_htc_set_opmode(priv);
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	/*
 	 * Stop ANI only if there are no associated station interfaces.
drivers/net/wireless/ath/ath9k/main.c +3 -2
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
 	struct ath_common *common = ath9k_hw_common(ah);
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
 	memset(iter_data, 0, sizeof(*iter_data));
 	memset(&iter_data->mask, 0xff, ETH_ALEN);
Quoted 108 lines · Oleksij Rempel

Hi Mathy,

thank you for your work!
suddenly this patch do not apply on top of
git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git

can you please update it.

Am 26.11.2013 19:13, schrieb Mathy Vanhoef:

Quoted 98 lines

From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +11 -6
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8
 *mac, struct ieee80211_vif *vif)
     struct ath9k_vif_iter_data *iter_data = data;
     int i;
 
-    for (i = 0; i < ETH_ALEN; i++)
-        iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+    if (iter_data->hw_macaddr != NULL) {
+        for (i = 0; i < ETH_ALEN; i++)
+            iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+    } else {
+        iter_data->hw_macaddr = mac;
+    }
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
                      struct ieee80211_vif *vif)
 {
     struct ath_common *common = ath9k_hw_common(priv->ah);
     struct ath9k_vif_iter_data iter_data;
 
     /*
-     * Use the hardware MAC address as reference, the hardware uses it
-     * together with the BSSID mask when matching addresses.
+     * Pick the MAC address of the first interface as the new hardware
+     * MAC address. The hardware will use it together with the BSSID mask
+     * when matching addresses.
      */
-    iter_data.hw_macaddr = common->macaddr;
+    iter_data.hw_macaddr = NULL;
     memset(&iter_data.mask, 0xff, ETH_ALEN);
 

if (vif)

drivers/net/wireless/ath/ath9k/htc_drv_main.c +5 -1
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct
 ath9k_htc_priv *priv,
         ath9k_htc_bssid_iter, &iter_data);
 
     memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+    if (iter_data.hw_macaddr)
+        memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
     ath_hw_setbssidmask(common);
 }
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct
 ieee80211_hw *hw,
         goto out;
     }
 
-    ath9k_htc_set_bssid_mask(priv, vif);
+    ath9k_htc_set_mac_bssid_mask(priv, vif);
 
     priv->vif_slot |= (1 << avp->index);
     priv->nvifs++;
drivers/net/wireless/ath/ath9k/htc_drv_main.c +1 -1
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct
 ieee80211_hw *hw,
 
     ath9k_htc_set_opmode(priv);
 
-    ath9k_htc_set_bssid_mask(priv, vif);
+    ath9k_htc_set_mac_bssid_mask(priv, vif);
 
     /*

* Stop ANI only if there are no associated station interfaces.

drivers/net/wireless/ath/ath9k/main.c +3 -2
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
     struct ath_common *common = ath9k_hw_common(ah);
 
     /*
-     * Use the hardware MAC address as reference, the hardware uses it
-     * together with the BSSID mask when matching addresses.
+     * Pick the MAC address of the first interface as the new hardware
+     * MAC address. The hardware will use it together with the BSSID mask
+     * when matching addresses.
      */
     memset(iter_data, 0, sizeof(*iter_data));
     memset(&iter_data->mask, 0xff, ETH_ALEN);
Quoted 8 lines
Quoted 6 lines

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

Signature · 4 lines
To unsubscribe from this list: send the line "unsubscribe
linux-wireless" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

#4 lore raw

Third time's the charm?
--
From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +17 -8
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
 	struct ath9k_vif_iter_data *iter_data = data;
 	int i;
 
-	for (i = 0; i < ETH_ALEN; i++)
-		iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	if (iter_data->hw_macaddr != NULL) {
+		for (i = 0; i < ETH_ALEN; i++)
+			iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	} else {
+		iter_data->hw_macaddr = mac;
+	}
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
 				     struct ieee80211_vif *vif)
 {
 	struct ath_common *common = ath9k_hw_common(priv->ah);
 	struct ath9k_vif_iter_data iter_data;
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
-	iter_data.hw_macaddr = common->macaddr;
+	iter_data.hw_macaddr = NULL;
 	memset(&iter_data.mask, 0xff, ETH_ALEN);
 
 	if (vif)
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
 		ath9k_htc_bssid_iter, &iter_data);
 
 	memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+	if (iter_data.hw_macaddr)
+		memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
 	ath_hw_setbssidmask(common);
 }
 
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
 		goto out;
 	}
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	priv->vif_slot |= (1 << avp->index);
 	priv->nvifs++;
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
 
 	ath9k_htc_set_opmode(priv);
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	/*
 	 * Stop ANI only if there are no associated station interfaces.
drivers/net/wireless/ath/ath9k/main.c +3 -2
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
 	struct ath_common *common = ath9k_hw_common(ah);
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
 	memset(iter_data, 0, sizeof(*iter_data));
 	memset(&iter_data->mask, 0xff, ETH_ALEN);
#5 lore raw
Quoted 21 lines · Mathy Vanhoef

Third time's the charm?
--
From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +2 -2
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
 	struct ath9k_vif_iter_data *iter_data = data;
 	int i;
 
-	for (i = 0; i < ETH_ALEN; i++)
-		iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	if (iter_data->hw_macaddr != NULL) {
+		for (i = 0; i < ETH_ALEN; i++)

drivers/net/wireless/ath/ath9k/htc_drv_main.c static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) · line 160

Quoted 10 lines
drivers/net/wireless/ath/ath9k/htc_drv_main.c +5 -1
+			iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	} else {
+		iter_data->hw_macaddr = mac;
+	}
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
 				     struct ieee80211_vif *vif)
 {

I'm not sure I see the point of renaming this function -- just personal preference?

Quoted 64 lines
drivers/net/wireless/ath/ath9k/htc_drv_main.c +10 -5
 	struct ath_common *common = ath9k_hw_common(priv->ah);
 	struct ath9k_vif_iter_data iter_data;
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
-	iter_data.hw_macaddr = common->macaddr;
+	iter_data.hw_macaddr = NULL;
 	memset(&iter_data.mask, 0xff, ETH_ALEN);
 
 	if (vif)
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
 		ath9k_htc_bssid_iter, &iter_data);
 
 	memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+	if (iter_data.hw_macaddr)
+		memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
 	ath_hw_setbssidmask(common);
 }
 
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
 		goto out;
 	}
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	priv->vif_slot |= (1 << avp->index);
 	priv->nvifs++;
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
 
 	ath9k_htc_set_opmode(priv);
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	/*
 	 * Stop ANI only if there are no associated station interfaces.
drivers/net/wireless/ath/ath9k/main.c +3 -2
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
 	struct ath_common *common = ath9k_hw_common(ah);
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
 	memset(iter_data, 0, sizeof(*iter_data));
 	memset(&iter_data->mask, 0xff, ETH_ALEN);
Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#6 lore raw

It was renamed to make it clear the function now changes both the BSSID and MAC registers.

Quoted 104 lines · John W. Linville
Quoted 21 lines · Mathy Vanhoef

Third time's the charm?
--
From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +2 -2
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
      struct ath9k_vif_iter_data *iter_data = data;
      int i;
 
-     for (i = 0; i < ETH_ALEN; i++)
-             iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+     if (iter_data->hw_macaddr != NULL) {
+             for (i = 0; i < ETH_ALEN; i++)

drivers/net/wireless/ath/ath9k/htc_drv_main.c static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) · line 160

Quoted 10 lines
drivers/net/wireless/ath/ath9k/htc_drv_main.c +5 -1
+                     iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+     } else {
+             iter_data->hw_macaddr = mac;
+     }
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
                                   struct ieee80211_vif *vif)
 {

I'm not sure I see the point of renaming this function -- just personal preference?

Quoted 54 lines
drivers/net/wireless/ath/ath9k/htc_drv_main.c +10 -5
      struct ath_common *common = ath9k_hw_common(priv->ah);
      struct ath9k_vif_iter_data iter_data;
 
      /*
-      * Use the hardware MAC address as reference, the hardware uses it
-      * together with the BSSID mask when matching addresses.
+      * Pick the MAC address of the first interface as the new hardware
+      * MAC address. The hardware will use it together with the BSSID mask
+      * when matching addresses.
       */
-     iter_data.hw_macaddr = common->macaddr;
+     iter_data.hw_macaddr = NULL;
      memset(&iter_data.mask, 0xff, ETH_ALEN);
 
      if (vif)
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
              ath9k_htc_bssid_iter, &iter_data);
 
      memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+     if (iter_data.hw_macaddr)
+             memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
      ath_hw_setbssidmask(common);
 }
 
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
              goto out;
      }
 
-     ath9k_htc_set_bssid_mask(priv, vif);
+     ath9k_htc_set_mac_bssid_mask(priv, vif);
 
      priv->vif_slot |= (1 << avp->index);
      priv->nvifs++;
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
 
      ath9k_htc_set_opmode(priv);
 
-     ath9k_htc_set_bssid_mask(priv, vif);
+     ath9k_htc_set_mac_bssid_mask(priv, vif);
 
      /*
       * Stop ANI only if there are no associated station interfaces.
drivers/net/wireless/ath/ath9k/main.c +0 -0
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
      struct ath_common *common = ath9k_hw_common(ah);

drivers/net/wireless/ath/ath9k/main.c void ath9k_calculate_iter_data(struct ieee80211_hw *hw, · line 893

Quoted 10 lines
drivers/net/wireless/ath/ath9k/main.c +3 -2
 
      /*
-      * Use the hardware MAC address as reference, the hardware uses it
-      * together with the BSSID mask when matching addresses.
+      * Pick the MAC address of the first interface as the new hardware
+      * MAC address. The hardware will use it together with the BSSID mask
+      * when matching addresses.
       */
      memset(iter_data, 0, sizeof(*iter_data));
      memset(&iter_data->mask, 0xff, ETH_ALEN);

--
John W. Linville Someday the world will need a hero, and you
[email protected] might be all we have. Be ready.

#7 lore raw

I have only one doubt in this patch.
It will overwrite original MAC. If you wont to restore it, then you need to reload module.

If no body against it, i can live it too.

Am 06.12.2013 21:30, schrieb Mathy:

Quoted 108 lines

It was renamed to make it clear the function now changes both the BSSID and MAC registers.

Quoted 104 lines · John W. Linville
Quoted 21 lines · Mathy Vanhoef

Third time's the charm?
--
From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +2 -2
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
      struct ath9k_vif_iter_data *iter_data = data;
      int i;
 
-     for (i = 0; i < ETH_ALEN; i++)
-             iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+     if (iter_data->hw_macaddr != NULL) {
+             for (i = 0; i < ETH_ALEN; i++)

drivers/net/wireless/ath/ath9k/htc_drv_main.c static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) · line 160

Quoted 10 lines
drivers/net/wireless/ath/ath9k/htc_drv_main.c +5 -1
+                     iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+     } else {
+             iter_data->hw_macaddr = mac;
+     }
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
                                   struct ieee80211_vif *vif)
 {

I'm not sure I see the point of renaming this function -- just personal preference?

Quoted 54 lines
drivers/net/wireless/ath/ath9k/htc_drv_main.c +10 -5
      struct ath_common *common = ath9k_hw_common(priv->ah);
      struct ath9k_vif_iter_data iter_data;
 
      /*
-      * Use the hardware MAC address as reference, the hardware uses it
-      * together with the BSSID mask when matching addresses.
+      * Pick the MAC address of the first interface as the new hardware
+      * MAC address. The hardware will use it together with the BSSID mask
+      * when matching addresses.
       */
-     iter_data.hw_macaddr = common->macaddr;
+     iter_data.hw_macaddr = NULL;
      memset(&iter_data.mask, 0xff, ETH_ALEN);
 
      if (vif)
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
              ath9k_htc_bssid_iter, &iter_data);
 
      memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+     if (iter_data.hw_macaddr)
+             memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
      ath_hw_setbssidmask(common);
 }
 
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
              goto out;
      }
 
-     ath9k_htc_set_bssid_mask(priv, vif);
+     ath9k_htc_set_mac_bssid_mask(priv, vif);
 
      priv->vif_slot |= (1 << avp->index);
      priv->nvifs++;
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
 
      ath9k_htc_set_opmode(priv);
 
-     ath9k_htc_set_bssid_mask(priv, vif);
+     ath9k_htc_set_mac_bssid_mask(priv, vif);
 
      /*
       * Stop ANI only if there are no associated station interfaces.
drivers/net/wireless/ath/ath9k/main.c +0 -0
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
      struct ath_common *common = ath9k_hw_common(ah);

drivers/net/wireless/ath/ath9k/main.c void ath9k_calculate_iter_data(struct ieee80211_hw *hw, · line 893

Quoted 10 lines
drivers/net/wireless/ath/ath9k/main.c +3 -2
 
      /*
-      * Use the hardware MAC address as reference, the hardware uses it
-      * together with the BSSID mask when matching addresses.
+      * Pick the MAC address of the first interface as the new hardware
+      * MAC address. The hardware will use it together with the BSSID mask
+      * when matching addresses.
       */
      memset(iter_data, 0, sizeof(*iter_data));
      memset(&iter_data->mask, 0xff, ETH_ALEN);

--
John W. Linville Someday the world will need a hero, and you
[email protected] might be all we have. Be ready.

Signature · 2 lines
Regards,
Oleksij
#8 lore raw
Quoted 5 lines · Oleksij Rempel

I have only one doubt in this patch.
It will overwrite original MAC. If you wont to restore it, then you need to reload module.

If no body against it, i can live it too.

I believe ethtool allows an API to read the eeprom-MAC addr. Maybe add support for that API to the ath9k_htc driver so that the original MAC can be read that way?

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#9 lore raw

The common->macaddr field is also updated in the ath9k driver (function ath9k_calculate_iter_data in main.c).

I just did a quick test. When using macchanger to assign a random MAC address, the original (permanent) MAC address is still retrieved properly. So there is no need to reload the module, macchanger can simply restore the permanent MAC. I assume the permanent MAC address is saved elsewhere?

Quoted 20 lines · Ben Greear
Quoted 6 lines · Oleksij Rempel

I have only one doubt in this patch.
It will overwrite original MAC. If you wont to restore it, then you need to reload module.

If no body against it, i can live it too.

I believe ethtool allows an API to read the eeprom-MAC addr. Maybe add support for that API to the ath9k_htc driver so that the original MAC can be read that way?

Thanks,
Ben

--
Ben Greear <[email protected]>
Candela Technologies Inc http://www.candelatech.com

#10 lore raw

Am 08.12.2013 19:09, schrieb Mathy:

Quoted 8 lines

The common->macaddr field is also updated in the ath9k driver (function ath9k_calculate_iter_data in main.c).

I just did a quick test. When using macchanger to assign a random MAC address, the original (permanent) MAC address is still retrieved properly. So there is no need to reload the module, macchanger can simply restore the permanent MAC. I assume the permanent MAC address is saved elsewhere?

Right now i have no time to digg deeper in it. I'm ok with this patch. Thanks a lot for your work!

Signature · 2 lines
Regards,
Oleksij
#11 lore raw
In reply to Mathy Vanhoef

Can we get some comments on this patch? It is attempting to address a CVE.

John

Quoted 95 lines · Mathy Vanhoef

Third time's the charm?
--
From: "Mathy Vanhoef" <[email protected]>

Pick the MAC address of the first virtual interface as the new hardware MAC address. Set BSSID mask according to this MAC address. This fixes CVE-2013-4579.

---

drivers/net/wireless/ath/ath9k/htc_drv_main.c +17 -8
index d441045..84359c3 100644
@@ -147,21 +147,26 @@ static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
 	struct ath9k_vif_iter_data *iter_data = data;
 	int i;
 
-	for (i = 0; i < ETH_ALEN; i++)
-		iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	if (iter_data->hw_macaddr != NULL) {
+		for (i = 0; i < ETH_ALEN; i++)
+			iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
+	} else {
+		iter_data->hw_macaddr = mac;
+	}
 }
 
-static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
+static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv,
 				     struct ieee80211_vif *vif)
 {
 	struct ath_common *common = ath9k_hw_common(priv->ah);
 	struct ath9k_vif_iter_data iter_data;
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
-	iter_data.hw_macaddr = common->macaddr;
+	iter_data.hw_macaddr = NULL;
 	memset(&iter_data.mask, 0xff, ETH_ALEN);
 
 	if (vif)
@@ -173,6 +178,10 @@ static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
 		ath9k_htc_bssid_iter, &iter_data);
 
 	memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
+
+	if (iter_data.hw_macaddr)
+		memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
+
 	ath_hw_setbssidmask(common);
 }
 
@@ -1083,7 +1092,7 @@ static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
 		goto out;
 	}
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	priv->vif_slot |= (1 << avp->index);
 	priv->nvifs++;
@@ -1148,7 +1157,7 @@ static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
 
 	ath9k_htc_set_opmode(priv);
 
-	ath9k_htc_set_bssid_mask(priv, vif);
+	ath9k_htc_set_mac_bssid_mask(priv, vif);
 
 	/*
 	 * Stop ANI only if there are no associated station interfaces.
drivers/net/wireless/ath/ath9k/main.c +3 -2
index b6aad69..99ab0aa 100644
@@ -885,8 +885,9 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
 	struct ath_common *common = ath9k_hw_common(ah);
 
 	/*
-	 * Use the hardware MAC address as reference, the hardware uses it
-	 * together with the BSSID mask when matching addresses.
+	 * Pick the MAC address of the first interface as the new hardware
+	 * MAC address. The hardware will use it together with the BSSID mask
+	 * when matching addresses.
 	 */
 	memset(iter_data, 0, sizeof(*iter_data));
 	memset(&iter_data->mask, 0xff, ETH_ALEN);
Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.