2024-01-26 22:36:15

by Kees Cook

[permalink] [raw]
Subject: [PATCH] wifi: brcmfmac: Adjust n_channels usage for __counted_by

After commit e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
cfg80211_scan_request with __counted_by"), the compiler may enforce
dynamic array indexing of req->channels to stay below n_channels. As a
result, n_channels needs to be increased _before_ accessing the newly
added array index. Increment it first, then use "i" for the prior index.
Solves this warning in the coming GCC that has __counted_by support:

../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c: In function 'brcmf_internal_escan_add_info':
../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:3783:46: warning: operation on 'req->
n_channels' may be undefined [-Wsequence-point]
3783 | req->channels[req->n_channels++] = chan;
| ~~~~~~~~~~~~~~~^~

Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by")
Cc: Arend van Spriel <[email protected]>
Cc: Franky Lin <[email protected]>
Cc: Hante Meuleman <[email protected]>
Cc: Kalle Valo <[email protected]>
Cc: Chi-hsien Lin <[email protected]>
Cc: Ian Lin <[email protected]>
Cc: Johannes Berg <[email protected]>
Cc: Wright Feng <[email protected]>
Cc: Hector Martin <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index 133c5ea6429c..28d6a30cc010 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -3779,8 +3779,10 @@ static int brcmf_internal_escan_add_info(struct cfg80211_scan_request *req,
if (req->channels[i] == chan)
break;
}
- if (i == req->n_channels)
- req->channels[req->n_channels++] = chan;
+ if (i == req->n_channels) {
+ req->n_channels++;
+ req->channels[i] = chan;
+ }

for (i = 0; i < req->n_ssids; i++) {
if (req->ssids[i].ssid_len == ssid_len &&
--
2.34.1



2024-01-27 16:38:01

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH] wifi: brcmfmac: Adjust n_channels usage for __counted_by

On Fri, Jan 26, 2024 at 11:31 PM Kees Cook <[email protected]> wrote:

> After commit e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
> cfg80211_scan_request with __counted_by"), the compiler may enforce
> dynamic array indexing of req->channels to stay below n_channels. As a
> result, n_channels needs to be increased _before_ accessing the newly
> added array index. Increment it first, then use "i" for the prior index.
> Solves this warning in the coming GCC that has __counted_by support:

Makes perfect sense.
Reviewed-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij

2024-01-27 17:00:42

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH] wifi: brcmfmac: Adjust n_channels usage for __counted_by



On 1/26/24 16:31, Kees Cook wrote:
> After commit e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
> cfg80211_scan_request with __counted_by"), the compiler may enforce
> dynamic array indexing of req->channels to stay below n_channels. As a
> result, n_channels needs to be increased _before_ accessing the newly
> added array index. Increment it first, then use "i" for the prior index.
> Solves this warning in the coming GCC that has __counted_by support:
>
> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c: In function 'brcmf_internal_escan_add_info':
> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:3783:46: warning: operation on 'req->
> n_channels' may be undefined [-Wsequence-point]
> 3783 | req->channels[req->n_channels++] = chan;
> | ~~~~~~~~~~~~~~~^~
>
> Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by")
> Cc: Arend van Spriel <[email protected]>
> Cc: Franky Lin <[email protected]>
> Cc: Hante Meuleman <[email protected]>
> Cc: Kalle Valo <[email protected]>
> Cc: Chi-hsien Lin <[email protected]>
> Cc: Ian Lin <[email protected]>
> Cc: Johannes Berg <[email protected]>
> Cc: Wright Feng <[email protected]>
> Cc: Hector Martin <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>

Reviewed-by: Gustavo A. R. Silva <[email protected]>

Thanks!
--
Gustavo

