This is a note to let you know that I've just added the patch titled wifi: cfg80211: Move cfg80211_scan_req_add_chan() n_channels increment earlier to the 6.13-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: wifi-cfg80211-move-cfg80211_scan_req_add_chan-n_chan.patch and it can be found in the queue-6.13 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit cf78981e8fc3405c4dcdf1854930478c3176f6d1 Author: Kees Cook <kees@xxxxxxxxxx> Date: Mon Dec 30 10:36:14 2024 -0800 wifi: cfg80211: Move cfg80211_scan_req_add_chan() n_channels increment earlier [ Upstream commit 3a0168626c138734490bc52c4105ce8e79d2f923 ] Since adding __counted_by(n_channels) to struct cfg80211_scan_request, anything adding to the channels array must increment n_channels first. Move n_channels increment earlier. Reported-by: John Rowley <lkml@xxxxxxxxxxxxx> Closes: https://lore.kernel.org/stable/1815535c709ba9d9.156c6a5c9cdf6e59.b249b6b6a5ee4634@localhost.localdomain/ Fixes: aa4ec06c455d ("wifi: cfg80211: use __counted_by where appropriate") Signed-off-by: Kees Cook <kees@xxxxxxxxxx> Reviewed-by: Gustavo A. R. Silva <gustavoars@xxxxxxxxxx> Link: https://patch.msgid.link/20241230183610.work.680-kees@xxxxxxxxxx Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/net/wireless/scan.c b/net/wireless/scan.c index 1c6fd45aa8093..ccdbeb6046399 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,