Skip to contentSkip to conversation

mac80211: fix NULL pointer dereference in ieee80211_compatible_rates

PATCH Superseded Helmut Schaa 5 participants 8 messages May 17, 2008 – May 19, 2008 mac80211

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mac80211: fix NULL pointer dereference in ieee80211_compatible_rates

Fix a possible NULL pointer dereference in ieee80211_compatible_rates introduced in the patch "mac80211: fix association with some APs".

---

net/mac80211/mlme.c +15 -8
index 76ad4ed..2642551 100644
@@ -664,15 +664,22 @@ static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss,
 	int i, j, count;
 	*rates = 0;
 	count = 0;
-	for (i = 0; i < bss->supp_rates_len; i++) {
-		int rate = (bss->supp_rates[i] & 0x7F) * 5;
 
-		for (j = 0; j < sband->n_bitrates; j++)
-			if (sband->bitrates[j].bitrate == rate) {
-				*rates |= BIT(j);
-				count++;
-				break;
-			}
+	if (bss) {
+		for (i = 0; i < bss->supp_rates_len; i++) {
+			int rate = (bss->supp_rates[i] & 0x7F) * 5;
+
+			for (j = 0; j < sband->n_bitrates; j++)
+				if (sband->bitrates[j].bitrate == rate) {
+					*rates |= BIT(j);
+					count++;
+					break;
+				}
+		}
+	} else {
+		for (i = 0; i < sband->n_bitrates; i++)
+			*rates |= BIT(i);
+		count = sband->n_bitrates;
 	}
 
 	return count;
#1 lore raw
Quoted 41 lines · Helmut Schaa

Fix a possible NULL pointer dereference in ieee80211_compatible_rates introduced in the patch "mac80211: fix association with some APs".

---

net/mac80211/mlme.c +15 -8
index 76ad4ed..2642551 100644
@@ -664,15 +664,22 @@ static int ieee80211_compatible_rates(struct
 ieee80211_sta_bss *bss,
       int i, j, count;
       *rates = 0;
       count = 0;
-       for (i = 0; i < bss->supp_rates_len; i++) {
-               int rate = (bss->supp_rates[i] & 0x7F) * 5;
 
-               for (j = 0; j < sband->n_bitrates; j++)
-                       if (sband->bitrates[j].bitrate == rate) {
-                               *rates |= BIT(j);
-                               count++;
-                               break;
-                       }
+       if (bss) {
+               for (i = 0; i < bss->supp_rates_len; i++) {
+                       int rate = (bss->supp_rates[i] & 0x7F) * 5;
+
+                       for (j = 0; j < sband->n_bitrates; j++)
+                               if (sband->bitrates[j].bitrate == rate) {
+                                       *rates |= BIT(j);
+                                       count++;
+                                       break;
+                               }
+               }
+       } else {
+               for (i = 0; i < sband->n_bitrates; i++)
+                       *rates |= BIT(i);
+               count = sband->n_bitrates;
       }
 
Quoted 2 lines
       return count;

Again, mac should rather solve the problem that we do not connect to AP's that are not in the BSS list
Personally I would NACK this as it's just hiding the real problem

The other issue is that we call ieee80211_rx_bss_put(dev, bss); before this call in ieee80211_send_assoc.

Tomas

#2 lore raw
Quoted 42 lines · Tomas Winkler
Quoted 41 lines · Helmut Schaa

Fix a possible NULL pointer dereference in ieee80211_compatible_rates introduced in the patch "mac80211: fix association with some APs".

---

net/mac80211/mlme.c +15 -8
index 76ad4ed..2642551 100644
@@ -664,15 +664,22 @@ static int ieee80211_compatible_rates(struct
 ieee80211_sta_bss *bss,
       int i, j, count;
       *rates = 0;
       count = 0;
-       for (i = 0; i < bss->supp_rates_len; i++) {
-               int rate = (bss->supp_rates[i] & 0x7F) * 5;
 
-               for (j = 0; j < sband->n_bitrates; j++)
-                       if (sband->bitrates[j].bitrate == rate) {
-                               *rates |= BIT(j);
-                               count++;
-                               break;
-                       }
+       if (bss) {
+               for (i = 0; i < bss->supp_rates_len; i++) {
+                       int rate = (bss->supp_rates[i] & 0x7F) * 5;
+
+                       for (j = 0; j < sband->n_bitrates; j++)
+                               if (sband->bitrates[j].bitrate == rate) {
+                                       *rates |= BIT(j);
+                                       count++;
+                                       break;
+                               }
+               }
+       } else {
+               for (i = 0; i < sband->n_bitrates; i++)
+                       *rates |= BIT(i);
+               count = sband->n_bitrates;
       }
 
Quoted 6 lines
Quoted 2 lines
       return count;

Again, mac should rather solve the problem that we do not connect to AP's that are not in the BSS list
Personally I would NACK this as it's just hiding the real problem

Ugh; is that what's happening? If the AP isn't in the BSS list of the card, then the card shouldn't be connecting to it. It should have been probe-scanned already and thus exist in the BSS list, right?

Dan

Quoted 8 lines

The other issue is that we call ieee80211_rx_bss_put(dev, bss); before this call in ieee80211_send_assoc.

Tomas
--
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

#3 lore raw
Quoted 5 lines · Dan Williams
Quoted 3 lines · Tomas Winkler

Again, mac should rather solve the problem that we do not connect to AP's that are not in the BSS list
Personally I would NACK this as it's just hiding the real problem

Quoted 8 lines

Ugh; is that what's happening? If the AP isn't in the BSS list of the card, then the card shouldn't be connecting to it. It should have been probe-scanned already and thus exist in the BSS list, right?

Dan

Quoted 2 lines

The other issue is that we call ieee80211_rx_bss_put(dev, bss); before this call in ieee80211_send_assoc.

This AP certainly should have been in the BSS list. As I stated in the original post, the system had been connected to that AP for about 18 hours before the NULL bss NULL event occurred.

Clearly the sequence of events is improbable and it may be some time before it happens again. What diagnostic information would be useful to capture if/when it occurs? Is there any other location that I should monitor?

Larry

#4 lore raw
Quoted 15 lines · Larry Finger
Quoted 5 lines · Dan Williams
Quoted 3 lines · Tomas Winkler

Again, mac should rather solve the problem that we do not connect to AP's that are not in the BSS list
Personally I would NACK this as it's just hiding the real problem

Quoted 8 lines

Ugh; is that what's happening? If the AP isn't in the BSS list of the card, then the card shouldn't be connecting to it. It should have been probe-scanned already and thus exist in the BSS list, right?

Dan

Quoted 2 lines

The other issue is that we call ieee80211_rx_bss_put(dev, bss); before this call in ieee80211_send_assoc.

Quoted 7 lines

This AP certainly should have been in the BSS list. As I stated in the original post, the system had been connected to that AP for about 18 hours before the NULL bss NULL event occurred.

Clearly the sequence of events is improbable and it may be some time before it happens again. What diagnostic information would be useful to capture if/when it occurs? Is there any other location that I should monitor?

I'd think a printk whenever a unique BSS item is removed from the BSS list; and the location of that removal in the code using __func__ and __LINE__ in the output.

Dan

#5 lore raw
In reply to Tomas Winkler

Am Sonntag, 18. Mai 2008 12:37:23 schrieb Tomas Winkler:

Quoted 2 lines

Again, mac should rather solve the problem that we do not connect to AP's that are not in the BSS list

I just tried that approach (see patch below) and could not find a regression at a first glance. Nevertheless I'm not sure in which situations a bss is removed from the list and if this approach would cause a regression?

Regards,
Helmut

net/mac80211/mlme.c +0 -0
index 76ad4ed..8595bfd 100644
@@ -678,7 +678,7 @@ static int ieee80211_compatible_rates(struct 

ieee80211_sta_bss *bss,
return count;
}

-static void ieee80211_send_assoc(struct net_device *dev,
+static int ieee80211_send_assoc(struct net_device *dev,
struct ieee80211_if_sta *ifsta)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -716,6 +716,10 @@ static void ieee80211_send_assoc(struct net_device *dev,
bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
local->hw.conf.channel->center_freq, ifsta->ssid, ifsta->ssid_len);
+
+ if (!bss)
+ return 1;
+
if (bss) {
if (bss->capability & WLAN_CAPABILITY_PRIVACY)
capab |= WLAN_CAPABILITY_PRIVACY;
@@ -829,6 +833,8 @@ static void ieee80211_send_assoc(struct net_device *dev,
memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);

ieee80211_sta_tx(dev, skb, 0);
+
+ return 0;
}

@@ -945,7 +951,11 @@ static void ieee80211_associate(struct net_device *dev,
return;
}

- ieee80211_send_assoc(dev, ifsta);
+ if (ieee80211_send_assoc(dev, ifsta)) {
+ printk(KERN_DEBUG "%s: send association request failed", dev->name);
+ ifsta->state = IEEE80211_DISABLED;
+ return;
+ }

mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
}

maintainer
#6 lore raw
In reply to Tomas Winkler
Quoted 3 lines

Again, mac should rather solve the problem that we do not connect to AP's that are not in the BSS list

You're talking about this a lot without showing any willingness to work on it. Personally, I don't care so I'm not going to work on making this a valid assertion, obviously it is not.


Quoted 2 lines

The other issue is that we call ieee80211_rx_bss_put(dev, bss); before this call in ieee80211_send_assoc.

Indeed, we (i.e. not just me!) should have caught this at the time the original patch was merged.

Helmut, can you please make a patch that addresses both issues by instead moving the compatible rates check into the "if (bss)" part in ieee80211_send_assoc() right after ieee80211_rx_bss_get()? And you can make "u64 rates = ~0;" the default to address the !bss case.

johannes

#7 lore raw
Quoted 7 lines · Johannes Berg
Quoted 3 lines

Again, mac should rather solve the problem that we do not connect to AP's that are not in the BSS list

You're talking about this a lot without showing any willingness to work on it. Personally, I don't care so I'm not going to work on making this a valid assertion, obviously it is not.

You are absolutely right I can imagine how it sounds, just I wish I had more time. So for now I'm just talking. If nobody will fix it till I clean my table I will fix it.

Quoted 5 lines
Quoted 2 lines

The other issue is that we call ieee80211_rx_bss_put(dev, bss); before this call in ieee80211_send_assoc.

Indeed, we (i.e. not just me!) should have caught this at the time the original patch was merged.

:)

Quoted 5 lines

Helmut, can you please make a patch that addresses both issues by instead moving the compatible rates check into the "if (bss)" part in ieee80211_send_assoc() right after ieee80211_rx_bss_get()? And you can make "u64 rates = ~0;" the default to address the !bss case.

Still not sure in what flow the bss can be removed from the list. send_assoc() is called after mac has received successful authentication response. I would like to see a trace of this. Is this easily reproducible ?

Thanks
Tomas

Quoted 2 lines

johannes