2014-09-20 22:59:07

by Emil Goode

[permalink] [raw]
Subject: [PATCH] brcmfmac: Fix off by one bug in brcmf_count_20mhz_channels()

In the brcmf_count_20mhz_channels function we are looping through a list
of channels received from firmware. Since the index of the first channel
is 0 the condition leads to an off by one bug. This is causing us to hit
the WARN_ON_ONCE(1) calls in the brcmu_d11n_decchspec function, which is
how I discovered the bug.

Introduced by:
commit b48d891676f756d48b4d0ee131e4a7a5d43ca417
("brcmfmac: rework wiphy structure setup")

Signed-off-by: Emil Goode <[email protected]>
---
drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
index 02fe706..93b5dd9 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
@@ -4918,7 +4918,7 @@ static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
struct brcmu_chan ch;
int i;

- for (i = 0; i <= total; i++) {
+ for (i = 0; i < total; i++) {
ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
cfg->d11inf.decchspec(&ch);

--
2.1.0



2014-09-22 09:56:47

by Arend van Spriel

[permalink] [raw]
Subject: Re: [PATCH] brcmfmac: Fix off by one bug in brcmf_count_20mhz_channels()

On 09/21/14 00:58, Emil Goode wrote:
> In the brcmf_count_20mhz_channels function we are looping through a list
> of channels received from firmware. Since the index of the first channel
> is 0 the condition leads to an off by one bug. This is causing us to hit
> the WARN_ON_ONCE(1) calls in the brcmu_d11n_decchspec function, which is
> how I discovered the bug.

The fix is fine. Would like to know what exactly is going wrong. Can you
provide a kernel log with brcmfmac debugging enabled, ie. insmod
brcmfmac.ko debug=0x1416

Regards,
Arend

> Introduced by:
> commit b48d891676f756d48b4d0ee131e4a7a5d43ca417
> ("brcmfmac: rework wiphy structure setup")
>
> Signed-off-by: Emil Goode<[email protected]>
> ---
> drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> index 02fe706..93b5dd9 100644
> --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> @@ -4918,7 +4918,7 @@ static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
> struct brcmu_chan ch;
> int i;
>
> - for (i = 0; i<= total; i++) {
> + for (i = 0; i< total; i++) {
> ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
> cfg->d11inf.decchspec(&ch);
>


2014-09-22 22:38:49

by Emil Goode

[permalink] [raw]
Subject: Re: [PATCH] brcmfmac: Fix off by one bug in brcmf_count_20mhz_channels()

Hello Arend,

Ok I will resend with your ack.

Best regards,

Emil

On Mon, Sep 22, 2014 at 11:49:56AM +0200, Arend van Spriel wrote:
> On 09/21/14 00:58, Emil Goode wrote:
> >In the brcmf_count_20mhz_channels function we are looping through a list
> >of channels received from firmware. Since the index of the first channel
> >is 0 the condition leads to an off by one bug. This is causing us to hit
> >the WARN_ON_ONCE(1) calls in the brcmu_d11n_decchspec function, which is
> >how I discovered the bug.
> >
> >Introduced by:
> >commit b48d891676f756d48b4d0ee131e4a7a5d43ca417
> >("brcmfmac: rework wiphy structure setup")
>
> My bad :-(. You can add:
>
> Acked-by: Arend van Spriel <[email protected]>
> >Signed-off-by: Emil Goode<[email protected]>
> >---
> > drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> >index 02fe706..93b5dd9 100644
> >--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> >+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> >@@ -4918,7 +4918,7 @@ static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
> > struct brcmu_chan ch;
> > int i;
> >
> >- for (i = 0; i<= total; i++) {
> >+ for (i = 0; i< total; i++) {
> > ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
> > cfg->d11inf.decchspec(&ch);
> >
>

2014-09-22 23:08:44

by Emil Goode

[permalink] [raw]
Subject: Re: [PATCH] brcmfmac: Fix off by one bug in brcmf_count_20mhz_channels()

Hello Arend,

Sorry for the late reply. I have attached a kernel log with brcmfmac
debugging enabled (without my patch applied).

Let me know if I can provide any other useful information.

Best regards,

Emil

On Mon, Sep 22, 2014 at 11:56:43AM +0200, Arend van Spriel wrote:
> On 09/21/14 00:58, Emil Goode wrote:
> >In the brcmf_count_20mhz_channels function we are looping through a list
> >of channels received from firmware. Since the index of the first channel
> >is 0 the condition leads to an off by one bug. This is causing us to hit
> >the WARN_ON_ONCE(1) calls in the brcmu_d11n_decchspec function, which is
> >how I discovered the bug.
>
> The fix is fine. Would like to know what exactly is going wrong. Can you
> provide a kernel log with brcmfmac debugging enabled, ie. insmod brcmfmac.ko
> debug=0x1416
>
> Regards,
> Arend
>
> >Introduced by:
> >commit b48d891676f756d48b4d0ee131e4a7a5d43ca417
> >("brcmfmac: rework wiphy structure setup")
> >
> >Signed-off-by: Emil Goode<[email protected]>
> >---
> > drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> >index 02fe706..93b5dd9 100644
> >--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> >+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> >@@ -4918,7 +4918,7 @@ static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
> > struct brcmu_chan ch;
> > int i;
> >
> >- for (i = 0; i<= total; i++) {
> >+ for (i = 0; i< total; i++) {
> > ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
> > cfg->d11inf.decchspec(&ch);
> >
>


Attachments:
(No filename) (1.70 kB)
dmesg_brcmfmac_debug.out (85.59 kB)
Download all attachments

2014-09-23 09:33:10

by Arend van Spriel

[permalink] [raw]
Subject: Re: [PATCH] brcmfmac: Fix off by one bug in brcmf_count_20mhz_channels()

On 09/23/14 01:08, Emil Goode wrote:
> Hello Arend,
>
> Sorry for the late reply. I have attached a kernel log with brcmfmac
> debugging enabled (without my patch applied).
>
> Let me know if I can provide any other useful information.

No problem, Emil

I was wondering what was returned on "chanspecs" query. So 17 channel
configs which is expected.

Regards,
Arend

> Best regards,
>
> Emil
>
> On Mon, Sep 22, 2014 at 11:56:43AM +0200, Arend van Spriel wrote:
>> On 09/21/14 00:58, Emil Goode wrote:
>>> In the brcmf_count_20mhz_channels function we are looping through a list
>>> of channels received from firmware. Since the index of the first channel
>>> is 0 the condition leads to an off by one bug. This is causing us to hit
>>> the WARN_ON_ONCE(1) calls in the brcmu_d11n_decchspec function, which is
>>> how I discovered the bug.
>>
>> The fix is fine. Would like to know what exactly is going wrong. Can you
>> provide a kernel log with brcmfmac debugging enabled, ie. insmod brcmfmac.ko
>> debug=0x1416
>>
>> Regards,
>> Arend
>>
>>> Introduced by:
>>> commit b48d891676f756d48b4d0ee131e4a7a5d43ca417
>>> ("brcmfmac: rework wiphy structure setup")
>>>
>>> Signed-off-by: Emil Goode<[email protected]>
>>> ---
>>> drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
>>> index 02fe706..93b5dd9 100644
>>> --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
>>> +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
>>> @@ -4918,7 +4918,7 @@ static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
>>> struct brcmu_chan ch;
>>> int i;
>>>
>>> - for (i = 0; i<= total; i++) {
>>> + for (i = 0; i< total; i++) {
>>> ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
>>> cfg->d11inf.decchspec(&ch);
>>>
>>


2014-09-22 09:50:00

by Arend van Spriel

[permalink] [raw]
Subject: Re: [PATCH] brcmfmac: Fix off by one bug in brcmf_count_20mhz_channels()

On 09/21/14 00:58, Emil Goode wrote:
> In the brcmf_count_20mhz_channels function we are looping through a list
> of channels received from firmware. Since the index of the first channel
> is 0 the condition leads to an off by one bug. This is causing us to hit
> the WARN_ON_ONCE(1) calls in the brcmu_d11n_decchspec function, which is
> how I discovered the bug.
>
> Introduced by:
> commit b48d891676f756d48b4d0ee131e4a7a5d43ca417
> ("brcmfmac: rework wiphy structure setup")

My bad :-(. You can add:

Acked-by: Arend van Spriel <[email protected]>
> Signed-off-by: Emil Goode<[email protected]>
> ---
> drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> index 02fe706..93b5dd9 100644
> --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
> @@ -4918,7 +4918,7 @@ static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
> struct brcmu_chan ch;
> int i;
>
> - for (i = 0; i<= total; i++) {
> + for (i = 0; i< total; i++) {
> ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
> cfg->d11inf.decchspec(&ch);
>