> ---
> drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
> index 133c5ea6429c..28d6a30cc010 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
> @@ -3779,8 +3779,10 @@ static int brcmf_internal_escan_add_info(struct cfg80211_scan_request *req,
> if (req->channels[i] == chan)
> break;
> }
> - if (i == req->n_channels)
> - req->channels[req->n_channels++] = chan;
> + if (i == req->n_channels) {
> + req->n_channels++;
> + req->channels[i] = chan;
> + }
>
> for (i = 0; i < req->n_ssids; i++) {
> if (req->ssids[i].ssid_len == ssid_len &&

2024-02-02 10:01:17

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH] wifi: brcmfmac: Adjust n_channels usage for __counted_by

On 2/1/2024 11:04 AM, Kalle Valo wrote:
> Kees Cook <[email protected]> wrote:
>
>> After commit e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
>> cfg80211_scan_request with __counted_by"), the compiler may enforce
>> dynamic array indexing of req->channels to stay below n_channels. As a
>> result, n_channels needs to be increased _before_ accessing the newly
>> added array index. Increment it first, then use "i" for the prior index.
>> Solves this warning in the coming GCC that has __counted_by support:
>>
>> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c: In function 'brcmf_internal_escan_add_info':
>> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:3783:46: warning: operation on 'req->
>> n_channels' may be undefined [-Wsequence-point]
>> 3783 | req->channels[req->n_channels++] = chan;
>> | ~~~~~~~~~~~~~~~^~
>>
>> Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by")
>> Cc: Arend van Spriel <[email protected]>
>> Cc: Franky Lin <[email protected]>
>> Cc: Hante Meuleman <[email protected]>
>> Cc: Kalle Valo <[email protected]>
>> Cc: Chi-hsien Lin <[email protected]>
>> Cc: Ian Lin <[email protected]>
>> Cc: Johannes Berg <[email protected]>
>> Cc: Wright Feng <[email protected]>
>> Cc: Hector Martin <[email protected]>
>> Cc: [email protected]
>> Cc: [email protected]
>> Signed-off-by: Kees Cook <[email protected]>
>> Reviewed-by: Hans de Goede <[email protected]>
>> Reviewed-by: Linus Walleij <[email protected]>
>> Reviewed-by: Gustavo A. R. Silva <[email protected]>
>
> I'm planning to queue this for wireless tree. Arend, ack?

This slipped past my broadcom email. As the Fixes commit is in 6.7 I
would say ACK.

Gr. AvS

2024-02-02 10:01:36

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH] wifi: brcmfmac: Adjust n_channels usage for __counted_by

On 2/2/2024 10:58 AM, Arend Van Spriel wrote:
> On 2/1/2024 11:04 AM, Kalle Valo wrote:
>> Kees Cook <[email protected]> wrote:
>>
>>> After commit e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
>>> cfg80211_scan_request with __counted_by"), the compiler may enforce
>>> dynamic array indexing of req->channels to stay below n_channels. As a
>>> result, n_channels needs to be increased _before_ accessing the newly
>>> added array index. Increment it first, then use "i" for the prior index.
>>> Solves this warning in the coming GCC that has __counted_by support:
>>>
>>> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c: In
>>> function 'brcmf_internal_escan_add_info':
>>> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:3783:46: warning: operation on 'req->
>>> n_channels' may be undefined [-Wsequence-point]
>>>   3783 |                 req->channels[req->n_channels++] = chan;
>>>        |                               ~~~~~~~~~~~~~~~^~
>>>
>>> Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
>>> cfg80211_scan_request with __counted_by")
>>> Cc: Arend van Spriel <[email protected]>
>>> Cc: Franky Lin <[email protected]>
>>> Cc: Hante Meuleman <[email protected]>
>>> Cc: Kalle Valo <[email protected]>
>>> Cc: Chi-hsien Lin <[email protected]>
>>> Cc: Ian Lin <[email protected]>
>>> Cc: Johannes Berg <[email protected]>
>>> Cc: Wright Feng <[email protected]>
>>> Cc: Hector Martin <[email protected]>
>>> Cc: [email protected]
>>> Cc: [email protected]
>>> Signed-off-by: Kees Cook <[email protected]>
>>> Reviewed-by: Hans de Goede <[email protected]>
>>> Reviewed-by: Linus Walleij <[email protected]>
>>> Reviewed-by: Gustavo A. R. Silva <[email protected]>
>>
>> I'm planning to queue this for wireless tree. Arend, ack?
>
> This slipped past my broadcom email. As the Fixes commit is in 6.7 I
> would say ACK.

Cc: to stable?

Gr. AvS


2024-02-02 16:45:55

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH] wifi: brcmfmac: Adjust n_channels usage for __counted_by

Kees Cook <[email protected]> wrote:

> After commit e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
> cfg80211_scan_request with __counted_by"), the compiler may enforce
> dynamic array indexing of req->channels to stay below n_channels. As a
> result, n_channels needs to be increased _before_ accessing the newly
> added array index. Increment it first, then use "i" for the prior index.
> Solves this warning in the coming GCC that has __counted_by support:
>
> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c: In function 'brcmf_internal_escan_add_info':
> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:3783:46: warning: operation on 'req->
> n_channels' may be undefined [-Wsequence-point]
> 3783 | req->channels[req->n_channels++] = chan;
> | ~~~~~~~~~~~~~~~^~
>
> Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by")
> Cc: Arend van Spriel <[email protected]>
> Cc: Franky Lin <[email protected]>
> Cc: Hante Meuleman <[email protected]>
> Cc: Kalle Valo <[email protected]>
> Cc: Chi-hsien Lin <[email protected]>
> Cc: Ian Lin <[email protected]>
> Cc: Johannes Berg <[email protected]>
> Cc: Wright Feng <[email protected]>
> Cc: Hector Martin <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>
> Reviewed-by: Hans de Goede <[email protected]>
> Reviewed-by: Linus Walleij <[email protected]>
> Reviewed-by: Gustavo A. R. Silva <[email protected]>

Patch applied to wireless.git, thanks.

5bdda0048c8d wifi: brcmfmac: Adjust n_channels usage for __counted_by

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

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


2024-02-02 18:10:15

by Arend Van Spriel

[permalink] [raw]
Subject: Re: [PATCH] wifi: brcmfmac: Adjust n_channels usage for __counted_by

On 2/2/2024 11:34 AM, Kalle Valo wrote:
> Arend Van Spriel <[email protected]> writes:
>
>> On 2/2/2024 10:58 AM, Arend Van Spriel wrote:
>>
>>> On 2/1/2024 11:04 AM, Kalle Valo wrote:
>>>> Kees Cook <[email protected]> wrote:
>>>>
>>>>> After commit e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
>>>>> cfg80211_scan_request with __counted_by"), the compiler may enforce
>>>>> dynamic array indexing of req->channels to stay below n_channels. As a
>>>>> result, n_channels needs to be increased _before_ accessing the newly
>>>>> added array index. Increment it first, then use "i" for the prior index.
>>>>> Solves this warning in the coming GCC that has __counted_by support:
>>>>>
>>>>> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c: In
>>>>> function 'brcmf_internal_escan_add_info':
>>>>> ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:3783:46: warning: operation on 'req->
>>>>> n_channels' may be undefined [-Wsequence-point]
>>>>>   3783 |                 req->channels[req->n_channels++] = chan;
>>>>>        |                               ~~~~~~~~~~~~~~~^~
>>>>>
>>>>> Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct
>>>>> cfg80211_scan_request with __counted_by")
>>>>> Cc: Arend van Spriel <[email protected]>
>>>>> Cc: Franky Lin <[email protected]>
>>>>> Cc: Hante Meuleman <[email protected]>
>>>>> Cc: Kalle Valo <[email protected]>
>>>>> Cc: Chi-hsien Lin <[email protected]>
>>>>> Cc: Ian Lin <[email protected]>
>>>>> Cc: Johannes Berg <[email protected]>
>>>>> Cc: Wright Feng <[email protected]>
>>>>> Cc: Hector Martin <[email protected]>
>>>>> Cc: [email protected]
>>>>> Cc: [email protected]
>>>>> Signed-off-by: Kees Cook <[email protected]>
>>>>> Reviewed-by: Hans de Goede <[email protected]>
>>>>> Reviewed-by: Linus Walleij <[email protected]>
>>>>> Reviewed-by: Gustavo A. R. Silva <[email protected]>
>>>>
>>>> I'm planning to queue this for wireless tree. Arend, ack?
>>> This slipped past my broadcom email. As the Fixes commit is in 6.7 I
>>> would say ACK.
>
> Thanks.
>
>> Cc: to stable?
>
> Is commit e3eac9f32ec0 in stable releases? (I don't follow stable and
> don't know what commits they take.) I propose that as we have Fixes tag
> let's not add cc but instead let stable maintainers to decide.

I confirmed the commit was in 6.7 and the latest released kernel is
always handled by stable kernel team. kernel.org main page always shows
the active stable/longterm releases. That said I have no problem with
your proposal.

Gr. AvS