From: John Rowley <lkml@johnrowley.me>
To: Kees Cook <kees@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>,
johannes@sipsolutions.net, linux-wireless@vger.kernel.org,
stable@vger.kernel.org, gustavoars@kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: UBSAN array-index-out-of-bounds: cfg80211_scan_6ghz
Date: Tue, 14 Jan 2025 11:37:49 +0000 (GMT) [thread overview]
Message-ID: <4e8eba1c-b0df-4930-8b88-319587f8ddd3@johnrowley.me> (raw)
In-Reply-To: <202412301022.BCAC61BD6C@keescook>
----------------------------------------
From: Kees Cook <kees@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
CC: John Rowley <lkml@johnrowley.me>; johannes@sipsolutions.net; linux-wireless@vger.kernel.org; stable@vger.kernel.org; gustavoars@kernel.org; linux-hardening@vger.kernel.org
Date: 30 Dec 2024 18:35:34
Subject: Re: UBSAN array-index-out-of-bounds: cfg80211_scan_6ghz
> On Sun, Dec 29, 2024 at 10:38:06PM -0700, Nathan Chancellor wrote:
>> Hi John,
>>
>> On Sat, Dec 28, 2024 at 11:21:27AM +0000, John Rowley wrote:
>>> Hi, I'm experiencing UBSAN array-index-out-of-bounds errors while using
>>> my Framework 13" AMD laptop with its Mediatek MT7922 wifi adapter
>>> (mt7921e).
>>>
>>> It seems to happen only once on boot, and occurs with both kernel
>>> versions 6.12.7 and 6.13-rc4, both compiled from vanilla upstream kernel
>>> sources on Fedora 41 using the kernel.org LLVM toolchain (19.1.6).
>>>
>>> I can try some other kernel series if necessary, and also a bisect if I
>>> find a working version, but that may take me a while.
>>
>> This looks related to UBSAN_BOUNDS and the fact that version of clang
>> supports the __counted_by attribute. I do not have much time at the
>> moment to look at this but I have added Kees, Gustavo, and
>> linux-hardening for further analysis.
>>
>> Cheers,
>> Nathan
>>
>>> I wasn't sure if I should mark this as a regression, as I'm not sure
>>> which/if there is a working kernel version at this point.
>>>
>>> Thanks.
>>>
>>> ----
>>>
>>> [ 17.754417] UBSAN: array-index-out-of-bounds in /data/linux/net/wireless/scan.c:766:2
>>> [ 17.754423] index 0 is out of range for type 'struct ieee80211_channel *[] __counted_by(n_channels)' (aka 'struct ieee80211_channel *[]')
>
> This is this line:
>
> request->channels[n_channels] = chan;
>
> and later:
>
> request->n_channels++;
>
> Patch should be:
>
> diff --git a/net/wireless/scan.c b/net/wireless/scan.c
> index 1c6fd45aa809..ccdbeb604639 100644
> --- a/net/wireless/scan.c
> +++ b/net/wireless/scan.c
> @@ -763,12 +763,11 @@ static void cfg80211_scan_req_add_chan(struct cfg80211_scan_request *request,
> }
> }
>
> + request->n_channels++;
> request->channels[n_channels] = chan;
> if (add_to_6ghz)
> request->scan_6ghz_params[request->n_6ghz_params].channel_idx =
> n_channels;
> -
> - request->n_channels++;
> }
>
> static bool cfg80211_find_ssid_match(struct cfg80211_colocated_ap *ap,
>
>
> --
> Kees Cook
Apologies for not replying sooner but the above patch works perfectly. Thanks!
prev parent reply other threads:[~2025-01-14 11:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1815535c709ba9d9.156c6a5c9cdf6e59.b249b6b6a5ee4634@localhost.localdomain>
2024-12-30 5:38 ` UBSAN array-index-out-of-bounds: cfg80211_scan_6ghz Nathan Chancellor
2024-12-30 18:35 ` Kees Cook
2025-01-14 11:37 ` John Rowley [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4e8eba1c-b0df-4930-8b88-319587f8ddd3@johnrowley.me \
--to=lkml@johnrowley.me \
--cc=gustavoars@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox