Skip to contentSkip to conversation

brcmfmac: avoid writing channel out of allocated array

PATCH Superseded Rafał Miłecki 3 participants 17 messages Jan 3, 2017 – Jan 17, 2017 Broadcom BRCM80211 IEEE802.11 wireless drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 brcmfmac: avoid writing channel out of allocated array

From: Rafał Miłecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array.

Fix this by detecting unexpected channel and ignoring it.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiphy bands")

---
I'm not sure what kind of material it is. It fixes possible memory corruption (serious thing?) but this bug was there since Apr 2015, so is it worth fixing in 4.10? Or maybe I should even cc stable?
I don't think any released firmware reports any unexpected channel, so I guess noone ever hit this problem. I just noticed this possible problem when working on another feature.

---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c         | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +14 -15
index 13ca3eb..0babfc7 100644
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 	u32 i, j;
 	u32 total;
 	u32 chaninfo;
-	u32 index;
 
 	pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,33 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 		    ch.bw == BRCMU_CHAN_BW_80)
 			continue;
 
-		channel = band->channels;
-		index = band->n_channels;
+		channel = NULL;
 		for (j = 0; j < band->n_channels; j++) {
-			if (channel[j].hw_value == ch.control_ch_num) {
-				index = j;
+			if (band->channels[j].hw_value == ch.control_ch_num) {
+				channel = &band->channels[j];
 				break;
 			}
 		}
-		channel[index].center_freq =
-			ieee80211_channel_to_frequency(ch.control_ch_num,
-						       band->band);
-		channel[index].hw_value = ch.control_ch_num;
+		if (!channel) {
+			brcmf_err("Firmware reported unexpected channel %d\n",
+				  ch.control_ch_num);
+			continue;
+		}
 
 		/* assuming the chanspecs order is HT20,
 		 * HT40 upper, HT40 lower, and VHT80.
 		 */
 		if (ch.bw == BRCMU_CHAN_BW_80) {
-			channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
+			channel->flags &= ~IEEE80211_CHAN_NO_80MHZ;
 		} else if (ch.bw == BRCMU_CHAN_BW_40) {
-			brcmf_update_bw40_channel_flag(&channel[index], &ch);
+			brcmf_update_bw40_channel_flag(channel, &ch);
 		} else {
 			/* enable the channel and disable other bandwidths
 			 * for now as mentioned order assure they are enabled
 			 * for subsequent chanspecs.
 			 */
-			channel[index].flags = IEEE80211_CHAN_NO_HT40 |
-					       IEEE80211_CHAN_NO_80MHZ;
+			channel->flags = IEEE80211_CHAN_NO_HT40 |
+					 IEEE80211_CHAN_NO_80MHZ;
 			ch.bw = BRCMU_CHAN_BW_20;
 			cfg->d11inf.encchspec(&ch);
 			chaninfo = ch.chspec;
@@ -5907,11 +5906,11 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 						       &chaninfo);
 			if (!err) {
 				if (chaninfo & WL_CHAN_RADAR)
-					channel[index].flags |=
+					channel->flags |=
 						(IEEE80211_CHAN_RADAR |
 						 IEEE80211_CHAN_NO_IR);
 				if (chaninfo & WL_CHAN_PASSIVE)
-					channel[index].flags |=
+					channel->flags |=
 						IEEE80211_CHAN_NO_IR;
 			}
 		}
Signature · 1 line
2.10.1
maintainer
#1 lore raw
Quoted 10 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array.

Fix this by detecting unexpected channel and ignoring it.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiphy bands")
Quoted 7 lines

---
I'm not sure what kind of material it is. It fixes possible memory corruption (serious thing?) but this bug was there since Apr 2015, so is it worth fixing in 4.10? Or maybe I should even cc stable?
I don't think any released firmware reports any unexpected channel, so I guess noone ever hit this problem. I just noticed this possible problem when working on another feature.

Looking at the change I was going to ask if you actually hit the issue you are addressing here. The channels in __wl_2ghz_channels and __wl_5ghz_channels are complete list of channels for the particular band so it would mean firmware behaves out-of-spec or firmware api was changed. For robustness a change is acceptable I guess.

My general policy is to submit fixes to wireless-drivers (and stable) only if it resolves a critical issue found during testing or a reported issue.

Quoted 21 lines
---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c         | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -2
index 13ca3eb..0babfc7 100644
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 	u32 i, j;
 	u32 total;
 	u32 chaninfo;
-	u32 index;
 
 	pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,33 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 		    ch.bw == BRCMU_CHAN_BW_80)
 			continue;
 
-		channel = band->channels;

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5881

Quoted 10 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -3
-		index = band->n_channels;
+		channel = NULL;
 		for (j = 0; j < band->n_channels; j++) {
-			if (channel[j].hw_value == ch.control_ch_num) {
-				index = j;
+			if (band->channels[j].hw_value == ch.control_ch_num) {
+				channel = &band->channels[j];
 				break;
 			}
 		}

You could have kept the index construct and simply check if j == band->n_channels here to determine something is wrong.

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5887

Quoted 4 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -4
-		channel[index].center_freq =
-			ieee80211_channel_to_frequency(ch.control_ch_num,
-						       band->band);
-		channel[index].hw_value = ch.control_ch_num;

So you are also removing these assignments which indeed seem redundant. Maybe make note of that in the commit message?

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5886

Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +5 -0
+		if (!channel) {
+			brcmf_err("Firmware reported unexpected channel %d\n",
+				  ch.control_ch_num);
+			continue;
+		}

As stated above something is really off when this happens so should we continue and try to make sense of what firmware provides or simply fail.

Regards,
Arend

#2 lore raw
Quoted 10 lines · Arend Van Spriel
Quoted 9 lines · On 3-1-2017 9:38, Rafa=C5=82 Mi=C5=82ecki wrote:

From: Rafa=C5=82 Mi=C5=82ecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array.

Fix this by detecting unexpected channel and ignoring it.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiph=

y bands")

Quoted 3 lines
Quoted 3 lines

---
I'm not sure what kind of material it is. It fixes possible memory corru=

ption

Quoted 1 line
Quoted 1 line

(serious thing?) but this bug was there since Apr 2015, so is it worth f=

ixing

Quoted 2 lines
Quoted 2 lines

in 4.10? Or maybe I should even cc stable?
I don't think any released firmware reports any unexpected channel, so I=

guess

Quoted 1 line
Quoted 1 line

noone ever hit this problem. I just noticed this possible problem when w=

orking

Quoted 7 lines
Quoted 1 line

on another feature.

Looking at the change I was going to ask if you actually hit the issue you are addressing here. The channels in __wl_2ghz_channels and __wl_5ghz_channels are complete list of channels for the particular band so it would mean firmware behaves out-of-spec or firmware api was changed. For robustness a change is acceptable I guess.

I guess that point of view depends on one's trust to the firmware. I think it's wrong if a wrong/bugged/hacked firmware can result in memory corruption in the kernel. Even if it's only about sizeof(struct ieee80211_channel).

Quoted 3 lines

My general policy is to submit fixes to wireless-drivers (and stable) only if it resolves a critical issue found during testing or a reported issue.

I'm OK with that.

Quoted 2 lines
Quoted 2 lines

---
.../broadcom/brcm80211/brcmfmac/cfg80211.c | 29 +++++++++++----=

-------

Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 14 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c

Quoted 4 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_c=

Quoted 4 lines

index 13ca3eb..0babfc7 100644

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -0
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_c=

fg80211_info *cfg,

Quoted 8 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf=

Quoted 8 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -1
      u32 i, j;
      u32 total;
      u32 chaninfo;
-     u32 index;
 
      pbuf =3D kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,33 @@ static int brcmf_construct_chaninfo(struct brcmf=

_cfg80211_info *cfg,

Quoted 8 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf= · line 5879

Quoted 8 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -3
                  ch.bw =3D=3D BRCMU_CHAN_BW_80)
                      continue;
 
-             channel =3D band->channels;
-             index =3D band->n_channels;
+             channel =3D NULL;
              for (j =3D 0; j < band->n_channels; j++) {
-                     if (channel[j].hw_value =3D=3D ch.control_ch_num) =

{

Quoted 2 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf= · line 5877

Quoted 2 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -1
-                             index =3D j;
+                     if (band->channels[j].hw_value =3D=3D ch.control_c=

h_num) {

Quoted 7 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf= · line 5881

Quoted 4 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -0
+                             channel =3D &band->channels[j];
                              break;
                      }
              }

You could have kept the index construct and simply check if j =3D=3D band->n_channels here to determine something is wrong.

I wanted to simplify code at the same time. Having channel[index] repeated 7 times was a hint for me it could be handled better. I should have made that clear, I'll fix improve this in V2.

Quoted 7 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,

Quoted 4 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -4
-             channel[index].center_freq =3D
-                     ieee80211_channel_to_frequency(ch.control_ch_num,
-                                                    band->band);
-             channel[index].hw_value =3D ch.control_ch_num;

So you are also removing these assignments which indeed seem redundant. Maybe make note of that in the commit message?

Good idea.

Quoted 2 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf= · line 5883

Quoted 2 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +2 -0
+             if (!channel) {
+                     brcmf_err("Firmware reported unexpected channel %d=

\n",

Quoted 6 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5886

Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
+                               ch.control_ch_num);
+                     continue;
+             }

As stated above something is really off when this happens so should we continue and try to make sense of what firmware provides or simply fail.

Well, I could image something like this happening and not being critical. The simplest case: Broadcom team releases a new firmware which supports extra 5 GHz channels (e.g. due to the IEEE standard change). Why should we refuse to run & support all "old" channel just because of tha= t?

What do you mean by "make sense of what firmware provides"? Would kind of solution would you suggest?

--=20
Rafa=C5=82

maintainer
#3 lore raw
Quoted 11 lines · Rafał Miłecki
Quoted 7 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5886

Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +5 -0
+             if (!channel) {
+                     brcmf_err("Firmware reported unexpected channel %d\n",
+                               ch.control_ch_num);
+                     continue;
+             }

As stated above something is really off when this happens so should we continue and try to make sense of what firmware provides or simply fail.

Well, I could image something like this happening and not being critical. The simplest case: Broadcom team releases a new firmware which supports extra 5 GHz channels (e.g. due to the IEEE standard change). Why should we refuse to run & support all "old" channel just because of that?

Fair enough. I was assuming we keep __wl_{2,5}ghz_channels up to date with IEEE standard.

Quoted 2 lines

What do you mean by "make sense of what firmware provides"? Would kind of solution would you suggest?

When the above assumption can be assured (by us) the only other scenario would be a change in the firmware API where we wrongly interpret the information retrieved. In this case all subsequent channels will likely result in bogus or accidental matches hence it seems better to bail out early.

Regards,
Arend

#4 lore raw
Quoted 3 lines · Arend Van Spriel
Quoted 2 lines · On 3-1-2017 12:31, Rafa=C5=82 Mi=C5=82ecki wrote:
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             if (!channel) {
+                     brcmf_err("Firmware reported unexpected channel =

%d\n",

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5886

Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
+                               ch.control_ch_num);
+                     continue;
+             }

As stated above something is really off when this happens so should we continue and try to make sense of what firmware provides or simply fail=

.

Quoted 1 line
Quoted 1 line

Well, I could image something like this happening and not being critical=

.

Quoted 3 lines
Quoted 3 lines

The simplest case: Broadcom team releases a new firmware which supports extra 5 GHz channels (e.g. due to the IEEE standard change). Why should we refuse to run & support all "old" channel just because of =

that?

Quoted 4 lines

Fair enough. I was assuming we keep __wl_{2,5}ghz_channels up to date with IEEE standard.

Quoted 8 lines
Quoted 2 lines

What do you mean by "make sense of what firmware provides"? Would kind of solution would you suggest?

When the above assumption can be assured (by us) the only other scenario would be a change in the firmware API where we wrongly interpret the information retrieved. In this case all subsequent channels will likely result in bogus or accidental matches hence it seems better to bail out early.

Good point, this actually gave me an idea for a small nice improvement. I remember I saw something like WL_VER in wl ioctl protocol, it was already bumped at some point by Broadcom, when chanspec format has changed. We should probably read this number from firmware and maybe refuse to run if version is newer than the one we know.

--=20
Rafa=C5=82

#5 lore raw

On 3 January 2017 at 15:14, Rafa=C5=82 Mi=C5=82ecki <[email protected]> wrot= e:

Quoted 5 lines
Quoted 3 lines · Arend Van Spriel
Quoted 2 lines · On 3-1-2017 12:31, Rafa=C5=82 Mi=C5=82ecki wrote:
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             if (!channel) {
+                     brcmf_err("Firmware reported unexpected channel=

%d\n",

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5886

Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
+                               ch.control_ch_num);
+                     continue;
+             }

As stated above something is really off when this happens so should we continue and try to make sense of what firmware provides or simply fai=

l.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Well, I could image something like this happening and not being critica=

l.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The simplest case: Broadcom team releases a new firmware which supports extra 5 GHz channels (e.g. due to the IEEE standard change). Why should we refuse to run & support all "old" channel just because of=

that?

Quoted 13 lines
Quoted 4 lines

Fair enough. I was assuming we keep __wl_{2,5}ghz_channels up to date with IEEE standard.

Quoted 8 lines
Quoted 2 lines

What do you mean by "make sense of what firmware provides"? Would kind of solution would you suggest?

When the above assumption can be assured (by us) the only other scenario would be a change in the firmware API where we wrongly interpret the information retrieved. In this case all subsequent channels will likely result in bogus or accidental matches hence it seems better to bail out early.

Quoted 6 lines

Good point, this actually gave me an idea for a small nice improvement. I remember I saw something like WL_VER in wl ioctl protocol, it was already bumped at some point by Broadcom, when chanspec format has changed. We should probably read this number from firmware and maybe refuse to run if version is newer than the one we know.

I was thinking about WLC_GET_VERSION and you seem to already have it in brcmfmac under nam BRCMF_C_GET_VERSION. If you wish to be prepared for firmware API change, I guess you should check version. It seems brcmfmac supports 1 and 2.

On the other hand if adding firmware with incompatible API you may want to have different directory or file names. I think this is what Intel does. This allows one to have multiple firmwares in /lib/firmware/ and switching between kernels freely.

--=20
Rafa=C5=82

#9 lore raw

PATCH v2 1/1 brcmfmac: avoid writing channel out of allocated array

In reply to Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. This never happened so far (we got a complete list of supported channels) but it means possible memory corruption so we should handle it anyway.

This patch simply detects unexpected channel and ignores it.

As we don't try to create new entry now, it's also safe to drop hw_value and center_freq assignment. For known channels we have these set anyway.

I decided to fix this issue by assigning NULL or a target channel to the channel variable. This was one of possible ways, I prefefred this one as it also avoids using channel[index] over and over.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiphy bands")

---
V2: Add extra comment in code for not-found channel.
Make it clear this problem have never been seen so far Explain why it's safe to drop extra assignments Note & reason changing channel variable usage

---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c         | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +17 -15
index 9c2c128..a16dd7b 100644
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 	u32 i, j;
 	u32 total;
 	u32 chaninfo;
-	u32 index;
 
 	pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,36 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 		    ch.bw == BRCMU_CHAN_BW_80)
 			continue;
 
-		channel = band->channels;
-		index = band->n_channels;
+		channel = NULL;
 		for (j = 0; j < band->n_channels; j++) {
-			if (channel[j].hw_value == ch.control_ch_num) {
-				index = j;
+			if (band->channels[j].hw_value == ch.control_ch_num) {
+				channel = &band->channels[j];
 				break;
 			}
 		}
-		channel[index].center_freq =
-			ieee80211_channel_to_frequency(ch.control_ch_num,
-						       band->band);
-		channel[index].hw_value = ch.control_ch_num;
+		if (!channel) {
+			/* It seems firmware supports some channel we never
+			 * considered. Something new in IEEE standard?
+			 */
+			brcmf_err("Firmware reported unexpected channel %d\n",
+				  ch.control_ch_num);
+			continue;
+		}
 
 		/* assuming the chanspecs order is HT20,
 		 * HT40 upper, HT40 lower, and VHT80.
 		 */
 		if (ch.bw == BRCMU_CHAN_BW_80) {
-			channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
+			channel->flags &= ~IEEE80211_CHAN_NO_80MHZ;
 		} else if (ch.bw == BRCMU_CHAN_BW_40) {
-			brcmf_update_bw40_channel_flag(&channel[index], &ch);
+			brcmf_update_bw40_channel_flag(channel, &ch);
 		} else {
 			/* enable the channel and disable other bandwidths
 			 * for now as mentioned order assure they are enabled
 			 * for subsequent chanspecs.
 			 */
-			channel[index].flags = IEEE80211_CHAN_NO_HT40 |
-					       IEEE80211_CHAN_NO_80MHZ;
+			channel->flags = IEEE80211_CHAN_NO_HT40 |
+					 IEEE80211_CHAN_NO_80MHZ;
 			ch.bw = BRCMU_CHAN_BW_20;
 			cfg->d11inf.encchspec(&ch);
 			chaninfo = ch.chspec;
@@ -5907,11 +5909,11 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 						       &chaninfo);
 			if (!err) {
 				if (chaninfo & WL_CHAN_RADAR)
-					channel[index].flags |=
+					channel->flags |=
 						(IEEE80211_CHAN_RADAR |
 						 IEEE80211_CHAN_NO_IR);
 				if (chaninfo & WL_CHAN_PASSIVE)
-					channel[index].flags |=
+					channel->flags |=
 						IEEE80211_CHAN_NO_IR;
 			}
 		}
Signature · 1 line
2.10.1
#8 lore raw
In reply to Arend Van Spriel
Quoted 10 lines · Arend Van Spriel
Quoted 9 lines · On 3-1-2017 9:38, Rafa=C5=82 Mi=C5=82ecki wrote:

From: Rafa=C5=82 Mi=C5=82ecki <[email protected]>
=20
Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. =20
Fix this by detecting unexpected channel and ignoring it. =20

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiph=

y bands")

Quoted 3 lines
Quoted 3 lines

---
I'm not sure what kind of material it is. It fixes possible memory corru=

ption

Quoted 1 line
Quoted 1 line

(serious thing?) but this bug was there since Apr 2015, so is it worth f=

ixing

Quoted 2 lines
Quoted 2 lines

in 4.10? Or maybe I should even cc stable?
I don't think any released firmware reports any unexpected channel, so I=

guess

Quoted 1 line
Quoted 1 line

noone ever hit this problem. I just noticed this possible problem when w=

orking

Quoted 11 lines
Quoted 1 line

on another feature.

Looking at the change I was going to ask if you actually hit the issue you are addressing here. The channels in __wl_2ghz_channels and __wl_5ghz_channels are complete list of channels for the particular band so it would mean firmware behaves out-of-spec or firmware api was changed. For robustness a change is acceptable I guess.

My general policy is to submit fixes to wireless-drivers (and stable) only if it resolves a critical issue found during testing or a reported issue.

That's also my preference. And I read somewhere (forgot where) that in kernel summit there was a discussion about having only regression fixes in -rc kernels. So the rules are getting stricter, which is a good thing as then we can make releases in a shorter cycle.

--=20
Kalle Valo

#6 lore raw
In reply to Rafał Miłecki
Quoted 1 line · Rafa=C5=82 Mi=C5=82ecki <[email protected]> writes:

On 3 January 2017 at 15:14, Rafa=C5=82 Mi=C5=82ecki <[email protected]> wr=

ote:

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines · Arend Van Spriel
Quoted 2 lines · On 3-1-2017 12:31, Rafa=C5=82 Mi=C5=82ecki wrote:
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             if (!channel) {
+                     brcmf_err("Firmware reported unexpected channe=

l %d\n",

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5886

Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
+                               ch.control_ch_num);
+                     continue;
+             }

As stated above something is really off when this happens so should we continue and try to make sense of what firmware provides or simply fa=

il.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Well, I could image something like this happening and not being critic=

al.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The simplest case: Broadcom team releases a new firmware which supports extra 5 GHz channels (e.g. due to the IEEE standard change). Why should we refuse to run & support all "old" channel just because o=

f that?

Quoted 25 lines
Quoted 13 lines
Quoted 4 lines

Fair enough. I was assuming we keep __wl_{2,5}ghz_channels up to date with IEEE standard.

Quoted 8 lines
Quoted 2 lines

What do you mean by "make sense of what firmware provides"? Would kind of solution would you suggest?

When the above assumption can be assured (by us) the only other scenario would be a change in the firmware API where we wrongly interpret the information retrieved. In this case all subsequent channels will likely result in bogus or accidental matches hence it seems better to bail out early.

Quoted 6 lines

Good point, this actually gave me an idea for a small nice improvement. I remember I saw something like WL_VER in wl ioctl protocol, it was already bumped at some point by Broadcom, when chanspec format has changed. We should probably read this number from firmware and maybe refuse to run if version is newer than the one we know.

I was thinking about WLC_GET_VERSION and you seem to already have it in brcmfmac under nam BRCMF_C_GET_VERSION. If you wish to be prepared for firmware API change, I guess you should check version. It seems brcmfmac supports 1 and 2.

Quoted 4 lines

On the other hand if adding firmware with incompatible API you may want to have different directory or file names. I think this is what Intel does. This allows one to have multiple firmwares in /lib/firmware/ and switching between kernels freely.

ath10k does something similar. IIRC we currently support four different, and incompatible, firmware releases now.

--=20
Kalle Valo

maintainer
#10 lore raw
In reply to Rafał Miłecki
Quoted 55 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. This never happened so far (we got a complete list of supported channels) but it means possible memory corruption so we should handle it anyway.

This patch simply detects unexpected channel and ignores it.

As we don't try to create new entry now, it's also safe to drop hw_value and center_freq assignment. For known channels we have these set anyway.

I decided to fix this issue by assigning NULL or a target channel to the channel variable. This was one of possible ways, I prefefred this one as it also avoids using channel[index] over and over.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiphy bands")

---
V2: Add extra comment in code for not-found channel.
Make it clear this problem have never been seen so far Explain why it's safe to drop extra assignments Note & reason changing channel variable usage

---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c         | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -5
index 9c2c128..a16dd7b 100644
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 	u32 i, j;
 	u32 total;
 	u32 chaninfo;
-	u32 index;
 
 	pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,36 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 		    ch.bw == BRCMU_CHAN_BW_80)
 			continue;
 
-		channel = band->channels;
-		index = band->n_channels;
+		channel = NULL;
 		for (j = 0; j < band->n_channels; j++) {
-			if (channel[j].hw_value == ch.control_ch_num) {
-				index = j;
+			if (band->channels[j].hw_value == ch.control_ch_num) {
+				channel = &band->channels[j];
 				break;
 			}
 		}

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5887

Quoted 10 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +6 -4
-		channel[index].center_freq =
-			ieee80211_channel_to_frequency(ch.control_ch_num,
-						       band->band);
-		channel[index].hw_value = ch.control_ch_num;
+		if (!channel) {
+			/* It seems firmware supports some channel we never
+			 * considered. Something new in IEEE standard?
+			 */
+			brcmf_err("Firmware reported unexpected channel %d\n",
+				  ch.control_ch_num);

Maybe rephrase to "Ignoring unexpected firmware channel %d\n" so end-users are not alarmed by this error message. I think using brcmf_err() is justified, but you may even consider chiming down to brcmf_dbg(INFO, ...).

Regards,
Arend

#7 lore raw
In reply to Rafał Miłecki
Quoted 1 line · Rafa=C5=82 Mi=C5=82ecki <[email protected]> writes:
Quoted 1 line

Review static int brcmf_construct_chaninfo(struct brcm=

Quoted 1 line
(quoted diff) +0 -0
@@ -5873,33 +5872,33 @@ static int brcmf_construct_chaninfo(struct brcm=

f_cfg80211_info *cfg,

Quoted 8 lines
Quoted 8 lines

Review static int brcmf_construct_chaninfo(struct brcm= · line 5879

Quoted 8 lines
(quoted diff) +1 -3
                  ch.bw =3D=3D BRCMU_CHAN_BW_80)
                      continue;
 
-             channel =3D band->channels;
-             index =3D band->n_channels;
+             channel =3D NULL;
              for (j =3D 0; j < band->n_channels; j++) {
-                     if (channel[j].hw_value =3D=3D ch.control_ch_num)=

{

Quoted 2 lines
Quoted 2 lines

Review static int brcmf_construct_chaninfo(struct brcm= · line 5877

Quoted 2 lines
(quoted diff) +1 -1
-                             index =3D j;
+                     if (band->channels[j].hw_value =3D=3D ch.control_=

ch_num) {

Quoted 11 lines
Quoted 7 lines

Review static int brcmf_construct_chaninfo(struct brcm= · line 5881

Quoted 4 lines
(quoted diff) +1 -0
+                             channel =3D &band->channels[j];
                              break;
                      }
              }

You could have kept the index construct and simply check if j =3D=3D band->n_channels here to determine something is wrong.

I wanted to simplify code at the same time. Having channel[index] repeated 7 times was a hint for me it could be handled better. I should have made that clear, I'll fix improve this in V2.

If you are making a patch to stable or -rc releases you should keep the patch as simple as possible and do all the cleanup later. But I see that you dropped "cc stable" in this patch so all is good, just a general remark.

--=20
Kalle Valo

#11 lore raw
In reply to Arend Van Spriel
Quoted 11 lines · Arend Van Spriel
Quoted 10 lines · On 3-1-2017 17:49, Rafa=C5=82 Mi=C5=82ecki wrote:

From: Rafa=C5=82 Mi=C5=82ecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. This never happened so far (we got a complete list of supported channels) but it means possible memory corruption so we should handle it anyway.

This patch simply detects unexpected channel and ignores it.

Quoted 8 lines
Quoted 8 lines

As we don't try to create new entry now, it's also safe to drop hw_value and center_freq assignment. For known channels we have these set anyway.

I decided to fix this issue by assigning NULL or a target channel to the channel variable. This was one of possible ways, I prefefred this one as it also avoids using channel[index] over and over.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiph=

y bands")

Quoted 8 lines
Quoted 8 lines

---
V2: Add extra comment in code for not-found channel.
Make it clear this problem have never been seen so far Explain why it's safe to drop extra assignments Note & reason changing channel variable usage
---
.../broadcom/brcm80211/brcmfmac/cfg80211.c | 32 ++++++++++++---=

-------

Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 17 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c

Quoted 4 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_c=

Quoted 4 lines

index 9c2c128..a16dd7b 100644

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -0
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_c=

fg80211_info *cfg,

Quoted 8 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf=

Quoted 8 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -1
      u32 i, j;
      u32 total;
      u32 chaninfo;
-     u32 index;
 
      pbuf =3D kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,36 @@ static int brcmf_construct_chaninfo(struct brcmf=

_cfg80211_info *cfg,

Quoted 8 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf= · line 5879

Quoted 8 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -3
                  ch.bw =3D=3D BRCMU_CHAN_BW_80)
                      continue;
 
-             channel =3D band->channels;
-             index =3D band->n_channels;
+             channel =3D NULL;
              for (j =3D 0; j < band->n_channels; j++) {
-                     if (channel[j].hw_value =3D=3D ch.control_ch_num) =

{

Quoted 2 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf= · line 5877

Quoted 2 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -1
-                             index =3D j;
+                     if (band->channels[j].hw_value =3D=3D ch.control_c=

h_num) {

Quoted 10 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,

Quoted 10 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -4
+                             channel =3D &band->channels[j];
                              break;
                      }
              }
-             channel[index].center_freq =3D
-                     ieee80211_channel_to_frequency(ch.control_ch_num,
-                                                    band->band);
-             channel[index].hw_value =3D ch.control_ch_num;
+             if (!channel) {
+                     /* It seems firmware supports some channel we neve=

r

Quoted 3 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,

Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
+                      * considered. Something new in IEEE standard?
+                      */
+                     brcmf_err("Firmware reported unexpected channel %d=

\n",

Quoted 6 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5887

Quoted 1 line
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -0
+                               ch.control_ch_num);

Maybe rephrase to "Ignoring unexpected firmware channel %d\n" so end-users are not alarmed by this error message. I think using brcmf_err() is justified, but you may even consider chiming down to brcmf_dbg(INFO, ...).

Can you suggest a better error message? It seems I'm too brave and I don't find this one alarming, so I need suggestion.

--=20
Rafa=C5=82

maintainer
#12 lore raw
Quoted 74 lines · Rafał Miłecki
Quoted 63 lines · Arend Van Spriel
Quoted 62 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. This never happened so far (we got a complete list of supported channels) but it means possible memory corruption so we should handle it anyway.

This patch simply detects unexpected channel and ignores it.

As we don't try to create new entry now, it's also safe to drop hw_value and center_freq assignment. For known channels we have these set anyway.

I decided to fix this issue by assigning NULL or a target channel to the channel variable. This was one of possible ways, I prefefred this one as it also avoids using channel[index] over and over.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiphy bands")

---
V2: Add extra comment in code for not-found channel.
Make it clear this problem have never been seen so far Explain why it's safe to drop extra assignments Note & reason changing channel variable usage

---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c         | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +6 -9
index 9c2c128..a16dd7b 100644
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
      u32 i, j;
      u32 total;
      u32 chaninfo;
-     u32 index;
 
      pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,36 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
                  ch.bw == BRCMU_CHAN_BW_80)
                      continue;
 
-             channel = band->channels;
-             index = band->n_channels;
+             channel = NULL;
              for (j = 0; j < band->n_channels; j++) {
-                     if (channel[j].hw_value == ch.control_ch_num) {
-                             index = j;
+                     if (band->channels[j].hw_value == ch.control_ch_num) {
+                             channel = &band->channels[j];
                              break;
                      }
              }
-             channel[index].center_freq =
-                     ieee80211_channel_to_frequency(ch.control_ch_num,
-                                                    band->band);
-             channel[index].hw_value = ch.control_ch_num;
+             if (!channel) {
+                     /* It seems firmware supports some channel we never
+                      * considered. Something new in IEEE standard?
Quoted 8 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5887

Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
+                      */
+                     brcmf_err("Firmware reported unexpected channel %d\n",
+                               ch.control_ch_num);

Maybe rephrase to "Ignoring unexpected firmware channel %d\n" so end-users are not alarmed by this error message. I think using brcmf_err() is justified, but you may even consider chiming down to brcmf_dbg(INFO, ...).

Quoted 2 lines

Can you suggest a better error message? It seems I'm too brave and I don't find this one alarming, so I need suggestion.

Uhm. There is a suggestion above. :-p

Regards,
Arend

#13 lore raw
Quoted 9 lines · Arend Van Spriel
Quoted 8 lines · On 4-1-2017 11:40, Rafa=C5=82 Mi=C5=82ecki wrote:
Quoted 6 lines · Arend Van Spriel
Quoted 5 lines · On 3-1-2017 17:49, Rafa=C5=82 Mi=C5=82ecki wrote:

From: Rafa=C5=82 Mi=C5=82ecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. Thi=

s

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

never happened so far (we got a complete list of supported channels) b=

ut

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

it means possible memory corruption so we should handle it anyway.

This patch simply detects unexpected channel and ignores it.

As we don't try to create new entry now, it's also safe to drop hw_val=

ue

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

and center_freq assignment. For known channels we have these set anywa=

y.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I decided to fix this issue by assigning NULL or a target channel to t=

he

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

channel variable. This was one of possible ways, I prefefred this one =

as

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

it also avoids using channel[index] over and over.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wi=

phy bands")

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

---
V2: Add extra comment in code for not-found channel.
Make it clear this problem have never been seen so far Explain why it's safe to drop extra assignments Note & reason changing channel variable usage
---
.../broadcom/brcm80211/brcmfmac/cfg80211.c | 32 ++++++++++++-=

---------

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 17 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf=

Quoted 4 lines

index 9c2c128..a16dd7b 100644

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -0
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf=

_cfg80211_info *cfg,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brc=

Quoted 8 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -1
      u32 i, j;
      u32 total;
      u32 chaninfo;
-     u32 index;
 
      pbuf =3D kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,36 @@ static int brcmf_construct_chaninfo(struct brc=

mf_cfg80211_info *cfg,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brc= · line 5879

Quoted 8 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -3
                  ch.bw =3D=3D BRCMU_CHAN_BW_80)
                      continue;
 
-             channel =3D band->channels;
-             index =3D band->n_channels;
+             channel =3D NULL;
              for (j =3D 0; j < band->n_channels; j++) {
-                     if (channel[j].hw_value =3D=3D ch.control_ch_num=

) {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brc= · line 5877

Quoted 2 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -1
-                             index =3D j;
+                     if (band->channels[j].hw_value =3D=3D ch.control=

_ch_num) {

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brc= · line 5885

Quoted 6 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -2
+                             channel =3D &band->channels[j];
                              break;
                      }
              }
-             channel[index].center_freq =3D
-                     ieee80211_channel_to_frequency(ch.control_ch_num=

,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,

Quoted 4 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +2 -2
-                                                    band->band);
-             channel[index].hw_value =3D ch.control_ch_num;
+             if (!channel) {
+                     /* It seems firmware supports some channel we ne=

ver

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,

Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
+                      * considered. Something new in IEEE standard?
+                      */
+                     brcmf_err("Firmware reported unexpected channel =

%d\n",

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, · line 5887

Quoted 1 line
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -0
+                               ch.control_ch_num);

Maybe rephrase to "Ignoring unexpected firmware channel %d\n" so end-users are not alarmed by this error message. I think using brcmf_err() is justified, but you may even consider chiming down to brcmf_dbg(INFO, ...).

Can you suggest a better error message? It seems I'm too brave and I don't find this one alarming, so I need suggestion.

Uhm. There is a suggestion above. :-p

... sorry, it seems I should take a break ;)

--=20
Rafa=C5=82

#14 lore raw

PATCH v3 1/1 brcmfmac: avoid writing channel out of allocated array

In reply to Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. This never happened so far (we got a complete list of supported channels) but it means possible memory corruption so we should handle it anyway.

This patch simply detects unexpected channel and ignores it.

As we don't try to create new entry now, it's also safe to drop hw_value and center_freq assignment. For known channels we have these set anyway.

I decided to fix this issue by assigning NULL or a target channel to the channel variable. This was one of possible ways, I prefefred this one as it also avoids using channel[index] over and over.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiphy bands")

---
V2: Add extra comment in code for not-found channel.
Make it clear this problem have never been seen so far Explain why it's safe to drop extra assignments Note & reason changing channel variable usage
V3: Update error message as suggested by Arend.

---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c         | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +17 -15
index 9c2c128..75ef23b 100644
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 	u32 i, j;
 	u32 total;
 	u32 chaninfo;
-	u32 index;
 
 	pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,36 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 		    ch.bw == BRCMU_CHAN_BW_80)
 			continue;
 
-		channel = band->channels;
-		index = band->n_channels;
+		channel = NULL;
 		for (j = 0; j < band->n_channels; j++) {
-			if (channel[j].hw_value == ch.control_ch_num) {
-				index = j;
+			if (band->channels[j].hw_value == ch.control_ch_num) {
+				channel = &band->channels[j];
 				break;
 			}
 		}
-		channel[index].center_freq =
-			ieee80211_channel_to_frequency(ch.control_ch_num,
-						       band->band);
-		channel[index].hw_value = ch.control_ch_num;
+		if (!channel) {
+			/* It seems firmware supports some channel we never
+			 * considered. Something new in IEEE standard?
+			 */
+			brcmf_err("Ignoring unexpected firmware channel %d\n",
+				  ch.control_ch_num);
+			continue;
+		}
 
 		/* assuming the chanspecs order is HT20,
 		 * HT40 upper, HT40 lower, and VHT80.
 		 */
 		if (ch.bw == BRCMU_CHAN_BW_80) {
-			channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
+			channel->flags &= ~IEEE80211_CHAN_NO_80MHZ;
 		} else if (ch.bw == BRCMU_CHAN_BW_40) {
-			brcmf_update_bw40_channel_flag(&channel[index], &ch);
+			brcmf_update_bw40_channel_flag(channel, &ch);
 		} else {
 			/* enable the channel and disable other bandwidths
 			 * for now as mentioned order assure they are enabled
 			 * for subsequent chanspecs.
 			 */
-			channel[index].flags = IEEE80211_CHAN_NO_HT40 |
-					       IEEE80211_CHAN_NO_80MHZ;
+			channel->flags = IEEE80211_CHAN_NO_HT40 |
+					 IEEE80211_CHAN_NO_80MHZ;
 			ch.bw = BRCMU_CHAN_BW_20;
 			cfg->d11inf.encchspec(&ch);
 			chaninfo = ch.chspec;
@@ -5907,11 +5909,11 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 						       &chaninfo);
 			if (!err) {
 				if (chaninfo & WL_CHAN_RADAR)
-					channel[index].flags |=
+					channel->flags |=
 						(IEEE80211_CHAN_RADAR |
 						 IEEE80211_CHAN_NO_IR);
 				if (chaninfo & WL_CHAN_PASSIVE)
-					channel[index].flags |=
+					channel->flags |=
 						IEEE80211_CHAN_NO_IR;
 			}
 		}
Signature · 1 line
2.10.1
maintainer Acked-by on v3 1/1
#15 lore raw
Quoted 1 line · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Not taking a break?

Quoted 8 lines

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. This never happened so far (we got a complete list of supported channels) but it means possible memory corruption so we should handle it anyway.

This patch simply detects unexpected channel and ignores it.

Quoted 8 lines

As we don't try to create new entry now, it's also safe to drop hw_value and center_freq assignment. For known channels we have these set anyway.

I decided to fix this issue by assigning NULL or a target channel to the channel variable. This was one of possible ways, I prefefred this one as it also avoids using channel[index] over and over.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiphy bands")
Quoted 87 lines

---
V2: Add extra comment in code for not-found channel.
Make it clear this problem have never been seen so far Explain why it's safe to drop extra assignments Note & reason changing channel variable usage
V3: Update error message as suggested by Arend.

---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c         | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +17 -15
index 9c2c128..75ef23b 100644
@@ -5825,7 +5825,6 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 	u32 i, j;
 	u32 total;
 	u32 chaninfo;
-	u32 index;
 
 	pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
 
@@ -5873,33 +5872,36 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 		    ch.bw == BRCMU_CHAN_BW_80)
 			continue;
 
-		channel = band->channels;
-		index = band->n_channels;
+		channel = NULL;
 		for (j = 0; j < band->n_channels; j++) {
-			if (channel[j].hw_value == ch.control_ch_num) {
-				index = j;
+			if (band->channels[j].hw_value == ch.control_ch_num) {
+				channel = &band->channels[j];
 				break;
 			}
 		}
-		channel[index].center_freq =
-			ieee80211_channel_to_frequency(ch.control_ch_num,
-						       band->band);
-		channel[index].hw_value = ch.control_ch_num;
+		if (!channel) {
+			/* It seems firmware supports some channel we never
+			 * considered. Something new in IEEE standard?
+			 */
+			brcmf_err("Ignoring unexpected firmware channel %d\n",
+				  ch.control_ch_num);
+			continue;
+		}
 
 		/* assuming the chanspecs order is HT20,
 		 * HT40 upper, HT40 lower, and VHT80.
 		 */
 		if (ch.bw == BRCMU_CHAN_BW_80) {
-			channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
+			channel->flags &= ~IEEE80211_CHAN_NO_80MHZ;
 		} else if (ch.bw == BRCMU_CHAN_BW_40) {
-			brcmf_update_bw40_channel_flag(&channel[index], &ch);
+			brcmf_update_bw40_channel_flag(channel, &ch);
 		} else {
 			/* enable the channel and disable other bandwidths
 			 * for now as mentioned order assure they are enabled
 			 * for subsequent chanspecs.
 			 */
-			channel[index].flags = IEEE80211_CHAN_NO_HT40 |
-					       IEEE80211_CHAN_NO_80MHZ;
+			channel->flags = IEEE80211_CHAN_NO_HT40 |
+					 IEEE80211_CHAN_NO_80MHZ;
 			ch.bw = BRCMU_CHAN_BW_20;
 			cfg->d11inf.encchspec(&ch);
 			chaninfo = ch.chspec;
@@ -5907,11 +5909,11 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
 						       &chaninfo);
 			if (!err) {
 				if (chaninfo & WL_CHAN_RADAR)
-					channel[index].flags |=
+					channel->flags |=
 						(IEEE80211_CHAN_RADAR |
 						 IEEE80211_CHAN_NO_IR);
 				if (chaninfo & WL_CHAN_PASSIVE)
-					channel[index].flags |=
+					channel->flags |=
 						IEEE80211_CHAN_NO_IR;
 			}
 		}
#16 lore raw
In reply to Rafał Miłecki
Quoted 13 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Our code was assigning number of channels to the index variable by default. If firmware reported channel we didn't predict this would result in using that initial index value and writing out of array. This never happened so far (we got a complete list of supported channels) but it means possible memory corruption so we should handle it anyway.

This patch simply detects unexpected channel and ignores it.

As we don't try to create new entry now, it's also safe to drop hw_value and center_freq assignment. For known channels we have these set anyway.

Quoted 7 lines

I decided to fix this issue by assigning NULL or a target channel to the channel variable. This was one of possible ways, I prefefred this one as it also avoids using channel[index] over and over.

Fixes 58de92d2f95e ("brcmfmac: use static superset of channels for wiphy bands")

Patch applied to wireless-drivers-next.git, thanks.

77c0d0cd10e7 brcmfmac: avoid writing channel out of allocated array

Signature · 6 lines
https://patchwork.kernel.org/patch/9496471/

Documentation about submitting wireless patches and checking status
from patchwork:

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches